Changeset 901


Ignore:
Timestamp:
Oct 2, 2024, 10:31:47 PM (2 days ago)
Author:
chronos
Message:
  • Fixed: More integer URL parameters checking.
  • Modified: More explicit function types.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/ClientVersion/ClientVersion.php

    r888 r901  
    3939  }
    4040
    41   function ShowItem()
     41  function ShowItem(): string
    4242  {
    43     if (array_key_exists('id', $_GET))
     43    $Id = 0;
     44    if (TryGetUrlParameterInt('id', $Id))
    4445    {
    4546      $YesNo = array('Ne', 'Ano');
    46       $DbResult = $this->System->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.($_GET['id']*1));
     47      $DbResult = $this->System->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$Id);
    4748      if ($DbResult->num_rows > 0)
    4849      {
    4950        $Version = $DbResult->fetch_assoc();
    5051
    51       $Output = '<h3>'.T('Client version').'</h3>';
    52       $Output .= '<table class="BaseTable">'.
    53         '<tr><td>'.T('Version').'</td><td>'.$Version['Version'].'</td></tr>'.
    54         '<tr><td>'.T('More information').'</td><td><a href="http://www.wowwiki.com/Patch_'.$Version['Version'].'">wowwiki.com'.
    55         '</a></td></tr>'.
    56         '<tr><td>'.T('Build number').'</td><td>'.$Version['BuildNumber'].'</td></tr>'.
    57         '<tr><td>'.T('Release date').'</td><td>'.HumanDate($Version['ReleaseDate']).'</td></tr>'.
    58         '<tr><td>'.T('Title').'</td><td>'.$Version['Title'].'</td></tr>'.
    59         '<tr><td>'.T('Imported').'</td><td>'.$YesNo[$Version['Imported']].'</td></tr>'.
    60         '</table>';
     52        $Output = '<h3>'.T('Client version').'</h3>';
     53        $Output .= '<table class="BaseTable">'.
     54          '<tr><td>'.T('Version').'</td><td>'.$Version['Version'].'</td></tr>'.
     55          '<tr><td>'.T('More information').'</td><td><a href="http://www.wowwiki.com/Patch_'.$Version['Version'].'">wowwiki.com'.
     56          '</a></td></tr>'.
     57          '<tr><td>'.T('Build number').'</td><td>'.$Version['BuildNumber'].'</td></tr>'.
     58          '<tr><td>'.T('Release date').'</td><td>'.HumanDate($Version['ReleaseDate']).'</td></tr>'.
     59          '<tr><td>'.T('Title').'</td><td>'.$Version['Title'].'</td></tr>'.
     60          '<tr><td>'.T('Imported').'</td><td>'.$YesNo[$Version['Imported']].'</td></tr>'.
     61          '</table>';
    6162        $Output .= '<div><a href="?">'.T('All versions list').'</a></div>';
    6263        if ($Version['Imported'])
     64        {
    6365          $Output .= '<div><a href="'.$this->System->Link('/progress/?Version='.
    6466            $Version['Version']).'">'.T('Progress').'</a></div>';
     67        }
    6568      } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    66     } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     69    } else $Output = ShowMessage(T('Id not valid'), MESSAGE_CRITICAL);
    6770    return $Output;
    6871  }
    6972
    70   function ShowList()
     73  function ShowList(): string
    7174  {
    7275    $this->Title = T('Game version');
  • trunk/Modules/News/News.php

    r893 r901  
    9797    $Output .= '<div class="shoutbox">';
    9898    $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, `News`.`Id`, '.
    99         '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
     99      '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
    100100    while ($Line = $DbResult->fetch_assoc())
    101101    {
     
    108108  function ShowItem()
    109109  {
    110     if (array_key_exists('i', $_GET))
     110    $Id = 0;
     111    if (TryGetUrlParameterInt('i', $Id))
    111112    {
    112113      $Output = '<h3>'.T('News').'</h3>';
    113114      $DbResult = $this->System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `News`.`Title`, `News`.`Id`, '.
    114         '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id` = '.($_GET['i'] * 1));
     115        '`User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`Id`=`News`.`User` WHERE `News`.`Id` = '.$Id);
    115116      if ($DbResult->num_rows == 1)
    116117      {
     
    118119        $Output .= '<h4>'.$Line['Title'].' ('.HumanDate($Line['Time']).')</h4><div>'.$Line['Text'].' ('.$Line['User'].')</div>';
    119120      } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
    120     } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
     121    } else $Output = ShowMessage(T('Id not valid'), MESSAGE_CRITICAL);
    121122    $Output .= '<br/><a href="'.$this->System->Link('/news/').'">'.T('All news').'</a>';
    122123    return $Output;
  • trunk/Modules/Translation/Form.php

    r900 r901  
    3030      else $Action = '';
    3131
    32     if (array_key_exists('ID', $_GET))
     32    $TextID = 0;
     33    if (TryGetUrlParameterInt('ID', $TextID))
    3334    {
    34       $TextID = $_GET['ID'] * 1;
    3535      $this->ID = $TextID;
    3636
  • trunk/includes/Global.php

    r894 r901  
    3030function ShowPageClass($Page)
    3131{
    32   global $TempPageContent, $System;
     32  global $System;
    3333
    3434  $System->Pages['temporary-page'] = get_class($Page);
     
    3838}
    3939
    40 function ShowPage($Content)
     40function ShowPage(string $Content): void
    4141{
    4242  global $TempPageContent, $System;
     
    5050}
    5151
    52 function GetMicrotime()
     52function GetMicrotime(): float
    5353{
    5454  list($Usec, $Sec) = explode(' ', microtime());
     
    5858$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
    5959
    60 function HumanSize($Value)
     60function HumanSize(float $Value): string
    6161{
    6262  global $UnitNames;
     
    7171}
    7272
    73 function GetQueryStringArray($QueryString)
     73function GetQueryStringArray(string $QueryString): array
    7474{
    7575  $Result = array();
     
    8787}
    8888
    89 function SetQueryStringArray($QueryStringArray)
     89function SetQueryStringArray(array $QueryStringArray): string
    9090{
    9191  $Parts = array();
     
    9797}
    9898
    99 function utf2ascii($text)
     99function utf2ascii(string $text): string
    100100{
    101101  $return = Str_Replace(
     
    109109}
    110110
    111 function getmonthyears($Days)
    112 {
    113   $month = floor($Days / 30);
    114   $year = floor($month / 12);
    115   $Days = floor($Days - $month * 30);
    116   $month = $month - $year * 12;
    117   return $year.'r '.$month.'m '.$Days.'d';
    118 }
    119 
    120 function GetTranslateGoogle($System, $text, $withouttitle = false)
     111function GetMonthYears(int $Days): string
     112{
     113  $Month = floor($Days / 30);
     114  $Year = floor($Month / 12);
     115  $Days = floor($Days - $Month * 30);
     116  $Month = $Month - $Year * 12;
     117  return $Year.'r '.$Month.'m '.$Days.'d';
     118}
     119
     120function GetTranslateGoogle($System, string $text, bool $withouttitle = false)
    121121{
    122122//  $text = 'Balthule\'s letter is dire. This Cult of the Dark Strand is a thorn in my side that must be removed. I have been dealing with some of the Dark Strand scum northeast of here at Ordil\'Aran. One of their number possesses a soul gem that I believe holds the secret to the cult\'s power.$b$bBring it to me, and I will be able to decipher the secrets held within.';
     
    165165}
    166166
    167 function GetPageList($TotalCount)
     167function GetPageList(int $TotalCount): array
    168168{
    169169  global $System;
     
    182182  $CurrentPage = $_SESSION['Page'];
    183183
    184 
    185184  $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> &nbsp; Stránky: ';
    186185
     
    230229$OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
    231230
    232 function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
    233 {
    234   global $OrderDirSQL, $OrderArrowImage, $Config, $System;
     231function GetOrderTableHeader(array $Columns, string $DefaultColumn, int $DefaultOrder = 0): array
     232{
     233  global $OrderDirSQL, $OrderArrowImage, $System;
    235234
    236235  if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
     
    278277}
    279278
    280 function ClientVersionSelection($Selected)
     279function ClientVersionSelection(string $Selected): string
    281280{
    282281  global $System;
     
    299298}
    300299
    301 function GetLanguageList()
     300function GetLanguageList(): array
    302301{
    303302  global $System;
     
    312311$Moderators = array('Překladatel', 'Moderátor', 'Administrátor');
    313312
    314 function HumanDate($SQLDateTime)
     313function HumanDate(string $SQLDateTime): string
    315314{
    316315  if ($SQLDateTime == '') return '&nbsp;';
     
    323322}
    324323
    325 function HumanDateTime($SQLDateTime)
     324function HumanDateTime(string $SQLDateTime): string
    326325{
    327326  if ($SQLDateTime == '') return '&nbsp;';
     
    365364}
    366365
    367 function GetBuildNumber($Version)
     366function GetBuildNumber(string $Version): int
    368367{
    369368  global $System, $BuildNumbers;
    370369
    371   if (isset($BuildNumbers[$Version]) == false)
    372   {
    373     $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"';
    374     $DbResult = $System->Database->query($sql);
    375     $DbRow = $DbResult->fetch_assoc();
    376     $BuildNumbers[$Version] = $DbRow['BuildNumber'];
     370  if (!isset($BuildNumbers)) $BuildNumbers = array();
     371  if (!array_key_exists($Version, $BuildNumbers))
     372  {
     373    $DbResult = $System->Database->select('ClientVersion', 'BuildNumber', '`Version` = "'.$Version.'"');
     374    if ($DbResult->num_rows == 1)
     375    {
     376      $DbRow = $DbResult->fetch_assoc();
     377      $BuildNumbers[$Version] = $DbRow['BuildNumber'];
     378    } else return 0;
    377379  }
    378380  return $BuildNumbers[$Version];
     
    380382
    381383// TODO: Client version build number should not be used in internal references
    382 function GetVersionWOW($BuildNumber)
     384function GetVersionWOW(int $BuildNumber): string
    383385{
    384386  global $System, $VersionsWOW;
    385387
    386   if (isset($VersionsWOW[$BuildNumber]) == false)
    387   {
    388     $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
    389     $DbResult = $System->Database->query($sql);
    390     $Version = $DbResult->fetch_assoc();
    391     $VersionsWOW[$BuildNumber] = $Version['Version'];
     388  if (!isset($VersionsWOW)) $VersionsWOW = array();
     389  if (!array_key_exists($BuildNumber, $VersionsWOW))
     390  {
     391    $DbResult = $System->Database->select('ClientVersion', 'Version', '`BuildNumber` = "'.$BuildNumber.'"');
     392    if ($DbResult->num_rows == 1)
     393    {
     394      $Version = $DbResult->fetch_assoc();
     395      $VersionsWOW[$BuildNumber] = $Version['Version'];
     396    } else return '';
    392397  }
    393398  return $VersionsWOW[$BuildNumber];
     
    414419  $TranslationTree = ModuleTranslation::Cast($System->ModuleManager->GetModule('Translation'))->GetTranslationTree();
    415420
    416   if (array_key_exists('group', $_GET)) $GroupId = $_GET['group'] * 1;
    417     else $GroupId = 1;
    418 
    419   if (isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.');
    420   return $GroupId;
    421 }
    422 
    423 function LoadCommandLineParameters()
     421  $GroupId = 0;
     422  if (TryGetUrlParameterInt('group', $GroupId))
     423  { 
     424    if (isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.');
     425    return $GroupId;
     426  }
     427  ErrorMessage('Group not valid.');
     428}
     429
     430function LoadCommandLineParameters(): void
    424431{
    425432  if (!array_key_exists('REMOTE_ADDR', $_SERVER))
     
    438445}
    439446
    440 function ShowTabs($Tabs)
     447function ShowTabs(array $Tabs): string
    441448{
    442449  $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     
    481488}
    482489
    483 function DeleteDirectory($dirname)
     490function DeleteDirectory(string $dirname): bool
    484491{
    485492  if (is_dir($dirname))
     
    501508}
    502509
    503 function ErrorMessage($Text)
     510function ErrorMessage(string $Text): void
    504511{
    505512  ShowPage($Text);
     
    507514}
    508515
    509 function GetIDbyName($Table)
     516function GetIDbyName(string $Table)
    510517{
    511518  global $System;
     
    519526}
    520527
    521 function GetTranslatNamesArray()
     528function GetTranslatNamesArray(): array
    522529{
    523530  $TablesColumn = array
     
    659666}
    660667
    661 function GetLevelMinMax($XP)
     668function GetLevelMinMax(int $XP): array
    662669{
    663670  $IndexLevel = 100;
     
    672679}
    673680
    674 function GetParameter($Name, $Default = '', $Numeric = false, $Session = false)
     681function GetParameter(string $Name, string $Default = '', bool $Numeric = false, bool $Session = false): string
    675682{
    676683  $Result = $Default;
     
    683690}
    684691
    685 function MakeActiveLinks($Content)
     692function MakeActiveLinks(string $Content): string
    686693{
    687694  $Content = htmlspecialchars($Content);
     
    712719define('MESSAGE_INFORMATION', 2);
    713720
    714 function ShowMessage($Text, $Type = MESSAGE_INFORMATION)
     721function ShowMessage(string $Text, int $Type = MESSAGE_INFORMATION)
    715722{
    716723  global $System;
     
    733740}
    734741
    735 function ProcessURL()
     742function ProcessURL(): array
    736743{
    737744  if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     
    840847  return implode('/', $Result);
    841848}
     849
     850function TryGetUrlParameterInt(string $Name, int &$Value): bool
     851{
     852  if (array_key_exists($Name, $_GET))
     853  {
     854    if (is_numeric($_GET[$Name]))
     855    {
     856      $Value = $_GET[$Name] * 1;
     857      return true;
     858    }
     859    return false;
     860  }
     861  return false;
     862}
Note: See TracChangeset for help on using the changeset viewer.