Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r878 r880  
    3434
    3535    $this->Config = $Config;
    36     if(isset($this->Config['Web']['Timezone']))
     36    if (isset($this->Config['Web']['Timezone']))
    3737      date_default_timezone_set($this->Config['Web']['Timezone']);
    3838    mb_internal_encoding("UTF-8");
    3939
    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'];
    4949    }
    5050
     
    6060    );
    6161
    62     if(GetRemoteAddress() != '')
     62    if (GetRemoteAddress() != '')
    6363    {
    6464      $this->BaseURL = $_SERVER["CONTEXT_PREFIX"];
     
    6868
    6969    // Detect interface locale
    70     if(isset($this->Config['Web']['Locale']))
     70    if (isset($this->Config['Web']['Locale']))
    7171      $this->LocaleManager->DefaultLangCode = $this->Config['Web']['Locale'];
    7272    $this->LocaleManager->LangCode = $this->LocaleManager->DefaultLangCode;
    73     if(count($this->PathItems) > 0)
     73    if (count($this->PathItems) > 0)
    7474    {
    7575      $NewLangCode = $this->PathItems[0];
    76       if(array_key_exists($NewLangCode, $this->LocaleManager->Available)) {
     76      if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) {
    7777        array_shift($this->PathItems);
    7878        $this->LocaleManager->LangCode = $NewLangCode;
    7979      }
    8080    }
    81     if(array_key_exists($this->LocaleManager->LangCode, $this->LocaleManager->Available))
     81    if (array_key_exists($this->LocaleManager->LangCode, $this->LocaleManager->Available))
    8282      $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode);
    8383
     
    109109
    110110    $ScriptStartTime = GetMicrotime();
    111     //if(GetRemoteAddress() != '')
     111    //if (GetRemoteAddress() != '')
    112112      session_start();
    113113
    114114    // 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);
    119119      else $_POST[$Index] = addslashes($_POST[$Index]);
    120120    }
    121     foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
     121    foreach ($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
    122122
    123123    $this->RegisterPageBar('Top');
     
    130130    $this->Setup->Start();
    131131    $this->Setup->UpdateManager->VersionTable = 'DbVersion';
    132     if($this->Setup->CheckState())
     132    if ($this->Setup->CheckState())
    133133    {
    134134      $this->ModuleManager->Start();
     
    136136
    137137    $this->BaseView = new BaseView($this);
    138     if($this->DoNotShowPage == false)
     138    if ($this->DoNotShowPage == false)
    139139    {
    140140      $this->ShowPage();
     
    145145  {
    146146    list($Usec, $Sec) = explode(' ', microtime());
    147     return ((float)$Usec + (float)$Sec);
     147    return (float)$Usec + (float)$Sec;
    148148  }
    149149
     
    152152    $Remaining = substr($Target, strlen($this->BaseURL));
    153153    $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))
    157157      {
    158         return($this->BaseURL.$Target);
    159       }
    160     }
    161     return($this->LinkLocale($Target));
     158        return $this->BaseURL.$Target;
     159      }
     160    }
     161    return $this->LinkLocale($Target);
    162162  }
    163163
     
    168168    $RemainingParts = explode('?', $Remaining);
    169169    $Directory = $RemainingParts[0];
    170     if(count($RemainingParts) > 1)
     170    if (count($RemainingParts) > 1)
    171171    {
    172172      $Params = $RemainingParts[1];
     
    180180
    181181    $DirectoryParts = explode('/', $Directory);
    182     foreach($DirectoryParts as $Index => $Item)
     182    foreach ($DirectoryParts as $Index => $Item)
    183183    {
    184184      $NewText = $TargetLocaleManager->CurrentLocale->Texts->Translate($Item, 'URL');
     
    187187    $Directory = implode('/', $DirectoryParts);
    188188    $Remaining = $Directory;
    189     if($Params != '') $Remaining .= '?'.$Params;
    190 
    191     return($Remaining);
     189    if ($Params != '') $Remaining .= '?'.$Params;
     190
     191    return $Remaining;
    192192  }
    193193
     
    198198    $RemainingParts = explode('?', $Remaining);
    199199    $Directory = $RemainingParts[0];
    200     if(count($RemainingParts) > 1)
     200    if (count($RemainingParts) > 1)
    201201    {
    202202      $Params = $RemainingParts[1];
     
    210210
    211211    $DirectoryParts = explode('/', $Directory);
    212     foreach($DirectoryParts as $Index => $Item)
     212    foreach ($DirectoryParts as $Index => $Item)
    213213    {
    214214      $NewText = $TargetLocaleManager->CurrentLocale->Texts->TranslateReverse($Item, 'URL');
     
    217217    $Directory = implode('/', $DirectoryParts);
    218218    $Remaining = $Directory;
    219     if($Params != '') $Remaining .= '?'.$Params;
    220 
    221     return($Remaining);
     219    if ($Params != '') $Remaining .= '?'.$Params;
     220
     221    return $Remaining;
    222222  }
    223223
    224224  function LinkLocale($Target, $Locale = '')
    225225  {
    226     if($Locale == '') $Locale = $this->LocaleManager->LangCode;
     226    if ($Locale == '') $Locale = $this->LocaleManager->LangCode;
    227227
    228228    $Target = $this->TranslateURL($Target, $Locale);
    229229
    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;
    233233  }
    234234
    235235  function RegisterPage($Path, $Handler)
    236236  {
    237     if(is_array($Path))
     237    if (is_array($Path))
    238238    {
    239239      $Page = &$this->Pages;
    240240      $LastKey = array_pop($Path);
    241       foreach($Path as $PathItem)
     241      foreach ($Path as $PathItem)
    242242      {
    243243        $Page = &$Page[$PathItem];
    244244      }
    245       if(!is_array($Page)) $Page = array('' => $Page);
     245      if (!is_array($Page)) $Page = array('' => $Page);
    246246      $Page[$LastKey] = $Handler;
    247247    } else $this->Pages[$Path] = $Handler;
     
    250250  function RegisterMenuItem($MenuItem, $Pos = NULL)
    251251  {
    252     if(is_null($Pos)) $this->Menu[] = $MenuItem;
     252    if (is_null($Pos)) $this->Menu[] = $MenuItem;
    253253      else {
    254254        array_splice($this->Menu, $Pos, 0, array($MenuItem));
     
    258258  function SearchPage($PathItems, $Pages)
    259259  {
    260     if(count($PathItems) == 0) $PathItems = array('');
     260    if (count($PathItems) == 0) $PathItems = array('');
    261261    $PathItem = $PathItems[0];
    262262    $PathItem = $this->LocaleManager->CurrentLocale->Texts->TranslateReverse($PathItem, 'URL');
    263263
    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]))
    267267      {
    268268        array_shift($PathItems);
    269         return($this->SearchPage($PathItems, $Pages[$PathItem]));
     269        return $this->SearchPage($PathItems, $Pages[$PathItem]);
    270270      } else
    271271      {
    272         if(count($PathItems) == 1) return($Pages[$PathItem]);
    273           else return(''); // Unexpected subpages
    274       }
    275     } else return('');
     272        if (count($PathItems) == 1) return $Pages[$PathItem];
     273          else return ''; // Unexpected subpages
     274      }
     275    } else return '';
    276276  }
    277277
     
    279279  {
    280280    // 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))
    282282      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'];
    284284      else $Referer = '';
    285     if(isset($this->ModuleManager->Modules['Log']))
     285    if (isset($this->ModuleManager->Modules['Log']))
    286286      $this->ModuleManager->Modules['Log']->WriteLog('Stránka "'.
    287287        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);
    289289  }
    290290
     
    295295    /* @var $Page Page */
    296296    $ClassName = $this->SearchPage($this->PathItems, $this->Pages);
    297     if(($ClassName != '') and (class_exists($ClassName)))
     297    if (($ClassName != '') and (class_exists($ClassName)))
    298298    {
    299299      $Page = new $ClassName($this);
    300300      $Output = $Page->GetOutput();
    301301      $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);
    303303    } else {
    304304      $Output2 = '';
    305       if((count($this->OnPageNotFound) == 2)
     305      if ((count($this->OnPageNotFound) == 2)
    306306        and method_exists($this->OnPageNotFound[0], $this->OnPageNotFound[1]))
    307307        $Output2 = call_user_func_array($this->OnPageNotFound, array());
    308      if($Output2 != '') $Output .= $this->BaseView->ShowPage($Output2);
     308     if ($Output2 != '') $Output .= $this->BaseView->ShowPage($Output2);
    309309      else {
    310310        $Output = $this->PageNotFound();
     
    338338  function HumanDate($Time)
    339339  {
    340     return(date('j.n.Y', $Time));
     340    return date('j.n.Y', $Time);
    341341  }
    342342}
Note: See TracChangeset for help on using the changeset viewer.