Changeset 507 for trunk/includes
- Timestamp:
- Feb 15, 2013, 10:12:08 PM (12 years ago)
- Location:
- trunk/includes
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Database.php
r457 r507 2 2 3 3 // Extended database class 4 // Date: 201 0-01-294 // Date: 2011-11-25 5 5 6 class Database extends mysqli 6 7 class DatabaseResult 7 8 { 8 var $HostName = 'localhost'; 9 var $UserName; 10 var $Password; 11 var $Schema; 12 var $Charset = 'utf8'; 13 var $Prefix = ''; 14 var $ShowSQLQuery = false; 15 var $ShowSQLError = false; 16 17 function open() 9 var $PDOStatement; 10 var $num_rows = 0; 11 12 function fetch_assoc() 18 13 { 19 parent::connect($this->HostName, $this->UserName, $this->Password, $this->Schema); 20 $this->charset($this->Charset); 14 return($this->PDOStatement->fetch(PDO::FETCH_ASSOC)); 15 } 16 17 function fetch_array() 18 { 19 return($this->PDOStatement->fetch(PDO::FETCH_BOTH)); 21 20 } 22 21 22 function fetch_row() 23 { 24 return($this->PDOStatement->fetch(PDO::FETCH_NUM)); 25 } 26 } 27 28 class Database 29 { 30 var $Prefix = ''; 31 var $Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()'); 32 var $Type = 'mysql'; // mysql, pgsql 33 var $PDO; 34 var $Error = ''; 35 var $insert_id; 36 var $LastQuery = ''; 37 var $ShowSQLError = false; 38 var $ShowSQLQuery = false; 39 40 function __construct($Host, $User, $Password, $Database) 41 { 42 if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 43 else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; 44 else $ConnectionString = ''; 45 $this->PDO = new PDO($ConnectionString, $User, $Password); 46 } 47 48 function select_db($Database) 49 { 50 $this->query('USE `'.$Database.'`'); 51 } 52 23 53 function query($Query) 24 54 { 25 26 if($this->ShowSQLQuery) 55 $this->LastQuery = $Query; 56 if($this->ShowSQLQuery == true) 57 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n"); 58 $Result = new DatabaseResult(); 59 $Result->PDOStatement = $this->PDO->query($Query); 60 if($Result->PDOStatement) 27 61 { 28 if(isset($_SERVER['REMOTE_ADDR'])) echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'); 29 else echo($Query."\n"); 62 $Result->num_rows = $Result->PDOStatement->rowCount(); 63 } else 64 { 65 $this->Error = $this->PDO->errorInfo(); 66 $this->Error = $this->Error[2]; 67 if(($this->Error != '') and ($this->ShowSQLError == true)) 68 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 30 69 } 31 $Result = parent::query($Query); 32 if(($this->error != '') and ($this->ShowSQLError)) 33 { 34 if(isset($_SERVER['REMOTE_ADDR'])) echo('<div><strong>SQL Error: </strong>'.$this->error.'<br />'.$Query.'</div>'); 35 echo('SQL Error: '.$this->error.' '.$Query."\n"); 36 } 37 70 $this->insert_id = $this->PDO->lastInsertId(); 38 71 return($Result); 39 72 } 40 73 41 74 function select($Table, $What = '*', $Condition = 1) 42 { 75 { 43 76 return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 44 77 } … … 56 89 { 57 90 $Name .= ',`'.$Key.'`'; 91 if(!in_array($Value, $this->Functions)) 92 { 93 if(is_null($Value)) $Value = 'NULL'; 94 else $Value = $this->PDO->quote($Value); 95 } 58 96 $Values .= ','.$Value; 59 97 } … … 61 99 $Values = substr($Values, 1); 62 100 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 101 $this->insert_id = $this->PDO->lastInsertId(); 63 102 } 64 103 … … 68 107 foreach($Data as $Key => $Value) 69 108 { 109 if(!in_array($Value, $this->Functions)) 110 { 111 if(is_null($Value)) $Value = 'NULL'; 112 else $Value = $this->PDO->quote($Value); 113 } 70 114 $Values .= ', `'.$Key.'`='.$Value; 71 115 } … … 80 124 foreach($Data as $Key => $Value) 81 125 { 126 if(!in_array($Value, $this->Functions)) 127 { 128 if(is_null($Value)) $Value = 'NULL'; 129 else $Value = $this->PDO->quote($Value); 130 } 82 131 $Name .= ',`'.$Key.'`'; 83 132 $Values .= ','.$Value; … … 94 143 $this->query('SET NAMES "'.$Charset.'"'); 95 144 } 145 146 function real_escape_string($Text) 147 { 148 return(addslashes($Text)); 149 } 150 151 } 96 152 97 function TimeToMysqlDateTime($Time) 98 { 99 return(date('Y-m-d H:i:s', $Time)); 100 } 153 function TimeToMysqlDateTime($Time) 154 { 155 if($Time == NULL) return(NULL); 156 else return(date('Y-m-d H:i:s', $Time)); 157 } 101 158 102 function MysqlDateTimeToTime($Time) 103 { 104 $Parts = explode(' ', $Time); 105 $DateParts = explode('-', $Parts[0]); 106 $TimeParts = explode(':', $Parts[1]); 107 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 108 return($Result); 109 } 159 function TimeToMysqlDate($Time) 160 { 161 if($Time == NULL) return(NULL); 162 else return(date('Y-m-d', $Time)); 163 } 110 164 111 function MysqlDateToTime($Time) 112 { 113 return($this->MysqlDateTimeToTime($Time.' 0:0:0')); 114 } 165 function TimeToMysqlTime($Time) 166 { 167 if($Time == NULL) return(NULL); 168 else return(date('H:i:s', $Time)); 169 } 170 171 function MysqlDateTimeToTime($DateTime) 172 { 173 if($DateTime == '') return(0); 174 $Parts = explode(' ', $DateTime); 175 $DateParts = explode('-', $Parts[0]); 176 $TimeParts = explode(':', $Parts[1]); 177 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 178 return($Result); 179 } 180 181 function MysqlDateToTime($Date) 182 { 183 if($Date == '') return(0); 184 return(MysqlDateTimeToTime($Date.' 0:0:0')); 185 } 186 187 function MysqlTimeToTime($Time) 188 { 189 if($Time == '') return(0); 190 return(MysqlDateTimeToTime('0000-00-00 '.$Time)); 115 191 } 116 192 -
trunk/includes/Page.php
r506 r507 189 189 if(isset($RSSChannels)) 190 190 foreach($RSSChannels as $Channel) 191 { 191 192 $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'. 192 193 $System->Link('/rss.php?channel='.$Channel['Channel']).'" type="application/rss+xml" />'; 194 } 193 195 $Output .= '<title>'.$System->Config['Web']['Title'].'</title> 194 196 </head> -
trunk/includes/error.php
r443 r507 1 1 <?php 2 3 include_once('global_function.php');4 2 5 3 function EmptyErrorHandler($Number, $Message, $Filename, $LineNumber, $Variables) … … 84 82 } 85 83 86 set_error_handler('CustomErrorHandler');84 //set_error_handler('CustomErrorHandler'); 87 85 88 86 ?> -
trunk/includes/global.php
r506 r507 1 1 <?php 2 2 3 $ScriptStartTime = GetMicrotime();4 5 if(isset($_SERVER['REMOTE_ADDR'])) session_start();6 7 // SQL injection hack protection8 foreach($_POST as $Index => $Item)9 {10 if(is_array($_POST[$Index]))11 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2);12 else $_POST[$Index] = addslashes($_POST[$Index]);13 }14 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);15 16 if(file_exists(dirname(__FILE__).'/config.php')) include_once(dirname(__FILE__).'/config.php');17 else die('Nenalezen konfigurační soubor config.php ve složce includes. '.18 'Vytvořte jej zkopírováním vzoru config.sample.php.');19 date_default_timezone_set($Config['Web']['Timezone']);20 3 include_once(dirname(__FILE__).'/Database.php'); 4 include_once(dirname(__FILE__).'/system.php'); 5 include_once(dirname(__FILE__).'/Update.php'); 21 6 include_once(dirname(__FILE__).'/rss.php'); 22 include_once(dirname(__FILE__).'/system.php');23 7 include_once(dirname(__FILE__).'/user.php'); 24 8 include_once(dirname(__FILE__).'/Page.php'); 25 26 $System = new System();27 $System->Init();28 $User = new User($System);29 30 9 include_once(dirname(__FILE__).'/error.php'); 31 10 32 $TranslationTree = GetTranslationTree(); 33 34 LogReferrer(); 11 GlobalInit(); 12 13 function GlobalInit() 14 { 15 global $System, $ScriptStartTime, $TranslationTree, $User, $StopAfterUpdateManager, 16 $UpdateManager, $Config; 17 18 $ScriptStartTime = GetMicrotime(); 19 20 if(isset($_SERVER['REMOTE_ADDR'])) session_start(); 21 22 if(file_exists(dirname(__FILE__).'/config.php')) include_once(dirname(__FILE__).'/config.php'); 23 else die('Nenalezen konfigurační soubor config.php ve složce includes. '. 24 'Vytvořte jej zkopírováním vzoru config.sample.php.'); 25 date_default_timezone_set($Config['Web']['Timezone']); 26 27 $Revision = 506; // Subversion revision 28 $ReleaseTime = '2013-02-15'; 29 30 $System = new System(); 31 $System->Init(); 32 33 // Check database persistence structure 34 $UpdateManager = new UpdateManager(); 35 $UpdateManager->Database = $System->Database; 36 $UpdateManager->Revision = $Revision; 37 if(isset($StopAfterUpdateManager)) return; 38 if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.'); 39 if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.'); 40 41 // SQL injection hack protection 42 foreach($_POST as $Index => $Item) 43 { 44 if(is_array($_POST[$Index])) 45 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2); 46 else $_POST[$Index] = addslashes($_POST[$Index]); 47 } 48 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 49 50 $User = new User($System); 51 52 set_error_handler('CustomErrorHandler'); 53 54 // TODO: Global initialized variable should be removed 55 $TranslationTree = GetTranslationTree(); 56 57 LogReferrer(); 58 } 35 59 36 60 $RSSChannels = array( … … 298 322 } 299 323 300 function MysqlDateTimeToTime($Time)301 {302 $Parts = explode(' ', $Time);303 $DateParts = explode('-', $Parts[0]);304 $TimeParts = explode(':', $Parts[1]);305 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);306 return($Result);307 }308 309 324 function GetLanguageList() 310 325 { … … 429 444 430 445 if(array_key_exists('language', $_GET)) $LanguageId = $_GET['language'] * 1; 431 else $LanguageId = 1;446 else $LanguageId = 2; 432 447 433 448 if(isset($LanguageList[$LanguageId]) == false) -
trunk/includes/system.php
r506 r507 24 24 function __construct() 25 25 { 26 $this->Database = new Database();27 26 $this->Config = array(); 28 27 } … … 30 29 function Init() 31 30 { 32 global $Config; 31 global $Config; 32 33 33 $this->Config = $Config; 34 $this->Database->HostName = $this->Config['Database']['Host']; 35 $this->Database->UserName = $this->Config['Database']['User']; 36 $this->Database->Password = $this->Config['Database']['Password']; 37 $this->Database->Schema = $this->Config['Database']['Database']; 38 $this->Database->Charset = $this->Config['Database']['Charset']; 34 $this->Database = new Database($this->Config['Database']['Host'], 35 $this->Config['Database']['User'], $this->Config['Database']['Password'], 36 $this->Config['Database']['Database']); 37 $this->Database->charset($this->Config['Database']['Charset']); 39 38 $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery']; 40 39 $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError']; 41 $this->Database->open();42 40 } 43 41
Note:
See TracChangeset
for help on using the changeset viewer.