Changeset 888 for trunk/Packages
- Timestamp:
- Dec 27, 2022, 7:50:23 PM (2 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 13 added
- 1 deleted
- 15 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Base.php
r861 r888 1 1 <?php 2 3 class System4 {5 /* @var Database */6 var $Database;7 8 function __construct()9 {10 $this->Database = new Database();11 }12 }13 2 14 3 class Base 15 4 { 16 /** @var Application */ 17 var $System; 18 /* @var Database */ 19 var $Database; 5 public System $System; 6 public Database $Database; 20 7 21 function __construct( Application$System)8 function __construct(System $System) 22 9 { 23 10 $this->System = &$System; 24 11 $this->Database = &$System->Database; 25 12 } 13 14 static function GetClassName() 15 { 16 return get_called_class(); 17 } 26 18 } 27 28 class Model extends Base29 {30 31 }32 33 class View extends Base34 {35 36 }37 38 class Controller extends Base39 {40 41 } -
trunk/Packages/Common/Common.php
r881 r888 11 11 include_once(dirname(__FILE__).'/Error.php'); 12 12 include_once(dirname(__FILE__).'/Base.php'); 13 include_once(dirname(__FILE__).'/Application.php'); 14 include_once(dirname(__FILE__).'/AppModule.php'); 13 include_once(dirname(__FILE__).'/View.php'); 14 include_once(dirname(__FILE__).'/Model.php'); 15 include_once(dirname(__FILE__).'/ModelDesc.php'); 16 include_once(dirname(__FILE__).'/Controller.php'); 17 include_once(dirname(__FILE__).'/System.php'); 18 include_once(dirname(__FILE__).'/Module.php'); 19 include_once(dirname(__FILE__).'/ModuleManager.php'); 15 20 include_once(dirname(__FILE__).'/Config.php'); 16 21 include_once(dirname(__FILE__).'/Page.php'); 17 22 include_once(dirname(__FILE__).'/Locale.php'); 18 23 include_once(dirname(__FILE__).'/Update.php'); 19 include_once(dirname(__FILE__).'/Setup.php');20 24 include_once(dirname(__FILE__).'/Table.php'); 25 include_once(dirname(__FILE__).'/Process.php'); 26 include_once(dirname(__FILE__).'/Generics.php'); 27 include_once(dirname(__FILE__).'/BigInt.php'); 28 include_once(dirname(__FILE__).'/Int128.php'); 29 include_once(dirname(__FILE__).'/Pdf.php'); 30 include_once(dirname(__FILE__).'/Modules/Setup.php'); 31 include_once(dirname(__FILE__).'/Modules/ModuleManager.php'); 21 32 22 33 class PackageCommon 23 34 { 24 var $Name; 25 var $Version; 26 var $License; 27 var $Creator; 28 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; 29 41 30 42 function __construct() 31 43 { 32 44 $this->Name = 'Common'; 33 $this->Version = '1.1'; 45 $this->Version = '1.2'; 46 $this->ReleaseDate = strtotime('2020-03-29'); 34 47 $this->Creator = 'Chronos'; 35 $this->License = 'GNU/GPL ';48 $this->License = 'GNU/GPLv3'; 36 49 $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/'; 37 50 } … … 40 53 class Paging 41 54 { 42 var$TotalCount;43 var$ItemPerPage;44 var$Around;45 var$SQLLimit;46 var$Page;55 public int $TotalCount; 56 public int $ItemPerPage; 57 public int $Around; 58 public string $SQLLimit; 59 public int $Page; 47 60 48 61 function __construct() … … 54 67 } 55 68 56 function Show() 69 function Show(): string 57 70 { 58 71 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); -
trunk/Packages/Common/Config.php
r880 r888 3 3 class Config 4 4 { 5 var$Data;5 public array $Data; 6 6 7 7 function __construct() … … 10 10 } 11 11 12 function ReadValue( $Name)12 function ReadValue(string $Name) 13 13 { 14 14 if (!is_array($Name)) $Name = explode('/', $Name); … … 22 22 } 23 23 24 function WriteValue( $Name, $Value)24 function WriteValue(string $Name, $Value) 25 25 { 26 26 if (!is_array($Name)) $Name = explode('/', $Name); … … 34 34 } 35 35 36 function LoadFromFile( $FileName)36 function LoadFromFile(string $FileName): void 37 37 { 38 38 $ConfigData = array(); … … 40 40 foreach ($this->Data as $Index => $Item) 41 41 { 42 if (array_key_exi ts($Index, $ConfigData))42 if (array_key_exists($Index, $ConfigData)) 43 43 $this->Data[$Index] = $ConfigData[$Index]; 44 44 } 45 45 } 46 46 47 function SaveToFile( $FileName)47 function SaveToFile(string $FileName): void 48 48 { 49 49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n"); 50 50 } 51 51 52 function GetAsArray() 52 function GetAsArray(): array 53 53 { 54 54 return $this->Data; -
trunk/Packages/Common/Database.php
r880 r888 2 2 3 3 // Extended database class 4 // Date: 2016-01-11 4 // Date: 2020-11-10 5 6 function microtime_float() 7 { 8 list($usec, $sec) = explode(" ", microtime()); 9 return (float)$usec + (float)$sec; 10 } 5 11 6 12 class DatabaseResult 7 13 { 8 var$PDOStatement;9 var$num_rows = 0;14 public PDOStatement $PDOStatement; 15 public int $num_rows = 0; 10 16 11 17 function fetch_assoc() … … 27 33 class Database 28 34 { 29 var $Prefix; 30 var $Functions; 31 var $Type; 32 var $PDO; 33 var $Error; 34 var $insert_id; 35 var $LastQuery; 36 var $ShowSQLError; 37 var $ShowSQLQuery; 38 var $LogSQLQuery; 39 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; 40 47 41 48 function __construct() 42 49 { 43 50 $this->Prefix = ''; 44 $this->Functions = array('NOW( )', 'CURDATE()', 'CURTIME()', 'UUID()');51 $this->Functions = array('NOW(', 'CURDATE(', 'CURTIME(', 'UUID(', 'SHA1('); 45 52 $this->Type = 'mysql'; // mysql, pgsql 46 53 $this->Error = ''; … … 50 57 $this->LogSQLQuery = false; 51 58 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 52 } 53 54 function Connect($Host, $User, $Password, $Database) 59 $this->Database = ''; 60 } 61 62 function Connect(string $Host, string $User, string $Password, string $Database): void 55 63 { 56 64 if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 57 65 else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; 58 66 else $ConnectionString = ''; 67 $this->Database = $Database; 59 68 try { 60 69 $this->PDO = new PDO($ConnectionString, $User, $Password); 61 62 70 } catch (Exception $E) 63 71 { … … 67 75 } 68 76 69 function Disconnect() 77 function Disconnect(): void 70 78 { 71 79 unset($this->PDO); 72 80 } 73 81 74 function Connected() 82 function Connected(): bool 75 83 { 76 84 return isset($this->PDO); 77 85 } 78 86 79 function select_db( $Database)87 function select_db(string $Database) 80 88 { 81 89 $this->query('USE `'.$Database.'`'); 82 90 } 83 91 84 function query($Query) 92 function query($Query): DatabaseResult 85 93 { 86 94 if (!$this->Connected()) throw new Exception(T('Not connected to database')); 87 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime ();95 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float(); 88 96 $this->LastQuery = $Query; 89 97 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 90 $Duration = ' ; '.round(microtime() - $QueryStartTime, 4). ' s'; 91 if ($this->LogSQLQuery == true) 98 { 99 $Time = round(microtime_float() - $QueryStartTime, 4); 100 $Duration = ' ; '.$Time. ' s'; 101 } 102 if (($this->LogSQLQuery == true) and ($Time != 0)) 92 103 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); 93 104 if ($this->ShowSQLQuery == true) … … 95 106 'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n"); 96 107 $Result = new DatabaseResult(); 97 $Result->PDOStatement = $this->PDO->query($Query); 98 if ($Result->PDOStatement) 99 { 100 $Result->num_rows = $Result->PDOStatement->rowCount(); 108 $Statement = $this->PDO->query($Query); 109 if ($Statement) 110 { 111 $Result->PDOStatement = $Statement; 112 $Result->num_rows = $Statement->rowCount(); 101 113 $this->insert_id = $this->PDO->lastInsertId(); 102 114 } else 103 115 { 104 $ this->Error = $this->PDO->errorInfo();105 $this->Error = $ this->Error[2];116 $Error = $this->PDO->errorInfo(); 117 $this->Error = $Error[2]; 106 118 if (($this->Error != '') and ($this->ShowSQLError == true)) 107 119 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); … … 111 123 } 112 124 113 function select( $Table, $What = '*', $Condition = 1)125 function select(string $Table, string $What = '*', string $Condition = '1'): DatabaseResult 114 126 { 115 127 return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 116 128 } 117 129 118 function delete( $Table, $Condition)130 function delete(string $Table, string $Condition): void 119 131 { 120 132 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 121 133 } 122 134 123 function insert($Table, $Data) 135 function insert(string $Table, array $Data): int 136 { 137 $this->query($this->GetInsert($Table, $Data)); 138 $this->insert_id = $this->PDO->lastInsertId(); 139 return $this->insert_id; 140 } 141 142 function IsFunction(string $Text): bool 143 { 144 $Pos = strpos($Text, '('); 145 return ($Pos !== false) && in_array(substr($Text, 0, $Pos + 1), $this->Functions); 146 } 147 148 function GetInsert(string $Table, array $Data): string 124 149 { 125 150 $Name = ''; … … 128 153 { 129 154 $Name .= ',`'.$Key.'`'; 130 if (!in_array($Value, $this->Functions)) 155 if (is_null($Value)) $Value = 'NULL'; 156 else if (!$this->IsFunction($Value)) 131 157 { 132 if (is_null($Value)) $Value = 'NULL'; 133 else $Value = $this->PDO->quote($Value); 158 $Value = $this->PDO->quote($Value); 134 159 } 135 160 $Values .= ','.$Value; … … 137 162 $Name = substr($Name, 1); 138 163 $Values = substr($Values, 1); 139 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 140 $this->insert_id = $this->PDO->lastInsertId(); 141 } 142 143 function update($Table, $Condition, $Data) 164 return 'INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'; 165 } 166 167 function update(string $Table, string $Condition, array $Data): void 168 { 169 $this->query($this->GetUpdate($Table, $Condition, $Data)); 170 } 171 172 function GetUpdate(string $Table, string $Condition, array $Data): string 144 173 { 145 174 $Values = ''; 146 175 foreach ($Data as $Key => $Value) 147 176 { 148 if (!in_array($Value, $this->Functions)) 177 if (is_null($Value)) $Value = 'NULL'; 178 else if (!$this->IsFunction($Value)) 149 179 { 150 if (is_null($Value)) $Value = 'NULL'; 151 else $Value = $this->PDO->quote($Value); 180 $Value = $this->PDO->quote($Value); 152 181 } 153 182 $Values .= ', `'.$Key.'`='.$Value; 154 183 } 155 184 $Values = substr($Values, 2); 156 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');157 } 158 159 function replace( $Table, $Data)185 return 'UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'; 186 } 187 188 function replace(string $Table, array $Data): void 160 189 { 161 190 $Name = ''; … … 163 192 foreach ($Data as $Key => $Value) 164 193 { 165 if (!in_array($Value, $this->Functions)) 194 if (is_null($Value)) $Value = 'NULL'; 195 else if (!$this->IsFunction($Value)) 166 196 { 167 if (is_null($Value)) $Value = 'NULL'; 168 else $Value = $this->PDO->quote($Value); 197 $Value = $this->PDO->quote($Value); 169 198 } 170 199 $Name .= ',`'.$Key.'`'; … … 173 202 $Name = substr($Name, 1); 174 203 $Values = substr($Values, 1); 175 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br />');176 204 $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 177 //echo($this->error().'<br>'); 178 } 179 180 function charset($Charset) 205 } 206 207 function charset(string $Charset): void 181 208 { 182 209 $this->query('SET NAMES "'.$Charset.'"'); 183 210 } 184 211 185 function real_escape_string( $Text)212 function real_escape_string(string $Text): string 186 213 { 187 214 return addslashes($Text); 188 215 } 189 216 190 function quote( $Text)217 function quote(string $Text): string 191 218 { 192 219 return $this->PDO->quote($Text); 193 220 } 194 221 195 public function __sleep() 222 public function __sleep(): array 196 223 { 197 224 return array('LastQuery'); 198 225 } 199 226 200 public function __wakeup() 201 { 227 public function __wakeup(): void 228 { 229 } 230 231 public function Transaction(array $Queries): void 232 { 233 $this->PDO->beginTransaction(); 234 foreach ($Queries as $Query) 235 { 236 $Statement = $this->PDO->prepare($Query); 237 $Statement->execute(); 238 } 239 $this->PDO->commit(); 240 } 241 242 public function TableExists(string $Name): bool 243 { 244 $DbResult = $this->query('SELECT * FROM information_schema.tables WHERE table_schema = "'.$this->Database. 245 '" AND table_name = "'.$Name.'" LIMIT 1'); 246 return $DbResult->num_rows != 0; 202 247 } 203 248 } -
trunk/Packages/Common/Error.php
r887 r888 16 16 } 17 17 18 function Start() 18 function Start(): void 19 19 { 20 20 set_error_handler(array($this, 'ErrorHandler')); … … 22 22 } 23 23 24 function Stop() 24 function Stop(): void 25 25 { 26 26 restore_error_handler(); … … 28 28 } 29 29 30 function ErrorHandler( $Number, $Message, $FileName, $LineNumber)30 function ErrorHandler(int $Number, string $Message, string $FileName, int $LineNumber, array $Variables = array()): bool 31 31 { 32 32 $ErrorType = array … … 63 63 } 64 64 65 function ExceptionHandler(Throwable $Exception) 65 function ExceptionHandler(Throwable $Exception): void 66 66 { 67 67 $Backtrace = $Exception->getTrace(); … … 88 88 } 89 89 90 function Report( $Backtrace)90 function Report(array $Backtrace): void 91 91 { 92 92 $Date = date('Y-m-d H:i:s'); -
trunk/Packages/Common/Image.php
r880 r888 9 9 class Font 10 10 { 11 var$Size;12 var$FileName;13 var$Color;11 public int $Size; 12 public string $FileName; 13 public int $Color; 14 14 15 15 function __construct() … … 23 23 class Pen 24 24 { 25 var$Color;26 var$X;27 var$Y;25 public int $Color; 26 public int $X; 27 public int $Y; 28 28 29 29 function __construct() … … 38 38 class Brush 39 39 { 40 var$Color;40 public int $Color; 41 41 42 42 function __construct() … … 49 49 class Image 50 50 { 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; 55 56 56 57 function __construct() … … 63 64 } 64 65 65 function SaveToFile( $FileName)66 function SaveToFile(string $FileName): void 66 67 { 67 68 if ($this->Type == IMAGETYPE_JPEG) … … 79 80 } 80 81 81 function LoadFromFile( $FileName)82 function LoadFromFile(string $FileName): void 82 83 { 83 84 $ImageInfo = getimagesize($FileName); … … 89 90 if ($this->Type == IMAGETYPE_GIF) 90 91 { 91 $this->Image = imagecreatefromgif ($FileName);92 $this->Image = imagecreatefromgif ($FileName); 92 93 } else 93 94 if ( $this->Type == IMAGETYPE_PNG) … … 97 98 } 98 99 99 function Output() 100 function Output(): void 100 101 { 101 102 $this->SaveToFile(NULL); 102 103 } 103 104 104 function SetSize( $Width, $Height)105 function SetSize(int $Width, int $Height): void 105 106 { 106 107 $NewImage = imagecreatetruecolor($Width, $Height); … … 110 111 } 111 112 112 function GetWidth() 113 function GetWidth(): int 113 114 { 114 115 return imagesx($this->Image); 115 116 } 116 117 117 function GetHeight() 118 function GetHeight(): int 118 119 { 119 120 return imagesy($this->Image); 120 121 } 121 122 122 function TextOut( $X, $Y, $Text)123 function TextOut(int $X, int $Y, string $Text): void 123 124 { 124 125 imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text); 125 126 } 126 127 127 function ConvertColor( $Color)128 function ConvertColor(int $Color): int 128 129 { 129 130 return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff); 130 131 } 131 132 132 function FillRect( $X1, $Y1, $X2, $Y2)133 function FillRect(int $X1, int $Y1, int $X2, int $Y2): void 133 134 { 134 135 imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color)); 135 136 } 136 137 137 function Line( $X1, $Y1, $X2, $Y2)138 function Line(int $X1, int $Y1, int $X2, int $Y2): void 138 139 { 139 140 imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color)); -
trunk/Packages/Common/Locale.php
r884 r888 3 3 class LocaleText 4 4 { 5 var$Data;6 var$Code;7 var$Title;5 public array $Data; 6 public string $Code; 7 public string $Title; 8 8 9 9 function __construct() … … 14 14 } 15 15 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 21 21 { 22 22 if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != '')) … … 25 25 } 26 26 27 function TranslateReverse( $Text, $Group = '')27 function TranslateReverse(string $Text, string $Group = ''): string 28 28 { 29 29 $Key = array_search($Text, $this->Data[$Group]); … … 35 35 class LocaleFile extends Model 36 36 { 37 var$Texts;38 var$Dir;37 public LocaleText $Texts; 38 public string $Dir; 39 39 40 40 function __construct(System $System) … … 44 44 } 45 45 46 function Load( $Language)46 function Load(string $Language): void 47 47 { 48 48 $FileName = $this->Dir.'/'.$Language.'.php'; … … 55 55 } 56 56 57 function AnalyzeCode( $Path)57 function AnalyzeCode(string $Path): void 58 58 { 59 59 // Search for php files … … 75 75 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); 76 76 $Content = substr($Content, strpos($Content, 'T(') + 2); 77 $Ord = ord($Previous); 78 //echo($Ord.','); 77 $Ord = ord($Previous); 79 78 if (!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 80 79 { … … 98 97 } 99 98 100 function SaveToFile( $FileName)99 function SaveToFile(string $FileName): void 101 100 { 102 101 $Content = '<?php'."\n". … … 119 118 } 120 119 121 function LoadFromDatabase( $Database, $LangCode)120 function LoadFromDatabase(Database $Database, string $LangCode): void 122 121 { 123 122 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); … … 132 131 } 133 132 134 function SaveToDatabase( Database $Database, $LangCode)135 { 136 $DbResult = $ Database->select('Language', '*', 'Code='.$Database->quote($LangCode));133 function SaveToDatabase(string $LangCode): void 134 { 135 $DbResult = $this->Database->select('Language', '*', 'Code='.$this->Database->quote($LangCode)); 137 136 if ($DbResult->num_rows > 0) 138 137 { 139 138 $Language = $DbResult->fetch_assoc(); 140 $ Database->delete('Locale', '`Language`='.$Language['Id']);139 $this->Database->delete('Locale', '`Language`='.$Language['Id']); 141 140 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));141 $this->Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 142 'VALUES('.$Language['Id'].','.$this->Database->quote($Index).','.$this->Database->quote($Item).')'); 143 } 144 } 145 146 function UpdateToDatabase(string $LangCode): void 147 { 148 $DbResult = $this->Database->select('Language', '*', '`Code`='.$this->Database->quote($LangCode)); 150 149 if ($DbResult->num_rows > 0) 151 150 { … … 153 152 foreach ($this->Texts->Data as $Index => $Item) 154 153 { 155 if (is_array($Item)) continue; 156 $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index). 154 $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index). 157 155 ') AND (`Language`='.($Language['Id']).')'); 158 156 if ($DbResult->num_rows > 0) 159 { 160 $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 161 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); 162 } else 163 { 164 $Database->insert('Locale', array('Language' => $Language['Id'], 165 'Original' => $Index, 'Translated' => $Item, 'Fuzzy' => 0)); 166 } 157 $this->Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 158 '(`Original` ='.$this->Database->quote($Index).')', array('Translated' => $Item)); 159 else $this->Database->insert('Locale', array('Language' => $Language['Id'], 160 'Original' => $Index, 'Translated' => $Item)); 167 161 } 168 162 } … … 172 166 class LocaleManager extends Model 173 167 { 174 var$CurrentLocale;175 var$Codes;176 var$Dir;177 var$LangCode;178 var$DefaultLangCode;179 var$Available;168 public LocaleFile $CurrentLocale; 169 public array $Codes; 170 public string $Dir; 171 public string $LangCode; 172 public string $DefaultLangCode; 173 public array $Available; 180 174 181 175 function __construct(System $System) … … 187 181 $this->DefaultLangCode = 'en'; 188 182 $this->Available = array(); 189 } 190 191 function LoadAvailable() 183 $this->Dir = ''; 184 } 185 186 function LoadAvailable(): void 192 187 { 193 188 $this->Available = array(); … … 206 201 } 207 202 208 function UpdateAll( $Directory)203 function UpdateAll(string $Directory): void 209 204 { 210 205 $Locale = new LocaleFile($this->System); … … 227 222 if (!array_key_exists($Index, $Locale->Texts->Data)) 228 223 unset($FileLocale->Texts->Data[$Index]); 229 $FileLocale->UpdateToDatabase($ this->System->Database, $FileLocale->Texts->Code);224 $FileLocale->UpdateToDatabase($FileLocale->Texts->Code); 230 225 $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php'; 231 226 $FileLocale->SaveToFile($FileName); … … 235 230 } 236 231 237 function LoadLocale( $Code)232 function LoadLocale(string $Code): void 238 233 { 239 234 if (array_key_exists($Code, $this->Available)) … … 246 241 247 242 // Short named global translation function 248 function T( $Text, $Group = '')243 function T(string $Text, string $Group = ''): string 249 244 { 250 245 global $GlobalLocaleManager; -
trunk/Packages/Common/Mail.php
r880 r888 9 9 class Mail 10 10 { 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; 22 public bool $TestMode; 21 23 22 24 function __construct() … … 25 27 $this->Boundary = md5(date('r', time())); 26 28 $this->AgentIdent = 'PHP/Mail'; 29 $this->TestMode = false; 27 30 $this->Clear(); 28 31 } 29 32 30 function Clear() 33 function Clear(): void 31 34 { 32 35 $this->Bodies = array(); … … 41 44 } 42 45 43 function AddToCombined( $Address)46 function AddToCombined(string $Address): void 44 47 { 45 48 $this->Recipients[] = array('Address' => $Address, 'Type' => 'SendCombined'); 46 49 } 47 50 48 function AddTo( $Address, $Name)51 function AddTo(string $Address, string $Name): void 49 52 { 50 53 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Send'); 51 54 } 52 55 53 function AddCc( $Address, $Name)56 function AddCc(string $Address, string $Name): void 54 57 { 55 58 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Copy'); 56 59 } 57 60 58 function AddBcc( $Address, $Name)61 function AddBcc(string $Address, string $Name): void 59 62 { 60 63 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'HiddenCopy'); 61 64 } 62 65 63 function AddBody( $Content, $MimeType = 'text/plain', $Charset = 'utf-8')66 function AddBody(string $Content, string $MimeType = 'text/plain', string $Charset = 'utf-8'): void 64 67 { 65 68 $this->Bodies[] = array('Content' => $Content, 'Type' => strtolower($MimeType), … … 67 70 } 68 71 69 function Organization( $org)72 function Organization(string $org): void 70 73 { 71 74 if (trim($org != '')) $this->xheaders['Organization'] = $org; 72 75 } 73 76 74 function Priority( $Priority)77 function Priority(int $Priority): bool 75 78 { 76 79 if (!intval($Priority)) return false; 77 80 78 if (!isset($this-> priorities[$Priority - 1])) return false;79 80 $this->xheaders['X-Priority'] = $this-> priorities[$Priority - 1];81 if (!isset($this->Priorities[$Priority - 1])) return false; 82 83 $this->xheaders['X-Priority'] = $this->Priorities[$Priority - 1]; 81 84 return true; 82 85 } 83 86 84 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT) 87 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT): void 85 88 { 86 89 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 88 91 } 89 92 90 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT) 93 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT): void 91 94 { 92 95 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 94 97 } 95 98 96 function Send() 99 function Send(): bool 97 100 { 98 101 if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body')); … … 132 135 if ($this->AgentIdent != '') $this->Headers['X-Mailer'] = $this->AgentIdent; 133 136 if ($this->ReplyTo != '') $this->Headers['Reply-To'] = $this->ReplyTo; 134 if ($this->From != '') $this->Headers['From'] = $this->From; 137 if ($this->From != '') 138 { 139 $IndexStart = strpos($this->From, '<'); 140 if ($IndexStart !== false) 141 { 142 $this->Headers['From'] = '=?utf-8?Q?'.quoted_printable_encode(trim(substr($this->From, 0, $IndexStart))).'?= '.substr($this->From, $IndexStart); 143 } else 144 { 145 $this->Headers['From'] = $this->From; 146 } 147 } 135 148 136 149 $Headers = ''; … … 144 157 if ($this->Subject == '') throw new Exception(T('Mail message missing Subject')); 145 158 146 147 $res = mail($To, $this->Subject, $Body, $Headers); 159 if ($this->TestMode) 160 { 161 echo('to: '.$To.', subject: '.$this->Subject.', body: '.$Body.', headers: '.$Headers); 162 $res = true; 163 } else 164 { 165 $res = mail($To, $this->Subject, $Body, $Headers); 166 } 148 167 return $res; 149 168 } 150 169 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))170 function ValidEmail(string $Address): bool 171 { 172 if (preg_match(".*<(.+)>", $Address, $regs)) $Address = $regs[1]; 173 if (preg_match("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address)) 155 174 return true; 156 175 else return false; 157 176 } 158 177 159 function CheckAdresses( $Addresses)178 function CheckAdresses(array $Addresses): void 160 179 { 161 180 foreach ($Addresses as $Address) 162 181 { 163 182 if (!$this->ValidEmail($Address)) 164 throw new Exception(sprintf(T('Mail message invalid address %s'), $Address)); 165 } 166 } 167 168 private function ContentEncoding($Charset) 183 { 184 throw new Exception(sprintf(T('Mail message invalid address %s'), $Address)); 185 } 186 } 187 } 188 189 private function ContentEncoding($Charset): string 169 190 { 170 191 if ($Charset != CHARSET_ASCII) return '8bit'; … … 172 193 } 173 194 174 private function BuildAttachment($Body) 195 private function BuildAttachment($Body): string 175 196 { 176 197 if (count($this->Attachments) > 0) … … 206 227 } 207 228 208 private function BuildBody() 229 private function BuildBody(): string 209 230 { 210 231 $Result = ''; … … 219 240 $this->Headers['Content-Transfer-Encoding'] = $this->ContentEncoding($this->Bodies[0]['Charset']); 220 241 } 221 222 242 223 243 foreach ($this->Bodies as $Body) -
trunk/Packages/Common/Module.php
r887 r888 1 1 <?php 2 2 3 /* This implementation will not support installation from remote source. Just4 * installation of already presented modules mainly to persistence preparation.5 */6 7 3 class ModuleType 8 4 { 9 5 const System = 0; 10 const Normal= 1;6 const Library = 1; 11 7 const Application = 2; 12 8 } … … 21 17 const Enable = 5; 22 18 const Disable = 6; 19 const InsertSampleData = 7; 23 20 } 24 21 … … 32 29 const Running = 5; 33 30 const NotRunning = 6; 34 } 35 36 class AppModule 37 { 38 var $Id; 39 var $Name; 40 var $Title; 41 var $Version;42 var $License;43 var $Creator;44 var $HomePage;45 var $Description;46 var $Running;47 var $Enabled;48 var $Installed;49 var $InstalledVersion;50 /** @var ModuleType */51 var $Type;52 var $Dependencies;53 /** @var Database */54 var $Database;55 /** @var System */56 var $System;57 /** @var AppModuleManager */58 var $Manager;59 var$OnChange;31 const System = 7; 32 const Library = 8; 33 const Application = 9; 34 } 35 36 class Module extends Model 37 { 38 public int $Id; 39 public string $Name; 40 public string $Title; 41 public string $Version; 42 public string $License; 43 public string $Creator; 44 public string $HomePage; 45 public string $Description; 46 public int $Type; // ModuleType 47 public array $Dependencies; 48 public array $Models; // Model 49 public bool $Running; 50 public bool $Enabled; 51 public bool $Installed; 52 public string $InstalledVersion; 53 public Database $Database; 54 public System $System; 55 public ModuleManager $Manager; 56 public $OnChange; 60 57 61 58 function __construct(System $System) 62 59 { 63 $this->System = &$System; 64 $this->Database = &$System->Database; 65 $this->Installed = false; 66 $this->Enabled = false; 67 $this->Running = false; 60 parent::__construct($System); 61 $this->Name = ''; 68 62 $this->HomePage = ''; 69 63 $this->License = ''; 70 64 $this->Version = ''; 71 65 $this->Creator = ''; 66 $this->Title = ''; 72 67 $this->Description = ''; 73 68 $this->Dependencies = array(); 74 $this->Type = ModuleType::Normal; 75 } 76 77 function Install() 69 $this->Models = array(); 70 $this->Type = ModuleType::Library; 71 $this->Installed = false; 72 $this->InstalledVersion = ''; 73 $this->Enabled = false; 74 $this->Running = false; 75 } 76 77 static function GetName() 78 { 79 $ClassName = get_called_class(); 80 if (substr($ClassName, 0, 6) == 'Module') return substr($ClassName, 6); 81 else return $ClassName; 82 } 83 84 static function GetModelDesc(): ModelDesc 85 { 86 $Desc = new ModelDesc(self::GetClassName()); 87 $Desc->AddString('Name'); 88 $Desc->AddString('Title'); 89 $Desc->AddString('Creator'); 90 $Desc->AddString('Version'); 91 $Desc->AddString('License'); 92 $Desc->AddBoolean('Installed'); 93 $Desc->AddString('InstalledVersion'); 94 $Desc->AddString('Description'); 95 return $Desc; 96 } 97 98 function Install(): void 78 99 { 79 100 if ($this->Installed) return; 80 101 $List = array(); 81 102 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled)); 82 $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled)); 83 $this->DoInstall(); 103 $this->Manager->PerformList($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled)); 84 104 $this->Installed = true; 105 $this->Enabled = true; // Automatically enable installed module 85 106 $this->InstalledVersion = $this->Version; 86 107 $this->Manager->Modules[$this->Name] = $this; 87 } 88 89 function Uninstall() 108 $this->DoBeforeInstall(); 109 if ($this->Manager->OnInstallModule != null) 110 { 111 call_user_func($this->Manager->OnInstallModule, $this); 112 } 113 $this->InstallModels($this->Models); 114 $this->DoInstall(); 115 } 116 117 function Uninstall(): void 90 118 { 91 119 if (!$this->Installed) return; … … 94 122 $List = array(); 95 123 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 96 $this->Manager->Perform ($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));124 $this->Manager->PerformList($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed)); 97 125 $this->DoUninstall(); 98 } 99 100 function Upgrade() 126 $this->UninstallModels($this->Models); 127 if ($this->Manager->OnUninstallModule != null) 128 { 129 call_user_func($this->Manager->OnUninstallModule, $this); 130 } 131 $this->DoAfterUninstall(); 132 } 133 134 function Upgrade(): void 101 135 { 102 136 if (!$this->Installed) return; … … 104 138 $List = array(); 105 139 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 106 $this->Manager->Perform ($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed));140 $this->Manager->PerformList($List, array(ModuleAction::Upgrade), array(ModuleCondition::Installed)); 107 141 $this->DoUpgrade(); 108 142 } 109 143 110 function Reinstall() 144 function InsertSampleData(): void 145 { 146 $this->DoInsertSampleData(); 147 } 148 149 function Reinstall(): void 111 150 { 112 151 $this->Uninstall(); … … 115 154 } 116 155 117 function Start() 156 function Start(): void 118 157 { 119 158 if ($this->Running) return; … … 121 160 $List = array(); 122 161 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning)); 123 $this->Manager->Perform ($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));162 $this->Manager->PerformList($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning)); 124 163 $this->DoStart(); 125 164 $this->Running = true; 126 165 } 127 166 128 function Stop() 167 function Stop(): void 129 168 { 130 169 if (!$this->Running) return; … … 132 171 $List = array(); 133 172 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running)); 134 $this->Manager->Perform ($List, array(ModuleAction::Stop), array(ModuleCondition::Running));173 $this->Manager->PerformList($List, array(ModuleAction::Stop), array(ModuleCondition::Running)); 135 174 $this->DoStop(); 136 175 } 137 176 138 function Restart() 177 function Restart(): void 139 178 { 140 179 $this->Stop(); … … 142 181 } 143 182 144 function Enable() 183 function Enable(): void 145 184 { 146 185 if ($this->Enabled) return; … … 148 187 $List = array(); 149 188 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotEnabled)); 150 $this->Manager->Perform ($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled));189 $this->Manager->PerformList($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled)); 151 190 $this->Enabled = true; 152 191 } 153 192 154 function Disable() 193 function Disable(): void 155 194 { 156 195 if (!$this->Enabled) return; … … 159 198 $List = array(); 160 199 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Enabled)); 161 $this->Manager->Perform($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled)); 162 } 163 164 protected function DoStart() 165 { 166 } 167 168 protected function DoStop() 169 { 170 } 171 172 protected function DoInstall() 173 { 174 } 175 176 protected function DoUninstall() 177 { 178 } 179 180 protected function DoUpgrade() 181 { 182 183 } 184 } 185 186 /* Manage installed modules */ 187 class AppModuleManager 188 { 189 var $Modules; 190 var $System; 191 var $FileName; 192 var $ModulesDir; 193 var $OnLoadModules; 194 195 function __construct(System $System) 196 { 197 $this->Modules = array(); 198 $this->System = &$System; 199 $this->FileName = dirname(__FILE__).'/../../Config/ModulesConfig.php'; 200 $this->ModulesDir = dirname(__FILE__).'/../../Modules'; 201 } 202 203 function Perform($List, $Actions, $Conditions = array(ModuleCondition::All)) 204 { 205 foreach ($List as $Index => $Module) 206 { 207 if (in_array(ModuleCondition::All, $Conditions) or 208 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or 209 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 210 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 211 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)) or 212 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 213 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions))) 200 $this->Manager->PerformList($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled)); 201 } 202 203 protected function DoStart(): void 204 { 205 } 206 207 protected function DoStop(): void 208 { 209 } 210 211 protected function DoBeforeInstall(): void 212 { 213 } 214 215 protected function DoInstall(): void 216 { 217 } 218 219 protected function DoUninstall(): void 220 { 221 } 222 223 protected function DoAfterUninstall(): void 224 { 225 } 226 227 protected function DoUpgrade(): string 228 { 229 return ''; 230 } 231 232 protected function DoInsertSampleData(): void 233 { 234 } 235 236 function AddModel(Model $Model): void 237 { 238 $this->Models[get_class($Model)] = $Model; 239 } 240 241 function InstallModels(array $Models): void 242 { 243 if ($this->Manager->OnInstallModel != null) 244 { 245 foreach ($Models as $Model) 214 246 { 215 foreach ($Actions as $Action) 216 { 217 if ($Action == ModuleAction::Start) $Module->Start(); 218 if ($Action == ModuleAction::Stop) $Module->Stop(); 219 if ($Action == ModuleAction::Install) $Module->Install(); 220 if ($Action == ModuleAction::Uninstall) $Module->Uninstall(); 221 if ($Action == ModuleAction::Enable) $Module->Enable(); 222 if ($Action == ModuleAction::Disable) $Module->Disable(); 223 if ($Action == ModuleAction::Upgrade) $Module->Upgrade(); 224 } 247 call_user_func($this->Manager->OnInstallModel, $Model::GetModelDesc(), $this); 225 248 } 226 249 } 227 250 } 228 251 229 function EnumDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All)) 230 { 231 foreach ($Module->Dependencies as $Dependency) 232 { 233 if (!array_key_exists($Dependency, $this->Modules)) 234 throw new Exception(sprintf(T('Module "%s" dependency "%s" not found'), $Module->Name, $Dependency)); 235 $DepModule = $this->Modules[$Dependency]; 236 if (in_array(ModuleCondition::All, $Conditions) or 237 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or 238 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 239 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 240 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 241 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 242 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))) 252 function UninstallModels(array $Models): void 253 { 254 if ($this->Manager->OnUninstallModel != null) 255 { 256 foreach (array_reverse($Models) as $Model) 243 257 { 244 array_push($List, $DepModule); 245 $this->EnumDependenciesCascade($DepModule, $List, $Conditions); 258 call_user_func($this->Manager->OnUninstallModel, $Model::GetModelDesc(), $this); 246 259 } 247 260 } 248 261 } 249 250 function EnumSuperiorDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All)) 251 { 252 foreach ($this->Modules as $RefModule) 253 { 254 if (in_array($Module->Name, $RefModule->Dependencies) and 255 (in_array(ModuleCondition::All, $Conditions) or 256 ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or 257 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 258 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 259 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 260 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 261 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))) 262 { 263 array_push($List, $RefModule); 264 $this->EnumSuperiorDependenciesCascade($RefModule, $List, $Conditions); 265 } 266 } 267 } 268 269 function Start() 270 { 271 $this->LoadModules(); 272 if (file_exists($this->FileName)) $this->LoadState(); 273 $this->StartEnabled(); 274 } 275 276 function StartAll() 277 { 278 $this->Perform($this->Modules, array(ModuleAction::Start)); 279 } 280 281 function StartEnabled() 282 { 283 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled)); 284 } 285 286 function StopAll() 287 { 288 $this->Perform($this->Modules, array(ModuleAction::Stop)); 289 } 290 291 function InstallAll() 292 { 293 $this->Perform($this->Modules, array(ModuleAction::Install)); 294 $this->SaveState(); 295 } 296 297 function UninstallAll() 298 { 299 $this->Perform($this->Modules, array(ModuleAction::Uninstall)); 300 $this->SaveState(); 301 } 302 303 function EnableAll() 304 { 305 $this->Perform($this->Modules, array(ModuleAction::Enable)); 306 $this->SaveState(); 307 } 308 309 function DisableAll() 310 { 311 $this->Perform($this->Modules, array(ModuleAction::Disable)); 312 $this->SaveState(); 313 } 314 315 function ModulePresent($Name) 316 { 317 return array_key_exists($Name, $this->Modules); 318 } 319 320 function ModuleEnabled($Name) 321 { 322 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Enabled; 323 } 324 325 function ModuleRunning($Name) 326 { 327 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Running; 328 } 329 330 /* @return Module */ 331 function SearchModuleById($Id) 332 { 333 foreach ($this->Modules as $Module) 334 { 335 //DebugLog($Module->Name.' '.$Module->Id); 336 if ($Module->Id == $Id) return $Module->Name; 337 } 338 return ''; 339 } 340 341 function LoadState() 342 { 343 $ConfigModules = array(); 344 include($this->FileName); 345 foreach ($ConfigModules as $Mod) 346 { 347 if (array_key_exists($Mod['Name'], $this->Modules)) 348 { 349 $this->Modules[$Mod['Name']] = $this->Modules[$Mod['Name']]; 350 $this->Modules[$Mod['Name']]->Enabled = $Mod['Enabled']; 351 $this->Modules[$Mod['Name']]->Installed = $Mod['Installed']; 352 $this->Modules[$Mod['Name']]->InstalledVersion = $Mod['Version']; 353 } 354 } 355 } 356 357 function SaveState() 358 { 359 $Data = array(); 360 foreach ($this->Modules as $Module) 361 { 362 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 363 'Version' => $Module->Version, 'Installed' => $Module->Installed); 364 } 365 file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data, true).";\n"); 366 } 367 368 function RegisterModule(AppModule $Module) 369 { 370 $this->Modules[$Module->Name] = &$Module; 371 $Module->Manager = &$this; 372 $Module->OnChange = &$this->OnModuleChange; 373 } 374 375 function UnregisterModule(AppModule $Module) 376 { 377 unset($this->Modules[array_search($Module, $this->Modules)]); 378 } 379 380 function LoadModulesFromDir($Directory) 381 { 382 $List = scandir($Directory); 383 foreach ($List as $Item) 384 { 385 if (is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..') and ($Item != '.svn')) 386 { 387 include_once($Directory.'/'.$Item.'/'.$Item.'.php'); 388 $ModuleName = 'Module'.$Item; 389 $this->RegisterModule(new $ModuleName($this->System)); 390 } 391 } 392 } 393 394 function LoadModules(): void 395 { 396 if (is_array($this->OnLoadModules) and (count($this->OnLoadModules) == 2) and method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 397 call_user_func($this->OnLoadModules); 398 else $this->LoadModulesFromDir($this->ModulesDir); 399 } 400 } 262 } -
trunk/Packages/Common/Modules/Setup.php
r887 r888 1 1 <?php 2 3 class ModuleSetup extends Module 4 { 5 public UpdateManager $UpdateManager; 6 7 function __construct(System $System) 8 { 9 global $DatabaseRevision; 10 11 parent::__construct($System); 12 $this->Name = 'Setup'; 13 $this->Version = '1.0'; 14 $this->Creator = 'Chronos'; 15 $this->License = 'GNU/GPLv3'; 16 $this->Description = 'Base setup module'; 17 $this->Revision = 1; 18 $this->Type = ModuleType::System; 19 20 // Check database persistence structure 21 $this->UpdateManager = new UpdateManager(); 22 $this->UpdateManager->Database = &$this->Database; 23 $this->UpdateManager->Revision = $DatabaseRevision; 24 $this->UpdateManager->InstallMethod = 'FullInstall'; 25 } 26 27 static function Cast(Module $Module): ModuleSetup 28 { 29 if ($Module instanceof ModuleSetup) 30 { 31 return $Module; 32 } 33 throw new Exception('Expected ModuleSetup type but '.gettype($Module)); 34 } 35 36 function DoStart(): void 37 { 38 Core::Cast($this->System)->RegisterPage([''], 'PageSetupRedirect'); 39 Core::Cast($this->System)->RegisterPage(['setup'], 'PageSetup'); 40 } 41 42 function DoStop(): void 43 { 44 unset($this->UpdateManager); 45 Core::Cast($this->System)->UnregisterPage(['']); 46 Core::Cast($this->System)->UnregisterPage(['setup']); 47 } 48 49 function CheckState(): bool 50 { 51 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and 52 $this->UpdateManager->IsUpToDate(); 53 } 54 55 function DoUpgrade(): string 56 { 57 $Updates = new Updates(); 58 $this->UpdateManager->Trace = $Updates->Get(); 59 $Output = $this->UpdateManager->Upgrade(); 60 return $Output; 61 } 62 } 2 63 3 64 class PageSetup extends Page 4 65 { 5 var $UpdateManager;6 var$ConfigDefinition;7 var$Config;8 var$DatabaseRevision;9 var$Revision;10 var $Updates;11 var $ConfigDir;12 13 function __construct( $System)66 public UpdateManager $UpdateManager; 67 public array $ConfigDefinition; 68 public array $Config; 69 public int $DatabaseRevision; 70 public int $Revision; 71 public string $ConfigDir; 72 public array $YesNo; 73 74 function __construct(System $System) 14 75 { 15 76 parent::__construct($System); 16 77 $this->Title = T('Application setup'); 17 //$this->ParentClass = 'Page Portal';78 //$this->ParentClass = 'PageSetupRedirect'; 18 79 $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config'; 19 80 $this->YesNo = array(false => T('No'), true => T('Yes')); 20 81 } 21 82 22 function LoginPanel() 83 function LoginPanel(): string 23 84 { 24 85 $Output = '<h3>Přihlášení k instalaci</h3>'. … … 32 93 } 33 94 34 function ControlPanel() 95 function ControlPanel(): string 35 96 { 36 97 $Output = '<h3>'.T('Instance management').'</h3>'; … … 49 110 $Output .= '<a href="?action=upgrade">'.T('Upgrade').'</a> '; 50 111 $Output .= '<a href="?action=insert_sample_data">Vložit vzorová data</a> '; 51 $Output .= '<a href="?action=reload _modules">Obnovit seznam modulů</a> ';112 $Output .= '<a href="?action=reload-modules">Obnovit seznam modulů</a> '; 52 113 $Output .= '<a href="?action=uninstall">Odinstalovat</a> '; 53 $Output .= '<a href=" ?action=modules">Správa modulů</a> ';114 $Output .= '<a href="'.$this->System->Link('/modules/').'">Správa modulů</a> '; 54 115 $Output .= '<a href="?action=models">Přegenerovat modely</a> '; 55 116 } else $Output .= '<a href="?action=install">Instalovat</a> '; … … 62 123 } 63 124 64 function Show() 125 function Show(): string 65 126 { 66 127 global $ConfigDefinition, $DatabaseRevision, $Config, $Updates; 67 128 68 $this->UpdateManager = $this->System->Setup->UpdateManager;129 $this->UpdateManager = ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager; 69 130 $DefaultConfig = new DefaultConfig(); 70 131 $this->ConfigDefinition = $DefaultConfig->Get(); … … 89 150 $Output .= 'Odhlášen'; 90 151 $Output .= $this->LoginPanel(); 91 } else92 if ($Action == 'models')152 } 153 else if ($Action == 'models') 93 154 { 94 155 $this->System->FormManager->UpdateSQLMeta(); 95 } else96 if ($Action == 'upgrade')156 } 157 else if ($Action == 'upgrade') 97 158 { 98 159 $Output .= '<h3>Povýšení</h3>'; 99 try { 100 $Output .= $this->System->Setup->Upgrade(); 101 } catch (Exception $E) { 160 try 161 { 162 $Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->DoUpgrade(); 163 $this->System->ModuleManager->UpgradeAll(array(ModuleCondition::System)); 164 } catch (Exception $E) 165 { 102 166 $Output .= $this->SystemMessage('Chyba aktualizace', 103 167 'Došlo k chybě v SQL dotazu při aktualizaci: <br/>'.$E->getMessage()); 104 168 } 105 169 $Output .= $this->ControlPanel(); 106 } else 107 if ($Action == 'install') 108 { 109 $Output .= '<h3>Instalace</h3>'; 110 $this->System->Setup->Install(); 170 } 171 else if ($Action == 'install') 172 { 173 $Output .= '<h3>Instalace systém</h3>'; 174 global $DatabaseRevision; 175 176 $this->Database->query("CREATE TABLE IF NOT EXISTS `".$this->UpdateManager->VersionTable."` (". 177 '`Id` int(11) NOT NULL AUTO_INCREMENT, '. 178 '`Revision` int(11) NOT NULL, '. 179 'PRIMARY KEY (`Id`) '. 180 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'); 181 $DbResult = $this->Database->select($this->UpdateManager->VersionTable, 'Id'); 182 if ($DbResult->num_rows == 0) 183 { 184 $this->Database->query("INSERT INTO `".$this->UpdateManager->VersionTable. 185 "` (`Id`, `Revision`) VALUES (1, ".$DatabaseRevision.");"); 186 } 187 $this->System->ModuleManager->InstallAll(array(ModuleCondition::System)); 111 188 $this->System->ModuleManager->LoadModules(); 112 189 $this->System->ModuleManager->SaveState(); 113 //$Output .= $this->System->Setup->Upgrade(); 114 $Output .= $this->ControlPanel(); 115 } else 116 if ($Action == 'uninstall') 117 { 118 $Output .= '<h3>Odinstalace</h3>'; 119 $this->System->Setup->Uninstall(); 120 $Output .= $this->ControlPanel(); 121 } else 122 if ($Action == 'reload_modules') 190 //$Output .= ModuleSetup::Cast($this->System->GetModule('Setup'))->Upgrade(); 191 $Output .= $this->ControlPanel(); 192 } 193 else if ($Action == 'uninstall') 194 { 195 $Output .= '<h3>Odinstalace vše</h3>'; 196 $this->System->ModuleManager->UninstallAll(array(ModuleCondition::All)); 197 $this->Database->query('DROP TABLE IF EXISTS `'.$this->UpdateManager->VersionTable.'`'); 198 $Output .= $this->ControlPanel(); 199 } 200 else if ($Action == 'reload-modules') 123 201 { 124 202 $Output .= '<h3>Znovunačtení seznamu modulů</h3>'; … … 126 204 $this->System->ModuleManager->SaveState(); 127 205 $Output .= $this->ControlPanel(); 128 } else129 if ($Action == 'insert_sample_data')206 } 207 else if ($Action == 'insert_sample_data') 130 208 { 131 209 $Output .= '<h3>Vložení vzorových dat</h3>'; 132 $this->System->Setup->InsertSampleData(); 133 $Output .= $this->ControlPanel(); 134 } else 135 if ($Action == 'modules') 136 { 137 $Output .= $this->ShowModules(); 138 } else 139 if ($Action == 'configure_save') 210 $this->System->ModuleManager->Perform(array(ModuleAction::InsertSampleData), array(ModuleCondition::Installed)); 211 $Output .= $this->ControlPanel(); 212 } 213 else if ($Action == 'configure_save') 140 214 { 141 215 $Output .= $this->ConfigSave($this->Config); 142 216 $Output .= $this->ControlPanel(); 143 } else144 if ($Action == 'configure')217 } 218 else if ($Action == 'configure') 145 219 { 146 220 $Output .= $this->PrepareConfig($this->Config); 147 } else 221 } 222 else 148 223 { 149 224 $Output .= $this->ControlPanel(); … … 163 238 } 164 239 165 function ShowModules() 166 { 167 $Output = ''; 168 if (array_key_exists('op', $_GET)) $Operation = $_GET['op']; 169 else $Operation = ''; 170 if ($Operation == 'install') 171 { 172 $this->System->ModuleManager->Modules[$_GET['name']]->Install(); 173 $this->System->ModuleManager->SaveState(); 174 $Output .= 'Modul '.$_GET['name'].' instalován<br/>'; 175 } else 176 if ($Operation == 'uninstall') 177 { 178 $this->System->ModuleManager->Modules[$_GET['name']]->Uninstall(); 179 $this->System->ModuleManager->SaveState(); 180 $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>'; 181 } else 182 if ($Operation == 'enable') 183 { 184 $this->System->ModuleManager->Modules[$_GET['name']]->Enable(); 185 $this->System->ModuleManager->SaveState(); 186 $Output .= 'Modul '.$_GET['name'].' povolen<br/>'; 187 } else 188 if ($Operation == 'disable') 189 { 190 $this->System->ModuleManager->Modules[$_GET['name']]->Disable(); 191 $this->System->ModuleManager->SaveState(); 192 $Output .= 'Modul '.$_GET['name'].' zakázán<br/>'; 193 } else 194 if ($Operation == 'upgrade') 195 { 196 $this->System->ModuleManager->Modules[$_GET['name']]->Upgrade(); 197 $this->System->ModuleManager->SaveState(); 198 $Output .= 'Modul '.$_GET['name'].' povýšen<br/>'; 199 } 200 $Output .= '<h3>Správa modulů</h3>'; 201 $Output .= $this->ShowList(); 202 return $Output; 203 } 204 205 function ShowList() 206 { 207 $Output = ''; 208 209 $Pageing = new Paging(); 210 $Pageing->TotalCount = count($this->System->ModuleManager->Modules); 211 $Table = new VisualTable(); 212 $Table->SetColumns(array( 213 array('Name' => 'Name', 'Title' => 'Jméno'), 214 array('Name' => 'Creator', 'Title' => 'Tvůrce'), 215 array('Name' => 'Version', 'Title' => 'Verze'), 216 array('Name' => 'License', 'Title' => 'Licence'), 217 array('Name' => 'Installed', 'Title' => 'Instalováno'), 218 array('Name' => 'Enabled', 'Title' => 'Povoleno'), 219 array('Name' => 'Description', 'Title' => 'Popis'), 220 array('Name' => 'Dependencies', 'Title' => 'Závislosti'), 221 array('Name' => '', 'Title' => 'Akce'), 222 )); 223 foreach ($this->System->ModuleManager->Modules as $Module) 224 { 225 if (($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies); 226 else $Dependencies = ' '; 227 $Actions = ''; 228 if ($Module->Installed == true) 229 { 230 $Actions .= ' <a href="?action=modules&op=uninstall&name='.$Module->Name.'">Odinstalovat</a>'; 231 if ($Module->Enabled == true) $Actions .= ' <a href="?action=modules&op=disable&name='.$Module->Name.'">Zakázat</a>'; 232 else $Actions .= ' <a href="?action=modules&op=enable&name='.$Module->Name.'">Povolit</a>'; 233 if ($Module->InstalledVersion != $Module->Version) $Actions .= ' <a href="?action=modules&op=upgrade&name='.$Module->Name.'">Povýšit</a>'; 234 } else $Actions .= ' <a href="?action=modules&op=install&name='.$Module->Name.'">Instalovat</a>'; 235 236 $Table->Table->Cells[] = array($Module->Name, 237 $Module->Creator, $Module->Version, 238 $Module->License, $this->YesNo[$Module->Installed], 239 $this->YesNo[$Module->Enabled], $Module->Description, 240 $Dependencies, $Actions); 241 } 242 $Output .= $Pageing->Show(); 243 $Output .= $Table->Show(); 244 $Output .= $Pageing->Show(); 245 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>'; 246 return $Output; 247 } 248 249 function PrepareConfig($Config) 240 function PrepareConfig($Config): string 250 241 { 251 242 $Output = ''; … … 255 246 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor "'.$this->ConfigDir.'/Config.php" není povolen pro zápis!'; 256 247 $Output .= '<h3>Nastavení systému</h3>'. 257 258 248 '<form action="?action=configure_save" method="post">'. 249 '<table>'; 259 250 foreach ($this->ConfigDefinition as $Def) 260 251 { … … 278 269 } 279 270 $Output .= '</td></tr>'. 280 281 282 271 '<tr><td colspan="2"><input type="submit" name="configure_save" value="'.T('Save').'"/></td></tr>'. 272 '</table>'. 273 '</form>'; 283 274 return $Output; 284 275 } … … 322 313 } 323 314 324 function CreateConfig($Config) 315 function CreateConfig($Config): string 325 316 { 326 317 $Output = "<?php\n\n". … … 359 350 class PageSetupRedirect extends Page 360 351 { 361 function Show() 352 function Show(): string 362 353 { 363 354 $Output = ''; 364 if (!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'<br>'; 365 else { 366 if (!$this->System->Setup->UpdateManager->IsInstalled()) 367 $Output .= T('System requires database initialization').'<br>'; 368 else 369 if (!$this->System->Setup->UpdateManager->IsUpToDate()) 370 $Output .= T('System requires database upgrade').'<br>'; 371 } 372 $Output .= sprintf(T('Front page was not configured. Continue to %s'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>'); 355 if (!$this->Database->Connected()) 356 { 357 $Output .= T('Can\'t connect to database.').'<br>'; 358 } else 359 { 360 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsInstalled()) 361 { 362 $Output .= T('System requires database initialization.').'<br>'; 363 } else 364 if (!ModuleSetup::Cast($this->System->GetModule('Setup'))->UpdateManager->IsUpToDate()) 365 { 366 $Output .= T('System requires database upgrade.').'<br>'; 367 } 368 } 369 $Output .= sprintf(T('Front page was not configured. Continue to %s.'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>'); 373 370 return $Output; 374 371 } 375 372 } 376 377 class Setup extends Model378 {379 var $UpdateManager;380 381 function Start()382 {383 global $DatabaseRevision;384 385 $this->System->RegisterPage('', 'PageSetupRedirect');386 $this->System->RegisterPage('setup', 'PageSetup');387 388 // Check database persistence structure389 $this->UpdateManager = new UpdateManager();390 $this->UpdateManager->Database = &$this->Database;391 $this->UpdateManager->Revision = $DatabaseRevision;392 $this->UpdateManager->InstallMethod = 'FullInstall';393 }394 395 function Stop()396 {397 unset($this->UpdateManager);398 $this->System->UnregisterPage('');399 $this->System->UnregisterPage('setup');400 }401 402 function CheckState()403 {404 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and405 $this->UpdateManager->IsUpToDate();406 }407 408 function Install()409 {410 global $DatabaseRevision;411 412 $this->Database->query('CREATE TABLE IF NOT EXISTS `'.$this->UpdateManager->VersionTable.'` (413 `Id` int(11) NOT NULL AUTO_INCREMENT,414 `Revision` int(11) NOT NULL,415 PRIMARY KEY (`Id`)416 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');417 $this->Database->query('INSERT INTO `'.$this->UpdateManager->VersionTable.'` (`Id`, `Revision`) VALUES418 (1, '.$DatabaseRevision.');');419 $this->Database->query("CREATE TABLE IF NOT EXISTS `Module` (420 `Id` int(11) NOT NULL AUTO_INCREMENT,421 `Name` varchar(255) NOT NULL,422 `Title` varchar(255) NOT NULL,423 PRIMARY KEY (`Id`)424 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");425 }426 427 function Uninstall()428 {429 $this->System->ModuleManager->UninstallAll();430 $this->Database->query('DROP TABLE `Module`');431 $this->Database->query('DROP TABLE `'.$this->UpdateManager->VersionTable.'`');432 }433 434 function IsInstalled()435 {436 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"');437 return $DbResult->num_rows > 0;438 }439 440 function Upgrade()441 {442 $Updates = new Updates();443 $this->UpdateManager->Trace = $Updates->Get();444 $Output = $this->UpdateManager->Upgrade();445 return $Output;446 }447 } -
trunk/Packages/Common/NetworkAddress.php
r880 r888 1 1 <?php 2 3 define('IPV4_BIT_WIDTH', 32); 2 4 3 5 class NetworkAddressIPv4 4 6 { 5 var$Address;6 var$Prefix;7 public int $Address; 8 public int $Prefix; 7 9 8 10 function __construct() … … 12 14 } 13 15 14 function GetNetMask() 16 function GetNetMask(): int 15 17 { 16 return 0xffffffff ^ ((1 << (32- $this->Prefix)) - 1);18 return ((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1); 17 19 } 18 20 19 function AddressToString() 21 function AddressToString(): string 20 22 { 21 23 return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))); 22 24 } 23 25 24 function AddressFromString( $Value)26 function AddressFromString(string $Value): void 25 27 { 26 28 $Parts = explode('.', $Value); … … 28 30 } 29 31 30 function GetRange() 32 function GetRange(): array 31 33 { 32 34 $From = new NetworkAddressIPv4(); 33 35 $From->Address = $this->Address; 34 $From->Prefix = 32;36 $From->Prefix = IPV4_BIT_WIDTH; 35 37 $HostMask = 0xffffffff ^ $this->GetNetMask(); 36 38 $To = new NetworkAddressIPv4(); 37 39 $To->Address = $From->Address + $HostMask; 38 $To->Prefix = 32;40 $To->Prefix = IPV4_BIT_WIDTH; 39 41 return array('From' => $From, 'To' => $To); 40 42 } 41 43 42 function ChangePrefix( $NewPrefix)44 function ChangePrefix(int $NewPrefix): void 43 45 { 44 46 $this->Prefix = $NewPrefix; 45 if ($this->Prefix > 32) $this->Prefix = 32;47 if ($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH; 46 48 if ($this->Prefix < 0) $this->Prefix = 0; 47 49 $this->Address = $this->Address & $this->GetNetMask(); 48 50 } 49 51 50 function Contain( $Address)52 function Contain(NetworkAddressIPv4 $Address): bool 51 53 { 52 54 $UpperNetmask = $this->GetNetMask(); 53 55 if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true; 54 56 else $Result = false; 55 //echo($Address->AddressToString().'/'.$Address->Prefix.' in '.$this->AddressToString().'/'.$this->Prefix.' '.$Result."\n");56 57 return $Result; 57 58 } 58 59 } 59 60 61 define('IPV6_BIT_WIDTH', 128); 62 60 63 class NetworkAddressIPv6 61 64 { 62 var$Address;63 var$Prefix;65 public string $Address; 66 public int $Prefix; 64 67 65 68 function __construct() … … 69 72 } 70 73 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 72 81 { 73 82 return inet_ntop($this->Address); 74 83 } 75 84 76 function AddressFromString( $Value)85 function AddressFromString(string $Value) 77 86 { 78 87 $this->Address = inet_pton($Value); 79 88 } 80 89 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 82 99 { 83 100 $Result = array(); … … 85 102 foreach ($Data as $Item) 86 103 { 87 88 104 $Result[] = dechex($Item & 15); 89 105 $Result[] = dechex(($Item >> 4) & 15); … … 92 108 } 93 109 94 function EncodeMAC( $MAC)110 function EncodeMAC(string $MAC): void 95 111 { 96 112 $MAC = explode(':', $MAC); … … 107 123 } 108 124 125 function Contain(NetworkAddressIPv6 $Address): bool 126 { 127 $UpperNetmask = $this->GetNetMask(); 128 if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true; 129 else $Result = false; 130 return $Result; 131 } 109 132 } -
trunk/Packages/Common/Page.php
r880 r888 3 3 class Page extends View 4 4 { 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; 9 12 10 13 function __construct(System $System) … … 13 16 $this->RawPage = false; 14 17 $this->OnSystemMessage = array(); 18 $this->Title = ""; 19 $this->Description = ""; 20 $this->ParentClass = ""; 15 21 } 16 22 17 function Show() 23 function Show(): string 18 24 { 19 25 return ''; 20 26 } 21 27 22 function GetOutput() 28 function GetOutput(): string 23 29 { 24 30 $Output = $this->Show(); … … 26 32 } 27 33 28 function SystemMessage( $Title, $Text)34 function SystemMessage(string $Title, string $Text): string 29 35 { 30 36 return call_user_func_array($this->OnSystemMessage, array($Title, $Text)); -
trunk/Packages/Common/PrefixMultiplier.php
r880 r888 72 72 class PrefixMultiplier 73 73 { 74 function TruncateDigits($Value, $Digits = 4) 74 function TruncateDigits($Value, $Digits = 4): string 75 75 { 76 76 for ($II = 2; $II > -6; $II--) … … 87 87 } 88 88 89 function Add($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal') 89 function Add($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal'): string 90 90 { 91 91 global $PrefixMultipliers; -
trunk/Packages/Common/RSS.php
r880 r888 3 3 class RSS 4 4 { 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; 11 11 12 12 function __construct() 13 13 { 14 14 $this->Charset = 'utf8'; 15 $this->Title = ''; 16 $this->Link = ''; 17 $this->Description = ''; 18 $this->WebmasterEmail = ''; 15 19 $this->Items = array(); 16 20 } 17 21 18 function Generate() 22 function Generate(): string 19 23 { 20 24 $Result = '<?xml version="1.0" encoding="'.$this->Charset.'" ?>'."\n". //<? -
trunk/Packages/Common/Table.php
r880 r888 3 3 class Control 4 4 { 5 var$Name;5 public string $Name; 6 6 7 function Show() 7 function Show(): string 8 8 { 9 9 return ''; … … 13 13 class Table 14 14 { 15 function GetCell($Y, $X) 15 function GetCell($Y, $X): string 16 16 { 17 17 return ''; … … 26 26 } 27 27 28 function RowsCount() 28 function RowsCount(): int 29 29 { 30 30 return 0; … … 34 34 class TableMemory extends Table 35 35 { 36 var$Cells;36 public array $Cells; 37 37 38 function GetCell($Y, $X) 38 function GetCell($Y, $X): string 39 39 { 40 40 return $this->Cells[$Y][$X]; 41 41 } 42 42 43 function RowsCount() 43 function RowsCount(): int 44 44 { 45 45 return count($this->Cells); … … 49 49 class TableSQL extends Table 50 50 { 51 var$Query;52 var$Database;53 var$Cells;51 public string $Query; 52 public Database $Database; 53 public array $Cells; 54 54 55 function GetCell($Y, $X) 55 function GetCell($Y, $X): string 56 56 { 57 57 return $this->Cells[$Y][$X]; … … 73 73 } 74 74 75 function RowsCount() 75 function RowsCount(): int 76 76 { 77 77 return count($this->Cells); … … 81 81 class TableColumn 82 82 { 83 var$Name;84 var$Title;83 public string $Name; 84 public string $Title; 85 85 } 86 86 87 87 class VisualTable extends Control 88 88 { 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; 99 99 100 100 function __construct() … … 126 126 } 127 127 128 function Show() 128 function Show(): string 129 129 { 130 130 $Output = '<table class="'.$this->Style.'">'; … … 148 148 } 149 149 150 function GetOrderHeader() 150 function GetOrderHeader(): string 151 151 { 152 152 if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; -
trunk/Packages/Common/UTF8.php
r887 r888 526 526 } 527 527 528 function ToUTF8( $String, $Charset = 'iso2')528 function ToUTF8(string $String, string $Charset = 'iso2'): string 529 529 { 530 530 $Result = ''; … … 540 540 } 541 541 542 function FromUTF8( $String, $Charset = 'iso2')542 function FromUTF8(string $String, string $Charset = 'iso2'): string 543 543 { 544 544 $Result = ''; -
trunk/Packages/Common/Update.php
r880 r888 3 3 class UpdateManager 4 4 { 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; 11 10 12 11 function __construct() … … 19 18 } 20 19 21 function GetDbVersion() 20 function GetDbVersion(): ?int 22 21 { 23 22 $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1'); … … 26 25 } 27 26 28 function IsInstalled() 27 function IsInstalled(): bool 29 28 { 30 29 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"'); … … 32 31 } 33 32 34 function IsUpToDate() 33 function IsUpToDate(): bool 35 34 { 36 35 return $this->Revision <= $this->GetDbVersion(); 37 36 } 38 37 39 function Upgrade() 38 function Upgrade(): string 40 39 { 41 40 $DbRevision = $this->GetDbVersion(); … … 43 42 while ($this->Revision > $DbRevision) 44 43 { 44 if (!array_key_exists($DbRevision, $this->Trace)) 45 die('Missing upgrade trace for revision '.$DbRevision); 45 46 $TraceItem = $this->Trace[$DbRevision]; 46 47 $Output .= 'Aktualizace na verzi '.$TraceItem['Revision'].':<br/>'; … … 57 58 } 58 59 59 function Install() 60 function Install(): void 60 61 { 61 62 $InstallMethod = $this->InstallMethod; 62 63 $InstallMethod($this); 63 $this->Update();64 64 } 65 65 66 function Uninstall() 66 function Uninstall(): void 67 67 { 68 69 68 } 70 69 71 function InsertSampleData() 70 function InsertSampleData(): void 72 71 { 73 72 $InstallMethod = $this->InsertSampleDataMethod; … … 75 74 } 76 75 77 function Execute( $Query)76 function Execute(string $Query): DatabaseResult 78 77 { 79 78 echo($Query.';<br/>');
Note:
See TracChangeset
for help on using the changeset viewer.