Changeset 816 for trunk/includes/system.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.