Changeset 816 for trunk/includes
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- Location:
- trunk/includes
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Application.php
r815 r816 3 3 class Application 4 4 { 5 6 5 var $Name; 6 var $System; 7 7 8 9 8 function Run() 9 { 10 10 11 11 } 12 12 } -
trunk/includes/Database.php
r800 r816 40 40 function __construct() 41 41 { 42 43 44 45 46 47 42 $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()'); 43 $this->Type = 'mysql'; // mysql, pgsql 44 $this->ShowSQLError = false; 45 $this->ShowSQLQuery = false; 46 $this->LogSQLQuery = false; 47 $this->LogFile = dirname(__FILE__).'/../Query.log'; 48 48 } 49 49 … … 63 63 function query($Query) 64 64 { 65 65 if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime(); 66 66 $this->LastQuery = $Query; 67 67 $Result = new DatabaseResult(); … … 167 167 function quote($Text) 168 168 { 169 169 return($this->PDO->quote($Text)); 170 170 } 171 171 -
trunk/includes/Locale.php
r815 r816 3 3 class LocaleText 4 4 { 5 6 7 5 var $Data; 6 var $Code; 7 var $Title; 8 8 9 9 function __construct() 10 10 { 11 12 13 14 } 15 16 17 18 19 20 21 22 23 24 25 11 $this->Data = array(); 12 $this->Code = 'en'; 13 $this->Title = 'English'; 14 } 15 16 function Load() 17 { 18 } 19 20 function Translate($Text) 21 { 22 if(array_key_exists($Text, $this->Data) and ($this->Data[$Text] != '')) 23 return($this->Data[$Text]); 24 else return($Text); 25 } 26 26 } 27 27 28 28 class LocaleFile extends Model 29 29 { 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 { 52 30 var $Texts; 31 var $Dir; 32 33 function __construct($System) 34 { 35 parent::__construct($System); 36 $this->Texts = new LocaleText(); 37 } 38 39 function Load($Language) 40 { 41 $FileName = $this->Dir.'/'.$Language.'.php'; 42 if(file_exists($FileName)) { 43 include_once($FileName); 44 $ClassName = 'LocaleText'.$Language; 45 $this->Texts = new $ClassName(); 46 } else throw new Exception('Language file '.$FileName.' not found'); 47 $this->Texts->Load(); 48 } 49 50 function AnalyzeCode($Path) 51 { 52 // Search for php files 53 53 $FileList = scandir($Path); 54 54 foreach($FileList as $FileName) 55 55 { 56 57 58 59 56 $FullName = $Path.'/'.$FileName; 57 if(($FileName == '.') or ($FileName == '..')) ; // Skip virtual items 58 else if(substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files 59 else if(is_dir($FullName)) $this->AnalyzeCode($FullName); 60 60 else if(file_exists($FullName)) 61 61 { 62 62 if(substr($FullName, -4) == '.php') 63 63 { 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 64 $Content = file_get_contents($FullName); 65 // Search occurence of T() function 66 while(strpos($Content, 'T(') !== false) 67 { 68 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); 69 $Content = substr($Content, strpos($Content, 'T(') + 2); 70 $Ord = ord($Previous); 71 //echo($Ord.','); 72 if(!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 73 { 74 // Do for non-alpha previous character 75 $Original = substr($Content, 0, strpos($Content, ')')); 76 $Original2 = ''; 77 if((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'")) 78 $Original2 = substr($Original, 1, -1); 79 if((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"')) 80 $Original2 = substr($Original, 1, -1); 81 if($Original2 != '') 82 { 83 if(!array_key_exists($Original2, $this->Texts->Data)) 84 $this->Texts->Data[$Original2] = ''; 85 } 86 } 87 } 88 88 } 89 89 } … … 93 93 function SaveToFile($FileName) 94 94 { 95 95 $Content = '<?php'."\n". 96 96 ''."\n". 97 97 'class LocaleText'.$this->Texts->Code.' extends LocaleText'."\n". 98 98 '{'."\n". 99 100 101 102 103 104 105 106 107 108 109 99 ' function Load()'."\n". 100 ' {'."\n". 101 ' $this->Code = \''.$this->Texts->Code.'\';'."\n". 102 ' $this->Title = \''.$this->Texts->Title.'\';'."\n". 103 ' $this->Data = array('."\n"; 104 foreach($this->Texts->Data as $Index => $Item) 105 { 106 $Content .= " '".$Index."' => '".$Item."',\n"; 107 } 108 $Content .= ' );'."\n". 109 ' }'."\n". 110 110 '}'."\n"; 111 111 file_put_contents($FileName, $Content); … … 114 114 function LoadFromDatabase($Database, $LangCode) 115 115 { 116 117 118 119 120 121 122 123 124 116 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); 117 if($DbResult->num_rows > 0) 118 { 119 $Language = $DbResult->fetch_assoc(); 120 $this->Texts->Data = array(); 121 $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$Language['Id']); 122 while($DbRow = $DbResult->fetch_assoc()) 123 $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated']; 124 } 125 125 } 126 126 127 127 function SaveToDatabase(Database $Database, $LangCode) 128 128 { 129 130 131 132 133 134 135 136 137 129 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); 130 if($DbResult->num_rows > 0) 131 { 132 $Language = $DbResult->fetch_assoc(); 133 $Database->delete('Locale', '`Language`='.$Language['Id']); 134 foreach($this->Texts->Data as $Index => $Item) 135 $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 136 'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')'); 137 } 138 138 } 139 139 140 140 function UpdateToDatabase(Database $Database, $LangCode) 141 141 { 142 143 144 145 146 147 { 148 149 150 142 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); 143 if($DbResult->num_rows > 0) 144 { 145 $Language = $DbResult->fetch_assoc(); 146 foreach($this->Texts->Data as $Index => $Item) 147 { 148 $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).') AND (`Language`='.($Language['Id']).')'); 149 if($DbResult->num_rows > 0) 150 $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 151 151 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); 152 152 else $Database->insert('Locale', array('Language' => $Language['Id'], 153 153 'Original' => $Index, 'Translated' => $Item)); 154 154 } 155 155 } 156 156 } 157 157 } … … 159 159 class LocaleManager extends Model 160 160 { 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 161 var $CurrentLocale; 162 var $Codes; 163 var $Dir; 164 165 function __construct($System) 166 { 167 parent::__construct($System); 168 $this->Codes = array('en'); 169 $this->CurrentLocale = new LocaleFile($System); 170 } 171 172 function LoadAvailable() 173 { 174 $this->Available = array(); 175 $FileList = scandir($this->Dir); 176 176 foreach($FileList as $FileName) 177 177 { 178 179 180 181 182 183 184 185 186 187 } 188 189 190 191 192 193 178 if(substr($FileName, -4) == '.php') 179 { 180 $Code = substr($FileName, 0, -4); 181 $Locale = new LocaleFile($this->System); 182 $Locale->Dir = $this->Dir; 183 $Locale->Load($Code); 184 $this->Available['Code'] = array('Code' => $Code, 'Title' => $Locale->Texts->Title); 185 } 186 } 187 } 188 189 function UpdateAll($Directory) 190 { 191 $Locale = new LocaleFile($this->System); 192 $Locale->AnalyzeCode($Directory); 193 $FileList = scandir($this->Dir); 194 194 foreach($FileList as $FileName) 195 195 { 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 196 if(substr($FileName, -4) == '.php') 197 { 198 $FileLocale = new LocaleFile($this->System); 199 $FileLocale->Dir = $this->Dir; 200 $FileLocale->Load(substr($FileName, 0, -4)); 201 202 // Add new 203 foreach($Locale->Texts->Data as $Index => $Item) 204 if(!array_key_exists($Index, $FileLocale->Texts->Data)) 205 $FileLocale->Texts->Data[$Index] = $Item; 206 // Remove old 207 foreach($FileLocale->Texts->Data as $Index => $Item) 208 if(!array_key_exists($Index, $Locale->Texts->Data)) 209 unset($FileLocale->Texts->Data[$Index]); 210 $FileLocale->UpdateToDatabase($this->System->Database, $FileLocale->Texts->Code); 211 $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php'; 212 $FileLocale->SaveToFile($FileName); 213 } 214 } 215 $this->CurrentLocale->Load($this->CurrentLocale->Texts->Code); 216 } 217 218 function LoadLocale($Code) 219 { 220 220 $this->CurrentLocale->Dir = $this->Dir; 221 222 221 $this->CurrentLocale->Load($Code); 222 } 223 223 } 224 224 … … 226 226 function T($Text) 227 227 { 228 229 230 231 232 } 228 global $LocaleManager; 229 230 if(isset($LocaleManager)) return($LocaleManager->CurrentLocale->Texts->Translate($Text)); 231 else return($Text); 232 } -
trunk/includes/Page.php
r768 r816 7 7 var $RawPage; 8 8 var $Title; 9 9 10 10 function __construct($System) 11 11 { … … 14 14 $this->RawPage = false; 15 15 } 16 17 18 19 20 } 21 16 17 function Show() 18 { 19 return(''); 20 } 21 22 22 function GetOutput() 23 { 24 25 23 { 24 $Output = $this->Show(); 25 return($Output); 26 26 } 27 27 } … … 29 29 class PageEdit extends Page 30 30 { 31 32 33 34 35 36 31 var $Table; 32 var $Definition; 33 var $ItemActions; 34 35 function __construct($System) 36 { 37 37 parent::__construct($System); 38 38 $this->Table = ''; … … 41 41 array('Name' => T('View'), 'URL' => '?action=view&id=#Id'), 42 42 ); 43 $this->AllowEdit = false; 43 $this->AllowEdit = false; 44 44 if($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id'); 45 46 47 48 49 50 if(array_key_exists('action', $_GET))45 } 46 47 function Show() 48 { 49 $Output = ''; 50 if(array_key_exists('action', $_GET)) 51 51 { 52 if($_GET['action'] == 'add') $Output .= $this->AddItem(); 52 if($_GET['action'] == 'add') $Output .= $this->AddItem(); 53 53 else if($_GET['action'] == 'view') $Output .= $this->ViewItem(); 54 54 else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem(); … … 56 56 else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem(); 57 57 else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL); 58 } else $Output .= $this->ViewList(); 59 return($Output); 58 } else $Output .= $this->ViewList(); 59 return($Output); 60 60 } 61 61 62 62 function ViewItem() 63 63 { 64 65 66 67 64 $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']); 65 if($DbResult->num_rows > 0) 66 { 67 $DbRow = $DbResult->fetch_assoc(); 68 68 69 69 $Output = T('Item'). … … 71 71 foreach($this->Definition as $DefIndex => $Def) 72 72 { 73 74 } 73 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>'; 74 } 75 75 $Output .= '<tr>'. 76 76 '</table>'; 77 78 if($this->AllowEdit) 79 80 81 82 83 84 85 return($Output); 77 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 78 if($this->AllowEdit) 79 { 80 $Output .= '<a href="?action=add">'.T('Add').'</a> '; 81 $Output .= '<a href="?action=edit&id='.$_GET['id'].'">'.T('Edit').'</a> '; 82 $Output .= '<a href="?action=delete&id='.$_GET['id'].'">'.T('Add').'</a> '; 83 } 84 $Output .= '<a href="?">'.T('List').'</a><br/>'; 85 return($Output); 86 86 } 87 87 88 88 function ViewList() 89 89 { 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 90 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`'); 91 $DbRow = $DbResult->fetch_row(); 92 $PageList = GetPageList($DbRow[0]); 93 $Output = $PageList['Output']; 94 95 $Output .= '<table class="BaseTable">'; 96 $TableColumns = array(); 97 foreach($this->Definition as $Index => $Def) 98 if($Def['InList']) 99 $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']); 100 if(count($this->ItemActions) > 0) 101 $TableColumns[] = array('Name' => '', 'Title' => 'Akce'); 102 103 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 104 $Output .= $Order['Output']; 105 106 $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']); 107 while($Item = $DbResult->fetch_assoc()) 108 { 109 $Output .= '<tr>'; 110 110 foreach($this->Definition as $Index => $Def) 111 111 if($Def['InList']) 112 112 { 113 114 113 if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>'; 114 else $Output .= '<td>'.$Item[$Index].'</td>'; 115 115 } 116 116 if(count($this->ItemActions) > 0) 117 { 118 119 120 121 122 117 { 118 $Output .= '<td>'; 119 foreach($this->ItemActions as $Index => $Action) 120 { 121 $URL = $Action['URL']; 122 if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL); 123 123 $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> '; 124 }124 } 125 125 $Output .= '</td>'; 126 126 } 127 $Output .= '</tr>'; 128 129 130 131 127 $Output .= '</tr>'; 128 } 129 $Output .= '</table>'; 130 if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>'; 131 return($Output); 132 132 } 133 134 133 134 function AddItem() 135 135 { 136 136 $Output = ''; 137 137 if($this->System->User->Licence(LICENCE_USER)) 138 138 { 139 140 141 142 143 144 $Items[$Index] = $_POST[$Index];145 146 147 $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION);148 } else149 139 if(array_key_exists('finish', $_GET)) 140 { 141 $Items = array(); 142 foreach($this->Definition as $Index => $Def) 143 { 144 $Items[$Index] = $_POST[$Index]; 145 } 146 $this->Database->insert($this->Table, $Items); 147 $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION); 148 } else 149 { 150 150 $Output .= '<form action="?action=add&finish=1" method="post">'. 151 151 '<fieldset><legend>'.T('New item').'</legend>'. … … 153 153 foreach($this->Definition as $DefIndex => $Def) 154 154 { 155 156 } 155 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>'; 156 } 157 157 $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'. 158 158 '</table>'. 159 159 '</fieldset>'. 160 160 '</form>'; 161 161 } 162 162 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 163 return($Output); 164 } 165 166 163 return($Output); 164 } 165 166 function DeleteItem() 167 167 { 168 168 if($this->System->User->Licence(LICENCE_USER)) … … 173 173 return($Output); 174 174 } 175 175 176 176 function GetControl($Type, $Name, $Value) 177 177 { 178 179 180 181 182 } 178 if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 179 else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>'; 180 else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 181 return($Output); 182 } 183 183 184 184 function ViewControl($Type, $Name, $Value) 185 185 { 186 187 188 189 190 191 } 186 if($Type == 'Text') $Output = $Value; 187 else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>'; 188 else if($Type == 'Boolean') $Output = $Value; 189 else $Output = $Value; 190 return($Output); 191 } 192 192 } -
trunk/includes/Update.php
r815 r816 11 11 function __construct() 12 12 { 13 14 15 13 $this->Revision = 0; 14 $this->Trace = array(); 15 $this->VersionTable = 'DbVersion'; 16 16 } 17 17 18 18 function GetDbVersion() 19 19 { 20 21 20 $DbResult = $this->Database->select('DbVersion', '*', 'Id=1'); 21 $Version = $DbResult->fetch_assoc(); 22 22 return($Version['Revision']); 23 23 } … … 25 25 function IsInstalled() 26 26 { 27 27 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"'); 28 28 return($DbResult->num_rows > 0); 29 29 } … … 31 31 function IsUpToDate() 32 32 { 33 33 return($this->Revision <= $this->GetDbVersion()); 34 34 } 35 35 36 36 function Update() 37 37 { 38 39 40 38 $DbRevision = $this->GetDbVersion(); 39 $Output = 'Počáteční revize databáze: '.$DbRevision.'<br/>'; 40 while($this->Revision > $DbRevision) 41 41 { 42 43 44 45 46 47 48 49 42 $TraceItem = $this->Trace[$DbRevision]; 43 $Output .= 'Aktualizace na verzi: '.$TraceItem['Revision'].'<br/>'; 44 $RevUpdate = $TraceItem['Function']; 45 $RevUpdate($this); 46 $DbRevision = $TraceItem['Revision']; 47 $this->Database->query('UPDATE `DbVersion` SET `Revision`= '.$TraceItem['Revision'].' WHERE `Id`=1'); 48 } 49 return($Output); 50 50 } 51 51 52 52 function Install() 53 53 { 54 55 56 54 $InstallMethod = $this->InstallMethod; 55 $InstallMethod($this); 56 $this->Update(); 57 57 } 58 58 … … 64 64 function Execute($Query) 65 65 { 66 67 68 66 echo($Query.'<br/>'); 67 flush(); 68 return($this->Database->query($Query)); 69 69 } 70 70 } -
trunk/includes/Version.php
r815 r816 6 6 // and system will need database update. 7 7 8 $Revision = 81 5; // Subversion revision8 $Revision = 816; // Subversion revision 9 9 $DatabaseRevision = 811; // Database structure revision 10 10 $ReleaseTime = '2015-02-22'; -
trunk/includes/global.php
r806 r816 42 42 $System = new System(); 43 43 $System->DoNotShowPage = true; 44 44 $System->Run(); 45 45 $User = $System->User; // Back compatibility, will be removed 46 46 } … … 48 48 class TempPage extends Page 49 49 { 50 51 52 53 54 50 function Show() 51 { 52 global $TempPageContent; 53 return($TempPageContent); 54 } 55 55 } 56 56 57 57 function ShowPageClass($Page) 58 58 { 59 59 global $TempPageContent, $System; 60 60 61 61 $System->Pages['temporary-page'] = get_class($Page); 62 62 $_SERVER['REDIRECT_QUERY_STRING'] = 'temporary-page'; 63 63 $System->PathItems = ProcessURL(); 64 64 $System->ShowPage(); 65 65 } 66 66 67 67 function ShowPage($Content) 68 68 { 69 69 global $TempPageContent, $System; 70 70 71 71 $TempPage = new TempPage($System); 72 72 $System->Pages['temporary-page'] = 'TempPage'; 73 74 73 $_SERVER['REDIRECT_QUERY_STRING'] = 'temporary-page'; 74 $TempPageContent = $Content; 75 75 $System->PathItems = ProcessURL(); 76 76 $System->ShowPage(); 77 77 } 78 78 … … 260 260 if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; 261 261 if(array_key_exists('OrderDir', $_GET) and (array_key_exists($_GET['OrderDir'], $OrderArrowImage))) 262 262 $_SESSION['OrderDir'] = $_GET['OrderDir']; 263 263 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn; 264 264 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder; … … 557 557 } 558 558 559 function GetTranslatNamesArray() 559 function GetTranslatNamesArray() 560 560 { 561 561 $TablesColumn = array … … 733 733 734 734 $IconName = array( 735 735 MESSAGE_INFORMATION => 'information', 736 736 MESSAGE_WARNING => 'warning', 737 737 MESSAGE_CRITICAL => 'critical' 738 738 ); 739 739 $BackgroundColor = array( 740 740 MESSAGE_INFORMATION => '#e0e0ff', 741 741 MESSAGE_WARNING => '#ffffe0', 742 742 MESSAGE_CRITICAL => '#ffe0e0' 743 743 ); 744 744 745 745 return('<div class="message" style="background-color: '.$BackgroundColor[$Type]. 746 747 748 746 ';"><table><tr><td class="icon"><img src="'. 747 $System->Link('/images/message/'.$IconName[$Type].'.png').'" alt="'. 748 $IconName[$Type].'"><td>'.$Text.'</td></tr></table></div>'); 749 749 } 750 750 751 751 function ProcessURL() 752 752 { 753 754 755 756 757 758 759 760 761 753 if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER)) 754 $PathString = $_SERVER['REDIRECT_QUERY_STRING']; 755 else $PathString = ''; 756 if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1); 757 $PathItems = explode('/', $PathString); 758 if(strpos(GetRequestURI(), '?') !== false) 759 $_SERVER['QUERY_STRING'] = substr(GetRequestURI(), strpos(GetRequestURI(), '?') + 1); 760 else $_SERVER['QUERY_STRING'] = ''; 761 parse_str($_SERVER['QUERY_STRING'], $_GET); 762 762 // SQL injection hack protection 763 763 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 764 764 return($PathItems); 765 765 } 766 766 767 767 function WriteLanguages($Selected) 768 768 { 769 770 771 772 773 774 775 776 777 778 779 780 781 769 global $System; 770 771 $Output = '<select name="Language">'; 772 $DbResult = $System->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1'); 773 while($Language = $DbResult->fetch_assoc()) 774 { 775 $Output .= '<option value="'.$Language['Id'].'"'; 776 if($Selected == $Language['Id']) 777 $Output .= ' selected="selected"'; 778 $Output .= '>'.$Language['Name'].'</option>'; 779 } 780 $Output .= '</select>'; 781 return($Output); 782 782 } 783 783 -
trunk/includes/system.php
r812 r816 25 25 function Init() 26 26 { 27 27 global $Config, $LocaleManager; 28 28 29 29 $this->Config = $Config; … … 59 59 $this->Menu = array 60 60 ( 61 /* 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 61 /* array( 62 'Title' => T('Files'), 63 'Hint' => 'Stahování různých pomocných souborů a programů', 64 'Link' => $this->Link('/download.php'), 65 'Permission' => LICENCE_ANONYMOUS, 66 'Icon' => '', 67 ), 68 */ 69 array( 70 'Title' => T('Instructions'), 71 'Hint' => 'Informace k překladu hry', 72 'Link' => $this->Link('/info.php'), 73 'Permission' => LICENCE_ANONYMOUS, 74 'Icon' => '', 75 ), 76 array( 77 'Title' => T('Data source'), 78 'Hint' => 'Informace o překladových skupinách', 79 'Link' => $this->Link('/TranslationList.php?action=grouplist'), 80 'Permission' => LICENCE_ANONYMOUS, 81 'Icon' => '', 82 ), 83 array( 84 'Title' => T('Presentation'), 85 'Hint' => 'Prezentace a motivace překladu', 86 'Link' => $this->Link('/promotion.php'), 87 'Permission' => LICENCE_ANONYMOUS, 88 'Icon' => '', 89 ), 90 array( 91 'Title' => T('IRC chat'), 92 'Hint' => 'IRC chat pro překladatele', 93 'Link' => 'http://embed.mibbit.com/?server=game.zdechov.net%3A6667&channel=%23wowpreklad&forcePrompt=true&charset=utf-8', 94 'Permission' => LICENCE_ANONYMOUS, 95 'Icon' => '', 96 ), 97 array( 98 'Title' => T('Administration'), 99 'Hint' => 'Volby pro správu', 100 'Link' => $this->Link('/admin/'), 101 'Permission' => LICENCE_ADMIN, 102 'Icon' => '', 103 ), 104 104 ); 105 105 } … … 108 108 { 109 109 global $System, $ScriptStartTime, $TranslationTree, $User, $StopAfterUpdateManager, 110 110 $UpdateManager, $Config, $DatabaseRevision; 111 111 112 112 $ScriptStartTime = GetMicrotime(); … … 129 129 foreach($_POST as $Index => $Item) 130 130 { 131 132 133 131 if(is_array($_POST[$Index])) 132 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2); 133 else $_POST[$Index] = addslashes($_POST[$Index]); 134 134 } 135 135 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); … … 166 166 if($this->DoNotShowPage == false) 167 167 { 168 168 $this->ShowPage(); 169 169 } 170 170 } … … 183 183 function RegisterPage($Path, $Handler) 184 184 { 185 185 if(is_array($Path)) 186 186 { 187 187 $Page = &$this->Pages; … … 198 198 function RegisterMenuItem($MenuItem, $Pos = NULL) 199 199 { 200 201 202 203 200 if(is_null($Pos)) $this->Menu[] = $MenuItem; 201 else { 202 array_splice($this->Menu, $Pos, 0, array($MenuItem)); 203 } 204 204 } 205 205 … … 216 216 } else 217 217 { 218 219 218 if(count($PathItems) == 1) return($Pages[$PathItem]); 219 else return(''); // Unexpected subpages 220 220 } 221 221 } else return(''); … … 224 224 function PageNotFound() 225 225 { 226 227 228 229 230 231 232 233 226 // Send correct HTTP status code to signal unknown page 227 if(array_key_exists('SERVER_PROTOCOL', $_SERVER)) 228 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); 229 if(array_key_exists('HTTP_REFERER', $_SERVER)) $Referer = ' Referer: '.$_SERVER['HTTP_REFERER']; 230 else $Referer = ''; 231 if(isset($this->ModuleManager->Modules['Log'])) 232 $this->ModuleManager->Modules['Log']->WriteLog('Stránka "'. 233 implode('/', $this->PathItems).'" nenalezena'.$Referer, LOG_TYPE_PAGE_NOT_FOUND); 234 234 return(ShowMessage(sprintf(T('Page "%s" not found'), implode('/', $this->PathItems)), MESSAGE_CRITICAL)); 235 235 } … … 237 237 function ShowPage() 238 238 { 239 239 $Output = ''; 240 240 /* @var $Page Page */ 241 241 $ClassName = $this->SearchPage($this->PathItems, $this->Pages); … … 248 248 } else { 249 249 $Output2 = ''; 250 250 if((count($this->OnPageNotFound) == 2) 251 251 and method_exists($this->OnPageNotFound[0], $this->OnPageNotFound[1])) 252 252 $Output2 = call_user_func_array($this->OnPageNotFound, array()); 253 253 if($Output2 != '') $Output .= $this->BaseView->ShowPage($Output2); 254 255 256 254 else { 255 $Output = $this->PageNotFound(); 256 $this->BaseView->Title = T('Page not found'); 257 257 $Output = $this->BaseView->ShowPage($Output); 258 259 258 } 259 } 260 260 echo($Output); 261 261 } … … 264 264 class BaseView extends View 265 265 { 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 266 var $Title; 267 268 function ShowTopBar() 269 { 270 global $LocaleManager; 271 272 $Output = '<div class="Menu">'; 273 if(!$this->System->User->Licence(LICENCE_USER)) 274 $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>'; 275 $Output .= '<span class="MenuItem"></span><span class="MenuItem2">'; 276 if($this->System->User->Licence(LICENCE_USER)) 277 { 278 //$DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team); 279 //$Team = $DbResult->fetch_assoc(); 280 //$Output .= ''<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>'; 281 $Output .= $this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">'.T('Logout').'</a>'. 282 ' <a href="'.$this->System->Link('/user.php?user='.$this->System->User->Id).'">'.T('My page').'</a>'. 283 ' <a href="'.$this->System->Link('/Options.php').'">'.T('Options').'</a>'. 284 ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='. 285 $this->System->User->Id.'&group=0&state=2&text=&entry=').'">'.T('Translated').'</a>'. 286 ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='. 287 $this->System->User->Id.'&group=0&state=3&text=&entry=').'">'.T('Unfinished').'</a>'. 288 ' <a title="Nikým nepřeložené texty" href="'. 289 $this->System->Link('/TranslationList.php?user=0&group=0&state=1&text=&entry=').'">'.T('Untranslated').'</a>'; 290 } else 291 { 292 $Output .= '<a href="'.$this->System->Link('/login/').'">'.T('Login').'</a> '. 293 '<a href="'.$this->System->Link('/registrace.php').'">'.T('Registration').'</a>'; 294 } 295 //$Output .= ' <form action="?setlocale" method="get">'; 296 $Output .= ' <select onchange="window.location=\'?locale=\'+this.value">'; 297 foreach($LocaleManager->Available as $Locale) 298 { 299 if($Locale['Code'] == $LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"'; 300 else $Selected = ''; 301 $Output .= '<option title="" value="'.$Locale['Code'].'"'.$Selected.' onchange="this.form.submit()">'.$Locale['Title'].'</option>'; 302 } 303 $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>'; 304 //$Output .= '</form>'; 305 $Output .= '</span></div>'; 306 return($Output); 307 } 308 309 function ShowLoginBox() 310 { 311 $Output = ''; 312 if($this->System->User->Licence(LICENCE_USER)) 313 { 314 // $Output .= 'Jste přihlášen jako: <b>'.$tUser->Id.'</b> <a href="index.php?Logout">Odhlásit</a>'; 315 } else 316 { 317 $Output .= '<strong>'.T('Login').':</strong> 318 <form action="" method="post"> 319 <table> 320 <tr> 321 <td><input type="text" name="LoginUser" size="13" /></td> 322 </tr> 323 <tr> 324 <td><input type="password" name="LoginPass" size="13" /></td> 325 </tr> 326 <tr> 327 <th><input type="submit" value="'.T('Do login').'" /></th> 328 </tr> 329 </table> 330 </form>'; 331 } 332 return($Output); 333 } 334 335 function ShowSearchBox() 336 { 337 $Output = '<strong>'.T('Search').':</strong>'. 338 '<form action="'.$this->System->Link('/search/').'" method="get"><div>'. 339 '<table>'. 340 '<tr>'. 341 '<td><input type="text" name="text" size="13" /></td>'. 342 '</tr>'. 343 '<tr>'. 344 '<th><input type="submit" value="'.T('Do search').'" /></th>'. 345 '</tr>'. 346 '</table></div>'. 347 '</form>'; 348 return($Output); 349 } 350 351 function ShowMainMenu() 352 { 353 $Output = '<strong>'.T('Menu').':</strong>'. 354 '<div class="verticalmenu"><ul>'; 355 foreach($this->System->Menu as $MenuItem) 356 if($this->System->User->Licence($MenuItem['Permission'])) 357 { 358 if(isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"'; 359 else $OnClick = ''; 360 if($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>'; 361 else $Icon = ''; 362 $Output .= '<li>'.$Icon.'<a class="verticalmenua" title="'.$MenuItem['Hint'].'" href="'. 363 $MenuItem['Link'].'"'.$OnClick.'>'.$MenuItem['Title'].'</a></li>'; 364 } 365 $Output .= '</ul></div>'; 366 return($Output); 367 } 368 369 function ShowTranslatedMenu() 370 { 371 global $TranslationTree; 372 373 $Output = '<strong>'.T('Translate groups').':</strong><br /><div id="TranslationMenu">'; 374 $DbResult = $this->System->Database->select('Group', '`Id`, `Name`', '1 ORDER BY `Name`'); 375 while($Group = $DbResult->fetch_assoc()) 376 { 377 $Output .= '<div id="menuitem-group'.$Group['Id'].'" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'. 378 '<a href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">'.str_replace(' ',' ',$Group['Name']).'</a></div>'. 379 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'; 380 $Output .= ' <a title="Zde můžete začít překládat" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&state=1&user=0&entry=&text=').'">Nepřeložené</a><br />'. 381 ' <a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&state=2&user=0&entry=&text=').'">Přeložené</a><br />'; 382 if($this->System->User->Licence(LICENCE_USER)) 383 { 384 $Output .= ' <a title="Nedokončené překlady" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&state=3').'">Rozepsané</a><br /> 385 <a title="Všechny překlady, které jste přeložil" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&state=1&user='.$this->System->User->Id).'&entry=&text=">Vlastní</a><br />'; 386 } 387 $Output .= ' <a title="Sestavit speciální filtr" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">Filtr</a><br />'; 388 $Output .= '</div>'; 389 } 390 $Output .= '</div>'; 391 return($Output); 392 } 393 394 function ShowHeader() 395 { 396 $Output = ''. 397 '<!DOCTYPE html>'. 398 '<html>'. 399 '<head>'. 400 '<meta http-equiv="content-type" content="text/html; charset='.$this->System->Config['Web']['Charset'].'" />'. 401 '<meta name="keywords" content="wow, quest, questy, questů, preklad, mangos, překlad, překládání, přeložený, přeložení, čeština, world of warcraft, open source, free, addon" />'. 402 '<meta name="description" content="'.$this->System->Config['Web']['Description'].'" />'. 403 '<meta name="robots" content="all" />'. 404 '<link rel="stylesheet" href="'.$this->System->Link('/style/style.css').'" type="text/css" media="all" />'. 405 '<script type="text/javascript" src="'.$this->System->Link('/style/global.js').'"></script>'. 406 '<link rel="shortcut icon" href="'.$this->System->Link('/images/favicon.ico').'" />'; 407 $Output .= $this->System->ModuleManager->Modules['News']->ShowRSSHeader(); 408 $Title = $this->System->Config['Web']['Title']; 409 if($this->Title != '') $Title = $this->Title.' - '.$Title; 410 $Output .= '<title>'.$Title.'</title>'. 411 '</head><body>'; 412 413 $Output .= $this->ShowTopBar(); 414 $Output .= '<table class="page"><tr><td class="menu">'; 415 $Output .= $this->ShowMainMenu(); 416 $Output .= $this->System->ModuleManager->Modules['User']->ShowOnlineList(); 417 $Output .= '<br />'; 418 $Output .= $this->ShowSearchBox(); 419 420 $Output .= '</td><td id="border-left"></td><td class="content">'; 421 return($Output); 422 } 423 424 function ShowFooter() 425 { 426 global $ScriptStartTime, $Revision, $ReleaseTime; 427 428 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2); 429 430 $Output = '</td>'. 431 431 '<td class="menu2">'; 432 433 432 $Output .= $this->ShowTranslatedMenu(); 433 $Output .= '</td>'. 434 434 '</tr><tr>'. 435 435 '<td colspan="4" class="page-bottom">'.T('Version').': '.$Revision.' ('.HumanDate($ReleaseTime).')'. … … 438 438 $this->System->Config['Web']['WebCounter']; 439 439 440 441 442 443 444 445 446 440 $Output .= '</td></tr>'; 441 if($this->System->Config['Web']['ShowRuntimeInfo'] == true) 442 $Output .= '<tr><td colspan="3" style="text-align: center;">'.T('Generating duration').': '. 443 $ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s '.T('Used memory').': '. 444 HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B <a href="http://validator.w3.org/check?uri='. 445 htmlentities('http://'.$_SERVER['HTTP_HOST'].GetRequestURI().'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>'; 446 $Output .= '</table>'. 447 447 '</body>'. 448 448 '</html>'; 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 449 return($Output); 450 } 451 452 function ShowPage($Content) 453 { 454 $Output = $this->ShowHeader().$Content.$this->ShowFooter(); 455 if($this->System->Config['Web']['FormatOutput']) 456 $Output = $this->FormatOutput($Output); 457 return($Output); 458 } 459 460 function FormatOutput($s) 461 { 462 $out = ''; 463 $nn = 0; 464 $n = 0; 465 while($s != '') 466 { 467 $start = strpos($s, '<'); 468 $end = strpos($s, '>'); 469 if($start != 0) 470 { 471 $end = $start - 1; 472 $start = 0; 473 } 474 $line = trim(substr($s, $start, $end + 1)); 475 if(strlen($line) > 0) 476 if($line[0] == '<') 477 { 478 if($s[$start + 1] == '/') 479 { 480 $n = $n - 2; 481 $nn = $n; 482 } else 483 { 484 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1); 485 else $cmd = substr($line, 1, strlen($line) - 2); 486 //echo('['.$cmd.']'); 487 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2; 488 } 489 }// else $line = '['.$line.']'; 490 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n")); 491 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n"); 492 $s = substr($s, $end + 1, strlen($s)); 493 $nn = $n; 494 } 495 return($out); 496 } 497 497 }
Note:
See TracChangeset
for help on using the changeset viewer.