source: trunk/includes/system.php@ 579

Last change on this file since 579 was 579, checked in by chronos, 12 years ago
  • Fixed: Various errors related to old global variables.
  • Property svn:executable set to *
File size: 17.3 KB
Line 
1<?php
2
3include_once('Database.php');
4include_once('Application.php');
5
6class System extends Application
7{
8 var $Database;
9 var $Config;
10 var $ModuleManager;
11 var $PathItems;
12 var $Menu;
13 var $RSSChannels;
14 var $DoNotShowPage;
15
16 function __construct()
17 {
18 $this->Config = array();
19 $this->Menu = array();
20 $this->RSSChannels = array();
21 $this->DoNotShowPage = false;
22 }
23
24 function Init()
25 {
26 global $Config;
27
28 $this->Config = $Config;
29 $this->Database = new Database();
30 $this->Database->Connect($this->Config['Database']['Host'],
31 $this->Config['Database']['User'], $this->Config['Database']['Password'],
32 $this->Config['Database']['Database']);
33 $this->Database->charset($this->Config['Database']['Charset']);
34 $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery'];
35 $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
36 $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];
37 $this->ModuleManager = new AppModuleManager();
38
39 $this->Menu = array
40 (
41 array(
42 'Title' => 'Stav dokončení',
43 'Hint' => 'Stav dokončení překládů',
44 'Link' => $this->Link('/statistic.php'),
45 'Permission' => LICENCE_ANONYMOUS,
46 'Icon' => '',
47 ),
48 array(
49 'Title' => 'Soubory',
50 'Hint' => 'Stahování různých pomocných souborů a programů',
51 'Link' => $this->Link('/download.php'),
52 'Permission' => LICENCE_ANONYMOUS,
53 'Icon' => '',
54 ),
55 array(
56 'Title' => 'Pokyny',
57 'Hint' => 'Informace k překladu hry',
58 'Link' => $this->Link('/info.php'),
59 'Permission' => LICENCE_ANONYMOUS,
60 'Icon' => '',
61 ),
62 array(
63 'Title' => 'Zdroje dat',
64 'Hint' => 'Informace o překladových skupinách',
65 'Link' => $this->Link('/TranslationList.php?action=grouplist'),
66 'Permission' => LICENCE_ANONYMOUS,
67 'Icon' => '',
68 ),
69 array(
70 'Title' => 'Prezentace',
71 'Hint' => 'Prezentace a motivace překladu',
72 'Link' => $this->Link('/promotion.php'),
73 'Permission' => LICENCE_ANONYMOUS,
74 'Icon' => '',
75 ),
76 array(
77 'Title' => 'IRC chat',
78 'Hint' => 'IRC chat pro překladatele',
79 'Link' => 'http://embed.mibbit.com/?server=game.zdechov.net%3A6667&amp;channel=%23wowpreklad&amp;forcePrompt=true&amp;charset=utf-8',
80 'Permission' => LICENCE_ANONYMOUS,
81 'Icon' => '',
82 ),
83 array(
84 'Title' => 'Správa',
85 'Hint' => 'Volby pro správu',
86 'Link' => $this->Link('/admin/'),
87 'Permission' => LICENCE_ADMIN,
88 'Icon' => '',
89 ),
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]);
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
148 $this->BaseView = new BaseView($this);
149 if($this->DoNotShowPage == false)
150 {
151 $this->PathItems = ProcessURL();
152 $this->ShowPage();
153 }
154 }
155
156 function GetMicrotime()
157 {
158 list($Usec, $Sec) = explode(' ', microtime());
159 return ((float)$Usec + (float)$Sec);
160 }
161
162 function Link($Target)
163 {
164 return($this->Config['Web']['BaseURL'].$Target);
165 }
166
167 function RegisterPage($Path, $Handler)
168 {
169 if(is_array($Path))
170 {
171 $Page = &$this->Pages;
172 $LastKey = array_pop($Path);
173 foreach($Path as $PathItem)
174 {
175 $Page = &$Page[$PathItem];
176 }
177 if(!is_array($Page)) $Page = array('' => $Page);
178 $Page[$LastKey] = $Handler;
179 } else $this->Pages[$Path] = $Handler;
180 }
181
182 function RegisterMenuItem($MenuItem, $Pos = NULL)
183 {
184 if(is_null($Pos)) $this->Menu[] = $MenuItem;
185 else {
186 array_splice($this->Menu, $Pos, 0, array($MenuItem));
187 }
188 }
189
190 function RegisterRSS($Channel, $Pos = NULL)
191 {
192 if(is_null($Pos)) $this->RSSChannels[] = $Channel;
193 else {
194 array_splice($this->RSSChannels, $Pos, 0, array($Channel));
195 }
196 }
197
198 function SearchPage($PathItems, $Pages)
199 {
200 if(count($PathItems) > 0) $PathItem = $PathItems[0];
201 else $PathItem = '';
202 if(array_key_exists($PathItem, $Pages))
203 {
204 if(is_array($Pages[$PathItem]))
205 {
206 array_shift($PathItems);
207 return($this->SearchPage($PathItems, $Pages[$PathItem]));
208 } else return($Pages[$PathItem]);
209 } else return('');
210 }
211
212 function PageNotFound()
213 {
214 return('Page '.implode('/', $this->PathItems).' not found.');
215 }
216
217 function ShowPage()
218 {
219 /* @var $Page Page */
220 $ClassName = $this->SearchPage($this->PathItems, $this->Pages);
221 if($ClassName != '')
222 {
223 $Page = new $ClassName($this);
224 $Output = $Page->GetOutput();
225 if($Page->RawPage == false) $Output = $this->BaseView->ShowPage($Output);
226 echo($Output);
227 } else echo($this->PageNotFound());
228 }
229}
230
231class BaseView extends View
232{
233 function ShowTopBar()
234 {
235 $Output = '<div class="Menu">';
236 if(!$this->System->User->Licence(LICENCE_USER))
237 $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>';
238 $Output .= '<span class="MenuItem"></span>';
239 if($this->System->User->Licence(LICENCE_USER))
240 {
241 //$DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team);
242 //$Team = $DbResult->fetch_assoc();
243 //$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>';
244 $Output .= '<span class="MenuItem2">'.$this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">Odhlášení</a>'.
245 ' <a href="'.$this->System->Link('/user.php?user='.$this->System->User->Id).'">Moje stránka</a>'.
246 ' <a href="'.$this->System->Link('/Options.php').'">Nastavení</a>'.
247 ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='.
248 $this->System->User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">Přeložené</a>'.
249 ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='.
250 $this->System->User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">Rozpracované</a>'.
251 ' <a title="Nikým nepřeložené texty" href="'.$this->System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">Nepřeložené</a>'.
252 '</span>';
253 } else
254 {
255 $Output .= '<span class="MenuItem2"><form action="'.$this->System->Link('/?action=login').'" method="post"> '.
256 'Jméno: <input type="text" name="LoginUser" size="8 " /> '.
257 'Heslo: <td><input type="password" name="LoginPass" size="8" /> '.
258 '<input type="submit" value="Přihlásit" /></form> &nbsp; '.
259 '<a href="'.$this->System->Link('/registrace.php').'">Registrace</a></span>';
260 }
261 $Output .= '</div>';
262 return($Output);
263 }
264
265 function ShowLoginBox()
266 {
267 $Output = '';
268 if($this->System->User->Licence(LICENCE_USER))
269 {
270 // $Output .= 'Jste přihlášen jako: <b>'.$tUser->Id.'</b> <a href="index.php?Logout">Odhlásit</a>';
271 } else
272 {
273 $Output .= '<strong>Přihlášení:</strong>
274 <form action="" method="post">
275 <table>
276 <tr>
277 <td><input type="text" name="LoginUser" size="13" /></td>
278 </tr>
279 <tr>
280 <td><input type="password" name="LoginPass" size="13" /></td>
281 </tr>
282 <tr>
283 <th><input type="submit" value="Přihlásit" /></th>
284 </tr>
285 </table>
286 </form>';
287 }
288 return($Output);
289 }
290
291 function ShowSearchBox()
292 {
293 $Output = '<strong>Hledání:</strong>'.
294 '<form action="'.$this->System->Link('/search/').'" method="get"><div>'.
295 '<table>'.
296 '<tr>'.
297 '<td><input type="text" name="text" size="13" /></td>'.
298 '</tr>'.
299 '<tr>'.
300 '<th><input type="submit" value="Hledat" /></th>'.
301 '</tr>'.
302 '</table></div>'.
303 '</form>';
304 return($Output);
305 }
306
307 function ShowMainMenu()
308 {
309 $Output = '<strong>Nabídka:</strong>'.
310 '<div class="verticalmenu"><ul>';
311 foreach($this->System->Menu as $MenuItem)
312 if($this->System->User->Licence($MenuItem['Permission']))
313 {
314 if(isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"';
315 else $OnClick = '';
316 if($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>';
317 else $Icon = '';
318 $Output .= '<li>'.$Icon.'<a class="verticalmenua" title="'.$MenuItem['Hint'].'" href="'.
319 $MenuItem['Link'].'"'.$OnClick.'>'.$MenuItem['Title'].'</a></li>';
320 }
321 $Output .= '</ul></div>';
322 return($Output);
323 }
324
325 function ShowTranslatedMenu()
326 {
327 global $TranslationTree;
328
329 $Output = '<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">';
330 $DbResult = $this->System->Database->select('Group', '`Id`, `Name`', '1 ORDER BY `Name`');
331 while($Group = $DbResult->fetch_assoc())
332 {
333 $Output .= '<div id="menuitem-group'.$Group['Id'].'" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'.
334 '<a href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;action=filter').'">'.$Group['Name'].'</a></div>'.
335 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">';
336 $Output .= '&nbsp;<a title="Zde můžete začít překládat" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user=0&amp;entry=&amp;text=').'">Nepřeložené</a><br />'.
337 '&nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=2&amp;user=0&amp;entry=&amp;text=').'">Přeložené</a><br />';
338 if($this->System->User->Licence(LICENCE_USER))
339 {
340 $Output .= '&nbsp;<a title="Nedokončené překlady" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=3').'">Rozepsané</a><br />
341 &nbsp;<a title="Všechny překlady, které jste přeložil" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user='.$this->System->User->Id).'&amp;entry=&amp;text=">Vlastní</a><br />';
342 }
343 $Output .= '&nbsp;<a title="Sestavit speciální filtr" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;action=filter').'">Filtr</a><br />';
344 $Output .= '</div>';
345 }
346 $Output .= '</div>';
347 return($Output);
348 }
349
350 function ShowHeader()
351 {
352 $Output = '<?xml version="1.0" encoding="'.$this->System->Config['Web']['Charset'].'"?>'.
353 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'.
354 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'.
355 '<head>'.
356 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->System->Config['Web']['Charset'].'" />'.
357 '<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" />'.
358 '<meta name="description" content="'.$this->System->Config['Web']['Title'].'" />'.
359 '<meta name="robots" content="all" />'.
360 '<link rel="stylesheet" href="'.$this->System->Link('/style/style.css').'" type="text/css" media="all" />'.
361 '<script type="text/javascript" src="'.$this->System->Link('/style/global.js').'"></script>'.
362 '<link rel="shortcut icon" href="'.$this->System->Link('/images/favicon.ico').'" />';
363 foreach($this->System->RSSChannels as $Channel)
364 {
365 $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.
366 $this->System->Link('/rss.php?channel='.$Channel['Channel']).'" type="application/rss+xml" />';
367 }
368 $Output .= '<title>'.$this->System->Config['Web']['Title'].'</title>'.
369 '</head><body>';
370
371 $Output .= $this->ShowTopBar();
372 $Output .= '<table class="page"><tr><td class="menu">';
373 $Output .= $this->ShowMainMenu();
374 $Output .= $this->System->ModuleManager->Modules['User']->ShowOnlineList();
375 $Output .= '<br />';
376 $Output .= $this->ShowSearchBox();
377 $Output .= '</td><td id="border-left"></td><td class="content">';
378 return($Output);
379 }
380
381 function ShowFooter()
382 {
383 global $ScriptStartTime, $Revision, $ReleaseTime;
384
385 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);
386
387 $Output = '</td>'.
388 '<td class="menu2">';
389 $Output .= $this->ShowTranslatedMenu();
390 $Output .= '</td>'.
391 '</tr><tr>'.
392 '<td colspan="4" class="page-bottom">Verze: '.$Revision.' ('.HumanDate($ReleaseTime).')'.
393 ' &nbsp; <a href="http://svn.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> &nbsp; '.
394 '<a href="http://svn.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> &nbsp; '.
395 $this->System->Config['Web']['WebCounter'];
396
397 $Output .= '</td></tr>';
398 if($this->System->Config['Web']['ShowRuntimeInfo'] == true)
399 $Output .= '<tr><td colspan="3" style="text-align: center;">Doba generování: '.
400 $ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; Použitá paměť: '.
401 HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B &nbsp;&nbsp; <a href="http://validator.w3.org/check?uri='.
402 htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>';
403 $Output .= '</table>'.
404 '</body>'.
405 '</html>';
406 $this->System->User->Store();
407 return($Output);
408 }
409
410 function ShowPage($Content)
411 {
412 $Output = $this->ShowHeader().$Content.$this->ShowFooter();
413 //if($this->System->Config['Web']['FormatOutput']) $Output = $this->FormatOutput($Output);
414 return($Output);
415 }
416
417 function FormatOutput($s)
418 {
419 $out = '';
420 $nn = 0;
421 $n = 0;
422 while($s != '')
423 {
424 $start = strpos($s, '<');
425 $end = strpos($s, '>');
426 if($start != 0)
427 {
428 $end = $start - 1;
429 $start = 0;
430 }
431 $line = trim(substr($s, $start, $end + 1));
432 if(strlen($line) > 0)
433 if($line[0] == '<')
434 {
435 if($s[$start + 1] == '/')
436 {
437 $n = $n - 2;
438 $nn = $n;
439 } else
440 {
441 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
442 else $cmd = substr($line, 1, strlen($line) - 2);
443 //echo('['.$cmd.']');
444 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2;
445 }
446 }// else $line = '['.$line.']';
447 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
448 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
449 $s = substr($s, $end + 1, strlen($s));
450 $nn = $n;
451 }
452 return($out);
453 }
454}
Note: See TracBrowser for help on using the repository browser.