
classes/route.php
<?
class route
{
private $uri;
private $values;
private $controllerPath;
private $templatePath;
private $path = '/home/host1379770/funny-pixels.ru/htdocs/music';
function route()
{
$this->uri = $_SERVER['REQUEST_URI'];
$uri = trim($this->uri, '/\\');
$this->values = explode('/', $uri);
if (empty($this->values['0']))
{
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'index' . '.php'))
$this->controllerPath = $this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'index' . '.php';
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'index' . '.php'))
$this->templatePath = $this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'index' . '.php';
}
else
{
if ($this->values['2'] == '' || $this->values[2] == 'page' || is_numeric($this->values[2]))
{
$error = true;
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->values['0'] . DIRECTORY_SEPARATOR . $this->values['1'] . '.php'))
{
$this->controllerPath = $this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->values['0'] . DIRECTORY_SEPARATOR . $this->values['1'] . '.php';
$error = false;
}
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . $this->values['0'] . DIRECTORY_SEPARATOR . $this->values['1'] . '.php'))
{
$this->templatePath = $this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . $this->values['0'] . DIRECTORY_SEPARATOR . $this->values['1'] . '.php';
$error = false;
}
if ($error)
{
$this->applyError();
}
}
else
{
$this->applyError();
}
}
}
private function applyError()
{
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'nofound' . DIRECTORY_SEPARATOR . 'index' . '.php'))
$this->controllerPath = $this->path . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'nofound' . DIRECTORY_SEPARATOR . 'index' . '.php';
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . 'nofound' . DIRECTORY_SEPARATOR . 'index' . '.php'))
$this->templatePath = $this->path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'practical' . DIRECTORY_SEPARATOR . 'nofound' . DIRECTORY_SEPARATOR . 'index' . '.php';
}
public function startController()
{
if (file_exists($this->controllerPath))
require($this->controllerPath);
//echo $this->controllerPath;
}
public function intro()
{
if (file_exists($this->templatePath))
require($this->templatePath);
//echo $this->templatePath;
}
public function getURI()
{
return $this->uri;
}
public function getControllerPath()
{
return $this->controllerPath;
}
public function getTemplatePath()
{
return $this->templatePath;
}
function getId()
{
return $this->values[2];
}
function getPage()
{
if ($this->values[3] == "page")
{
if (is_numeric($this->values[4]) && $this->values[4] >= 0)
return $this->values[4];
}
if ($this->values[2] == "page")
{
if (is_numeric($this->values[3]) && $this->values[3] >= 0)
return $this->values[3];
}
//return "жерарж акбар"; */
}
function getWidget($name)
{
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'index' . '.php'))
require($this->path . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'index' . '.php');
if (file_exists($this->path . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'index' . '.php'))
require($this->path . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . 'index' . '.php');
}
}
?>
core.php
<?
// PATH_TO_LIB_FILE
require($path . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'library.php');
// CONECT_TO_DATABASE
$db = mysql_connect ($config['mysql']['host'], $config['mysql']['user'], $config['mysql']['pass']);
mysql_select_db ($config['mysql']['db'], $db);
mysql_set_charset($config['mysql']['charset']);
class EFabc
{
public $route = null;
public $user = null;
function EFabc()
{
$this->route = new route();
$this->user = new user();
}
}
$EFabc = new EFabc();
//require($EFabc->route->getControllerPath());
$EFabc->route->startController();
// PATH_TO_TEMPLATE
if ($config['framework']['development'] == 'true')
require($path . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'console.php');
else
require($path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $config['path']['template'] . DIRECTORY_SEPARATOR . 'index.php');
?>