array ( 'BaseIndex' => 0, 'Definition' => array ( array('', '', pow(2, 0)), array('Ki', 'kibi', pow(2, 10)), array('Mi', 'mebi', pow(2, 20)), array('Gi', 'gibi', pow(2, 30)), array('Ti', 'tebi', pow(2, 40)), array('Pi', 'pebi', pow(2, 50)), array('Ei', 'exbi', pow(2, 60)), array('Zi', 'zebi', pow(2, 70)), array('Yi', 'yobi', pow(2, 80)), ), ), 'Decimal' => array ( 'BaseIndex' => 8, 'Definition' => array ( array('y', 'yocto', pow(10, -24)), array('z', 'zepto', pow(10, -21)), array('a', 'atto', pow(10, -18)), array('f', 'femto', pow(10, -15)), array('p', 'piko', pow(10, -12)), array('n', 'nano', pow(10, -9)), array('u', 'mikro', pow(10, -6)), array('m', 'mili', pow(10, -3)), array('', '', pow(10, 0)), array('k', 'kilo', pow(10, 3)), array('M', 'mega', pow(10, 6)), array('G', 'giga', pow(10, 9)), array('T', 'tera', pow(10, 12)), array('P', 'peta', pow(10, 15)), array('E', 'exa', pow(10, 18)), array('Z', 'zetta', pow(10, 21)), array('Y', 'yotta', pow(10, 24)), ), ), 'Time' => array ( 'BaseIndex' => 8, 'Definition' => array ( array('ys', 'yoctosekunda', pow(10, -24)), array('zs', 'zeptosekunda', pow(10, -21)), array('as', 'attosekunda', pow(10, -18)), array('fs', 'femtosekunda', pow(10, -15)), array('ps', 'pikosekunda', pow(10, -12)), array('ns', 'nanosekunda', pow(10, -9)), array('us', 'mikrosekunda', pow(10, -6)), array('ms', 'milisekunda', pow(10, -3)), array('s', 'sekund', 1), array('minut', 'minuta', 60), array('hodin', 'hodina', 60 * 60) , array('dnů', 'den', 24 * 60 * 60), array('týdnů', 'týden', 7 * 24 * 60 * 60), array('měsíců', 'měsíc', 30 * 24 * 60 * 60), array('roků', 'rok', 364 * 24 * 60 * 60), array('desitiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60), array('staletí', 'staletí', 100 * 364 * 24 * 60 * 60), array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60), ), ), ); function ErrorHandler() { } class System { var $Modules = array(); var $Database; var $Config; var $TimeStart; var $Translation; function __construct() { global $Config; // Change current directory to script location $BaseDir = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/')); if($BaseDir != '') chdir($BaseDir); if(array_key_exists('argv', $_SERVER)) $_GET = array_merge($_GET, ParseCommandLineArgs($_SERVER['argv'])); // SQL injection hack protection foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item); foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item); if(isset($_SERVER['REMOTE_ADDR'])) session_start(); $FileName = dirname(__FILE__).'/../Application/Config/Config.php'; if(file_exists($FileName)) include_once($FileName); else die('Nenalezen soubor '.$FileName.'. Vytvořte jej kopií ze souboru ConfigSample.php umístěném ve stejné složce.'); $this->Config = $Config; $FileName = dirname(__FILE__).'/../Application/Localization/'.$Config['Web']['Locale'].'.php'; if(file_exists($FileName)) include_once($FileName); else die('Nenalezen soubor '.$FileName.'. Buď máte špatně nastaven jazyk nebo vám chybí jazykový soubor.'); $this->Translation = $Translation; $this->TimeStart = $this->GetMicrotime(); $this->Database = new Database($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']); $this->Database->Prefix = $this->Config['Database']['Prefix']; $this->Database->charset($this->Config['Database']['Charset']); $this->ModuleManager = new AppModuleManager($this); } function Run() { if(array_key_exists('Module', $_GET)) $Module = $_GET['Module']; else $Module = 'HomePage'; $ControllerName = $Module.'Controller'; $FileName = dirname(__FILE__).'/../Module/'.$Module.'/Controller.php'; if(!file_exists($FileName)) echo('Soubor '.$FileName.' nenalezen.'); else include($FileName); if(class_exists($ControllerName)) { $Controller = new $ControllerName($this); echo($Controller->Process()); } else echo('Modul '.$ControllerName.' nenalezen.'); } function ModulePresent($Name) { return(array_key_exists($Name, $this->Modules)); } function AddModule($Name) { $this->Modules[$Name] = new $Name($this); } function HumanDate($Time) { return(date('j.n.Y', $Time)); } function TruncateDigits($Value, $Digits = 4) { for($II = 2; $II > -6; $II--) { if($Value >= pow(10, $II)) { if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits; $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1); break; } } return($Value); } function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal') { global $PrefixMultipliers; $Negative = ($Value < 0); $Value = abs($Value); if(($Unit == '') and ($PrefixType != 'Time')) return($this->TruncateDigits($Value, $Digits)); $I = $PrefixMultipliers[$PrefixType]['BaseIndex']; if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit); if($Value > 1) { while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1)) $I = $I + 1; } else if($Value < 1) { while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1)) $I = $I - 1; } $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]; // Truncate digits count $Value = $this->TruncateDigits($Value, $Digits); if($Negative) $Value = -$Value; return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit); } function NetworkPortState($Address, $Port, $Timeout = 1) { set_error_handler('ErrorHandler'); if($Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout)) { fclose($Socket); $Result = true; } else $Result = false; restore_error_handler(); return($Result); } function GetMicrotime() { list($Usec, $Sec) = explode(' ', microtime()); return((float)$Usec + (float)$Sec); } function Translate($Text) { if(array_key_exists($Text, $this->Translation)) return($this->Translation[$Text]); else return('#'.$Text); } function GetRemoteAddress() { if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ; else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR']; else $IP = '0.0.0.0'; return($IP); } }