Changeset 887 for trunk/Packages/Common
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/AppModule.php
r880 r887 36 36 class AppModule 37 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; 60 61 function __construct(System $System) 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 bool $Running; 47 public bool $Enabled; 48 public bool $Installed; 49 public string $InstalledVersion; 50 public int $Type; 51 public array $Dependencies; 52 public Database $Database; 53 public Application $System; 54 public AppModuleManager $Manager; 55 public $OnChange; 56 public array $Models; 57 58 function __construct(Application $System) 62 59 { 63 60 $this->System = &$System; … … 73 70 $this->Dependencies = array(); 74 71 $this->Type = ModuleType::Normal; 75 } 76 77 function Install() 72 $this->Models = array(); 73 } 74 75 function Install(): void 78 76 { 79 77 if ($this->Installed) return; … … 87 85 } 88 86 89 function Uninstall() 87 function Uninstall(): void 90 88 { 91 89 if (!$this->Installed) return; … … 98 96 } 99 97 100 function Upgrade() 98 function Upgrade(): void 101 99 { 102 100 if (!$this->Installed) return; … … 108 106 } 109 107 110 function Reinstall() 108 function Reinstall(): void 111 109 { 112 110 $this->Uninstall(); … … 115 113 } 116 114 117 function Start() 115 function Start(): void 118 116 { 119 117 if ($this->Running) return; … … 126 124 } 127 125 128 function Stop() 126 function Stop(): void 129 127 { 130 128 if (!$this->Running) return; … … 136 134 } 137 135 138 function Restart() 136 function Restart(): void 139 137 { 140 138 $this->Stop(); … … 142 140 } 143 141 144 function Enable() 142 function Enable(): void 145 143 { 146 144 if ($this->Enabled) return; … … 152 150 } 153 151 154 function Disable() 152 function Disable(): void 155 153 { 156 154 if (!$this->Enabled) return; … … 162 160 } 163 161 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 162 protected function DoStart(): void 163 { 164 } 165 166 protected function DoStop(): void 167 { 168 } 169 170 protected function DoInstall(): void 171 { 172 } 173 174 protected function DoUninstall(): void 175 { 176 } 177 178 protected function DoUpgrade(): void 179 { 180 } 181 182 function AddModel(Model $Model): void 183 { 184 $this->Models[get_class($Model)] = $Model; 183 185 } 184 186 } … … 187 189 class AppModuleManager 188 190 { 189 var$Modules;190 var$System;191 var$FileName;192 var$ModulesDir;193 var$OnLoadModules;191 public array $Modules; 192 public System $System; 193 public string $FileName; 194 public string $ModulesDir; 195 public $OnLoadModules; 194 196 195 197 function __construct(System $System) … … 201 203 } 202 204 203 function Perform( $List, $Actions, $Conditions = array(ModuleCondition::All))205 function Perform(array $List, array $Actions, array $Conditions = array(ModuleCondition::All)): void 204 206 { 205 207 foreach ($List as $Index => $Module) … … 227 229 } 228 230 229 function EnumDependenciesCascade( $Module, &$List,$Conditions = array(ModuleCondition::All))231 function EnumDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All)) 230 232 { 231 233 foreach ($Module->Dependencies as $Dependency) … … 248 250 } 249 251 250 function EnumSuperiorDependenciesCascade( $Module, &$List,$Conditions = array(ModuleCondition::All))252 function EnumSuperiorDependenciesCascade(AppModule $Module, array &$List, array $Conditions = array(ModuleCondition::All)) 251 253 { 252 254 foreach ($this->Modules as $RefModule) … … 267 269 } 268 270 269 function Start() 271 function Start(): void 270 272 { 271 273 $this->LoadModules(); … … 274 276 } 275 277 276 function StartAll() 278 function StartAll(): void 277 279 { 278 280 $this->Perform($this->Modules, array(ModuleAction::Start)); 279 281 } 280 282 281 function StartEnabled() 283 function StartEnabled(): void 282 284 { 283 285 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled)); 284 286 } 285 287 286 function StopAll() 288 function StopAll(): void 287 289 { 288 290 $this->Perform($this->Modules, array(ModuleAction::Stop)); 289 291 } 290 292 291 function InstallAll() 293 function InstallAll(): void 292 294 { 293 295 $this->Perform($this->Modules, array(ModuleAction::Install)); … … 295 297 } 296 298 297 function UninstallAll() 299 function UninstallAll(): void 298 300 { 299 301 $this->Perform($this->Modules, array(ModuleAction::Uninstall)); … … 301 303 } 302 304 303 function EnableAll() 305 function EnableAll(): void 304 306 { 305 307 $this->Perform($this->Modules, array(ModuleAction::Enable)); … … 307 309 } 308 310 309 function DisableAll() 311 function DisableAll(): void 310 312 { 311 313 $this->Perform($this->Modules, array(ModuleAction::Disable)); … … 313 315 } 314 316 315 function ModulePresent( $Name)317 function ModulePresent(string $Name): bool 316 318 { 317 319 return array_key_exists($Name, $this->Modules); 318 320 } 319 321 320 function ModuleEnabled( $Name)322 function ModuleEnabled(string $Name): bool 321 323 { 322 324 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Enabled; 323 325 } 324 326 325 function ModuleRunning( $Name)327 function ModuleRunning(string $Name): bool 326 328 { 327 329 return array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Running; 328 330 } 329 331 330 /* @return Module */ 331 function SearchModuleById($Id) 332 function GetModule(string $Name): AppModule 333 { 334 return $this->Modules[$Name]; 335 } 336 337 function SearchModuleById(int $Id): string 332 338 { 333 339 foreach ($this->Modules as $Module) … … 339 345 } 340 346 341 function LoadState() 347 function LoadState(): void 342 348 { 343 349 $ConfigModules = array(); … … 355 361 } 356 362 357 function SaveState() 363 function SaveState(): void 358 364 { 359 365 $Data = array(); … … 369 375 } 370 376 371 function RegisterModule(AppModule $Module) 377 function RegisterModule(AppModule $Module): void 372 378 { 373 379 $this->Modules[$Module->Name] = &$Module; … … 376 382 } 377 383 378 function UnregisterModule(AppModule $Module) 384 function UnregisterModule(AppModule $Module): void 379 385 { 380 386 unset($this->Modules[array_search($Module, $this->Modules)]); 381 387 } 382 388 383 function LoadModulesFromDir( $Directory)389 function LoadModulesFromDir(string $Directory): void 384 390 { 385 391 $List = scandir($Directory); … … 395 401 } 396 402 397 function LoadModules() 403 function LoadModules(): void 398 404 { 399 405 if (is_array($this->OnLoadModules) and (count($this->OnLoadModules) == 2) and method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 400 $this->OnLoadModules();406 call_user_func($this->OnLoadModules); 401 407 else $this->LoadModulesFromDir($this->ModulesDir); 402 408 } -
trunk/Packages/Common/Application.php
r873 r887 3 3 class ModelDef 4 4 { 5 var$OnChange;6 5 public array $OnChange; 6 7 7 function __construct() 8 8 { 9 9 $this->OnChange = array(); 10 10 } 11 12 function DoOnChange() 11 12 function DoOnChange(): void 13 13 { 14 14 foreach ($this->OnChange as $Callback) … … 17 17 } 18 18 } 19 20 function RegisterOnChange( $SysName, $Callback)19 20 function RegisterOnChange(string $SysName, callable $Callback): void 21 21 { 22 22 $this->OnChange[$SysName] = $Callback; 23 23 } 24 25 function UnregisterOnChange( $SysName)24 25 function UnregisterOnChange(string $SysName): void 26 26 { 27 27 unset($this->OnChange[$SysName]); … … 29 29 } 30 30 31 class Command 32 { 33 public string $Name; 34 public string $Description; 35 public $Callback; 36 37 function __construct(string $Name, string $Description, callable $Callback) 38 { 39 $this->Name = $Name; 40 $this->Description = $Description; 41 $this->Callback = $Callback; 42 } 43 } 44 31 45 class Application extends System 32 46 { 33 var$Name;34 /** @var AppModuleManager */35 var $ModuleManager;36 var $Modules;37 var $Models;38 47 public string $Name; 48 public AppModuleManager $ModuleManager; 49 public array $Models; 50 public array $CommandLine; 51 public array $Pages; 52 39 53 function __construct() 40 54 { … … 42 56 $this->Name = 'Application'; 43 57 $this->ModuleManager = new AppModuleManager($this); 44 $this->Modules = array();45 58 $this->Models = array(); 59 $this->CommandLine = array(); 60 $this->Pages = array(); 61 62 $this->RegisterCommandLine('list', 'Prints available commands', array($this, 'ListCommands')); 46 63 } 47 48 function RegisterModel($SysName, $Model) 64 65 function GetModule(string $Name): AppModule 66 { 67 return $this->ModuleManager->Modules[$Name]; 68 } 69 70 function RegisterModel(string $SysName, array $Model): void 49 71 { 50 72 $NewModelDef = new ModelDef(); … … 53 75 } 54 76 55 function UnregisterModel( $SysName)77 function UnregisterModel(string $SysName): void 56 78 { 57 79 unset($this->Models[$SysName]); 58 80 } 59 60 function R un()81 82 function RegisterCommandLine(string $Name, string $Description, callable $Callback): void 61 83 { 84 $this->CommandLine[$Name] = new Command($Name, $Description, $Callback); 85 } 62 86 87 function UnrgisterCommandLine(string $Name): void 88 { 89 unset($this->CommandLine[$Name]); 90 } 91 92 function ListCommands(array $Parameters) 93 { 94 $Output = 'Available commands:'."\n"; 95 foreach ($this->CommandLine as $Command) 96 { 97 $Output .= ' '.$Command->Name.' - '.$Command->Description."\n"; 98 } 99 echo($Output."\n"); 100 } 101 102 function RegisterPage(array $Path, string $Handler): void 103 { 104 $Page = &$this->Pages; 105 $LastKey = array_pop($Path); 106 foreach ($Path as $PathItem) 107 { 108 $Page = &$Page[$PathItem]; 109 } 110 if (!is_array($Page)) $Page = array('' => $Page); 111 $Page[$LastKey] = $Handler; 112 } 113 114 function UnregisterPage(array $Path): void 115 { 116 $Page = &$this->Pages; 117 $LastKey = array_pop($Path); 118 foreach ($Path as $PathItem) 119 { 120 $Page = &$Page[$PathItem]; 121 } 122 unset($Page[$LastKey]); 123 } 124 125 function Run(): void 126 { 127 } 128 129 function Link(string $Target): string 130 { 131 return $Target; 63 132 } 64 133 } -
trunk/Packages/Common/Base.php
r790 r887 3 3 class System 4 4 { 5 /* @var Database */ 6 var $Database; 5 public Database $Database; 7 6 8 7 function __construct() … … 14 13 class Base 15 14 { 16 /** @var Application */ 17 var $System; 18 /* @var Database */ 19 var $Database; 15 public Application $System; 16 public Database $Database; 20 17 21 function __construct( Application$System)18 function __construct(System $System) 22 19 { 23 20 $this->System = &$System; -
trunk/Packages/Common/Common.php
r874 r887 26 26 class PackageCommon 27 27 { 28 var$Name;29 var$Version;30 var$ReleaseDate;31 var$License;32 var$Creator;33 var$Homepage;28 public string $Name; 29 public string $Version; 30 public int $ReleaseDate; 31 public string $License; 32 public string $Creator; 33 public string $Homepage; 34 34 35 35 function __construct() … … 46 46 class Paging 47 47 { 48 var$TotalCount;49 var$ItemPerPage;50 var$Around;51 var$SQLLimit;52 var$Page;48 public int $TotalCount; 49 public int $ItemPerPage; 50 public int $Around; 51 public string $SQLLimit; 52 public int $Page; 53 53 54 54 function __construct() … … 60 60 } 61 61 62 function Show() 62 function Show(): string 63 63 { 64 64 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); -
trunk/Packages/Common/Database.php
r874 r887 2 2 3 3 // Extended database class 4 // Date: 20 16-01-114 // Date: 2020-11-10 5 5 6 6 function microtime_float() … … 13 13 { 14 14 var $PDOStatement; 15 var$num_rows = 0;15 public int $num_rows = 0; 16 16 17 17 function fetch_assoc() … … 33 33 class Database 34 34 { 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 46 47 47 function __construct() … … 57 57 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 58 58 } 59 60 61 function Connect($Host, $User, $Password, $Database) 59 60 function Connect(string $Host, string $User, string $Password, string $Database) 62 61 { 63 62 if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; … … 79 78 } 80 79 81 function Connected() 80 function Connected(): bool 82 81 { 83 82 return isset($this->PDO); 84 83 } 85 84 86 function select_db( $Database)85 function select_db(string $Database) 87 86 { 88 87 $this->query('USE `'.$Database.'`'); 89 88 } 90 89 91 function query($Query) 90 function query($Query): DatabaseResult 92 91 { 93 92 if (!$this->Connected()) throw new Exception(T('Not connected to database')); … … 99 98 $Time = round(microtime_float() - $QueryStartTime, 4); 100 99 $Duration = ' ; '.$Time. ' s'; 101 } 100 } 102 101 if (($this->LogSQLQuery == true) and ($Time != 0)) 103 102 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); … … 112 111 $this->insert_id = $this->PDO->lastInsertId(); 113 112 } else 114 { 115 $ this->Error = $this->PDO->errorInfo();116 $this->Error = $ this->Error[2];113 { 114 $Error = $this->PDO->errorInfo(); 115 $this->Error = $Error[2]; 117 116 if (($this->Error != '') and ($this->ShowSQLError == true)) 118 117 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); … … 122 121 } 123 122 124 function select( $Table, $What = '*', $Condition = 1)123 function select(string $Table, string $What = '*', string $Condition = '1'): DatabaseResult 125 124 { 126 125 return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 127 126 } 128 127 129 function delete( $Table,$Condition)128 function delete(string $Table, string $Condition) 130 129 { 131 130 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 132 131 } 133 132 134 function insert( $Table,$Data)133 function insert(string $Table, array $Data) 135 134 { 136 135 $this->query($this->GetInsert($Table, $Data)); 137 136 $this->insert_id = $this->PDO->lastInsertId(); 138 137 } 139 140 function GetInsert( $Table, $Data)138 139 function GetInsert(string $Table, array $Data): string 141 140 { 142 141 $Name = ''; … … 157 156 } 158 157 159 function update( $Table, $Condition,$Data)158 function update(string $Table, string $Condition, array $Data) 160 159 { 161 160 $this->query($this->GetUpdate($Table, $Condition, $Data)); 162 161 } 163 164 function GetUpdate( $Table, $Condition, $Data)162 163 function GetUpdate(string $Table, string $Condition, array $Data): string 165 164 { 166 165 $Values = ''; … … 178 177 } 179 178 180 function replace( $Table,$Data)179 function replace(string $Table, array $Data) 181 180 { 182 181 $Name = ''; … … 199 198 } 200 199 201 function charset( $Charset)200 function charset(string $Charset) 202 201 { 203 202 $this->query('SET NAMES "'.$Charset.'"'); 204 203 } 205 204 206 function real_escape_string( $Text)205 function real_escape_string(string $Text): string 207 206 { 208 207 return addslashes($Text); 209 208 } 210 209 211 function quote( $Text)210 function quote(string $Text): string 212 211 { 213 212 return $this->PDO->quote($Text); … … 222 221 { 223 222 } 224 225 public function Transaction( $Queries)223 224 public function Transaction(array $Queries) 226 225 { 227 226 //echo('|'."\n"); -
trunk/Packages/Common/Error.php
r873 r887 3 3 class ErrorHandler 4 4 { 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; 9 9 10 10 function __construct() … … 75 75 } 76 76 77 function ShowDefaultError( $Message)77 function ShowDefaultError(string $Message): void 78 78 { 79 79 $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". -
trunk/Packages/Common/Generics.php
r869 r887 5 5 var $Items = array(); 6 6 7 function Add($Item) 7 function Add($Item): void 8 8 { 9 9 $this->Items[] = $Item; 10 10 } 11 11 12 function RemoveAt(int $Index) 12 function RemoveAt(int $Index): void 13 13 { 14 14 unset($this->Items[$Index]); -
trunk/Packages/Common/Image.php
r874 r887 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); … … 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
r874 r887 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 … … 98 98 } 99 99 100 function SaveToFile( $FileName)100 function SaveToFile(string $FileName): void 101 101 { 102 102 $Content = '<?php'."\n". … … 119 119 } 120 120 121 function LoadFromDatabase( $Database, $LangCode)121 function LoadFromDatabase(Database $Database, string $LangCode): void 122 122 { 123 123 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); … … 132 132 } 133 133 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)); 137 137 if ($DbResult->num_rows > 0) 138 138 { 139 139 $Language = $DbResult->fetch_assoc(); 140 $ Database->delete('Locale', '`Language`='.$Language['Id']);140 $this->Database->delete('Locale', '`Language`='.$Language['Id']); 141 141 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)); 150 150 if ($DbResult->num_rows > 0) 151 151 { … … 153 153 foreach ($this->Texts->Data as $Index => $Item) 154 154 { 155 $DbResult = $ Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).155 $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index). 156 156 ') AND (`Language`='.($Language['Id']).')'); 157 157 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'], 161 161 'Original' => $Index, 'Translated' => $Item)); 162 162 } … … 167 167 class LocaleManager extends Model 168 168 { 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; 175 175 176 176 function __construct(System $System) … … 182 182 $this->DefaultLangCode = 'en'; 183 183 $this->Available = array(); 184 } 185 186 function LoadAvailable() 184 $this->Dir = ''; 185 } 186 187 function LoadAvailable(): void 187 188 { 188 189 $this->Available = array(); … … 201 202 } 202 203 203 function UpdateAll( $Directory)204 function UpdateAll(string $Directory): void 204 205 { 205 206 $Locale = new LocaleFile($this->System); … … 222 223 if (!array_key_exists($Index, $Locale->Texts->Data)) 223 224 unset($FileLocale->Texts->Data[$Index]); 224 $FileLocale->UpdateToDatabase($ this->System->Database, $FileLocale->Texts->Code);225 $FileLocale->UpdateToDatabase($FileLocale->Texts->Code); 225 226 $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php'; 226 227 $FileLocale->SaveToFile($FileName); … … 230 231 } 231 232 232 function LoadLocale( $Code)233 function LoadLocale(string $Code): void 233 234 { 234 235 if (array_key_exists($Code, $this->Available)) … … 241 242 242 243 // Short named global translation function 243 function T( $Text, $Group = '')244 function T(string $Text, string $Group = ''): string 244 245 { 245 246 global $GlobalLocaleManager; -
trunk/Packages/Common/Mail.php
r874 r887 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; 21 22 22 23 function __construct() … … 28 29 } 29 30 30 function Clear() 31 function Clear(): void 31 32 { 32 33 $this->Bodies = array(); … … 41 42 } 42 43 43 function AddToCombined( $Address)44 function AddToCombined(string $Address): void 44 45 { 45 46 $this->Recipients[] = array('Address' => $Address, 'Type' => 'SendCombined'); 46 47 } 47 48 48 function AddTo( $Address, $Name)49 function AddTo(string $Address, string $Name): void 49 50 { 50 51 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Send'); 51 52 } 52 53 53 function AddCc( $Address, $Name)54 function AddCc(string $Address, string $Name): void 54 55 { 55 56 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Copy'); 56 57 } 57 58 58 function AddBcc( $Address, $Name)59 function AddBcc(string $Address, string $Name): void 59 60 { 60 61 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'HiddenCopy'); 61 62 } 62 63 63 function AddBody( $Content, $MimeType = 'text/plain', $Charset = 'utf-8')64 function AddBody(string $Content, string $MimeType = 'text/plain', string $Charset = 'utf-8'): void 64 65 { 65 66 $this->Bodies[] = array('Content' => $Content, 'Type' => strtolower($MimeType), … … 67 68 } 68 69 69 function Organization( $org)70 function Organization(string $org): void 70 71 { 71 72 if (trim($org != '')) $this->xheaders['Organization'] = $org; 72 73 } 73 74 74 function Priority( $Priority)75 function Priority(int $Priority): bool 75 76 { 76 77 if (!intval($Priority)) return false; 77 78 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]; 81 82 return true; 82 83 } 83 84 84 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT) 85 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT): void 85 86 { 86 87 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 88 89 } 89 90 90 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT) 91 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT): void 91 92 { 92 93 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 94 95 } 95 96 96 function Send() 97 function Send(): bool 97 98 { 98 99 if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body')); … … 144 145 if ($this->Subject == '') throw new Exception(T('Mail message missing Subject')); 145 146 146 147 147 $res = mail($To, $this->Subject, $Body, $Headers); 148 148 return $res; 149 149 } 150 150 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)) 155 155 return true; 156 156 else return false; 157 157 } 158 158 159 function CheckAdresses( $Addresses)159 function CheckAdresses(array $Addresses): void 160 160 { 161 161 foreach ($Addresses as $Address) 162 162 { 163 163 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 169 171 { 170 172 if ($Charset != CHARSET_ASCII) return '8bit'; … … 172 174 } 173 175 174 private function BuildAttachment($Body) 176 private function BuildAttachment($Body): string 175 177 { 176 178 if (count($this->Attachments) > 0) … … 206 208 } 207 209 208 private function BuildBody() 210 private function BuildBody(): string 209 211 { 210 212 $Result = ''; … … 219 221 $this->Headers['Content-Transfer-Encoding'] = $this->ContentEncoding($this->Bodies[0]['Charset']); 220 222 } 221 222 223 223 224 foreach ($this->Bodies as $Body) -
trunk/Packages/Common/Page.php
r874 r887 3 3 class Page extends View 4 4 { 5 var$FullTitle;6 var$ShortTitle;7 var$ParentClass;8 var$ClearPage;5 public string $FullTitle; 6 public string $ShortTitle; 7 public string $ParentClass; 8 public bool $ClearPage; 9 9 var $OnSystemMessage; 10 var$Load;11 var$Unload;10 public string $Load; 11 public string $Unload; 12 12 13 function __construct( $System)13 function __construct(System $System) 14 14 { 15 15 parent::__construct($System); 16 16 $this->ClearPage = false; 17 17 $this->OnSystemMessage = array(); 18 $this->FullTitle = ""; 19 $this->ShortTitle = ""; 20 $this->ParentClass = ""; 18 21 } 19 22 20 function Show() 23 function Show(): string 21 24 { 22 25 return ''; 23 26 } 24 27 25 function GetOutput() 28 function GetOutput(): string 26 29 { 27 30 $Output = $this->Show(); … … 29 32 } 30 33 31 function SystemMessage( $Title, $Text)34 function SystemMessage(string $Title, string $Text): string 32 35 { 33 36 return call_user_func_array($this->OnSystemMessage, array($Title, $Text)); -
trunk/Packages/Common/RSS.php
r874 r887 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/Setup.php
r874 r887 3 3 class PageSetup extends Page 4 4 { 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)5 public UpdateManager $UpdateManager; 6 public array $ConfigDefinition; 7 public array $Config; 8 public int $DatabaseRevision; 9 public int $Revision; 10 public string $ConfigDir; 11 public array $YesNo; 12 13 function __construct(System $System) 14 14 { 15 15 parent::__construct($System); 16 $this->Title = T('Application setup'); 16 $this->FullTitle = T('Application setup'); 17 $this->ShortTitle = T('Application setup'); 17 18 //$this->ParentClass = 'PagePortal'; 18 19 $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config'; … … 20 21 } 21 22 22 function LoginPanel() 23 function LoginPanel(): string 23 24 { 24 25 $Output = '<h3>Přihlášení k instalaci</h3>'. … … 32 33 } 33 34 34 function ControlPanel() 35 function ControlPanel(): string 35 36 { 36 37 $Output = '<h3>'.T('Instance management').'</h3>'; … … 62 63 } 63 64 64 function Show() 65 function Show(): string 65 66 { 66 67 global $ConfigDefinition, $DatabaseRevision, $Config, $Updates; … … 163 164 } 164 165 165 function ShowModules() 166 function ShowModules(): string 166 167 { 167 168 $Output = ''; … … 170 171 if ($Operation == 'install') 171 172 { 172 $this->System->ModuleManager-> Modules[$_GET['name']]->Install();173 $this->System->ModuleManager->GetModule($_GET['name'])->Install(); 173 174 $this->System->ModuleManager->SaveState(); 174 175 $Output .= 'Modul '.$_GET['name'].' instalován<br/>'; … … 176 177 if ($Operation == 'uninstall') 177 178 { 178 $this->System->ModuleManager-> Modules[$_GET['name']]->Uninstall();179 $this->System->ModuleManager->GetModule($_GET['name'])->Uninstall(); 179 180 $this->System->ModuleManager->SaveState(); 180 181 $Output .= 'Modul '.$_GET['name'].' odinstalován<br/>'; … … 182 183 if ($Operation == 'enable') 183 184 { 184 $this->System->ModuleManager-> Modules[$_GET['name']]->Enable();185 $this->System->ModuleManager->GetModule($_GET['name'])->Enable(); 185 186 $this->System->ModuleManager->SaveState(); 186 187 $Output .= 'Modul '.$_GET['name'].' povolen<br/>'; … … 188 189 if ($Operation == 'disable') 189 190 { 190 $this->System->ModuleManager-> Modules[$_GET['name']]->Disable();191 $this->System->ModuleManager->GetModule($_GET['name'])->Disable(); 191 192 $this->System->ModuleManager->SaveState(); 192 193 $Output .= 'Modul '.$_GET['name'].' zakázán<br/>'; … … 194 195 if ($Operation == 'upgrade') 195 196 { 196 $this->System->ModuleManager-> Modules[$_GET['name']]->Upgrade();197 $this->System->ModuleManager->GetModule($_GET['name'])->Upgrade(); 197 198 $this->System->ModuleManager->SaveState(); 198 199 $Output .= 'Modul '.$_GET['name'].' povýšen<br/>'; … … 203 204 } 204 205 205 function ShowList() 206 function ShowList(): string 206 207 { 207 208 $Output = ''; … … 247 248 } 248 249 249 function PrepareConfig($Config) 250 function PrepareConfig($Config): string 250 251 { 251 252 $Output = ''; … … 322 323 } 323 324 324 function CreateConfig($Config) 325 function CreateConfig($Config): string 325 326 { 326 327 $Output = "<?php\n\n". … … 359 360 class PageSetupRedirect extends Page 360 361 { 361 function Show() 362 function Show(): string 362 363 { 363 364 $Output = ''; … … 377 378 class Setup extends Model 378 379 { 379 var $UpdateManager;380 public UpdateManager $UpdateManager; 380 381 381 382 function Start() … … 383 384 global $DatabaseRevision; 384 385 385 $this->System->RegisterPage( '', 'PageSetupRedirect');386 $this->System->RegisterPage( 'setup', 'PageSetup');386 $this->System->RegisterPage([''], 'PageSetupRedirect'); 387 $this->System->RegisterPage(['setup'], 'PageSetup'); 387 388 388 389 // Check database persistence structure … … 396 397 { 397 398 unset($this->UpdateManager); 398 $this->System->UnregisterPage( '');399 $this->System->UnregisterPage( 'setup');400 } 401 402 function CheckState() 399 $this->System->UnregisterPage(['']); 400 $this->System->UnregisterPage(['setup']); 401 } 402 403 function CheckState(): bool 403 404 { 404 405 return $this->Database->Connected() and $this->UpdateManager->IsInstalled() and … … 432 433 } 433 434 434 function IsInstalled() 435 function IsInstalled(): bool 435 436 { 436 437 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"'); … … 438 439 } 439 440 440 function Upgrade() 441 function Upgrade(): string 441 442 { 442 443 $Updates = new Updates(); -
trunk/Packages/Common/Table.php
r874 r887 5 5 var $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
r874 r887 526 526 } 527 527 528 function ToUTF8 ($String, $Charset = 'iso2')528 function ToUTF8string ($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 = ''; … … 546 546 for ($I = 0; $I < strlen($String); $I++) 547 547 { 548 if (ord($String {$I}) & 0x80) // UTF control character548 if (ord($String[$I]) & 0x80) // UTF control character 549 549 { 550 if (ord($String {$I}) & 0x40) // First550 if (ord($String[$I]) & 0x40) // First 551 551 { 552 552 if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset])); 553 $UTFPrefix = $String {$I};553 $UTFPrefix = $String[$I]; 554 554 } 555 else $UTFPrefix .= $String {$I}; // Next555 else $UTFPrefix .= $String[$I]; // Next 556 556 } else 557 557 { 558 558 if ($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset])); 559 559 $UTFPrefix = ''; 560 $Result .= $String {$I};560 $Result .= $String[$I]; 561 561 } 562 562 } -
trunk/Packages/Common/Update.php
r874 r887 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() … … 63 62 $InstallMethod = $this->InstallMethod; 64 63 $InstallMethod($this); 65 $this->Update();66 64 } 67 65 … … 77 75 } 78 76 79 function Execute( $Query)77 function Execute(string $Query): DatabaseResult 80 78 { 81 79 echo($Query.';<br/>');
Note:
See TracChangeset
for help on using the changeset viewer.