Changeset 887 for trunk/Application/Core.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r886 r887 14 14 class Core extends Application 15 15 { 16 /** @var Type */ 17 var $Type; 18 var $Pages; 19 var $Bars; 20 /** @var FormManager */ 21 var $FormManager; 22 /** @var Config */ 23 var $ConfigManager; 24 var $PathItems; 25 var $RootURLFolder; 26 var $ShowPage; 27 var $Setup; 28 var $CommandLine; 29 var $PageHeaders; 30 var $BaseView; 16 public Type $Type; 17 public array $Bars; 18 public FormManager $FormManager; 19 public array $Config; 20 public Config $ConfigManager; 21 public array $PathItems; 22 public string $RootURLFolder; 23 public bool $ShowPage; 24 public Setup $Setup; 25 public array $PageHeaders; 26 public BaseView $BaseView; 27 public LocaleManager $LocaleManager; 28 public array $LinkLocaleExceptions; 31 29 32 30 function __construct() 33 31 { 34 32 parent::__construct(); 35 $this->Modules = array(); 36 $this->Pages = array(); 33 $this->Config = array(); 37 34 $this->ModuleManager->FileName = dirname(__FILE__).'/../Config/ModulesConfig.php'; 38 35 $this->FormManager = new FormManager($this->Database); … … 42 39 if (substr($this->RootURLFolder, -10, 10) == '/index.php') 43 40 $this->RootURLFolder = substr($this->RootURLFolder, 0, -10); 44 $this->CommandLine = array();45 41 $this->PageHeaders = array(); 46 } 47 48 function RegisterPage($Path, $Handler) 49 { 50 if (is_array($Path)) 51 { 52 $Page = &$this->Pages; 53 $LastKey = array_pop($Path); 54 foreach ($Path as $PathItem) 55 { 56 $Page = &$Page[$PathItem]; 57 } 58 if (!is_array($Page)) $Page = array('' => $Page); 59 $Page[$LastKey] = $Handler; 60 } else $this->Pages[$Path] = $Handler; 61 } 62 63 function UnregisterPage($Path) 64 { 65 unset($this->Pages[$Path]); 66 } 67 68 function SearchPage($PathItems, $Pages) 42 $this->LinkLocaleExceptions = array(); 43 } 44 45 function SearchPage(array $PathItems, array $Pages): ?string 69 46 { 70 47 if (count($PathItems) > 0) $PathItem = $PathItems[0]; … … 80 57 } 81 58 82 function PageNotFound() 83 { 84 return 'Page '.implode('/', $this->PathItems).' not found.'; 85 } 86 87 function ShowPage() 59 function ShowPage(): void 88 60 { 89 61 $this->BaseView = new BaseView($this); … … 94 66 { 95 67 $Page = new $ClassName($this); 96 } else { 68 } else 69 { 97 70 $Page = new PageMissing($this); 98 71 } … … 100 73 } 101 74 102 function ModulePresent( $Name)103 { 104 return array_key_exists($Name, $this->Module s);105 } 106 107 function AddModule($Module) 108 { 109 $this->Module s[get_class($Module)] = $Module;110 } 111 112 function HumanDate( $Time)75 function ModulePresent(string $Name): bool 76 { 77 return array_key_exists($Name, $this->ModuleManager->Modules); 78 } 79 80 function AddModule($Module): void 81 { 82 $this->ModuleManager->Modules[get_class($Module)] = $Module; 83 } 84 85 function HumanDate(int $Time): string 113 86 { 114 87 return date('j.n.Y', $Time); 115 88 } 116 89 117 function Link( $Target)90 function Link(string $Target): string 118 91 { 119 92 return $this->RootURLFolder.$Target; 120 93 } 121 94 122 function ShowAction( $Id)95 function ShowAction(string $Id): string 123 96 { 124 97 $Output = ''; … … 131 104 if ($Action['Icon'] == '') $Action['Icon'] = 'clear.png'; 132 105 if (substr($Action['URL'], 0, 4) != 'http') $Action['URL'] = $this->Link($Action['URL']); 133 if (!defined('NEW_PERMISSION') or $this->User->CheckPermission('System', 'Read', 'Item', $Id))106 if (!defined('NEW_PERMISSION') or ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('System', 'Read', 'Item', $Id)) 134 107 $Output .= '<img alt="'.$Action['Title'].'" src="'.$this->Link('/images/favicons/'.$Action['Icon']). 135 108 '" width="16" height="16" /> <a href="'.$Action['URL'].'">'.$Action['Title'].'</a>'; … … 138 111 } 139 112 140 function RunCommon() 141 { 142 global $Database, $ScriptTimeStart, $ConfigFileName, $Mail, $Type, 143 $DatabaseRevision, $Config, $GlobalLocaleManager; 113 function RunCommon(): void 114 { 115 global $Database, $ScriptTimeStart, $ConfigFileName, $Config, $GlobalLocaleManager; 144 116 145 117 date_default_timezone_set('Europe/Prague'); … … 199 171 } 200 172 201 function Run() 173 function Run(): void 202 174 { 203 175 $this->RunCommon(); … … 213 185 { 214 186 $NewLangCode = $this->PathItems[0]; 215 if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) 187 if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) 216 188 { 217 189 array_shift($this->PathItems); … … 226 198 } 227 199 228 function RunCommandLine() 200 function RunCommandLine(): void 229 201 { 230 202 global $argv; … … 236 208 { 237 209 $Command = $this->CommandLine[$argv[1]]; 238 $Output = call_user_func($Command ['Callback'], $argv);210 $Output = call_user_func($Command->Callback, $argv); 239 211 } else $Output = 'Command "'.$argv[1].'" not supported.'."\n"; 240 } else $Output = 'No command was given as parameter '."\n";212 } else $Output = 'No command was given as parameter. Use "list" to show available commands.'."\n"; 241 213 echo($Output); 242 214 } 243 215 244 function RegisterCommandLine($Name, $Callback) 245 { 246 $this->CommandLine[$Name] = array('Name' => $Name, 'Callback' => $Callback); 247 } 248 249 function RegisterPageBar($Name) 216 function RegisterPageBar(string $Name): void 250 217 { 251 218 $this->Bars[$Name] = array(); 252 219 } 253 220 254 function UnregisterPageBar( $Name)221 function UnregisterPageBar(string $Name): void 255 222 { 256 223 unset($this->Bars[$Name]); 257 224 } 258 225 259 function RegisterPageBarItem( $BarName, $ItemName, $Callback)226 function RegisterPageBarItem(string $BarName, string $ItemName, callable $Callback): void 260 227 { 261 228 $this->Bars[$BarName][$ItemName] = $Callback; 262 229 } 263 230 264 function RegisterPageHeader($Name, $Callback) 231 function UnregisterPageBarItem(string $BarName, string $ItemName): void 232 { 233 unset($this->Bars[$BarName][$ItemName]); 234 } 235 236 function RegisterPageHeader(string $Name, callable $Callback): void 265 237 { 266 238 $this->PageHeaders[$Name] = $Callback; 239 } 240 241 function UnregisterPageHeader(string $Name): void 242 { 243 unset($this->PageHeaders[$Name]); 267 244 } 268 245 } … … 270 247 class PageMissing extends Page 271 248 { 272 var $FullTitle = 'Stránka nenalezena'; 273 var $ShortTitle = 'Stránka nenalezena'; 274 275 function __construct($System) 249 function __construct(System $System) 276 250 { 277 251 parent::__construct($System); 252 $this->FullTitle = 'Stránka nenalezena'; 253 $this->ShortTitle = 'Stránka nenalezena'; 278 254 $this->ParentClass = 'PagePortal'; 279 255 } 280 256 281 function Show() 257 function Show(): string 282 258 { 283 259 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
Note:
See TracChangeset
for help on using the changeset viewer.