Changeset 880 for trunk/Application


Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
Location:
trunk/Application
Files:
4 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}
  • trunk/Application/DefaultConfig.php

    r861 r880  
    66  {
    77    $IsDeveloper = in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'));
    8     return(array(
     8    return array(
    99      array('Name' => 'SystemPassword', 'Type' => 'PasswordEncoded', 'Default' => '', 'Title' => 'System password'),
    1010      array('Name' => 'Database/Host', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Server'),
     
    4646      array('Name' => 'OriginalLanguage', 'Type' => 'Integer', 'Default' => 1, 'Title' => 'Original language'),
    4747      array('Name' => 'EnableGoogleTranslate', 'Type' => 'Boolean', 'Default' => false, 'Title' => 'Enable Google translate'),
    48     ));
     48    );
    4949  }
    5050}
  • trunk/Application/UpdateTrace.php

    r879 r880  
    24832483
    24842484  $DbResult = $System->Database->query('SELECT `TablePrefix` FROM `Group`');
    2485   while($Group = $DbResult->fetch_assoc())
     2485  while ($Group = $DbResult->fetch_assoc())
    24862486  {
    24872487    $Manager->Execute('ALTER TABLE `'.$Group['TablePrefix'].'` ADD FOREIGN KEY ( `Language` ) REFERENCES `Language` ('.
     
    25322532  // Set all string collation to utf8 general
    25332533  $DbResult = $Manager->Execute("SHOW TABLES");
    2534   while($DbRow = $DbResult->fetch_row())
     2534  while ($DbRow = $DbResult->fetch_row())
    25352535  {
    25362536    $Manager->Execute("ALTER TABLE `".$DbRow[0]."` CONVERT TO CHARACTER SET utf8");
     
    29462946
    29472947function UpdateTo872($Manager)
    2948 {       
     2948{
    29492949  // Allow to store IPv6 addresses
    29502950  $Manager->Execute('ALTER TABLE `UserOnline` CHANGE `IpAddress` `IpAddress` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT "";');
     
    29572957
    29582958function UpdateTo873($Manager)
    2959 {       
     2959{
    29602960  $Manager->Execute('ALTER TABLE `User` CHANGE `XP` `XP` INT(11) NOT NULL DEFAULT "0";');
    29612961  $Manager->Execute('ALTER TABLE `User` CHANGE `TranslatedCount` `TranslatedCount` INT(11) NOT NULL DEFAULT "0";');
     
    29712971  function Get()
    29722972  {
    2973     return(array(
     2973    return array(
    29742974      498 => array('Revision' => 506, 'Function' => 'UpdateTo506'),
    29752975      506 => array('Revision' => 510, 'Function' => 'UpdateTo510'),
     
    30063006      867 => array('Revision' => 872, 'Function' => 'UpdateTo872'),
    30073007      872 => array('Revision' => 873, 'Function' => 'UpdateTo873'),
    3008     ));
     3008    );
    30093009  }
    30103010}
  • trunk/Application/View.php

    r864 r880  
    99    //$Output .= ' <form action="?setlocale" method="get">';
    1010    $Output = ' <select onchange="window.location=this.value">';
    11     foreach($this->System->LocaleManager->Available as $Locale)
     11    foreach ($this->System->LocaleManager->Available as $Locale)
    1212    {
    1313      $Remaining = substr($_SERVER["REQUEST_URI"], strlen($this->System->BaseURL));
    14       if(substr($Remaining, 1, strlen($Locale['Code'].'/')) == $this->System->LocaleManager->LangCode.'/')
     14      if (substr($Remaining, 1, strlen($Locale['Code'].'/')) == $this->System->LocaleManager->LangCode.'/')
    1515        $Remaining = substr($Remaining, strlen('/'.$Locale['Code']));
    16       if($Locale['Code'] == $this->System->LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"';
     16      if ($Locale['Code'] == $this->System->LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"';
    1717        else $Selected = '';
    1818      $Remaining = $this->System->TranslateReverseURL($Remaining, $this->System->LocaleManager->LangCode);
     
    2323    $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>';
    2424
    25     return($Output);
     25    return $Output;
    2626  }
    2727
     
    2929  {
    3030    $Output = '<div class="Menu">';
    31     if(isset($this->System->User))
     31    if (isset($this->System->User))
    3232    {
    33       if(!$this->System->User->Licence(LICENCE_USER))
     33      if (!$this->System->User->Licence(LICENCE_USER))
    3434        $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>';
    3535    }
     
    3838    // Show bars items
    3939    $Bar = '';
    40     foreach($this->System->Bars['Top'] as $BarItem)
     40    foreach ($this->System->Bars['Top'] as $BarItem)
    4141      $Bar .= call_user_func($BarItem);
    42       if(trim($Bar) != '') $Output .= $Bar;
     42      if (trim($Bar) != '') $Output .= $Bar;
    4343      else $Output .= '&nbsp;';
    4444
     
    4646    //$Output .= '</form>';
    4747    $Output .= '</span></div>';
    48     return($Output);
     48    return $Output;
    4949  }
    5050
     
    5353    $Output = '<strong>'.T('Menu').':</strong>'.
    5454      '<div class="verticalmenu"><ul>';
    55     foreach($this->System->Menu as $MenuItem)
    56       if(!isset($this->System->User) or $this->System->User->Licence($MenuItem['Permission']))
     55    foreach ($this->System->Menu as $MenuItem)
     56      if (!isset($this->System->User) or $this->System->User->Licence($MenuItem['Permission']))
    5757      {
    58         if(isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"';
     58        if (isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"';
    5959        else $OnClick = '';
    60         if($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>';
     60        if ($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>';
    6161        else $Icon = '';
    6262        $Output .= '<li>'.$Icon.'<a class="verticalmenua" title="'.$MenuItem['Hint'].'" href="'.
     
    6464      }
    6565      $Output .= '</ul></div>';
    66       return($Output);
     66      return $Output;
    6767  }
    6868
     
    8383    // Show page headers
    8484    $Bar = '';
    85     foreach($this->System->PageHeaders as $Item)
     85    foreach ($this->System->PageHeaders as $Item)
    8686      $Output .= call_user_func($Item);
    8787
    8888    $Title = $this->System->Config['Web']['Title'];
    89     if($this->Title != '') $Title = $this->Title.' - '.$Title;
     89    if ($this->Title != '') $Title = $this->Title.' - '.$Title;
    9090    $Output .= '<title>'.$Title.'</title>'.
    9191    '<script src="'.$this->System->Link('/style/respond.js').'"></script>'.
     
    9898    // Show bars items
    9999    $Bar = '';
    100     foreach($this->System->Bars['Left'] as $BarItem)
     100    foreach ($this->System->Bars['Left'] as $BarItem)
    101101      $Bar .= call_user_func($BarItem);
    102       if(trim($Bar) != '') $Output .= $Bar;
     102      if (trim($Bar) != '') $Output .= $Bar;
    103103      else $Output .= '&nbsp;';
    104104
    105105    $Output .= '</td><td id="border-left"></td><td class="content">';
    106     return($Output);
     106    return $Output;
    107107  }
    108108
     
    117117    // Show bars items
    118118    $Bar = '';
    119     foreach($this->System->Bars['Right'] as $BarItem)
     119    foreach ($this->System->Bars['Right'] as $BarItem)
    120120      $Bar .= call_user_func($BarItem);
    121       if(trim($Bar) != '') $Output .= $Bar;
     121      if (trim($Bar) != '') $Output .= $Bar;
    122122      else $Output .= '&nbsp;';
    123123    $Output .= '</td>';
     
    129129
    130130    $Output .= '</td></tr>';
    131     if($this->System->Config['Web']['ShowRuntimeInfo'] == true)
     131    if ($this->System->Config['Web']['ShowRuntimeInfo'] == true)
    132132      $Output .= '<tr><td colspan="3" style="text-align: center;">'.T('Generating duration').': '.
    133133    $ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; '.T('Used memory').': '.
     
    137137      '</body>'.
    138138      '</html>';
    139     return($Output);
     139    return $Output;
    140140  }
    141141
     
    143143  {
    144144    $Output = $this->ShowHeader().$Content.$this->ShowFooter();
    145     if($this->System->Config['Web']['FormatOutput'])
     145    if ($this->System->Config['Web']['FormatOutput'])
    146146      $Output = $this->FormatOutput($Output);
    147     return($Output);
     147    return $Output;
    148148  }
    149149
     
    153153    $nn = 0;
    154154    $n = 0;
    155     while($s != '')
     155    while ($s != '')
    156156    {
    157157      $start = strpos($s, '<');
    158158      $end = strpos($s, '>');
    159       if($start != 0)
     159      if ($start != 0)
    160160      {
    161161        $end = $start - 1;
     
    163163      }
    164164      $line = trim(substr($s, $start, $end + 1));
    165       if(strlen($line) > 0)
    166         if($line[0] == '<')
     165      if (strlen($line) > 0)
     166        if ($line[0] == '<')
    167167        {
    168           if($s[$start + 1] == '/')
     168          if ($s[$start + 1] == '/')
    169169          {
    170170            $n = $n - 2;
     
    172172          } else
    173173          {
    174             if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
     174            if (strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
    175175            else $cmd = substr($line, 1, strlen($line) - 2);
    176176            //echo('['.$cmd.']');
    177             if(strpos($s, '</'.$cmd.'>')) $n = $n + 2;
     177            if (strpos($s, '</'.$cmd.'>')) $n = $n + 2;
    178178          }
    179179        }// else $line = '['.$line.']';
    180         //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
    181         if($nn < 0) $nn = 0;
    182         if($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
     180        //if ($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
     181        if ($nn < 0) $nn = 0;
     182        if ($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
    183183        $s = substr($s, $end + 1, strlen($s));
    184184        $nn = $n;
    185185    }
    186     return($out);
     186    return $out;
    187187  }
    188188}
Note: See TracChangeset for help on using the changeset viewer.