Modules = array(); $this->Pages = array(); $this->ModuleManager = new AppModuleManager($this); $this->ModuleManager->FileName = dirname(__FILE__).'/../Config/ModulesConfig.php'; $this->Database = new Database(); $this->FormManager = new FormManager($this->Database); $this->ShowPage = true; $this->ConfigManager = new Config(); $this->RootURLFolder = $_SERVER['SCRIPT_NAME']; if(substr($this->RootURLFolder, -10, 10) == '/index.php') $this->RootURLFolder = substr($this->RootURLFolder, 0, -10); } function RegisterPage($Path, $Handler) { if(is_array($Path)) { $Page = &$this->Pages; $LastKey = array_pop($Path); foreach($Path as $PathItem) { $Page = &$Page[$PathItem]; } if(!is_array($Page)) $Page = array('' => $Page); $Page[$LastKey] = $Handler; } else $this->Pages[$Path] = $Handler; } function UnregisterPage($Path) { unset($this->Pages[$Path]); } function SearchPage($PathItems, $Pages) { if(count($PathItems) > 0) $PathItem = $PathItems[0]; else $PathItem = ''; if(array_key_exists($PathItem, $Pages)) { if(is_array($Pages[$PathItem])) { array_shift($PathItems); return($this->SearchPage($PathItems, $Pages[$PathItem])); } else return($Pages[$PathItem]); } else return(''); } function PageNotFound() { return('Page '.implode('/', $this->PathItems).' not found.'); } function ShowPage() { /* @var $Page Page */ $ClassName = $this->SearchPage($this->PathItems, $this->Pages); if($ClassName != '') { $Page = new $ClassName($this); $Page->GetOutput(); } else { $Page = new PageMissing($this); $Page->GetOutput(); } } function ModulePresent($Name) { return(array_key_exists($Name, $this->Modules)); } function AddModule($Module) { //echo('Přidávám modul '.get_class($Module).'
'); $this->Modules[get_class($Module)] = $Module; } function HumanDate($Time) { return(date('j.n.Y', $Time)); } function Link($Target) { return($this->RootURLFolder.$Target); } function ShowAction($Id) { $Output = ''; $DbResult = $this->Database->query('SELECT *, `ActionIcon`.`Name` AS `Icon` FROM `Action` '. 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '. 'WHERE (`Action`.`Id`='.$Id.')'); if($DbResult->num_rows > 0) { $Action = $DbResult->fetch_assoc(); if($Action['Icon'] == '') $Action['Icon'] = 'clear.png'; if(substr($Action['URL'], 0, 4) != 'http') $Action['URL'] = $this->Link($Action['URL']); if(!defined('NEW_PERMISSION') or $this->User->CheckPermission('System', 'Read', 'Item', $Id)) $Output .= ''.$Action['Title'].' '.$Action['Title'].''; } return($Output); } function Run() { global $Database, $ScriptTimeStart, $ConfigFileName, $Mail, $Type, $DatabaseRevision, $Config; date_default_timezone_set('Europe/Prague'); mb_internal_encoding("UTF-8"); $ScriptTimeStart = GetMicrotime(); // SQL injection hack protection foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item); foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item); if(isset($_SERVER['REMOTE_ADDR'])) session_start(); $ConfigFileName = dirname(__FILE__).'/../config.php'; if(file_exists($ConfigFileName)) $this->ConfigManager->LoadFromFile($ConfigFileName); //$this->Config = $this->ConfigManager->GetAsArray(); $this->Config = &$Config; try { $this->Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']); $this->Database->Prefix = $this->Config['Database']['Prefix']; $this->Database->charset($this->Config['Database']['Charset']); $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError']; $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery']; } catch (Exception $E) { //$Output .= 'Nelze se připojit k databázi.'; } if(isset($this->Config['Web']['RootFolder'])) $this->RootURLFolder = $this->Config['Web']['RootFolder']; $this->FormManager->Root = $this->RootURLFolder; $this->RegisterPageBar('Top'); $Database = $this->Database; RegisterFormClasses($this->FormManager); // Register and start existing modules $this->Setup = new Setup($this); $this->Setup->Start(); if($this->Setup->CheckState()) { $this->ModuleManager->Start(); } if($this->ShowPage) { $this->PathItems = ProcessURL(); $this->ShowPage(); } } function RegisterPageBar($Name) { $this->Bars[$Name] = array(); } function UnregisterPageBar($Name) { unset($this->Bars[$Name]); } function RegisterPageBarItem($BarName, $ItemName, $Callback) { $this->Bars[$BarName][$ItemName] = $Callback; } } class PageMissing extends Page { var $FullTitle = 'Stránka nenalezena'; var $ShortTitle = 'Stránka nenalezena'; function __construct($System) { parent::__construct($System); $this->ParentClass = 'PageEatingPlace'; } function Show() { Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); return('

Požadovaná stránka neexistuje.

'); } }