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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.