Changeset 577 for trunk/includes/system.php
- Timestamp:
- Sep 11, 2013, 10:37:54 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/system.php
r573 r577 2 2 3 3 include_once('Database.php'); 4 5 class System 4 include_once('Application.php'); 5 6 class System extends Application 6 7 { 7 8 var $Database; … … 11 12 var $Menu; 12 13 var $RSSChannels; 14 var $DoNotShowPage; 13 15 14 16 function __construct() … … 17 19 $this->Menu = array(); 18 20 $this->RSSChannels = array(); 21 $this->DoNotShowPage = false; 19 22 } 20 23 … … 85 88 'Icon' => '', 86 89 ), 87 ); 90 ); 91 } 92 93 function Run() 94 { 95 global $System, $ScriptStartTime, $TranslationTree, $User, $StopAfterUpdateManager, 96 $UpdateManager, $Config, $DatabaseRevision; 97 98 $ScriptStartTime = GetMicrotime(); 99 100 if(isset($_SERVER['REMOTE_ADDR'])) session_start(); 101 102 if(!isset($Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.'); 103 date_default_timezone_set($Config['Web']['Timezone']); 104 105 $this->Init(); 106 107 // Check database persistence structure 108 $UpdateManager = new UpdateManager(); 109 $UpdateManager->Database = $this->Database; 110 $UpdateManager->Revision = $DatabaseRevision; 111 if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.'); 112 if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.'); 113 114 // SQL injection hack protection 115 foreach($_POST as $Index => $Item) 116 { 117 if(is_array($_POST[$Index])) 118 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2); 119 else $_POST[$Index] = addslashes($_POST[$Index]); 120 } 121 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 88 122 123 // TODO: Global initialized variable should be removed 124 $TranslationTree = GetTranslationTree(); 125 126 // Initialize application modules 127 $this->ModuleManager->RegisterModule(new ModuleError($System)); 128 $this->ModuleManager->Modules['Error']->ShowError = $Config['Web']['ShowPHPError']; 129 $this->ModuleManager->RegisterModule(new ModuleLog($System)); 130 $this->ModuleManager->RegisterModule(new ModuleUser($System)); 131 $this->ModuleManager->RegisterModule(new ModuleAoWoW($System)); 132 $this->ModuleManager->RegisterModule(new ModuleReferrer($System)); 133 $this->ModuleManager->Modules['Referrer']->Excluded[] = $System->Config['Web']['Host']; 134 $this->ModuleManager->RegisterModule(new ModuleTeam($System)); 135 $this->ModuleManager->RegisterModule(new ModuleDictionary($System)); 136 $this->ModuleManager->RegisterModule(new ModuleTranslation($System)); 137 $this->ModuleManager->RegisterModule(new ModuleImport($System)); 138 $this->ModuleManager->RegisterModule(new ModuleExport($System)); 139 $this->ModuleManager->RegisterModule(new ModuleServer($System)); 140 $this->ModuleManager->RegisterModule(new ModuleClientVersion($System)); 141 $this->ModuleManager->RegisterModule(new ModuleShoutBox($System)); 142 $this->ModuleManager->RegisterModule(new ModuleNews($System)); 143 $this->ModuleManager->RegisterModule(new ModuleWiki($System)); 144 $this->ModuleManager->RegisterModule(new ModuleSearch($System)); 145 $this->ModuleManager->RegisterModule(new ModuleFrontPage($System)); 146 $this->ModuleManager->StartAll(); 147 $User = &$this->User; // Back compatibility, will be removed 148 149 $this->BaseView = new BaseView($this); 150 if($this->DoNotShowPage == false) 151 { 152 $this->PathItems = ProcessURL(); 153 $this->ShowPage(); 154 } 89 155 } 90 156 … … 157 223 { 158 224 $Page = new $ClassName($this); 159 $Page->GetOutput(); 225 $Output = $Page->GetOutput(); 226 if($Page->RawPage == false) $Output = $this->BaseView->ShowPage($Output); 227 echo($Output); 160 228 } else echo($this->PageNotFound()); 161 229 } 162 230 } 231 232 class BaseView extends View 233 { 234 function ShowTopBar() 235 { 236 $Output = '<div class="Menu">'; 237 if(!$this->System->User->Licence(LICENCE_USER)) 238 $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>'; 239 $Output .= '<span class="MenuItem"></span>'; 240 if($this->System->User->Licence(LICENCE_USER)) 241 { 242 //$DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team); 243 //$Team = $DbResult->fetch_assoc(); 244 //$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>'; 245 $Output .= '<span class="MenuItem2">'.$this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">Odhlášení</a>'. 246 ' <a href="'.$this->System->Link('/user.php?user='.$this->System->User->Id).'">Moje stránka</a>'. 247 ' <a href="'.$this->System->Link('/Options.php').'">Nastavení</a>'. 248 ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='. 249 $this->System->User->Id.'&group=0&state=2&text=&entry=').'">Přeložené</a>'. 250 ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='. 251 $this->System->User->Id.'&group=0&state=3&text=&entry=').'">Rozpracované</a>'. 252 ' <a title="Nikým nepřeložené texty" href="'.$this->System->Link('/TranslationList.php?user=0&group=0&state=1&text=&entry=').'">Nepřeložené</a>'. 253 '</span>'; 254 } else 255 { 256 $Output .= '<span class="MenuItem2"><form action="'.$this->System->Link('/?action=login').'" method="post"> '. 257 'Jméno: <input type="text" name="LoginUser" size="8 " /> '. 258 'Heslo: <td><input type="password" name="LoginPass" size="8" /> '. 259 '<input type="submit" value="Přihlásit" /></form> '. 260 '<a href="'.$this->System->Link('/registrace.php').'">Registrace</a></span>'; 261 } 262 $Output .= '</div>'; 263 return($Output); 264 } 265 266 function ShowLoginBox() 267 { 268 $Output = ''; 269 if($this->System->User->Licence(LICENCE_USER)) 270 { 271 // $Output .= 'Jste přihlášen jako: <b>'.$tUser->Id.'</b> <a href="index.php?Logout">Odhlásit</a>'; 272 } else 273 { 274 $Output .= '<strong>Přihlášení:</strong> 275 <form action="" method="post"> 276 <table> 277 <tr> 278 <td><input type="text" name="LoginUser" size="13" /></td> 279 </tr> 280 <tr> 281 <td><input type="password" name="LoginPass" size="13" /></td> 282 </tr> 283 <tr> 284 <th><input type="submit" value="Přihlásit" /></th> 285 </tr> 286 </table> 287 </form>'; 288 } 289 return($Output); 290 } 291 292 function ShowSearchBox() 293 { 294 $Output = '<strong>Hledání:</strong>'. 295 '<form action="'.$this->System->Link('/search/').'" method="get"><div>'. 296 '<table>'. 297 '<tr>'. 298 '<td><input type="text" name="text" size="13" /></td>'. 299 '</tr>'. 300 '<tr>'. 301 '<th><input type="submit" value="Hledat" /></th>'. 302 '</tr>'. 303 '</table></div>'. 304 '</form>'; 305 return($Output); 306 } 307 308 function ShowMainMenu() 309 { 310 $Output = '<strong>Nabídka:</strong>'. 311 '<div class="verticalmenu"><ul>'; 312 foreach($this->System->Menu as $MenuItem) 313 if($this->System->User->Licence($MenuItem['Permission'])) 314 { 315 if(isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"'; 316 else $OnClick = ''; 317 if($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>'; 318 else $Icon = ''; 319 $Output .= '<li>'.$Icon.'<a class="verticalmenua" title="'.$MenuItem['Hint'].'" href="'. 320 $MenuItem['Link'].'"'.$OnClick.'>'.$MenuItem['Title'].'</a></li>'; 321 } 322 $Output .= '</ul></div>'; 323 return($Output); 324 } 325 326 function ShowTranslatedMenu() 327 { 328 global $TranslationTree; 329 330 $Output = '<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">'; 331 $DbResult = $this->System->Database->select('Group', '`Id`, `Name`', '1 ORDER BY `Name`'); 332 while($Group = $DbResult->fetch_assoc()) 333 { 334 $Output .= '<div id="menuitem-group'.$Group['Id'].'" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'. 335 '<a href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">'.$Group['Name'].'</a></div>'. 336 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'; 337 $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 />'. 338 ' <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 />'; 339 if($this->System->User->Licence(LICENCE_USER)) 340 { 341 $Output .= ' <a title="Nedokončené překlady" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&state=3').'">Rozepsané</a><br /> 342 <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 />'; 343 } 344 $Output .= ' <a title="Sestavit speciální filtr" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">Filtr</a><br />'; 345 $Output .= '</div>'; 346 } 347 $Output .= '</div>'; 348 return($Output); 349 } 350 351 function ShowHeader() 352 { 353 $Output = '<?xml version="1.0" encoding="'.$this->System->Config['Web']['Charset'].'"?>'. 354 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'. 355 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'. 356 '<head>'. 357 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->System->Config['Web']['Charset'].'" />'. 358 '<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" />'. 359 '<meta name="description" content="'.$this->System->Config['Web']['Title'].'" />'. 360 '<meta name="robots" content="all" />'. 361 '<link rel="stylesheet" href="'.$this->System->Link('/style/style.css').'" type="text/css" media="all" />'. 362 '<script type="text/javascript" src="'.$this->System->Link('/style/global.js').'"></script>'. 363 '<link rel="shortcut icon" href="'.$this->System->Link('/images/favicon.ico').'" />'; 364 foreach($this->System->RSSChannels as $Channel) 365 { 366 $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'. 367 $this->System->Link('/rss.php?channel='.$Channel['Channel']).'" type="application/rss+xml" />'; 368 } 369 $Output .= '<title>'.$this->System->Config['Web']['Title'].'</title>'. 370 '</head><body>'; 371 372 $Output .= $this->ShowTopBar(); 373 $Output .= '<table class="page"><tr><td class="menu">'; 374 $Output .= $this->ShowMainMenu(); 375 $Output .= $this->System->ModuleManager->Modules['User']->ShowOnlineList(); 376 $Output .= '<br />'; 377 $Output .= $this->ShowSearchBox(); 378 $Output .= '</td><td id="border-left"></td><td class="content">'; 379 return($Output); 380 } 381 382 function ShowFooter() 383 { 384 global $ScriptStartTime, $Revision, $ReleaseTime; 385 386 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2); 387 388 $Output = '</td>'. 389 '<td class="menu2">'; 390 $Output .= $this->ShowTranslatedMenu(); 391 $Output .= '</td>'. 392 '</tr><tr>'. 393 '<td colspan="4" class="page-bottom">Verze: '.$Revision.' ('.HumanDate($ReleaseTime).')'. 394 ' <a href="http://svn.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> '. 395 '<a href="http://svn.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> '. 396 $this->System->Config['Web']['WebCounter']; 397 398 $Output .= '</td></tr>'; 399 if($this->System->Config['Web']['ShowRuntimeInfo'] == true) 400 $Output .= '<tr><td colspan="3" style="text-align: center;">Doba generování: '. 401 $ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s Použitá paměť: '. 402 HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B <a href="http://validator.w3.org/check?uri='. 403 htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>'; 404 $Output .= '</table>'. 405 '</body>'. 406 '</html>'; 407 $this->System->User->Store(); 408 return($Output); 409 } 410 411 function ShowPage($Content) 412 { 413 $Output = $this->ShowHeader().$Content.$this->ShowFooter(); 414 //if($this->System->Config['Web']['FormatOutput']) $Output = $this->FormatOutput($Output); 415 return($Output); 416 } 417 418 function FormatOutput($s) 419 { 420 $out = ''; 421 $nn = 0; 422 $n = 0; 423 while($s != '') 424 { 425 $start = strpos($s, '<'); 426 $end = strpos($s, '>'); 427 if($start != 0) 428 { 429 $end = $start - 1; 430 $start = 0; 431 } 432 $line = trim(substr($s, $start, $end + 1)); 433 if(strlen($line) > 0) 434 if($line[0] == '<') 435 { 436 if($s[$start + 1] == '/') 437 { 438 $n = $n - 2; 439 $nn = $n; 440 } else 441 { 442 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1); 443 else $cmd = substr($line, 1, strlen($line) - 2); 444 //echo('['.$cmd.']'); 445 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2; 446 } 447 }// else $line = '['.$line.']'; 448 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n")); 449 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n"); 450 $s = substr($s, $end + 1, strlen($s)); 451 $nn = $n; 452 } 453 return($out); 454 } 455 }
Note:
See TracChangeset
for help on using the changeset viewer.