Changeset 69 for trunk/Application/Core.php
- Timestamp:
- Feb 28, 2016, 10:54:30 AM (9 years ago)
- Location:
- trunk/Application
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r68 r69 1 1 <?php 2 2 3 class Application 3 $ConfigFileName = dirname(__FILE__).'/../Config/Config.php'; 4 if(file_exists($ConfigFileName)) include_once($ConfigFileName); 5 6 include_once(dirname(__FILE__).'/../Global.php'); 7 include_once(dirname(__FILE__).'/Version.php'); 8 include_once(dirname(__FILE__).'/View.php'); 9 include_once(dirname(__FILE__).'/UpdateTrace.php'); 10 include_once(dirname(__FILE__).'/DefaultConfig.php'); 11 12 class Core extends Application 4 13 { 5 var $Database; 14 var $Pages; 15 var $ShowPage; 16 var $BaseURL; 6 17 7 function Start() 18 function __construct() 19 { 20 parent::__construct(); 21 $this->Pages = array(); 22 $this->ShowPage = true; 23 $this->BaseURL = $_SERVER['SCRIPT_NAME']; 24 if(substr($this->BaseURL, -10, 10) == '/index.php') 25 $this->BaseURL = substr($this->BaseURL, 0, -10); 26 } 27 28 function RunCommon() 8 29 { 9 30 global $Config, $DatabaseRevision; 10 11 $FileName = dirname(__FILE__).'/config.php';12 if(file_exists($FileName)) include_once($FileName);13 else {14 die('Configuration file "'.$FileName.'" not found.');15 }16 31 17 32 session_start(); … … 33 48 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item); 34 49 35 // Check database persistence structure 36 $UpdateManager = new UpdateManager(); 37 $UpdateManager->Database = $this->Database; 38 $UpdateManager->Revision = $DatabaseRevision; 39 if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.'); 40 if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.'); 50 $this->Config = &$Config; 41 51 52 // Register and start existing modules 53 $this->Setup = new Setup($this); 54 $this->Setup->Start(); 55 if($this->Setup->CheckState()) 56 { 57 $this->ModuleManager->Start(); 58 } 59 } 60 61 function Run() 62 { 63 $this->RunCommon(); 64 if($this->ShowPage) 65 { 66 $this->PathItems = ProcessURL(); 67 $this->ShowPage(); 68 } 69 } 70 71 function ShowPage() 72 { 73 $this->BaseView = new BaseView($this); 74 75 /* @var $Page Page */ 76 $ClassName = $this->SearchPage($this->PathItems, $this->Pages); 77 if($ClassName != '') 78 { 79 $Page = new $ClassName($this); 80 } else { 81 $Page = new PageMissing($this); 82 } 83 echo($this->BaseView->GetOutput($Page)); 84 } 85 86 function RegisterPage($Path, $Handler) 87 { 88 if(is_array($Path)) 89 { 90 $Page = &$this->Pages; 91 $LastKey = array_pop($Path); 92 foreach($Path as $PathItem) 93 { 94 $Page = &$Page[$PathItem]; 95 } 96 if(!is_array($Page)) $Page = array('' => $Page); 97 $Page[$LastKey] = $Handler; 98 } else $this->Pages[$Path] = $Handler; 99 } 100 101 function UnregisterPage($Path) 102 { 103 unset($this->Pages[$Path]); 104 } 105 106 function SearchPage($PathItems, $Pages) 107 { 108 if(count($PathItems) > 0) $PathItem = $PathItems[0]; 109 else $PathItem = ''; 110 if(array_key_exists($PathItem, $Pages)) 111 { 112 if(is_array($Pages[$PathItem])) 113 { 114 array_shift($PathItems); 115 return($this->SearchPage($PathItems, $Pages[$PathItem])); 116 } else return($Pages[$PathItem]); 117 } else return(''); 118 } 119 120 function Link($Target) 121 { 122 return($this->BaseURL.$Target); 42 123 } 43 124 } 125 126 class PageMissing extends Page 127 { 128 function __construct($System) 129 { 130 parent::__construct($System); 131 $this->ParentClass = ''; 132 $this->Title = T('Page not found'); 133 } 134 135 function Show() 136 { 137 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); 138 return('<h3 align="center">'.T('Required page not found')); 139 } 140 }
Note:
See TracChangeset
for help on using the changeset viewer.