Changeset 14 for Common


Ignore:
Timestamp:
Aug 3, 2021, 11:36:12 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated files to newer version.
Location:
Common
Files:
14 added
3 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • Common/Base.php

    r7 r14  
    11<?php
    2 
    3 class System
    4 {
    5   /* @var Database */
    6   var $Database;
    7 
    8   function __construct()
    9   {
    10     $this->Database = new Database();
    11   }
    12 }
    132
    143class Base
    154{
    16   /** @var Application */
    17   var $System;
    18   /* @var Database */
    19   var $Database;
     5  public System $System;
     6  public Database $Database;
    207
    21   function __construct(Application $System)
     8  function __construct(System $System)
    229  {
    2310    $this->System = &$System;
    2411    $this->Database = &$System->Database;
    2512  }
     13
     14  static function GetClassName()
     15  {
     16    return get_called_class();
     17  }
    2618}
    27 
    28 class Model extends Base
    29 {
    30 
    31 }
    32 
    33 class View extends Base
    34 {
    35 
    36 }
    37 
    38 class Controller extends Base
    39 {
    40 
    41 }
  • Common/Common.php

    r12 r14  
    1111include_once(dirname(__FILE__).'/Error.php');
    1212include_once(dirname(__FILE__).'/Base.php');
    13 include_once(dirname(__FILE__).'/Application.php');
    14 include_once(dirname(__FILE__).'/AppModule.php');
     13include_once(dirname(__FILE__).'/View.php');
     14include_once(dirname(__FILE__).'/Model.php');
     15include_once(dirname(__FILE__).'/ModelDesc.php');
     16include_once(dirname(__FILE__).'/Controller.php');
     17include_once(dirname(__FILE__).'/System.php');
     18include_once(dirname(__FILE__).'/Module.php');
     19include_once(dirname(__FILE__).'/ModuleManager.php');
    1520include_once(dirname(__FILE__).'/Config.php');
    1621include_once(dirname(__FILE__).'/Page.php');
    1722include_once(dirname(__FILE__).'/Locale.php');
    1823include_once(dirname(__FILE__).'/Update.php');
    19 include_once(dirname(__FILE__).'/Setup.php');
    2024include_once(dirname(__FILE__).'/Table.php');
    2125include_once(dirname(__FILE__).'/Process.php');
     26include_once(dirname(__FILE__).'/Generics.php');
     27include_once(dirname(__FILE__).'/BigInt.php');
     28include_once(dirname(__FILE__).'/Int128.php');
     29include_once(dirname(__FILE__).'/Pdf.php');
     30include_once(dirname(__FILE__).'/Modules/Setup.php');
     31include_once(dirname(__FILE__).'/Modules/ModuleManager.php');
    2232
    2333class PackageCommon
    2434{
    25   var $Name;
    26   var $Version;
    27   var $ReleaseDate;
    28   var $License;
    29   var $Creator;
    30   var $Homepage;
     35  public string $Name;
     36  public string $Version;
     37  public int $ReleaseDate;
     38  public string $License;
     39  public string $Creator;
     40  public string $Homepage;
    3141
    3242  function __construct()
    3343  {
    3444    $this->Name = 'Common';
    35     $this->Version = '1.4';
    36     $this->ReleaseDate = strtotime('2020-04-07');
     45    $this->Version = '1.2';
     46    $this->ReleaseDate = strtotime('2020-03-29');
    3747    $this->Creator = 'Chronos';
    38     $this->License = 'GNU/GPL';
     48    $this->License = 'GNU/GPLv3';
    3949    $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/';
    4050  }
     
    4353class Paging
    4454{
    45   var $TotalCount;
    46   var $ItemPerPage;
    47   var $Around;
    48   var $SQLLimit;
    49   var $Page;
     55  public int $TotalCount;
     56  public int $ItemPerPage;
     57  public int $Around;
     58  public string $SQLLimit;
     59  public int $Page;
    5060
    51   function __construct($System)
     61  function __construct()
    5262  {
     63    global $System;
     64
    5365    $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
    5466    $this->Around = $System->Config['Web']['VisiblePagingItems'];
    5567  }
    5668
    57   function Show()
     69  function Show(): string
    5870  {
    5971    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
  • Common/Config.php

    r10 r14  
    33class Config
    44{
    5   var $Data;
     5  public array $Data;
    66
    77  function __construct()
     
    1010  }
    1111
    12   function ReadValue($Name)
     12  function ReadValue(string $Name)
    1313  {
    1414    if (!is_array($Name)) $Name = explode('/', $Name);
     
    2222  }
    2323
    24   function WriteValue($Name, $Value)
     24  function WriteValue(string $Name, $Value)
    2525  {
    2626    if (!is_array($Name)) $Name = explode('/', $Name);
     
    3434  }
    3535
    36   function LoadFromFile($FileName)
     36  function LoadFromFile(string $FileName): void
    3737  {
    3838    $ConfigData = array();
     
    4040    foreach ($this->Data as $Index => $Item)
    4141    {
    42       if (array_key_exits($Index, $ConfigData))
     42      if (array_key_exists($Index, $ConfigData))
    4343        $this->Data[$Index] = $ConfigData[$Index];
    4444    }
    4545  }
    4646
    47   function SaveToFile($FileName)
     47  function SaveToFile(string $FileName): void
    4848  {
    4949    file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n");
    5050  }
    5151
    52   function GetAsArray()
     52  function GetAsArray(): array
    5353  {
    5454    return $this->Data;
  • Common/Database.php

    r12 r14  
    22
    33// Extended database class
    4 // Date: 2020-04-07
     4// Date: 2020-11-10
    55
    66function microtime_float()
     
    1212class DatabaseResult
    1313{
    14   var $PDOStatement;
    15   var $num_rows = 0;
     14  public PDOStatement $PDOStatement;
     15  public int $num_rows = 0;
    1616
    1717  function fetch_assoc()
     
    3333class Database
    3434{
    35   var $Prefix;
    36   var $Functions;
    37   var $Type;
    38   var $PDO;
    39   var $Error;
    40   var $insert_id;
    41   var $LastQuery;
    42   var $ShowSQLError;
    43   var $ShowSQLQuery;
    44   var $LogSQLQuery;
    45   var $LogFile;
     35  public string $Prefix;
     36  public array $Functions;
     37  public string $Type;
     38  public PDO $PDO;
     39  public string $Error;
     40  public string $insert_id;
     41  public string $LastQuery;
     42  public bool $ShowSQLError;
     43  public bool $ShowSQLQuery;
     44  public bool $LogSQLQuery;
     45  public string $LogFile;
     46  public string $Database;
    4647
    4748  function __construct()
    4849  {
    4950    $this->Prefix = '';
    50     $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
     51    $this->Functions = array('NOW(', 'CURDATE(', 'CURTIME(', 'UUID(', 'SHA1(');
    5152    $this->Type = 'mysql';  // mysql, pgsql
    5253    $this->Error = '';
     
    5657    $this->LogSQLQuery = false;
    5758    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    58   }
    59  
    60 
    61   function Connect($Host, $User, $Password, $Database)
     59    $this->Database = '';
     60  }
     61
     62  function Connect(string $Host, string $User, string $Password, string $Database): void
    6263  {
    6364    if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
    6465      else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
    6566      else $ConnectionString = '';
     67    $this->Database = $Database;
    6668    try {
    6769      $this->PDO = new PDO($ConnectionString, $User, $Password);
    68 
    6970    } catch (Exception $E)
    7071    {
     
    7475  }
    7576
    76   function Disconnect()
     77  function Disconnect(): void
    7778  {
    7879    unset($this->PDO);
    7980  }
    8081
    81   function Connected()
     82  function Connected(): bool
    8283  {
    8384    return isset($this->PDO);
    8485  }
    8586
    86   function select_db($Database)
     87  function select_db(string $Database)
    8788  {
    8889    $this->query('USE `'.$Database.'`');
    8990  }
    9091
    91   function query($Query)
     92  function query($Query): DatabaseResult
    9293  {
    9394    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
    9495    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
    95     $this->LastQuery = $Query;   
     96    $this->LastQuery = $Query;
     97    //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float());
    9698    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    97       $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s';
    98     if ($this->LogSQLQuery == true)
     99    {
     100      $Time = round(microtime_float() - $QueryStartTime, 4);
     101      $Duration = ' ; '.$Time. ' s';
     102    }
     103    if (($this->LogSQLQuery == true) and ($Time != 0))
    99104      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    100105    if ($this->ShowSQLQuery == true)
     
    102107      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    103108    $Result = new DatabaseResult();
    104     $Result->PDOStatement = $this->PDO->query($Query);
    105     if ($Result->PDOStatement)
    106     {
    107       $Result->num_rows = $Result->PDOStatement->rowCount();
     109    $Statement = $this->PDO->query($Query);
     110    if ($Statement)
     111    {
     112      $Result->PDOStatement = $Statement;
     113      $Result->num_rows = $Statement->rowCount();
    108114      $this->insert_id = $this->PDO->lastInsertId();
    109115    } else
    110     {     
    111       $this->Error = $this->PDO->errorInfo();
    112       $this->Error = $this->Error[2];
     116    {
     117      $Error = $this->PDO->errorInfo();
     118      $this->Error = $Error[2];
    113119      if (($this->Error != '') and ($this->ShowSQLError == true))
    114120        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     
    118124  }
    119125
    120   function select($Table, $What = '*', $Condition = 1)
     126  function select(string $Table, string $What = '*', string $Condition = '1'): DatabaseResult
    121127  {
    122128    return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
    123129  }
    124130
    125   function delete($Table, $Condition)
     131  function delete(string $Table, string $Condition): void
    126132  {
    127133    $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
    128134  }
    129135
    130   function insert($Table, $Data)
     136  function insert(string $Table, array $Data): int
    131137  {
    132138    $this->query($this->GetInsert($Table, $Data));
    133139    $this->insert_id = $this->PDO->lastInsertId();
    134   }
    135  
    136   function GetInsert($Table, $Data)
     140    return $this->insert_id;
     141  }
     142
     143  function IsFunction(string $Text): bool
     144  {
     145    $Pos = strpos($Text, '(');
     146    return ($Pos !== false) && in_array(substr($Text, 0, $Pos + 1), $this->Functions);
     147  }
     148
     149  function GetInsert(string $Table, array $Data): string
    137150  {
    138151    $Name = '';
     
    141154    {
    142155      $Name .= ',`'.$Key.'`';
    143       if (!in_array($Value, $this->Functions))
     156      if (is_null($Value)) $Value = 'NULL';
     157      else if (!$this->IsFunction($Value))
    144158      {
    145         if (is_null($Value)) $Value = 'NULL';
    146         else $Value = $this->PDO->quote($Value);
     159        $Value = $this->PDO->quote($Value);
    147160      }
    148161      $Values .= ','.$Value;
     
    153166  }
    154167
    155   function update($Table, $Condition, $Data)
     168  function update(string $Table, string $Condition, array $Data): void
    156169  {
    157170    $this->query($this->GetUpdate($Table, $Condition, $Data));
    158171  }
    159  
    160   function GetUpdate($Table, $Condition, $Data)
     172
     173  function GetUpdate(string $Table, string $Condition, array $Data): string
    161174  {
    162175    $Values = '';
    163176    foreach ($Data as $Key => $Value)
    164177    {
    165       if (!in_array($Value, $this->Functions))
     178      if (is_null($Value)) $Value = 'NULL';
     179      else if (!$this->IsFunction($Value))
    166180      {
    167         if (is_null($Value)) $Value = 'NULL';
    168         else $Value = $this->PDO->quote($Value);
     181        $Value = $this->PDO->quote($Value);
    169182      }
    170183      $Values .= ', `'.$Key.'`='.$Value;
     
    174187  }
    175188
    176   function replace($Table, $Data)
     189  function replace(string $Table, array $Data): void
    177190  {
    178191    $Name = '';
     
    180193    foreach ($Data as $Key => $Value)
    181194    {
    182       if (!in_array($Value, $this->Functions))
     195      if (is_null($Value)) $Value = 'NULL';
     196      else if (!$this->IsFunction($Value))
    183197      {
    184         if (is_null($Value)) $Value = 'NULL';
    185         else $Value = $this->PDO->quote($Value);
     198        $Value = $this->PDO->quote($Value);
    186199      }
    187200      $Name .= ',`'.$Key.'`';
     
    195208  }
    196209
    197   function charset($Charset)
     210  function charset(string $Charset): void
    198211  {
    199212    $this->query('SET NAMES "'.$Charset.'"');
    200213  }
    201214
    202   function real_escape_string($Text)
     215  function real_escape_string(string $Text): string
    203216  {
    204217    return addslashes($Text);
    205218  }
    206219
    207   function quote($Text)
     220  function quote(string $Text): string
    208221  {
    209222    return $this->PDO->quote($Text);
    210223  }
    211224
    212   public function __sleep()
     225  public function __sleep(): array
    213226  {
    214227    return array('LastQuery');
    215228  }
    216229
    217   public function __wakeup()
    218   {
    219   }
    220  
    221   public function Transaction($Queries)
    222   {
    223       $this->PDO->beginTransaction();
    224       foreach ($Queries as $Query)
    225       {
    226         $Statement = $this->PDO->prepare($Query);
    227         $Statement->execute();
    228       }         
    229       $this->PDO->commit();
     230  public function __wakeup(): void
     231  {
     232  }
     233
     234  public function Transaction(array $Queries): void
     235  {
     236    //echo('|'."\n");
     237    $this->PDO->beginTransaction();
     238    foreach ($Queries as $Query)
     239    {
     240      //echo('|'.$Query."\n");
     241      $Statement = $this->PDO->prepare($Query);
     242      $Statement->execute();
     243    }
     244    $this->PDO->commit();
     245  }
     246
     247  public function TableExists(string $Name): bool
     248  {
     249    $DbResult = $this->query('SELECT * FROM information_schema.tables  WHERE table_schema = "'.$this->Database.
     250    '" AND table_name = "'.$Name.'" LIMIT 1');
     251    return $DbResult->num_rows != 0;
    230252  }
    231253}
  • Common/Error.php

    r10 r14  
    33class ErrorHandler
    44{
    5   var $Encoding;
    6   var $ShowError;
    7   var $UserErrors;
    8   var $OnError;
     5  public string $Encoding;
     6  public bool $ShowError;
     7  public int $UserErrors;
     8  public $OnError;
    99
    1010  function __construct()
     
    6363  }
    6464
    65   function ExceptionHandler(Exception $Exception)
     65  function ExceptionHandler(Throwable $Exception)
    6666  {
    6767    $Backtrace = $Exception->getTrace();
     
    7575  }
    7676
    77   function ShowDefaultError($Message)
     77  function ShowDefaultError(string $Message): void
    7878  {
    7979    $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
  • Common/Image.php

    r10 r14  
    99class Font
    1010{
    11   var $Size;
    12   var $FileName;
    13   var $Color;
     11  public int $Size;
     12  public string $FileName;
     13  public int $Color;
    1414
    1515  function __construct()
     
    2323class Pen
    2424{
    25   var $Color;
    26   var $X;
    27   var $Y;
     25  public int $Color;
     26  public int $X;
     27  public int $Y;
    2828
    2929  function __construct()
     
    3838class Brush
    3939{
    40   var $Color;
     40  public int $Color;
    4141
    4242  function __construct()
     
    4949class Image
    5050{
    51   var $Image;
    52   var $Type;
    53   var $Font;
    54   var $Pen;
     51  public $Image;
     52  public int $Type;
     53  public Font $Font;
     54  public Pen $Pen;
     55  public Brush $Brush;
    5556
    5657  function __construct()
     
    6364  }
    6465
    65   function SaveToFile($FileName)
     66  function SaveToFile(string $FileName): void
    6667  {
    6768    if ($this->Type == IMAGETYPE_JPEG)
     
    7980  }
    8081
    81   function LoadFromFile($FileName)
     82  function LoadFromFile(string $FileName): void
    8283  {
    8384    $ImageInfo = getimagesize($FileName);
     
    8990    if ($this->Type == IMAGETYPE_GIF)
    9091    {
    91       $this->Image = imagecreatefromgif($FileName);
     92      $this->Image = imagecreatefromgif ($FileName);
    9293    } else
    9394    if ( $this->Type == IMAGETYPE_PNG)
     
    9798  }
    9899
    99   function Output()
     100  function Output(): void
    100101  {
    101102    $this->SaveToFile(NULL);
    102103  }
    103104
    104   function SetSize($Width, $Height)
     105  function SetSize(int $Width, int $Height): void
    105106  {
    106107    $NewImage = imagecreatetruecolor($Width, $Height);
     
    110111  }
    111112
    112   function GetWidth()
     113  function GetWidth(): int
    113114  {
    114115    return imagesx($this->Image);
    115116  }
    116117
    117   function GetHeight()
     118  function GetHeight(): int
    118119  {
    119120    return imagesy($this->Image);
    120121  }
    121122
    122   function TextOut($X, $Y, $Text)
     123  function TextOut(int $X, int $Y, string $Text): void
    123124  {
    124125    imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text);
    125126  }
    126127
    127   function ConvertColor($Color)
     128  function ConvertColor(int $Color): int
    128129  {
    129130    return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff);
    130131  }
    131132
    132   function FillRect($X1, $Y1, $X2, $Y2)
     133  function FillRect(int $X1, int $Y1, int $X2, int $Y2): void
    133134  {
    134135    imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color));
    135136  }
    136137
    137   function Line($X1, $Y1, $X2, $Y2)
     138  function Line(int $X1, int $Y1, int $X2, int $Y2): void
    138139  {
    139140    imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color));
  • Common/Locale.php

    r10 r14  
    33class LocaleText
    44{
    5   var $Data;
    6   var $Code;
    7   var $Title;
     5  public array $Data;
     6  public string $Code;
     7  public string $Title;
    88
    99  function __construct()
     
    1414  }
    1515
    16   function Load()
    17   {
    18   }
    19 
    20   function Translate($Text, $Group = '')
     16  function Load(): void
     17  {
     18  }
     19
     20  function Translate(string $Text, string $Group = ''): string
    2121  {
    2222    if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != ''))
     
    2525  }
    2626
    27   function TranslateReverse($Text, $Group = '')
     27  function TranslateReverse(string $Text, string $Group = ''): string
    2828  {
    2929    $Key = array_search($Text, $this->Data[$Group]);
     
    3535class LocaleFile extends Model
    3636{
    37   var $Texts;
    38   var $Dir;
     37  public LocaleText $Texts;
     38  public string $Dir;
    3939
    4040  function __construct(System $System)
     
    4444  }
    4545
    46   function Load($Language)
     46  function Load(string $Language): void
    4747  {
    4848    $FileName = $this->Dir.'/'.$Language.'.php';
     
    5555  }
    5656
    57   function AnalyzeCode($Path)
     57  function AnalyzeCode(string $Path): void
    5858  {
    5959    // Search for php files
     
    9898  }
    9999
    100   function SaveToFile($FileName)
     100  function SaveToFile(string $FileName): void
    101101  {
    102102    $Content = '<?php'."\n".
     
    119119  }
    120120
    121   function LoadFromDatabase($Database, $LangCode)
     121  function LoadFromDatabase(Database $Database, string $LangCode): void
    122122  {
    123123    $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     
    132132  }
    133133
    134   function SaveToDatabase(Database $Database, $LangCode)
    135   {
    136     $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     134  function SaveToDatabase(string $LangCode): void
     135  {
     136    $DbResult = $this->Database->select('Language', '*', 'Code='.$this->Database->quote($LangCode));
    137137    if ($DbResult->num_rows > 0)
    138138    {
    139139      $Language = $DbResult->fetch_assoc();
    140       $Database->delete('Locale', '`Language`='.$Language['Id']);
     140      $this->Database->delete('Locale', '`Language`='.$Language['Id']);
    141141      foreach ($this->Texts->Data as $Index => $Item)
    142         $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
    143         'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')');
    144     }
    145   }
    146 
    147   function UpdateToDatabase(Database $Database, $LangCode)
    148   {
    149     $DbResult = $Database->select('Language', '*', '`Code`='.$Database->quote($LangCode));
     142        $this->Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
     143        'VALUES('.$Language['Id'].','.$this->Database->quote($Index).','.$this->Database->quote($Item).')');
     144    }
     145  }
     146
     147  function UpdateToDatabase(string $LangCode): void
     148  {
     149    $DbResult = $this->Database->select('Language', '*', '`Code`='.$this->Database->quote($LangCode));
    150150    if ($DbResult->num_rows > 0)
    151151    {
     
    153153      foreach ($this->Texts->Data as $Index => $Item)
    154154      {
    155         $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).
     155        $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index).
    156156          ') AND (`Language`='.($Language['Id']).')');
    157157        if ($DbResult->num_rows > 0)
    158         $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
    159           '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item));
    160         else $Database->insert('Locale', array('Language' => $Language['Id'],
     158        $this->Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
     159          '(`Original` ='.$this->Database->quote($Index).')', array('Translated' => $Item));
     160        else $this->Database->insert('Locale', array('Language' => $Language['Id'],
    161161         'Original' => $Index, 'Translated' => $Item));
    162162      }
     
    167167class LocaleManager extends Model
    168168{
    169   var $CurrentLocale;
    170   var $Codes;
    171   var $Dir;
    172   var $LangCode;
    173   var $DefaultLangCode;
    174   var $Available;
     169  public LocaleFile $CurrentLocale;
     170  public array $Codes;
     171  public string $Dir;
     172  public string $LangCode;
     173  public string $DefaultLangCode;
     174  public array $Available;
    175175
    176176  function __construct(System $System)
     
    182182    $this->DefaultLangCode = 'en';
    183183    $this->Available = array();
    184   }
    185 
    186   function LoadAvailable()
     184    $this->Dir = '';
     185  }
     186
     187  function LoadAvailable(): void
    187188  {
    188189    $this->Available = array();
     
    201202  }
    202203
    203   function UpdateAll($Directory)
     204  function UpdateAll(string $Directory): void
    204205  {
    205206    $Locale = new LocaleFile($this->System);
     
    222223          if (!array_key_exists($Index, $Locale->Texts->Data))
    223224            unset($FileLocale->Texts->Data[$Index]);
    224         $FileLocale->UpdateToDatabase($this->System->Database, $FileLocale->Texts->Code);
     225        $FileLocale->UpdateToDatabase($FileLocale->Texts->Code);
    225226        $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php';
    226227        $FileLocale->SaveToFile($FileName);
     
    230231  }
    231232
    232   function LoadLocale($Code)
     233  function LoadLocale(string $Code): void
    233234  {
    234235    if (array_key_exists($Code, $this->Available))
     
    241242
    242243// Short named global translation function
    243 function T($Text, $Group = '')
     244function T(string $Text, string $Group = ''): string
    244245{
    245246  global $GlobalLocaleManager;
  • Common/Mail.php

    r10 r14  
    99class Mail
    1010{
    11   var $Priorities;
    12   var $Subject;
    13   var $From;
    14   var $Recipients;
    15   var $Bodies;
    16   var $Attachments;
    17   var $AgentIdent;
    18   var $Organization;
    19   var $ReplyTo;
    20   var $Headers;
     11  public string $Subject;
     12  public string $From;
     13  public array $Recipients;
     14  public array $Bodies;
     15  public array $Attachments;
     16  public string $AgentIdent;
     17  public string $Organization;
     18  public string $ReplyTo;
     19  public array $Headers;
     20  private array $Priorities;
     21  private string $Boundary;
    2122
    2223  function __construct()
     
    2829  }
    2930
    30   function Clear()
     31  function Clear(): void
    3132  {
    3233    $this->Bodies = array();
     
    4142  }
    4243
    43   function AddToCombined($Address)
     44  function AddToCombined(string $Address): void
    4445  {
    4546    $this->Recipients[] = array('Address' => $Address, 'Type' => 'SendCombined');
    4647  }
    4748
    48   function AddTo($Address, $Name)
     49  function AddTo(string $Address, string $Name): void
    4950  {
    5051    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Send');
    5152  }
    5253
    53   function AddCc($Address, $Name)
     54  function AddCc(string $Address, string $Name): void
    5455  {
    5556    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Copy');
    5657  }
    5758
    58   function AddBcc($Address, $Name)
     59  function AddBcc(string $Address, string $Name): void
    5960  {
    6061    $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'HiddenCopy');
    6162  }
    6263
    63   function AddBody($Content, $MimeType = 'text/plain', $Charset = 'utf-8')
     64  function AddBody(string $Content, string $MimeType = 'text/plain', string $Charset = 'utf-8'): void
    6465  {
    6566    $this->Bodies[] = array('Content' => $Content, 'Type' => strtolower($MimeType),
     
    6768  }
    6869
    69   function Organization($org)
     70  function Organization(string $org): void
    7071  {
    7172    if (trim($org != '')) $this->xheaders['Organization'] = $org;
    7273  }
    7374
    74   function Priority($Priority)
     75  function Priority(int $Priority): bool
    7576  {
    7677    if (!intval($Priority)) return false;
    7778
    78     if (!isset($this->priorities[$Priority - 1])) return false;
    79 
    80     $this->xheaders['X-Priority'] = $this->priorities[$Priority - 1];
     79    if (!isset($this->Priorities[$Priority - 1])) return false;
     80
     81    $this->xheaders['X-Priority'] = $this->Priorities[$Priority - 1];
    8182    return true;
    8283  }
    8384
    84   function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT)
     85  function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT): void
    8586  {
    8687    $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType,
     
    8889  }
    8990
    90   function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT)
     91  function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT): void
    9192  {
    9293    $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType,
     
    9495  }
    9596
    96   function Send()
     97  function Send(): bool
    9798  {
    9899    if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body'));
     
    144145    if ($this->Subject == '') throw new Exception(T('Mail message missing Subject'));
    145146
    146 
    147147    $res = mail($To, $this->Subject, $Body, $Headers);
    148148    return $res;
    149149  }
    150150
    151   function ValidEmail($Address)
    152   {
    153     if (ereg(".*<(.+)>", $Address, $regs)) $Address = $regs[1];
    154     if (ereg("^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))
     151  function ValidEmail(string $Address): bool
     152  {
     153    if (preg_match(".*<(.+)>", $Address, $regs)) $Address = $regs[1];
     154    if (preg_match("^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))
    155155      return true;
    156156      else return false;
    157157  }
    158158
    159   function CheckAdresses($Addresses)
     159  function CheckAdresses(array $Addresses): void
    160160  {
    161161    foreach ($Addresses as $Address)
    162162    {
    163163      if (!$this->ValidEmail($Address))
    164   throw new Exception(sprintf(T('Mail message invalid address %s'), $Address));
    165     }
    166   }
    167 
    168   private function ContentEncoding($Charset)
     164      {
     165        throw new Exception(sprintf(T('Mail message invalid address %s'), $Address));
     166      }
     167    }
     168  }
     169
     170  private function ContentEncoding($Charset): string
    169171  {
    170172    if ($Charset != CHARSET_ASCII) return '8bit';
     
    172174  }
    173175
    174   private function BuildAttachment($Body)
     176  private function BuildAttachment($Body): string
    175177  {
    176178    if (count($this->Attachments) > 0)
     
    206208  }
    207209
    208   private function BuildBody()
     210  private function BuildBody(): string
    209211  {
    210212    $Result = '';
     
    219221      $this->Headers['Content-Transfer-Encoding'] = $this->ContentEncoding($this->Bodies[0]['Charset']);
    220222    }
    221 
    222223
    223224    foreach ($this->Bodies as $Body)
  • Common/NetworkAddress.php

    r10 r14  
    11<?php
     2
     3define('IPV4_BIT_WIDTH', 32);
    24
    35class NetworkAddressIPv4
    46{
    5   var $Address;
    6   var $Prefix;
     7  public int $Address;
     8  public int $Prefix;
    79
    810  function __construct()
     
    1214  }
    1315
    14   function GetNetMask()
     16  function GetNetMask(): int
    1517  {
    16     return 0xffffffff ^ ((1 << (32 - $this->Prefix)) - 1);
     18    return ((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1);
    1719  }
    1820
    19   function AddressToString()
     21  function AddressToString(): string
    2022  {
    2123    return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255)));
    2224  }
    2325
    24   function AddressFromString($Value)
     26  function AddressFromString(string $Value): void
    2527  {
    2628    $Parts = explode('.', $Value);
     
    2830  }
    2931
    30   function GetRange()
     32  function GetRange(): array
    3133  {
    3234    $From = new NetworkAddressIPv4();
    3335    $From->Address = $this->Address;
    34     $From->Prefix = 32;
     36    $From->Prefix = IPV4_BIT_WIDTH;
    3537    $HostMask = 0xffffffff ^ $this->GetNetMask();
    3638    $To = new NetworkAddressIPv4();
    3739    $To->Address = $From->Address + $HostMask;
    38     $To->Prefix = 32;
     40    $To->Prefix = IPV4_BIT_WIDTH;
    3941    return array('From' => $From, 'To' => $To);
    4042  }
    4143
    42   function ChangePrefix($NewPrefix)
     44  function ChangePrefix(int $NewPrefix): void
    4345  {
    4446    $this->Prefix = $NewPrefix;
    45     if ($this->Prefix > 32) $this->Prefix = 32;
     47    if ($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH;
    4648    if ($this->Prefix < 0) $this->Prefix = 0;
    4749    $this->Address = $this->Address & $this->GetNetMask();
    4850  }
    4951
    50   function Contain($Address)
     52  function Contain(NetworkAddressIPv4 $Address): bool
    5153  {
    5254    $UpperNetmask = $this->GetNetMask();
    5355    if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;
    5456      else $Result = false;
    55     //echo($Address->AddressToString().'/'.$Address->Prefix.' in '.$this->AddressToString().'/'.$this->Prefix.' '.$Result."\n");
    5657    return $Result;
    5758  }
    5859}
    5960
     61define('IPV6_BIT_WIDTH', 128);
     62
    6063class NetworkAddressIPv6
    6164{
    62   var $Address;
    63   var $Prefix;
     65  public string $Address;
     66  public int $Prefix;
    6467
    6568  function __construct()
     
    6972  }
    7073
    71   function AddressToString()
     74  function GetNetMask(): string
     75  {
     76    return Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)),
     77      Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH - $this->Prefix)), IntToInt128(1)));
     78  }
     79
     80  function AddressToString(): string
    7281  {
    7382    return inet_ntop($this->Address);
    7483  }
    7584
    76   function AddressFromString($Value)
     85  function AddressFromString(string $Value)
    7786  {
    7887    $this->Address = inet_pton($Value);
    7988  }
    8089
    81   function GetOctets()
     90  function ChangePrefix(int $NewPrefix): void
     91  {
     92    $this->Prefix = $NewPrefix;
     93    if ($this->Prefix > IPV6_BIT_WIDTH) $this->Prefix = IPV6_BIT_WIDTH;
     94    if ($this->Prefix < 0) $this->Prefix = 0;
     95    $this->Address = Int128And($this->Address, $this->GetNetMask());
     96  }
     97
     98  function GetOctets(): array
    8299  {
    83100    $Result = array();
     
    92109  }
    93110
    94   function EncodeMAC($MAC)
     111  function EncodeMAC(string $MAC): void
    95112  {
    96113    $MAC = explode(':', $MAC);
     
    107124  }
    108125
     126  function Contain(NetworkAddressIPv6 $Address): bool
     127  {
     128    $UpperNetmask = $this->GetNetMask();
     129    if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true;
     130      else $Result = false;
     131    return $Result;
     132  }
    109133}
  • Common/Page.php

    r10 r14  
    33class Page extends View
    44{
    5   var $Title;
    6   var $ParentClass;
    7   var $RawPage;
    8   var $OnSystemMessage;
     5  public string $Title;
     6  public string $Description;
     7  public string $ParentClass;
     8  public bool $RawPage;
     9  public $OnSystemMessage;
     10  public string $Load;
     11  public string $Unload;
    912
    1013  function __construct(System $System)
     
    1316    $this->RawPage = false;
    1417    $this->OnSystemMessage = array();
     18    $this->Title = "";
     19    $this->Description = "";
     20    $this->ParentClass = "";
    1521  }
    1622
    17   function Show()
     23  function Show(): string
    1824  {
    1925    return '';
    2026  }
    2127
    22   function GetOutput()
     28  function GetOutput(): string
    2329  {
    2430    $Output = $this->Show();
     
    2632  }
    2733
    28   function SystemMessage($Title, $Text)
     34  function SystemMessage(string $Title, string $Text): string
    2935  {
    3036    return call_user_func_array($this->OnSystemMessage, array($Title, $Text));
  • Common/PrefixMultiplier.php

    r10 r14  
    7272class PrefixMultiplier
    7373{
    74   function TruncateDigits($Value, $Digits = 4)
     74  function TruncateDigits($Value, $Digits = 4): string
    7575  {
    7676    for ($II = 2; $II > -6; $II--)
     
    8787  }
    8888
    89   function Add($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
     89  function Add($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal'): string
    9090  {
    9191    global $PrefixMultipliers;
  • Common/Process.php

    r13 r14  
    33class Process
    44{
    5   var $Command;
    6   var $Handle;
    7   var $Pipes;
    8   var $Environment;
    9   var $WorkingDir;
    10  
     5  public string $Command;
     6  public $Handle;
     7  public array $Pipes;
     8  public array $Environment;
     9  public ?string $WorkingDir;
     10
    1111  function __construct()
    1212  {
     
    1717    $this->WorkingDir = null;
    1818  }
    19  
    20   function Start()
     19
     20  function Start(): void
    2121  {
    2222    if (!$this->IsRunning())
     
    2828      );
    2929
    30       $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 
     30      $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes,
    3131        $this->WorkingDir, $this->Environment);
    3232      stream_set_blocking($this->Pipes[0], FALSE);
     
    3535    }
    3636  }
    37  
    38   function Stop()
     37
     38  function Stop(): void
    3939  {
    40     if ($this->IsRunning()) 
     40    if ($this->IsRunning())
    4141    {
    4242      proc_close($this->Handle);
     
    4444    }
    4545  }
    46  
    47   function IsRunning()
     46
     47  function IsRunning(): bool
    4848  {
    4949    return is_resource($this->Handle);
  • Common/RSS.php

    r12 r14  
    33class RSS
    44{
    5   var $Charset;
    6   var $Title;
    7   var $Link;
    8   var $Description;
    9   var $WebmasterEmail;
    10   var $Items;
     5  public string $Charset;
     6  public string $Title;
     7  public string $Link;
     8  public string $Description;
     9  public string $WebmasterEmail;
     10  public array $Items;
    1111
    1212  function __construct()
    1313  {
    14     $this->Charset = 'utf-8';
     14    $this->Charset = 'utf8';
     15    $this->Title = '';
     16    $this->Link = '';
     17    $this->Description = '';
     18    $this->WebmasterEmail = '';
    1519    $this->Items = array();
    1620  }
    1721
    18   function Generate()
     22  function Generate(): string
    1923  {
    20     Header('Content-Type: text/xml; charset=utf-8');
    2124    $Result = '<?xml version="1.0" encoding="'.$this->Charset.'" ?>'."\n". //<?
    22       '<rss version="2.0">'."\n".
    23       "  <channel>\n".
    24       "    <title>".$this->Title."</title>\n".
    25       "    <link>".$this->Link."</link>\n".
    26       "    <description>".$this->Description."</description>\n".
    27       "    <language>cs</language>\n".
    28       "    <webMaster>".$this->WebmasterEmail."</webMaster>\n".
    29       "    <pubDate>".date('r')."</pubDate>\n".
    30       "    <ttl>20</ttl>\n";
     25  '<rss version="2.0">'."\n".
     26  "  <channel>\n".
     27  "    <title>".$this->Title."</title>\n".
     28  "    <link>".$this->Link."</link>\n".
     29  "    <description>".$this->Description."</description>\n".
     30  "    <language>cs</language>\n".
     31  "    <webMaster>".$this->WebmasterEmail."</webMaster>\n".
     32  "    <pubDate>".date('r')."</pubDate>\n".
     33  "    <ttl>20</ttl>\n";
    3134    foreach ($this->Items as $Item)
    3235    {
     
    3437        '      <title>'.htmlspecialchars($Item['Title'])."</title>\n".
    3538        '      <description>'.htmlspecialchars($Item['Description'])."</description>\n".
    36         '      <pubDate>'.date('r',$Item['Time'])."</pubDate>\n".
    37         '      <link>'.$Item['Link']."</link>\n".
     39  '      <pubDate>'.date('r',$Item['Time'])."</pubDate>\n".
     40  '      <link>'.$Item['Link']."</link>\n".
    3841        "    </item>\n";
    3942    }
  • Common/Table.php

    r12 r14  
    33class Control
    44{
    5   var $Name;
     5  public string $Name;
    66
    7   function Show()
     7  function Show(): string
    88  {
    99    return '';
     
    1313class Table
    1414{
    15   function GetCell($Y, $X)
     15  function GetCell($Y, $X): string
    1616  {
    1717    return '';
     
    2626  }
    2727
    28   function RowsCount()
     28  function RowsCount(): int
    2929  {
    3030    return 0;
     
    3434class TableMemory extends Table
    3535{
    36   var $Cells;
     36  public array $Cells;
    3737
    38   function GetCell($Y, $X)
     38  function GetCell($Y, $X): string
    3939  {
    4040    return $this->Cells[$Y][$X];
    4141  }
    4242
    43   function RowsCount()
     43  function RowsCount(): int
    4444  {
    4545    return count($this->Cells);
     
    4949class TableSQL extends Table
    5050{
    51   var $Query;
    52   var $Database;
    53   var $Cells;
     51  public string $Query;
     52  public Database $Database;
     53  public array $Cells;
    5454
    55   function GetCell($Y, $X)
     55  function GetCell($Y, $X): string
    5656  {
    5757    return $this->Cells[$Y][$X];
     
    7373  }
    7474
    75   function RowsCount()
     75  function RowsCount(): int
    7676  {
    7777    return count($this->Cells);
     
    8181class TableColumn
    8282{
    83   var $Name;
    84   var $Title;
     83  public string $Name;
     84  public string $Title;
    8585}
    8686
    8787class VisualTable extends Control
    8888{
    89   var $Cells;
    90   var $Columns;
    91   var $OrderSQL;
    92   var $OrderColumn;
    93   var $OrderDirection;
    94   var $OrderArrowImage;
    95   var $DefaultColumn;
    96   var $DefaultOrder;
    97   var $Table;
    98   var $Style;
     89  public array $Cells;
     90  public array $Columns;
     91  public string $OrderSQL;
     92  public string $OrderColumn;
     93  public int $OrderDirection;
     94  public array $OrderArrowImage;
     95  public string $DefaultColumn;
     96  public int $DefaultOrder;
     97  public TableMemory $Table;
     98  public string $Style;
    9999
    100   function __construct($System)
     100  function __construct()
    101101  {
     102    global $System;
     103
    102104    $this->Columns = array();
    103105    $this->Table = new TableMemory();
     
    124126  }
    125127
    126   function Show()
     128  function Show(): string
    127129  {
    128130    $Output = '<table class="'.$this->Style.'">';
     
    146148  }
    147149
    148   function GetOrderHeader()
     150  function GetOrderHeader(): string
    149151  {
    150152    if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
  • Common/UTF8.php

    r10 r14  
    526526  }
    527527
    528   function ToUTF8($String, $Charset = 'iso2')
     528  function ToUTF8string(string $String, string $Charset = 'iso2'): string
    529529  {
    530530    $Result = '';
     
    540540  }
    541541
    542   function FromUTF8($String, $Charset = 'iso2')
     542  function FromUTF8(string $String, string $Charset = 'iso2'): string
    543543  {
    544544    $Result = '';
     
    546546    for ($I = 0; $I < strlen($String); $I++)
    547547    {
    548       if (ord($String{$I}) & 0x80) // UTF control character
     548      if (ord($String[$I]) & 0x80) // UTF control character
    549549      {
    550         if (ord($String{$I}) & 0x40) // First
     550        if (ord($String[$I]) & 0x40) // First
    551551        {
    552552          if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset]));
    553           $UTFPrefix = $String{$I};
     553          $UTFPrefix = $String[$I];
    554554        }
    555         else $UTFPrefix .= $String{$I}; // Next
     555        else $UTFPrefix .= $String[$I]; // Next
    556556      } else
    557557      {
    558558        if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset]));
    559559        $UTFPrefix = '';
    560         $Result .= $String{$I};
     560        $Result .= $String[$I];
    561561      }
    562562    }
  • Common/Update.php

    r10 r14  
    33class UpdateManager
    44{
    5   var $Revision;
    6   var $Trace;
    7   var $VersionTable;
    8   /* @var Database */
    9   var $Database;
    10   var $InstallMethod;
     5  public int $Revision;
     6  public array $Trace;
     7  public string $VersionTable;
     8  public Database $Database;
     9  public string $InstallMethod;
    1110
    1211  function __construct()
     
    1918  }
    2019
    21   function GetDbVersion()
     20  function GetDbVersion(): ?int
    2221  {
    2322    $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
     
    2625  }
    2726
    28   function IsInstalled()
     27  function IsInstalled(): bool
    2928  {
    3029    $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"');
     
    3231  }
    3332
    34   function IsUpToDate()
     33  function IsUpToDate(): bool
    3534  {
    3635    return $this->Revision <= $this->GetDbVersion();
    3736  }
    3837
    39   function Upgrade()
     38  function Upgrade(): string
    4039  {
    4140    $DbRevision = $this->GetDbVersion();
     
    5958  }
    6059
    61   function Install()
     60  function Install(): void
    6261  {
    6362    $InstallMethod = $this->InstallMethod;
    6463    $InstallMethod($this);
    65     $this->Update();
    6664  }
    6765
    68   function Uninstall()
     66  function Uninstall(): void
    6967  {
    70 
    7168  }
    7269
    73   function InsertSampleData()
     70  function InsertSampleData(): void
    7471  {
    7572    $InstallMethod = $this->InsertSampleDataMethod;
     
    7774  }
    7875
    79   function Execute($Query)
     76  function Execute(string $Query): DatabaseResult
    8077  {
    8178    echo($Query.';<br/>');
Note: See TracChangeset for help on using the changeset viewer.