Changeset 880 for trunk/Application/Core.php
- Timestamp:
- Apr 7, 2020, 10:15:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r878 r880 34 34 35 35 $this->Config = $Config; 36 if (isset($this->Config['Web']['Timezone']))36 if (isset($this->Config['Web']['Timezone'])) 37 37 date_default_timezone_set($this->Config['Web']['Timezone']); 38 38 mb_internal_encoding("UTF-8"); 39 39 40 if (isset($this->Config['Database']))41 { 42 $this->Database->Connect($this->Config['Database']['Host'],43 $this->Config['Database']['User'], $this->Config['Database']['Password'],44 $this->Config['Database']['Database']);45 $this->Database->charset($this->Config['Database']['Charset']);46 $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery'];47 $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];48 $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];40 if (isset($this->Config['Database'])) 41 { 42 $this->Database->Connect($this->Config['Database']['Host'], 43 $this->Config['Database']['User'], $this->Config['Database']['Password'], 44 $this->Config['Database']['Database']); 45 $this->Database->charset($this->Config['Database']['Charset']); 46 $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery']; 47 $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError']; 48 $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery']; 49 49 } 50 50 … … 60 60 ); 61 61 62 if (GetRemoteAddress() != '')62 if (GetRemoteAddress() != '') 63 63 { 64 64 $this->BaseURL = $_SERVER["CONTEXT_PREFIX"]; … … 68 68 69 69 // Detect interface locale 70 if (isset($this->Config['Web']['Locale']))70 if (isset($this->Config['Web']['Locale'])) 71 71 $this->LocaleManager->DefaultLangCode = $this->Config['Web']['Locale']; 72 72 $this->LocaleManager->LangCode = $this->LocaleManager->DefaultLangCode; 73 if (count($this->PathItems) > 0)73 if (count($this->PathItems) > 0) 74 74 { 75 75 $NewLangCode = $this->PathItems[0]; 76 if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) {76 if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) { 77 77 array_shift($this->PathItems); 78 78 $this->LocaleManager->LangCode = $NewLangCode; 79 79 } 80 80 } 81 if (array_key_exists($this->LocaleManager->LangCode, $this->LocaleManager->Available))81 if (array_key_exists($this->LocaleManager->LangCode, $this->LocaleManager->Available)) 82 82 $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode); 83 83 … … 109 109 110 110 $ScriptStartTime = GetMicrotime(); 111 //if (GetRemoteAddress() != '')111 //if (GetRemoteAddress() != '') 112 112 session_start(); 113 113 114 114 // SQL injection hack protection 115 foreach ($_POST as $Index => $Item)116 { 117 if (is_array($_POST[$Index]))118 foreach ($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2);115 foreach ($_POST as $Index => $Item) 116 { 117 if (is_array($_POST[$Index])) 118 foreach ($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2); 119 119 else $_POST[$Index] = addslashes($_POST[$Index]); 120 120 } 121 foreach ($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);121 foreach ($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 122 122 123 123 $this->RegisterPageBar('Top'); … … 130 130 $this->Setup->Start(); 131 131 $this->Setup->UpdateManager->VersionTable = 'DbVersion'; 132 if ($this->Setup->CheckState())132 if ($this->Setup->CheckState()) 133 133 { 134 134 $this->ModuleManager->Start(); … … 136 136 137 137 $this->BaseView = new BaseView($this); 138 if ($this->DoNotShowPage == false)138 if ($this->DoNotShowPage == false) 139 139 { 140 140 $this->ShowPage(); … … 145 145 { 146 146 list($Usec, $Sec) = explode(' ', microtime()); 147 return ( (float)$Usec + (float)$Sec);147 return (float)$Usec + (float)$Sec; 148 148 } 149 149 … … 152 152 $Remaining = substr($Target, strlen($this->BaseURL)); 153 153 $TargetParts = explode('/', $Remaining); 154 if (count($TargetParts) > 0)155 { 156 if (in_array($TargetParts[0], $this->LinkLocaleExceptions))154 if (count($TargetParts) > 0) 155 { 156 if (in_array($TargetParts[0], $this->LinkLocaleExceptions)) 157 157 { 158 return ($this->BaseURL.$Target);159 } 160 } 161 return ($this->LinkLocale($Target));158 return $this->BaseURL.$Target; 159 } 160 } 161 return $this->LinkLocale($Target); 162 162 } 163 163 … … 168 168 $RemainingParts = explode('?', $Remaining); 169 169 $Directory = $RemainingParts[0]; 170 if (count($RemainingParts) > 1)170 if (count($RemainingParts) > 1) 171 171 { 172 172 $Params = $RemainingParts[1]; … … 180 180 181 181 $DirectoryParts = explode('/', $Directory); 182 foreach ($DirectoryParts as $Index => $Item)182 foreach ($DirectoryParts as $Index => $Item) 183 183 { 184 184 $NewText = $TargetLocaleManager->CurrentLocale->Texts->Translate($Item, 'URL'); … … 187 187 $Directory = implode('/', $DirectoryParts); 188 188 $Remaining = $Directory; 189 if ($Params != '') $Remaining .= '?'.$Params;190 191 return ($Remaining);189 if ($Params != '') $Remaining .= '?'.$Params; 190 191 return $Remaining; 192 192 } 193 193 … … 198 198 $RemainingParts = explode('?', $Remaining); 199 199 $Directory = $RemainingParts[0]; 200 if (count($RemainingParts) > 1)200 if (count($RemainingParts) > 1) 201 201 { 202 202 $Params = $RemainingParts[1]; … … 210 210 211 211 $DirectoryParts = explode('/', $Directory); 212 foreach ($DirectoryParts as $Index => $Item)212 foreach ($DirectoryParts as $Index => $Item) 213 213 { 214 214 $NewText = $TargetLocaleManager->CurrentLocale->Texts->TranslateReverse($Item, 'URL'); … … 217 217 $Directory = implode('/', $DirectoryParts); 218 218 $Remaining = $Directory; 219 if ($Params != '') $Remaining .= '?'.$Params;220 221 return ($Remaining);219 if ($Params != '') $Remaining .= '?'.$Params; 220 221 return $Remaining; 222 222 } 223 223 224 224 function LinkLocale($Target, $Locale = '') 225 225 { 226 if ($Locale == '') $Locale = $this->LocaleManager->LangCode;226 if ($Locale == '') $Locale = $this->LocaleManager->LangCode; 227 227 228 228 $Target = $this->TranslateURL($Target, $Locale); 229 229 230 if ($Locale == $this->LocaleManager->DefaultLangCode)231 return ($this->BaseURL.$Target);232 return ($this->BaseURL.'/'.$Locale.$Target);230 if ($Locale == $this->LocaleManager->DefaultLangCode) 231 return $this->BaseURL.$Target; 232 return $this->BaseURL.'/'.$Locale.$Target; 233 233 } 234 234 235 235 function RegisterPage($Path, $Handler) 236 236 { 237 if (is_array($Path))237 if (is_array($Path)) 238 238 { 239 239 $Page = &$this->Pages; 240 240 $LastKey = array_pop($Path); 241 foreach ($Path as $PathItem)241 foreach ($Path as $PathItem) 242 242 { 243 243 $Page = &$Page[$PathItem]; 244 244 } 245 if (!is_array($Page)) $Page = array('' => $Page);245 if (!is_array($Page)) $Page = array('' => $Page); 246 246 $Page[$LastKey] = $Handler; 247 247 } else $this->Pages[$Path] = $Handler; … … 250 250 function RegisterMenuItem($MenuItem, $Pos = NULL) 251 251 { 252 if (is_null($Pos)) $this->Menu[] = $MenuItem;252 if (is_null($Pos)) $this->Menu[] = $MenuItem; 253 253 else { 254 254 array_splice($this->Menu, $Pos, 0, array($MenuItem)); … … 258 258 function SearchPage($PathItems, $Pages) 259 259 { 260 if (count($PathItems) == 0) $PathItems = array('');260 if (count($PathItems) == 0) $PathItems = array(''); 261 261 $PathItem = $PathItems[0]; 262 262 $PathItem = $this->LocaleManager->CurrentLocale->Texts->TranslateReverse($PathItem, 'URL'); 263 263 264 if (array_key_exists($PathItem, $Pages))265 { 266 if (is_array($Pages[$PathItem]))264 if (array_key_exists($PathItem, $Pages)) 265 { 266 if (is_array($Pages[$PathItem])) 267 267 { 268 268 array_shift($PathItems); 269 return ($this->SearchPage($PathItems, $Pages[$PathItem]));269 return $this->SearchPage($PathItems, $Pages[$PathItem]); 270 270 } else 271 271 { 272 if (count($PathItems) == 1) return($Pages[$PathItem]);273 else return (''); // Unexpected subpages274 } 275 } else return ('');272 if (count($PathItems) == 1) return $Pages[$PathItem]; 273 else return ''; // Unexpected subpages 274 } 275 } else return ''; 276 276 } 277 277 … … 279 279 { 280 280 // Send correct HTTP status code to signal unknown page 281 if (array_key_exists('SERVER_PROTOCOL', $_SERVER))281 if (array_key_exists('SERVER_PROTOCOL', $_SERVER)) 282 282 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); 283 if (array_key_exists('HTTP_REFERER', $_SERVER)) $Referer = ' Referer: '.$_SERVER['HTTP_REFERER'];283 if (array_key_exists('HTTP_REFERER', $_SERVER)) $Referer = ' Referer: '.$_SERVER['HTTP_REFERER']; 284 284 else $Referer = ''; 285 if (isset($this->ModuleManager->Modules['Log']))285 if (isset($this->ModuleManager->Modules['Log'])) 286 286 $this->ModuleManager->Modules['Log']->WriteLog('Stránka "'. 287 287 implode('/', $this->PathItems).'" nenalezena'.$Referer, LOG_TYPE_PAGE_NOT_FOUND); 288 return (ShowMessage(sprintf(T('Page "%s" not found'), implode('/', $this->PathItems)), MESSAGE_CRITICAL));288 return ShowMessage(sprintf(T('Page "%s" not found'), implode('/', $this->PathItems)), MESSAGE_CRITICAL); 289 289 } 290 290 … … 295 295 /* @var $Page Page */ 296 296 $ClassName = $this->SearchPage($this->PathItems, $this->Pages); 297 if (($ClassName != '') and (class_exists($ClassName)))297 if (($ClassName != '') and (class_exists($ClassName))) 298 298 { 299 299 $Page = new $ClassName($this); 300 300 $Output = $Page->GetOutput(); 301 301 $this->BaseView->Title = $Page->Title; 302 if ($Page->RawPage == false) $Output = $this->BaseView->ShowPage($Output);302 if ($Page->RawPage == false) $Output = $this->BaseView->ShowPage($Output); 303 303 } else { 304 304 $Output2 = ''; 305 if ((count($this->OnPageNotFound) == 2)305 if ((count($this->OnPageNotFound) == 2) 306 306 and method_exists($this->OnPageNotFound[0], $this->OnPageNotFound[1])) 307 307 $Output2 = call_user_func_array($this->OnPageNotFound, array()); 308 if ($Output2 != '') $Output .= $this->BaseView->ShowPage($Output2);308 if ($Output2 != '') $Output .= $this->BaseView->ShowPage($Output2); 309 309 else { 310 310 $Output = $this->PageNotFound(); … … 338 338 function HumanDate($Time) 339 339 { 340 return (date('j.n.Y', $Time));340 return date('j.n.Y', $Time); 341 341 } 342 342 }
Note:
See TracChangeset
for help on using the changeset viewer.