Changeset 841 for trunk/includes
- Timestamp:
- Jan 12, 2016, 10:33:43 PM (9 years ago)
- Location:
- trunk/includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Locale.php
r840 r841 162 162 var $Codes; 163 163 var $Dir; 164 var $LangCode; 165 var $DefaultLangCode; 166 var $Available; 164 167 165 168 function __construct(System $System) … … 168 171 $this->Codes = array('en'); 169 172 $this->CurrentLocale = new LocaleFile($System); 173 $this->LangCode = 'en'; 174 $this->DefaultLangCode = 'en'; 175 $this->Available = array(); 170 176 } 171 177 … … 218 224 function LoadLocale($Code) 219 225 { 220 $this->CurrentLocale->Dir = $this->Dir; 221 $this->CurrentLocale->Load($Code); 226 if(array_key_exists($Code, $this->Available)) 227 { 228 $this->CurrentLocale->Dir = $this->Dir; 229 $this->CurrentLocale->Load($Code); 230 } else throw new Exception('Unsupported locale code '.$Code); 222 231 } 223 232 } … … 226 235 function T($Text) 227 236 { 228 global $ LocaleManager;229 230 if(isset($ LocaleManager)) return($LocaleManager->CurrentLocale->Texts->Translate($Text));237 global $GlobalLocaleManager; 238 239 if(isset($GlobalLocaleManager)) return($GlobalLocaleManager->CurrentLocale->Texts->Translate($Text)); 231 240 else return($Text); 232 241 } -
trunk/includes/Version.php
r840 r841 6 6 // and system will need database update. 7 7 8 $Revision = 84 0; // Subversion revision8 $Revision = 841; // Subversion revision 9 9 $DatabaseRevision = 811; // Database structure revision 10 $ReleaseTime = '2016-01-1 1';10 $ReleaseTime = '2016-01-12'; -
trunk/includes/system.php
r838 r841 23 23 function Init() 24 24 { 25 global $Config, $LocaleManager; 26 27 $this->Config = $Config; 25 global $GlobalLocaleManager; 26 28 27 $this->Database->Connect($this->Config['Database']['Host'], 29 28 $this->Config['Database']['User'], $this->Config['Database']['Password'], … … 34 33 $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery']; 35 34 36 $this->PathItems = ProcessURL(); 37 // Initialize locale 38 $LocaleManager = new LocaleManager($this); 39 $LocaleManager->Dir = dirname(dirname(__FILE__)).'/locale'; 40 $LocaleManager->Available = array( 35 $this->LocaleManager = new LocaleManager($this); 36 $this->LocaleManager->Dir = dirname(dirname(__FILE__)).'/locale'; 37 $this->LocaleManager->Available = array( 41 38 'cs' => array('Code' => 'cs', 'Title' => 'Česky'), 42 39 'en' => array('Code' => 'en', 'Title' => 'English'), 43 40 ); 44 $Code = $Config['Web']['Locale']; 45 if (isset($_SESSION)) 46 if(array_key_exists('Locale', $_SESSION)) $Code = $_SESSION['Locale']; 47 if (isset($_GET)) 48 if(array_key_exists('locale', $_GET)) $Code = $_GET['locale']; 49 50 //echo(phpinfo()); 51 if(!array_key_exists($Code, $LocaleManager->Available)) $Code = 'en'; 52 $_SESSION['Locale'] = $Code; 53 $LocaleManager->LoadLocale($Code); 41 $GlobalLocaleManager = $this->LocaleManager; 42 $this->LinkLocaleExceptions = array('images', 'style', 'tmp'); 43 44 $this->PathItems = ProcessURL(); 45 46 // Detect interface locale 47 $this->LocaleManager->DefaultLangCode = $this->Config['Web']['Locale']; 48 $this->LocaleManager->LangCode = $this->LocaleManager->DefaultLangCode; 49 if(count($this->PathItems) > 0) 50 { 51 $NewLangCode = $this->PathItems[0]; 52 if(array_key_exists($NewLangCode, $this->LocaleManager->Available)) { 53 array_shift($this->PathItems); 54 $this->LocaleManager->LangCode = $NewLangCode; 55 } 56 } 57 $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode); 54 58 55 59 $this->Menu = array … … 103 107 function Run() 104 108 { 105 global $ScriptStartTime, $TranslationTree, $StopAfterUpdateManager, 106 $UpdateManager, $Config, $DatabaseRevision; 107 109 global $ScriptStartTime, $TranslationTree, $StopAfterUpdateManager, $Config, 110 $UpdateManager, $DatabaseRevision; 111 112 $this->Config = $Config; 108 113 $ScriptStartTime = GetMicrotime(); 109 114 110 115 if(GetRemoteAddress() != '') session_start(); 111 116 112 if(!isset($ Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.');113 date_default_timezone_set($ Config['Web']['Timezone']);117 if(!isset($this->Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.'); 118 date_default_timezone_set($this->Config['Web']['Timezone']); 114 119 115 120 $this->Init(); … … 136 141 // Initialize application modules 137 142 $this->ModuleManager->RegisterModule(new ModuleError($this)); 138 $this->ModuleManager->Modules['Error']->ErrorHandler->ShowError = $ Config['Web']['ShowPHPError'];143 $this->ModuleManager->Modules['Error']->ErrorHandler->ShowError = $this->Config['Web']['ShowPHPError']; 139 144 $this->ModuleManager->RegisterModule(new ModuleLog($this)); 140 145 $this->ModuleManager->RegisterModule(new ModuleUser($this)); … … 177 182 function Link($Target) 178 183 { 179 return($this->Config['Web']['BaseURL'].$Target); 184 $Remaining = substr($Target, count($this->Config['Web']['BaseURL'])); 185 $TargetParts = explode('/', $Remaining); 186 if(count($TargetParts) > 0) 187 { 188 if(in_array($TargetParts[0], $this->LinkLocaleExceptions)) 189 { 190 return($this->Config['Web']['BaseURL'].$Target); 191 } 192 } 193 return($this->LinkLocale($Target)); 194 } 195 196 function LinkLocale($Target, $Locale = '') 197 { 198 if($Locale == '') $Locale = $this->LocaleManager->LangCode; 199 if($Locale == $this->LocaleManager->DefaultLangCode) 200 return($this->Config['Web']['BaseURL'].$Target); 201 return($this->Config['Web']['BaseURL'].'/'.$Locale.$Target); 180 202 } 181 203 … … 237 259 { 238 260 $Output = ''; 261 239 262 /* @var $Page Page */ 240 263 $ClassName = $this->SearchPage($this->PathItems, $this->Pages); … … 265 288 var $Title; 266 289 290 function ShowLocaleSelector() 291 { 292 //$Output .= ' <form action="?setlocale" method="get">'; 293 $Output = ' <select onchange="window.location=this.value">'; 294 foreach($this->System->LocaleManager->Available as $Locale) 295 { 296 $Remaining = substr($_SERVER["REQUEST_URI"], strlen($this->System->Config['Web']['BaseURL'])); 297 if(substr($Remaining, 1, strlen($Locale['Code'].'/')) == $this->System->LocaleManager->LangCode.'/') 298 $Remaining = substr($Remaining, strlen('/'.$Locale['Code'])); 299 if($Locale['Code'] == $this->System->LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"'; 300 else $Selected = ''; 301 $URL = $this->System->LinkLocale($Remaining, $Locale['Code']); 302 $Output .= '<option title="" value="'.$URL.'"'.$Selected.' onchange="this.form.submit()">'.$Locale['Title'].'</option>'; 303 } 304 $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>'; 305 306 return($Output); 307 } 308 267 309 function ShowTopBar() 268 310 { 269 global $LocaleManager;270 271 311 $Output = '<div class="Menu">'; 272 312 if(!$this->System->User->Licence(LICENCE_USER)) … … 292 332 '<a href="'.$this->System->Link('/registrace.php').'">'.T('Registration').'</a>'; 293 333 } 294 //$Output .= ' <form action="?setlocale" method="get">'; 295 $Output .= ' <select onchange="window.location=\'?locale=\'+this.value">'; 296 foreach($LocaleManager->Available as $Locale) 297 { 298 if($Locale['Code'] == $LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"'; 299 else $Selected = ''; 300 $Output .= '<option title="" value="'.$Locale['Code'].'"'.$Selected.' onchange="this.form.submit()">'.$Locale['Title'].'</option>'; 301 } 302 $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>'; 334 $Output .= $this->ShowLocaleSelector(); 303 335 //$Output .= '</form>'; 304 336 $Output .= '</span></div>';
Note:
See TracChangeset
for help on using the changeset viewer.