- Timestamp:
- Dec 6, 2021, 11:33:48 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 14 added
- 3 deleted
- 29 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/BaseView.php
r94 r95 3 3 class BaseView extends View 4 4 { 5 function ShowPage( $Content)5 function ShowPage(string $Content): string 6 6 { 7 7 global $ReleaseTime, $Revision; … … 22 22 ' <a href="https://app.zdechov.net/estetistic/">Zdrojový kód</a></div>'; 23 23 $Output .= '</body></html>'; 24 echo($Output);24 return $Output; 25 25 } 26 26 27 function GetOutput( $Page)27 function GetOutput(Page $Page): string 28 28 { 29 29 $Output = $this->ShowPage($Page->Show()); -
trunk/Application/Core.php
r92 r95 6 6 include_once(dirname(__FILE__).'/../Global.php'); 7 7 include_once(dirname(__FILE__).'/Version.php'); 8 include_once(dirname(__FILE__).'/ View.php');8 include_once(dirname(__FILE__).'/BaseView.php'); 9 9 include_once(dirname(__FILE__).'/UpdateTrace.php'); 10 10 include_once(dirname(__FILE__).'/DefaultConfig.php'); 11 11 12 class Core extends Application12 class Core extends System 13 13 { 14 var$Pages;15 var$ShowPage;16 var$BaseURL;17 var$UseSession;14 public array $Pages; 15 public bool $ShowPage; 16 public string $BaseURL; 17 public bool $UseSession; 18 18 19 19 function __construct() … … 28 28 } 29 29 30 function RunCommon() 30 function RunCommon(): void 31 31 { 32 32 global $Config, $DatabaseRevision, $WithoutSessionStart; … … 38 38 //$ErrorHandler->Start(); 39 39 40 try { 40 try 41 { 41 42 $this->Database = new Database(); 42 43 $this->Database->Connect($Config['Database']['Host'], $Config['Database']['User'], … … 55 56 $this->Config = &$Config; 56 57 57 // Register and start existing modules 58 $this->Setup = new Setup($this); 59 $this->Setup->Start(); 60 if ($this->Setup->CheckState()) 58 $this->StartModules(); 59 } 60 61 function StartModules(): void 62 { 63 $ModuleSetup = $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/Setup.php'); 64 $ModuleSetup->Install(); 65 $ModuleSetup->Start(); 66 $this->ModuleManager->LoadModules(); 67 $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/ModuleManager.php'); 68 if (file_exists($this->ModuleManager->FileName)) $this->ModuleManager->LoadState(); 69 if (ModuleSetup::Cast($ModuleSetup)->CheckState()) 61 70 { 62 $this->ModuleManager->Start ();71 $this->ModuleManager->StartAll(array(ModuleCondition::Enabled)); 63 72 } 64 73 } 65 74 66 function Run() 75 function Run(): void 67 76 { 68 77 $this->RunCommon(); … … 74 83 } 75 84 76 function ShowPage() 85 static function Cast(System $System): Core 86 { 87 if ($System instanceof Core) 88 { 89 return $System; 90 } 91 throw new Exception('Expected Core type but '.gettype($System)); 92 } 93 94 function ShowPage(): void 77 95 { 78 96 $this->BaseView = new BaseView($this); … … 89 107 } 90 108 91 function RegisterPage($Path, $Handler) 92 { 93 if (is_array($Path)) 94 { 95 $Page = &$this->Pages; 96 $LastKey = array_pop($Path); 97 foreach ($Path as $PathItem) 98 { 99 $Page = &$Page[$PathItem]; 100 } 101 if (!is_array($Page)) $Page = array('' => $Page); 102 $Page[$LastKey] = $Handler; 103 } else $this->Pages[$Path] = $Handler; 104 } 105 106 function UnregisterPage($Path) 107 { 108 unset($this->Pages[$Path]); 109 } 110 111 function SearchPage($PathItems, $Pages) 109 function SearchPage(array $PathItems, array $Pages): string 112 110 { 113 111 if (count($PathItems) > 0) $PathItem = $PathItems[0]; … … 123 121 } 124 122 125 function Link( $Target)123 function Link(string $Target): string 126 124 { 127 125 return $this->BaseURL.$Target; … … 138 136 } 139 137 140 function Show() 138 function Show(): string 141 139 { 142 140 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); -
trunk/Application/DefaultConfig.php
r92 r95 3 3 class DefaultConfig 4 4 { 5 function Get() 5 function Get(): array 6 6 { 7 7 $IsDeveloper = in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1')); -
trunk/Application/UpdateTrace.php
r92 r95 1 1 <?php 2 2 3 function FullInstall($Manager) 3 function FullInstall($Manager): void 4 4 { 5 5 $Manager->Execute('CREATE TABLE IF NOT EXISTS `SystemVersion` ( … … 29 29 } 30 30 31 function UpdateTo67($Manager) 31 function UpdateTo67($Manager): void 32 32 { 33 33 $Manager->Execute('RENAME TABLE `measure` TO `Measure`;'); … … 58 58 } 59 59 60 function UpdateTo79($Manager) 60 function UpdateTo79($Manager): void 61 61 { 62 62 $DbResult = $Manager->Execute('SELECT `DataTable`,`DataType` FROM `Measure`;'); … … 78 78 class Updates 79 79 { 80 function Get() 80 function Get(): array 81 81 { 82 82 return array( -
trunk/Application/Version.php
r94 r95 6 6 // and system will need database update. 7 7 8 $Revision = 9 4;8 $Revision = 95; 9 9 $DatabaseRevision = 79; 10 $ReleaseTime = strtotime('202 0-05-25');10 $ReleaseTime = strtotime('2021-12-06'); -
trunk/Global.php
r92 r95 5 5 include_once('Packages/Common/Common.php'); 6 6 7 function HumanDate( $Time)7 function HumanDate(int $Time): string 8 8 { 9 9 return date('j.n.Y', $Time); 10 10 } 11 11 12 function GetMicrotime() 12 function GetMicrotime(): string 13 13 { 14 14 list($Usec, $Sec) = explode(" ", microtime()); … … 16 16 } 17 17 18 function MakeLink( $Target, $Title)18 function MakeLink(string $Target, string $Title): string 19 19 { 20 20 return '<a href="'.$Target.'">'.$Title.'</a>'; 21 21 } 22 22 23 function Table( $Table)23 function Table(array $Table): string 24 24 { 25 25 $Result = '<table cellspacing="0" class="BasicTable">'; … … 39 39 } 40 40 41 function ShowEditTable( $ClassName, $Values)41 function ShowEditTable(string $ClassName, array $Values): string 42 42 { 43 43 global $Classes, $Types; … … 72 72 } 73 73 74 function ProcessURL() 74 function ProcessURL(): array 75 75 { 76 76 if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER)) … … 86 86 } 87 87 88 function GetQueryStringArray( $QueryString)88 function GetQueryStringArray(string $QueryString): array 89 89 { 90 90 $Result = array(); … … 102 102 } 103 103 104 function SetQueryStringArray( $QueryStringArray)104 function SetQueryStringArray(array $QueryStringArray): string 105 105 { 106 106 $Parts = array(); -
trunk/Graph.php
r92 r95 5 5 class MeasureGraph 6 6 { 7 var$Database;8 var$FontSize;9 var$FontFileNameName;10 var$ValueToImageHeigthCoefficient;11 var$DefaultWidth;12 var$DefaultHeight;7 public Database $Database; 8 public int $FontSize; 9 public string $FontFileNameName; 10 public float $ValueToImageHeigthCoefficient; 11 public int $DefaultWidth; 12 public int $DefaultHeight; 13 13 14 14 function __construct(Database $Database) … … 22 22 } 23 23 24 function Render() 24 function Render(): void 25 25 { 26 26 global $Config; … … 138 138 $TimeRange = $EndTime - $StartTime; 139 139 $TimeMarksIndex = 0; 140 while ((($TimeRange / $TimeMarks[$TimeMarksIndex]) > 1) and ($TimeMarksIndex < (count($TimeMarks) - 1))) 140 while ((($TimeRange / $TimeMarks[$TimeMarksIndex]) > 1) and ($TimeMarksIndex < (count($TimeMarks) - 1))) 141 141 $TimeMarksIndex += 1; 142 142 if ($TimeMarksIndex < 2) $TimeMarksIndex = 2; -
trunk/Install/deb/debian/control
r83 r95 8 8 Package: estetistic 9 9 Architecture: all 10 Depends: ${shlibs:Depends}, ${misc:Depends}, apache2, php, dbconfig-mysql11 Description: Simple BrainFuck IDE written in Lazarus/FPC.12 HomePage: http://svn.zdechov.net/trac/ LazFuck10 Depends: ${shlibs:Depends}, ${misc:Depends}, apache2, php, php-gd, dbconfig-mysql 11 Description: PHP based graphing tool 12 HomePage: http://svn.zdechov.net/trac/estetistic -
trunk/Modules/Admin/Admin.php
r92 r95 1 1 <?php 2 2 3 class ModuleAdmin extends AppModule3 class ModuleAdmin extends Module 4 4 { 5 5 function __construct($System) … … 14 14 } 15 15 16 function DoStart() 16 function DoStart(): void 17 17 { 18 $this->System->RegisterPage('admin', 'PageAdmin'); 19 } 20 21 function DoInstall() 22 { 23 } 24 25 function DoUninstall() 26 { 27 } 28 29 function DoUpgrade() 30 { 18 $this->System->RegisterPage(['admin'], 'PageAdmin'); 31 19 } 32 20 } … … 39 27 } 40 28 41 function Show() 29 function Show(): string 42 30 { 43 31 if (array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = ''; … … 62 50 } 63 51 64 function ShowNone() 52 function ShowNone(): string 65 53 { 66 54 $Table = array( … … 78 66 } 79 67 80 function ShowEdit() 68 function ShowEdit(): string 81 69 { 82 70 $DbResult = $this->Database->select('Measure', '*', 'Id='.addslashes($_GET['MeasureId'])); … … 86 74 } 87 75 88 function ShowAdd() 76 function ShowAdd(): string 89 77 { 90 78 $Values = array(); … … 92 80 } 93 81 94 function ShowRebuildCache() 82 function ShowDelete(): string 83 { 84 return ''; 85 } 86 87 function ShowRebuildCache(): string 95 88 { 96 89 echo("Vytvařím novou cache...<br>"); … … 100 93 $Measure->RebuildMeasureCache(); 101 94 echo('Dokončeno<br>'); 95 return ''; 102 96 } 103 97 } -
trunk/Modules/Measure/Measure.php
r92 r95 3 3 include_once(dirname(__FILE__).'/Page.php'); 4 4 5 class ModuleMeasure extends AppModule5 class ModuleMeasure extends Module 6 6 { 7 7 function __construct($System) … … 16 16 } 17 17 18 function DoStart() 19 { 20 $this->System->RegisterPage( '', 'PageMain');21 } 22 23 function DoInstall() 24 { 25 $this->Database->query('CREATE TABLE IF NOT EXISTS `Measure` (26 `Id` int(11) NOT NULL auto_increment,27 `Name` varchar(255) collate utf8_general_ci NOT NULL,28 `Description` varchar(255) collate utf8_general_ci NOT NULL,29 `Divider` int(11) NOT NULL default 1,30 `Unit` varchar(16) collate utf8_general_ci NOT NULL,31 `Continuity` tinyint(1) NOT NULL default 0,32 `Period` int(11) NOT NULL default 60,33 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all",34 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain",35 `Info` varchar(255) collate utf8_general_ci NOT NULL,36 `Enabled` int(11) NOT NULL default 1,37 `Cumulative` int(11) NOT NULL default 0,38 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data",39 `DataType` varchar(32) collate utf8_general_ci NOT NULL,40 PRIMARY KEY (`Id`)41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');42 43 44 function DoUninstall() 18 function DoStart(): void 19 { 20 $this->System->RegisterPage(array(''), 'PageMain'); 21 } 22 23 function DoInstall(): void 24 { 25 $this->Database->query('CREATE TABLE IF NOT EXISTS `Measure` ( 26 `Id` int(11) NOT NULL auto_increment, 27 `Name` varchar(255) collate utf8_general_ci NOT NULL, 28 `Description` varchar(255) collate utf8_general_ci NOT NULL, 29 `Divider` int(11) NOT NULL default 1, 30 `Unit` varchar(16) collate utf8_general_ci NOT NULL, 31 `Continuity` tinyint(1) NOT NULL default 0, 32 `Period` int(11) NOT NULL default 60, 33 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all", 34 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain", 35 `Info` varchar(255) collate utf8_general_ci NOT NULL, 36 `Enabled` int(11) NOT NULL default 1, 37 `Cumulative` int(11) NOT NULL default 0, 38 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data", 39 `DataType` varchar(32) collate utf8_general_ci NOT NULL, 40 PRIMARY KEY (`Id`) 41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 42 } 43 44 function DoUninstall(): void 45 45 { 46 46 $this->Database->query('DROP TABLE IF EXISTS `Measure`'); 47 }48 49 function DoUpgrade()50 {51 52 47 } 53 48 } … … 81 76 } 82 77 83 function TimeSegment( $Level)78 function TimeSegment(int $Level): int 84 79 { 85 80 return pow($this->LevelReducing, $Level) * 60; 86 81 } 87 82 88 function GetDataTable() 83 function GetDataTable(): string 89 84 { 90 85 return 'data_'.$this->Data['Name']; 91 86 } 92 87 93 function AlignTime( $Time, $TimeSegment)88 function AlignTime(int $Time, int $TimeSegment): int 94 89 { 95 90 return round(($Time - $this->ReferenceTime) / $TimeSegment) * $TimeSegment + … … 97 92 } 98 93 99 function Load( $Id)94 function Load(int $Id): void 100 95 { 101 96 $Result = $this->Database->select('Measure', '*', '`Id`='.$Id); … … 108 103 } 109 104 110 function AddValue( $Value, $Time)105 function AddValue(float $Value, int $Time): void 111 106 { 112 107 $Result = $this->Database->select($this->Data['DataTable'], '*', '(`Measure`='.$this->Data['Id'].') AND '. … … 163 158 } 164 159 165 function UpdateHigherLevels( $Time)160 function UpdateHigherLevels(int $Time): void 166 161 { 167 162 for ($Level = 1; $Level <= $this->MaxLevel; $Level++) … … 206 201 207 202 /* Compute one value for upper time level from multiple values */ 208 function ComputeOneValue( $LeftTime, $RightTime, $Values, $Level)203 function ComputeOneValue(int $LeftTime, int $RightTime, array $Values, int $Level): array 209 204 { 210 205 $NewValue = array('Min' => +1000000000000000000, 'Avg' => 0, 'Max' => -1000000000000000000); … … 294 289 } 295 290 296 function GetTimeRange( $Level)291 function GetTimeRange(int $Level): array 297 292 { 298 293 // Get first and last time … … 317 312 318 313 // Load one nearest value newer then given time 319 function LoadRightSideValue( $Level, $Time)314 function LoadRightSideValue(int $Level, int $Time): array 320 315 { 321 316 $Result = array(); … … 350 345 351 346 // Load one nearest value older then given time 352 function LoadLeftSideValue( $Level, $Time)347 function LoadLeftSideValue(int $Level, int $Time): array 353 348 { 354 349 $Result = array(); … … 382 377 } 383 378 384 function GetValues( $TimeFrom, $TimeTo, $Level)379 function GetValues(int $TimeFrom, int $TimeTo, int $Level): array 385 380 { 386 381 //$AbsoluteTime = GetTimeRange($this->DataId); … … 430 425 } 431 426 432 function RebuildMeasureCache() 427 function RebuildMeasureCache(): void 433 428 { 434 429 echo('Velicina '.$this->Data['Name']."<br>\n"); … … 508 503 } 509 504 510 function RebuildAllMeasuresCache() 505 function RebuildAllMeasuresCache(): void 511 506 { 512 507 $Result = $this->Database->select('Measure', 'Id'); 513 508 while ($Row = $Result->fetch_array()) 514 509 { 515 $Measure = new Measure( );510 $Measure = new Measure($this->Database); 516 511 $Measure->Load($Row['Id']); 517 512 $Measure->RebuildMeasureCache(); … … 520 515 } 521 516 522 function ClearData() 517 function ClearData(): void 523 518 { 524 519 $this->Database->delete($this->Data['DataTable'], '1'); -
trunk/Modules/Measure/Page.php
r92 r95 44 44 $this->Time = time(); 45 45 } 46 47 function GetTimeRange() 46 47 function GetTimeRange(): string 48 48 { 49 49 if (!array_key_exists($_SESSION['Period'], $this->GraphTimeRanges)) 50 50 $_SESSION['Period'] = 'day'; 51 51 52 52 $Result = $this->GraphTimeRanges[$_SESSION['Period']]['period']; 53 53 if ($Result == -1) … … 61 61 } 62 62 63 function EditTime($Time) 63 function EditTime($Time): string 64 64 { 65 65 $Output = '<form style="display: inline;" action="?Operation=SetTime&Time='.$Time.'" method="post">'; … … 119 119 return $Output; 120 120 } 121 122 function GetFirstMeasure($Measure) 121 122 function GetFirstMeasure($Measure): array 123 123 { 124 124 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` ASC LIMIT 1'); … … 135 135 } 136 136 137 function GetLastMeasure($Measure) 137 function GetLastMeasure($Measure): array 138 138 { 139 139 $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` DESC LIMIT 1'); … … 149 149 return array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue); 150 150 } 151 152 function LoadMeasure($Id) 151 152 function LoadMeasure($Id): array 153 153 { 154 154 $DbResult = $this->Database->select('Measure', '*', '( `Enabled`=1) AND (`Id`='.$Id.') AND ((`PermissionView`="all") OR (`PermissionView`="'. 155 gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))'); 155 gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))'); 156 156 $DbRow = $DbResult->fetch_array(); 157 157 return $DbRow; 158 158 } 159 159 160 160 /* Produce table with available measures */ 161 function ShowMeasureTable() 161 function ShowMeasureTable(): string 162 162 { 163 163 $PrefixMultiplier = new PrefixMultiplier(); … … 195 195 $LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'. 196 196 $Interpolate.'</td><td>'.$Measure['Info'].'</td>'; 197 if (array_key_exists('Debug', $_GET)) 197 if (array_key_exists('Debug', $_GET)) 198 198 $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>'; 199 199 $Output .= '</tr>'; … … 203 203 } 204 204 205 function ShowGraph() 205 function ShowGraph(): string 206 206 { 207 207 $Output = '<strong>Graf:</strong><br>'; … … 217 217 } 218 218 219 function ShowTimeRange() 219 function ShowTimeRange(): string 220 220 { 221 221 $Output = ''; … … 269 269 270 270 } 271 272 function HandleURL() 273 { 274 global $Config; 275 276 foreach ($Config['DefaultVariables'] as $Index => $Variable) 271 272 function HandleURL(): void 273 { 274 foreach ($this->System->Config['DefaultVariables'] as $Index => $Variable) 277 275 { 278 276 if (!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable; … … 285 283 $_SESSION['Period'] = $_GET['Period']; 286 284 // Update time start according time period 287 if ($_SESSION['Period'] == 'all') 285 if ($_SESSION['Period'] == 'all') 288 286 { 289 287 $Measure = $this->LoadMeasure($_SESSION['Measure']); … … 322 320 $_SESSION['TimeSpecify'] = $_GET['TimeSpecify']; 323 321 } 324 322 325 323 if (array_key_exists('Move', $_GET)) 326 324 { 327 325 $Move = $_GET['Move']; 328 if ($Move == 'Left') 326 if ($Move == 'Left') 329 327 { 330 328 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] - $this->GetTimeRange(); 331 329 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] - $this->GetTimeRange(); 332 330 } else 333 if ($Move == 'Right') 331 if ($Move == 'Right') 334 332 { 335 333 $_SESSION['TimeStart'] = $_SESSION['TimeStart'] + $this->GetTimeRange(); 336 334 $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] + $this->GetTimeRange(); 337 } else 335 } else 338 336 if ($Move == 'Now') 339 337 { … … 358 356 } 359 357 360 function Show() 358 function Show(): string 361 359 { 362 360 global $Config; … … 364 362 $Debug = 0; 365 363 $this->HandleURL(); 366 364 367 365 $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>'; 368 366 -
trunk/Packages/Common/Base.php
r94 r95 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 $this->System = $System; 24 $this->Database = $System->Database; 10 $this->System = &$System; 11 $this->Database = &$System->Database; 12 } 13 14 static function GetClassName() 15 { 16 return get_called_class(); 25 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
r94 r95 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'); 21 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'); 22 32 23 33 class PackageCommon 24 34 { 25 var$Name;26 var$Version;27 var$ReleaseDate;28 var$License;29 var$Creator;30 var$Homepage;35 public string $Name; 36 public string $Version; 37 public int $ReleaseDate; 38 public string $License; 39 public string $Creator; 40 public string $Homepage; 31 41 32 42 function __construct() 33 43 { 34 44 $this->Name = 'Common'; 35 $this->Version = '1. 3';36 $this->ReleaseDate = strtotime('20 19-10-04');45 $this->Version = '1.2'; 46 $this->ReleaseDate = strtotime('2020-03-29'); 37 47 $this->Creator = 'Chronos'; 38 $this->License = 'GNU/GPL ';48 $this->License = 'GNU/GPLv3'; 39 49 $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/'; 40 50 } 41 51 } 42 52 43 class Paging extends Base53 class Paging 44 54 { 45 var$TotalCount;46 var$ItemPerPage;47 var$Around;48 var$SQLLimit;49 var$Page;55 public int $TotalCount; 56 public int $ItemPerPage; 57 public int $Around; 58 public string $SQLLimit; 59 public int $Page; 50 60 51 function __construct( Application &$System)61 function __construct() 52 62 { 53 parent::__construct($System);63 global $System; 54 64 55 65 $this->ItemPerPage = $System->Config['Web']['ItemsPerPage']; … … 57 67 } 58 68 59 function Show() 69 function Show(): string 60 70 { 61 71 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); -
trunk/Packages/Common/Config.php
r92 r95 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
r92 r95 2 2 3 3 // Extended database class 4 // Date: 20 16-01-114 // Date: 2020-11-10 5 5 6 6 function microtime_float() … … 12 12 class DatabaseResult 13 13 { 14 var$PDOStatement;15 var$num_rows = 0;14 public PDOStatement $PDOStatement; 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 public string $Database; 46 47 47 48 function __construct() 48 49 { 49 50 $this->Prefix = ''; 50 $this->Functions = array('NOW( )', 'CURDATE()', 'CURTIME()', 'UUID()');51 $this->Functions = array('NOW(', 'CURDATE(', 'CURTIME(', 'UUID(', 'SHA1('); 51 52 $this->Type = 'mysql'; // mysql, pgsql 52 53 $this->Error = ''; … … 56 57 $this->LogSQLQuery = false; 57 58 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 58 }59 60 61 function Connect( $Host, $User, $Password, $Database)59 $this->Database = ''; 60 } 61 62 function Connect(string $Host, string $User, string $Password, string $Database): void 62 63 { 63 64 if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 64 65 else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; 65 66 else $ConnectionString = ''; 67 $this->Database = $Database; 66 68 try { 67 69 $this->PDO = new PDO($ConnectionString, $User, $Password); 68 69 70 } catch (Exception $E) 70 71 { … … 74 75 } 75 76 76 function Disconnect() 77 function Disconnect(): void 77 78 { 78 79 unset($this->PDO); 79 80 } 80 81 81 function Connected() 82 function Connected(): bool 82 83 { 83 84 return isset($this->PDO); 84 85 } 85 86 86 function select_db( $Database)87 function select_db(string $Database) 87 88 { 88 89 $this->query('USE `'.$Database.'`'); 89 90 } 90 91 91 function query($Query) 92 function query($Query): DatabaseResult 92 93 { 93 94 if (!$this->Connected()) throw new Exception(T('Not connected to database')); … … 96 97 //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float()); 97 98 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 98 $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s'; 99 if ($this->LogSQLQuery == true) 99 { 100 $Time = round(microtime_float() - $QueryStartTime, 4); 101 $Duration = ' ; '.$Time. ' s'; 102 } 103 if (($this->LogSQLQuery == true) and ($Time != 0)) 100 104 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); 101 105 if ($this->ShowSQLQuery == true) … … 103 107 'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n"); 104 108 $Result = new DatabaseResult(); 105 $Result->PDOStatement = $this->PDO->query($Query); 106 if ($Result->PDOStatement) 107 { 108 $Result->num_rows = $Result->PDOStatement->rowCount(); 109 $Statement = $this->PDO->query($Query); 110 if ($Statement) 111 { 112 $Result->PDOStatement = $Statement; 113 $Result->num_rows = $Statement->rowCount(); 109 114 $this->insert_id = $this->PDO->lastInsertId(); 110 115 } else 111 { 112 $ this->Error = $this->PDO->errorInfo();113 $this->Error = $ this->Error[2];116 { 117 $Error = $this->PDO->errorInfo(); 118 $this->Error = $Error[2]; 114 119 if (($this->Error != '') and ($this->ShowSQLError == true)) 115 120 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); … … 119 124 } 120 125 121 function select( $Table, $What = '*', $Condition = 1)126 function select(string $Table, string $What = '*', string $Condition = '1'): DatabaseResult 122 127 { 123 128 return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 124 129 } 125 130 126 function delete( $Table, $Condition)131 function delete(string $Table, string $Condition): void 127 132 { 128 133 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 129 134 } 130 135 131 function insert( $Table, $Data)136 function insert(string $Table, array $Data): int 132 137 { 133 138 $this->query($this->GetInsert($Table, $Data)); 134 139 $this->insert_id = $this->PDO->lastInsertId(); 135 } 136 137 function GetInsert($Table, $Data) 140 return $this->insert_id; 141 } 142 143 function IsFunction(string $Text): bool 144 { 145 $Pos = strpos($Text, '('); 146 return ($Pos !== false) && in_array(substr($Text, 0, $Pos + 1), $this->Functions); 147 } 148 149 function GetInsert(string $Table, array $Data): string 138 150 { 139 151 $Name = ''; … … 142 154 { 143 155 $Name .= ',`'.$Key.'`'; 144 if (!in_array($Value, $this->Functions)) 156 if (is_null($Value)) $Value = 'NULL'; 157 else if (!$this->IsFunction($Value)) 145 158 { 146 if (is_null($Value)) $Value = 'NULL'; 147 else $Value = $this->PDO->quote($Value); 159 $Value = $this->PDO->quote($Value); 148 160 } 149 161 $Values .= ','.$Value; … … 154 166 } 155 167 156 function update( $Table, $Condition, $Data)168 function update(string $Table, string $Condition, array $Data): void 157 169 { 158 170 $this->query($this->GetUpdate($Table, $Condition, $Data)); 159 171 } 160 161 function GetUpdate( $Table, $Condition, $Data)172 173 function GetUpdate(string $Table, string $Condition, array $Data): string 162 174 { 163 175 $Values = ''; 164 176 foreach ($Data as $Key => $Value) 165 177 { 166 if (!in_array($Value, $this->Functions)) 178 if (is_null($Value)) $Value = 'NULL'; 179 else if (!$this->IsFunction($Value)) 167 180 { 168 if (is_null($Value)) $Value = 'NULL'; 169 else $Value = $this->PDO->quote($Value); 181 $Value = $this->PDO->quote($Value); 170 182 } 171 183 $Values .= ', `'.$Key.'`='.$Value; … … 175 187 } 176 188 177 function replace( $Table, $Data)189 function replace(string $Table, array $Data): void 178 190 { 179 191 $Name = ''; … … 181 193 foreach ($Data as $Key => $Value) 182 194 { 183 if (!in_array($Value, $this->Functions)) 195 if (is_null($Value)) $Value = 'NULL'; 196 else if (!$this->IsFunction($Value)) 184 197 { 185 if (is_null($Value)) $Value = 'NULL'; 186 else $Value = $this->PDO->quote($Value); 198 $Value = $this->PDO->quote($Value); 187 199 } 188 200 $Name .= ',`'.$Key.'`'; … … 196 208 } 197 209 198 function charset( $Charset)210 function charset(string $Charset): void 199 211 { 200 212 $this->query('SET NAMES "'.$Charset.'"'); 201 213 } 202 214 203 function real_escape_string( $Text)215 function real_escape_string(string $Text): string 204 216 { 205 217 return addslashes($Text); 206 218 } 207 219 208 function quote( $Text)220 function quote(string $Text): string 209 221 { 210 222 return $this->PDO->quote($Text); 211 223 } 212 224 213 public function __sleep() 225 public function __sleep(): array 214 226 { 215 227 return array('LastQuery'); 216 228 } 217 229 218 public function __wakeup() 219 { 220 } 221 222 public function Transaction($Queries) 223 { 224 $this->PDO->beginTransaction(); 225 foreach ($Queries as $Query) 226 { 227 $Statement = $this->PDO->prepare($Query); 228 $Statement->execute(); 229 } 230 $this->PDO->commit(); 230 public function __wakeup(): void 231 { 232 } 233 234 public function Transaction(array $Queries): void 235 { 236 //echo('|'."\n"); 237 $this->PDO->beginTransaction(); 238 foreach ($Queries as $Query) 239 { 240 //echo('|'.$Query."\n"); 241 $Statement = $this->PDO->prepare($Query); 242 $Statement->execute(); 243 } 244 $this->PDO->commit(); 245 } 246 247 public function TableExists(string $Name): bool 248 { 249 $DbResult = $this->query('SELECT * FROM information_schema.tables WHERE table_schema = "'.$this->Database. 250 '" AND table_name = "'.$Name.'" LIMIT 1'); 251 return $DbResult->num_rows != 0; 231 252 } 232 253 } -
trunk/Packages/Common/Error.php
r92 r95 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() … … 63 63 } 64 64 65 function ExceptionHandler( Exception$Exception)65 function ExceptionHandler(Throwable $Exception) 66 66 { 67 67 $Backtrace = $Exception->getTrace(); … … 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". … … 85 85 $Output .= '<pre>'.$Message.'</pre><br/>'; 86 86 $Output .= '</body></html>'; 87 error_log($Message);88 87 echo($Output); 89 88 } -
trunk/Packages/Common/Image.php
r92 r95 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() … … 33 33 $this->Y = 0; 34 34 } 35 36 35 } 37 36 38 37 class Brush 39 38 { 40 var$Color;39 public int $Color; 41 40 42 41 function __construct() … … 44 43 $this->Color = COLOR_BLACK; 45 44 } 46 47 45 } 48 46 49 47 class Image 50 48 { 51 var $Image; 52 var $Type; 53 var $Font; 54 var $Pen; 49 public $Image; 50 public int $Type; 51 public Font $Font; 52 public Pen $Pen; 53 public Brush $Brush; 55 54 56 55 function __construct() … … 63 62 } 64 63 65 function SaveToFile( $FileName)64 function SaveToFile(string $FileName): void 66 65 { 67 66 if ($this->Type == IMAGETYPE_JPEG) … … 71 70 if ($this->Type == IMAGETYPE_GIF) 72 71 { 73 imagegif 72 imagegif($this->Image, $FileName); 74 73 } else 75 74 if ($this->Type == IMAGETYPE_PNG) … … 79 78 } 80 79 81 function LoadFromFile( $FileName)80 function LoadFromFile(string $FileName): void 82 81 { 83 82 $ImageInfo = getimagesize($FileName); … … 89 88 if ($this->Type == IMAGETYPE_GIF) 90 89 { 91 $this->Image = imagecreatefromgif ($FileName);90 $this->Image = imagecreatefromgif ($FileName); 92 91 } else 93 92 if ( $this->Type == IMAGETYPE_PNG) … … 97 96 } 98 97 99 function Output() 98 function Output(): void 100 99 { 101 $this->SaveToFile( NULL);100 $this->SaveToFile(''); 102 101 } 103 102 104 function SetSize( $Width, $Height)103 function SetSize(int $Width, int $Height): void 105 104 { 106 105 $NewImage = imagecreatetruecolor($Width, $Height); … … 110 109 } 111 110 112 function GetWidth() 111 function GetWidth(): int 113 112 { 114 113 return imagesx($this->Image); 115 114 } 116 115 117 function GetHeight() 116 function GetHeight(): int 118 117 { 119 118 return imagesy($this->Image); 120 119 } 121 120 122 function TextOut( $X, $Y, $Text)121 function TextOut(int $X, int $Y, string $Text): void 123 122 { 124 123 imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text); 125 124 } 126 125 127 function ConvertColor( $Color)126 function ConvertColor(int $Color): int 128 127 { 129 128 return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff); 130 129 } 131 130 132 function FillRect( $X1, $Y1, $X2, $Y2)131 function FillRect(int $X1, int $Y1, int $X2, int $Y2): void 133 132 { 134 133 imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color)); 135 134 } 136 135 137 function Line( $X1, $Y1, $X2, $Y2)136 function Line(int $X1, int $Y1, int $X2, int $Y2): void 138 137 { 139 138 imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color)); -
trunk/Packages/Common/Locale.php
r92 r95 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
r92 r95 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/NetworkAddress.php
r92 r95 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(); … … 92 109 } 93 110 94 function EncodeMAC( $MAC)111 function EncodeMAC(string $MAC): void 95 112 { 96 113 $MAC = explode(':', $MAC); … … 107 124 } 108 125 126 function Contain(NetworkAddressIPv6 $Address): bool 127 { 128 $UpperNetmask = $this->GetNetMask(); 129 if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true; 130 else $Result = false; 131 return $Result; 132 } 109 133 } -
trunk/Packages/Common/Page.php
r92 r95 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
r92 r95 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/Process.php
r93 r95 3 3 class Process 4 4 { 5 var$Command;6 var$Handle;7 var$Pipes;8 var$Environment;9 var$WorkingDir;10 5 public string $Command; 6 public $Handle; 7 public array $Pipes; 8 public array $Environment; 9 public ?string $WorkingDir; 10 11 11 function __construct() 12 12 { … … 17 17 $this->WorkingDir = null; 18 18 } 19 20 function Start() 19 20 function Start(): void 21 21 { 22 if (!$this->IsRunning())22 if (!$this->IsRunning()) 23 23 { 24 24 $DescriptorSpec = array( … … 28 28 ); 29 29 30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 31 31 $this->WorkingDir, $this->Environment); 32 32 stream_set_blocking($this->Pipes[0], FALSE); … … 35 35 } 36 36 } 37 38 function Stop() 37 38 function Stop(): void 39 39 { 40 if ($this->IsRunning())40 if ($this->IsRunning()) 41 41 { 42 42 proc_close($this->Handle); … … 44 44 } 45 45 } 46 47 function IsRunning() 46 47 function IsRunning(): bool 48 48 { 49 return (is_resource($this->Handle));49 return is_resource($this->Handle); 50 50 } 51 51 } -
trunk/Packages/Common/RSS.php
r92 r95 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
r94 r95 1 1 <?php 2 2 3 class Control extends Base3 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 function __construct( Application $System)100 function __construct() 101 101 { 102 parent::__construct($System);102 global $System; 103 103 104 104 $this->Columns = array(); 105 105 $this->Table = new TableMemory(); 106 106 $this->OrderDirSQL = array('ASC', 'DESC'); 107 $this->OrderArrowImage = array($ this->System->Link('/images/sort_asc.png'),108 $ this->System->Link('/images/sort_desc.png'));107 $this->OrderArrowImage = array($System->Link('/images/sort_asc.png'), 108 $System->Link('/images/sort_desc.png')); 109 109 $this->DefaultOrder = 0; 110 110 $this->Style = 'BaseTable'; … … 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
r92 r95 526 526 } 527 527 528 function ToUTF8 ($String, $Charset = 'iso2')528 function ToUTF8string(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 = ''; … … 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
r92 r95 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(); … … 59 58 } 60 59 61 function Install() 60 function Install(): void 62 61 { 63 62 $InstallMethod = $this->InstallMethod; 64 63 $InstallMethod($this); 65 $this->Update();66 64 } 67 65 68 function Uninstall() 66 function Uninstall(): void 69 67 { 70 71 68 } 72 69 73 function InsertSampleData() 70 function InsertSampleData(): void 74 71 { 75 72 $InstallMethod = $this->InsertSampleDataMethod; … … 77 74 } 78 75 79 function Execute( $Query)76 function Execute(string $Query): DatabaseResult 80 77 { 81 78 echo($Query.';<br/>'); -
trunk/Point.php
r92 r95 3 3 class Point 4 4 { 5 var$X;6 var$Y;5 public int $X; 6 public int $Y; 7 7 8 function __construct( $X,$Y)8 function __construct(int $X, int $Y) 9 9 { 10 10 $this->X = $X; … … 13 13 } 14 14 15 function NewPoint( $X, $Y)15 function NewPoint(int $X, int $Y): Point 16 16 { 17 17 $Point = new Point($X, $Y); … … 20 20 21 21 /* Linear interpolation between two points */ 22 function Interpolation(Point $P1, Point $P2, $X) 22 function Interpolation(Point $P1, Point $P2, $X): float 23 23 { 24 24 $Y = ($P2->Y - $P1->Y) / ($P2->X - $P1->X) * ($X - $P1->X) + $P1->Y; -
trunk/Types.php
r92 r95 3 3 $Types = array( 4 4 'Boolean' => array( 5 6 5 ), 7 6 'String' => array( 8 9 7 ), 10 8 'Integer' => array( 11 12 9 ), 13 10 ); -
trunk/add.php
r92 r95 16 16 if (array_key_exists('Time', $_GET)) $Time = $_GET['Time'] * 1; 17 17 AddValue(addslashes($_GET['MeasureId']), addslashes($_GET['Value']), $Time); 18 $AddedValues = $AddedValues + 1; 18 $AddedValues = $AddedValues + 1; 19 19 } 20 20 … … 26 26 if (array_key_exists('Time'.$I, $_GET)) $Time = $_GET['Time'.$I] * 1; 27 27 AddValue(addslashes($_GET['MeasureId'.$I]), addslashes($_GET['Value'.$I]), $Time); 28 $AddedValues = $AddedValues + 1; 28 $AddedValues = $AddedValues + 1; 29 29 $I++; 30 30 } … … 32 32 if ($AddedValues == 0) echo('Nebyly zadány potřebné parametry MeasureId a Value.'."\n"); 33 33 34 function AddValue( $MeasureId, $Value, $Time)34 function AddValue(int $MeasureId, float $Value, int $Time): void 35 35 { 36 36 global $Core;
Note:
See TracChangeset
for help on using the changeset viewer.