source: trunk/includes/global.php@ 498

Last change on this file since 498 was 498, checked in by chronos, 12 years ago
  • Upraveno: Optimalizace výpisu překladových položek v seznamu.
  • Přidáno: Nastavení časové zóny z PHP.
  • Upraveno: Tabulky převedeny z myisam na innodb. Doplněny indexy a cizí klíče. Provedeny některé optimalizace načítání.
File size: 14.1 KB
Line 
1<?php
2
3$ScriptStartTime = GetMicrotime();
4
5if(isset($_SERVER['REMOTE_ADDR'])) session_start();
6
7// SQL injection hack protection
8foreach($_POST as $Index => $Item)
9{
10 if(is_array($_POST[$Index]))
11 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2);
12 else $_POST[$Index] = addslashes($_POST[$Index]);
13}
14foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
15
16include_once(dirname(__FILE__).'/global_function.php');
17if(file_exists(dirname(__FILE__).'/config.php')) include_once(dirname(__FILE__).'/config.php');
18 else die('Nenalezen konfigurační soubor config.php ve složce includes. Vytvořte jej zkopírováním vzoru config.sample.php.');
19date_default_timezone_set($Config['Web']['Timezone']);
20include_once(dirname(__FILE__).'/Database.php');
21include_once(dirname(__FILE__).'/rss.php');
22include_once(dirname(__FILE__).'/system.php');
23include_once(dirname(__FILE__).'/user.php');
24
25$System = new System();
26$System->Init();
27$User = new User($System);
28
29include_once(dirname(__FILE__).'/error.php');
30
31$TranslationTree = GetTranslationTree();
32$LanguageList = GetLanguageList();
33
34LogReferrer();
35
36function GetMicrotime()
37{
38 list($Usec, $Sec) = explode(' ', microtime());
39 return ((float)$Usec + (float)$Sec);
40}
41
42function ShowShoutbox()
43{
44 global $System, $Config, $User, $System;
45
46 $Output = '<strong><a href="'.$System->Link('/action.php?action=ShoutBoxView').'">Kecátko:</a></strong>';
47 if($User->Licence(LICENCE_USER))
48 $Output .= ' <a href="'.$System->Link('/action.php?action=shoutbox').'">Vložit</a>';
49 $Output .= '<div class="box"><table>';
50 $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
51 while($Line = $DbResult->fetch_assoc())
52 $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>';
53 $Output .= '</table></div>';
54 return($Output);
55}
56
57function ShowTopBar()
58{
59 global $Config, $System, $User, $System;
60
61 echo('<div class="Menu">');
62 echo('<span class="MenuItem"></span>');
63 if($User->Licence(LICENCE_USER))
64 {
65 //$DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$User->Team);
66 //$Team = $DbResult->fetch_assoc();
67 //echo('<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>');
68 echo('<span class="MenuItem2">'.$User->Name.' <a href="'.$System->Link('/?action=logout').'">Odhlášení</a> <a href="'.$System->Link('/Options.php').'">Nastavení</a>');
69 echo(' <a title="Vámi přeložené texty" href="'.$System->Link('/TranslationList.php?user='.$User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">Přeložené</a>');
70 echo(' <a title="Vaše rozpracované text" href="'.$System->Link('/TranslationList.php?user='.$User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">Rozpracované</a>');
71 echo(' <a title="Nikým nepřeložené texty" href="'.$System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">Nepřeložené</a>');
72 echo('</span>');
73 } else
74 {
75 echo('<span class="MenuItem2"><form action="?action=login" method="post"> Jméno: <input type="text" name="LoginUser" size="8 " /> Heslo: <td><input type="password" name="LoginPass" size="8" /> <input type="submit" value="Přihlásit" /></form> &nbsp; <a href="'.$System->Link('/registrace.php').'">Registrace</a></span>');
76 }
77 echo('</div>');
78}
79
80function ShowLoginBox()
81{
82 global $User;
83
84 if($User->Licence(LICENCE_USER))
85 {
86 // echo 'Jste přihlášen jako: <b>'.$User->Id.'</b> <a href="index.php?Logout">Odhlásit</a>';
87 } else
88 {
89 echo('<strong>Přihlášení:</strong>
90 <form action="" method="post">
91 <table>
92 <tr>
93 <td><input type="text" name="LoginUser" size="13" /></td>
94 </tr>
95 <tr>
96 <td><input type="password" name="LoginPass" size="13" /></td>
97 </tr>
98 <tr>
99 <th><input type="submit" value="Přihlásit" /></th>
100 </tr>
101 </table>
102 </form>');
103 }
104}
105
106function ShowSearchBox()
107{
108 global $System;
109
110 echo('<strong>Hledání:</strong>'.
111 '<form action="'.$System->Link('/action.php').'" method="get"><div>'.
112 '<input type="hidden" name="action" value="search" />'.
113 '<table>'.
114 '<tr>'.
115 '<td><input type="text" name="search" size="13" /></td>'.
116 '</tr>'.
117 '<tr>'.
118 '<th><input type="submit" value="Hledat" /></th>'.
119 '</tr>'.
120 '</table></div>'.
121 '</form>');
122}
123
124function ShowMainMenu()
125{
126 global $TranslationTree, $Config, $User, $System;
127
128 $Menu = array
129 (
130 $System->Link('/') => array(LICENCE_ANONYMOUS, 'Hlavní stránka', 'Domů'),
131 $System->Link('/dictionary.php') => array(LICENCE_ANONYMOUS, 'Slovník WoW výrazů', 'Slovníček'),
132 $System->Link('/statistic.php') => array(LICENCE_ANONYMOUS, 'Stav dokončení překládů', 'Stav dokončení'),
133 $System->Link('/userlist.php?action=nofilter') => array(LICENCE_ANONYMOUS, 'Seznam registrovaných uživatelů', 'Překladatelé'),
134 $System->Link('/team.php?search=') => array(LICENCE_ANONYMOUS, 'Seznam překladatelských týmů', 'Týmy'),
135 $System->Link('/serverlist.php') => array(LICENCE_ANONYMOUS, 'Seznam serverů, kde je nasazena čeština v praxi', 'Servery'),
136 $System->Link('/export/') => array(LICENCE_ANONYMOUS, 'Zde si můžete stáhnout přeložené texty', 'Exporty'),
137 $System->Link('/download.php') => array(LICENCE_ANONYMOUS, 'Stahování různých pomocných souborů a programů', 'Soubory'),
138 $System->Link('/info.php') => array(LICENCE_ANONYMOUS, 'Informace k překladu hry', 'Informace'),
139 $System->Link('/TranslationList.php?action=grouplist') => array(LICENCE_ANONYMOUS, 'Informace o překladových skupinách', 'Zdroje dat'),
140 $System->Link('/banners.php') => array(LICENCE_ANONYMOUS, 'Informace k propagaci tohoto projektu', 'Propagace'),
141 $System->Link('/promotion.php') => array(LICENCE_ANONYMOUS, 'Prezentace a motivace překladu', 'Prezentace'),
142 $System->Link('/version.php') => array(LICENCE_ANONYMOUS, 'Seznam verzí herního klienta', 'Verze hry'),
143 $System->Link('/aowow/') => array(LICENCE_ANONYMOUS, 'Vyhledávací databáze podobná WoWHead s překlady', 'AoWoW'),
144'http://embed.mibbit.com/?server=game.zdechov.net%3A6667&amp;channel=%23wowpreklad&amp;forcePrompt=true&amp;charset=utf-8' => array(LICENCE_ANONYMOUS, 'IRC chat pro překladatele', 'Chat'),
145 $System->Link('/admin/') => array(LICENCE_ADMIN, 'Volby pro správu', 'Administrace'),
146 );
147
148 echo('<strong>Hlavní menu:</strong>'.
149 '<div class="verticalmenu"><ul>');
150 foreach($Menu as $MenuTarget => $MenuItem)
151 {
152 if(isset($MenuItem[3])) $OnClick = ' onclick="'.$MenuItem[3].'"';
153 else $OnClick = '';
154 if($User->Licence($MenuItem[0])) echo('<li><a class="verticalmenua" title="'.$MenuItem[1].'" href="'.$MenuTarget.'"'.$OnClick.'>'.$MenuItem[2].'</a></li>');
155 }
156 echo('</ul></div>');
157}
158
159function ShowTranslatedMenu()
160{
161 global $TranslationTree, $User, $System;
162
163 echo('<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">');
164 foreach($TranslationTree as $Group)
165 {
166 echo('<div id="menuitem-group'.$Group['Id'].'" onmousemove="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'.
167 '<a href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;action=filter').'">'.$Group['Name'].'</a></div>'.
168 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmousemove="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">');
169 echo('&nbsp;<a title="Zde můžete začít překládat" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user=0&amp;entry=&amp;text=').'">Nepřeložené</a><br />'.
170 '&nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=2&amp;user=0&amp;entry=&amp;text=').'">Přeložené</a><br />');
171 if($User->Licence(LICENCE_USER))
172 {
173 echo('&nbsp;<a title="Nedokončené překlady" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=3').'">Rozepsané</a><br />
174 &nbsp;<a title="Všechny překlady, které jste přeložil" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user='.$User->Id).'&amp;entry=&amp;text=">Vlastní</a><br />');
175 }
176 echo('&nbsp;<a title="Sestavit speciální filtr" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;action=filter').'">Filtr</a><br />');
177 echo('</div>');
178 }
179 echo ('</div>');
180}
181
182function ShowOnlineUserList()
183{
184 global $System, $Moderators, $User;
185
186 echo('Online překladatelé:<br />');
187 $DbResult = $System->Database->query('SELECT `Name`, `GM`, `ID` FROM `User` WHERE `LastLogin` >= NOW() - 300 AND ((`LastLogout` < `LastLogin`) OR (ISNULL(`LastLogout`)))');
188 while($DbUser = $DbResult->fetch_assoc())
189 {
190 if($User->Licence(LICENCE_MODERATOR)) $Name = '<a href="user.php?user='.$DbUser['ID'].'">'.$DbUser['Name'].'</a>';
191 else $Name = $DbUser['Name'];
192 $TextGM = '';
193 echo('<strong>'.$Name.'</strong>'.$TextGM.'<br />');
194 }
195}
196
197function ShowPage()
198{
199 global $User, $RSSChannels, $PageFooterRequested, $System;
200
201 echo('<?xml version="1.0" encoding="'.$System->Config['Web']['Charset'].'"?>
202 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
203<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'.
204'<head>'.
205'<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$System->Config['Web']['Charset'].'" />'.
206'<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" />'.
207'<meta name="description" content="'.$System->Config['Web']['Title'].'" />'.
208'<meta name="robots" content="all" />'.
209'<link rel="stylesheet" href="'.$System->Link('/style/style.css').'" type="text/css" media="all" />'.
210'<script type="text/javascript" src="'.$System->Link('/style/global.js').'"></script>'.
211'<link rel="shortcut icon" href="'.$System->Link('/images/favicon.ico').'" />');
212 if(isset($RSSChannels))
213 foreach($RSSChannels as $Channel)
214 echo(' <link rel="alternate" title="'.$Channel['Title'].'" href="'.$Channel['URL'].'" type="application/rss+xml" />');
215 echo('<title>'.$System->Config['Web']['Title'].'</title>
216</head>
217<body>');
218/*
219echo('<table id="bannertable"><tr>'.
220 '<td id="banner1"></td>'.
221 '<td id="banner"><div id="bannertitle">'.$Config['Web']['Title'].'</div></td>'.
222 '<td id="banner2"></td></tr>'.
223'</table>');
224*/
225
226 if(array_key_exists('action', $_GET))
227 {
228 if($_GET['action'] == 'login')
229 {
230 if(array_key_exists('LoginUser', $_POST) and array_key_exists('LoginPass', $_POST))
231 {
232 $User->Login($_POST['LoginUser'], $_POST['LoginPass']);
233 if($User->Role == LICENCE_ANONYMOUS)
234 {
235 $Message = 'Jméno nebo heslo bylo zadáno špatně.';
236 $MessageType = MESSAGE_CRITICAL;
237 } else
238 {
239 $Message = 'Přihlášení proběhlo úspěšně. Vítej <strong>'.$User->Name.'</strong>!';
240 $MessageType = MESSAGE_INFORMATION;
241 }
242 } else
243 {
244 $Message = 'Nebylo zadáno jméno a heslo.';
245 $MessageType = MESSAGE_CRITICAL;
246 }
247 } else
248 if($_GET['action'] == 'logout')
249 {
250 if($User->Role != LICENCE_ANONYMOUS)
251 {
252 WriteLog('Odhlášení', LOG_TYPE_USER);
253 $User->Logout();
254 $Message = 'Byl jsi odhlášen.';
255 $MessageType = MESSAGE_INFORMATION;
256 }
257 }
258 }
259 ShowTopBar();
260
261 echo('<table class="page"><tr><td class="menu">');
262 ShowMainMenu();
263 ShowOnlineUserList();
264 echo('<br />');
265 ShowSearchBox();
266 echo('</td><td id="border-left"></td><td class="content">');
267 $PageFooterRequested = true;
268 if(isset($Message)) ShowMessage($Message, $MessageType);
269}
270
271$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
272
273function HumanSize($Value)
274{
275 global $UnitNames;
276
277 $UnitIndex = 0;
278 while($Value > 1024)
279 {
280 $Value = round($Value / 1024, 3);
281 $UnitIndex++;
282 }
283 return($Value.' '.$UnitNames[$UnitIndex]);
284}
285
286function ShowFooter()
287{
288 global $System, $ScriptStartTime, $PageFooterRequested, $User;
289
290 if(isset($PageFooterRequested))
291 {
292 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);
293
294 echo('</td>');
295 echo('<td class="menu2">');
296 ShowTranslatedMenu();
297 echo('</td>'.
298 '</tr><tr>'.
299 '<td colspan="4" class="page-bottom">Autoři: '.$System->Config['Web']['Authors'].
300 ' &nbsp; <a href="http://svn.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> &nbsp; '.
301 '<a href="http://svn.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> &nbsp; '.
302 $System->Config['Web']['WebCounter']);
303
304 echo('</td></tr>');
305 if($System->Config['Web']['ShowRuntimeInfo'] == true) echo('<tr><td colspan="3" style="text-align: center;">Doba generování: '.$ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B &nbsp;&nbsp; <a href="http://validator.w3.org/check?uri='.htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>');
306 echo('</table>'.
307 '</body>'.
308 '</html>');
309 $User->Store();
310 }
311}
312
313function GetQueryStringArray($QueryString)
314{
315 $Result = array();
316 $Parts = explode('&', $QueryString);
317 foreach($Parts as $Part)
318 {
319 if($Part != '')
320 {
321 if(!strpos($Part, '=')) $Part .= '=';
322 $Item = explode('=', $Part);
323 $Result[$Item[0]] = $Item[1];
324 }
325 }
326 return($Result);
327}
328
329function SetQueryStringArray($QueryStringArray)
330{
331 $Parts = array();
332 foreach($QueryStringArray as $Index => $Item)
333 {
334 $Parts[] = $Index.'='.$Item;
335 }
336 return(implode('&', $Parts));
337}
338
339?>
Note: See TracBrowser for help on using the repository browser.