source: trunk/includes/global.php@ 331

Last change on this file since 331 was 331, checked in by maron, 15 years ago

Prezentace addonu

File size: 15.6 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('config.php');
17include_once('error.php');
18include_once('databaseconection.php');
19include_once('global_function.php');
20include_once('rss.php');
21include_once('system.php');
22
23$Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password']);
24$Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']);
25$Database->SelectDatabase($Config['Database']['Database']);
26
27$TranslationTree = GetTranslationTree();
28$LanguageList = GetLanguageList();
29
30$System = new System();
31$System->Init();
32
33function GetMicrotime()
34{
35 list($Usec, $Sec) = explode(' ', microtime());
36 return ((float)$Usec + (float)$Sec);
37}
38
39function ShowShoutbox()
40{
41 global $Database, $Config;
42
43 echo('<strong><a href="'.$Config['Web']['BaseURL'].'action.php?action=ShoutBoxView">Shoutbox:</a></strong>');
44 if(Licence(LICENCE_USER)) echo(' <a href="'.$Config['Web']['BaseURL'].'action.php?action=shoutbox">Vložit</a>');
45 echo('<div class="box"><table>');
46 $ID = $Database->SQLCommand('SELECT * FROM shoutbox ORDER BY ID DESC LIMIT 20');
47 while($Line = mysql_fetch_assoc($ID))
48 echo('<tr><td><strong>'.$Line['user'].'</strong>: '.htmlspecialchars($Line['text']).'</td></tr>');
49 echo('</table></div>');
50}
51
52function ShowTopBar()
53{
54 global $Config, $Database;
55
56 echo('<div class="Menu">');
57 echo('<span class="MenuItem"></span>');
58 if(Licence(LICENCE_USER))
59 {
60 $DbResult = $Database->SQLCommand('SELECT `team`, `user` FROM `user` WHERE ID='.$_SESSION['UserID']);
61 $User = mysql_fetch_assoc($DbResult);
62 $DbResult = $Database->SQLCommand('SELECT `Id`, `Name` FROM `Team` WHERE Id='.$User['team']);
63 $Team = mysql_fetch_assoc($DbResult);
64
65 //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>');
66 echo('<span class="MenuItem2">'.$User['user'].' <a href="'.$Config['Web']['BaseURL'].'?Logout">Odhlášení</a> <a href="'.$Config['Web']['BaseURL'].'Options.php">Nastavení</a></span>');
67 } else
68 {
69 echo('<span class="MenuItem2"><form action="?" 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="'.$Config['Web']['BaseURL'].'registrace.php">Registrace</a></span>');
70 }
71 echo('</div>');
72}
73
74function ShowLoginBox()
75{
76 if(Licence(LICENCE_USER))
77 {
78 // echo 'Jste přihlášen jako: <b>'.$_SESSION['User'].'</b> <a href="index.php?Logout">Odhlásit</a>';
79 } else
80 {
81 echo('<strong>Přihlášení:</strong>
82 <form action="" method="post">
83 <table>
84 <tr>
85 <td><input type="text" name="LoginUser" size="13" /></td>
86 </tr>
87 <tr>
88 <td><input type="password" name="LoginPass" size="13" /></td>
89 </tr>
90 <tr>
91 <th><input type="submit" value="Přihlásit" /></th>
92 </tr>
93 </table>
94 </form>');
95 }
96}
97
98function ShowSearchBox()
99{
100 global $Config;
101
102 echo('<strong>Hledání:</strong>'.
103 '<form action="'.$Config['Web']['BaseURL'].'action.php" method="get"><div>'.
104 '<input type="hidden" name="action" value="search" />'.
105 '<table>'.
106 '<tr>'.
107 '<td><input type="text" name="search" size="13" /></td>'.
108 '</tr>'.
109 '<tr>'.
110 '<th><input type="submit" value="Hledat" /></th>'.
111 '</tr>'.
112 '</table></div>'.
113 '</form>');
114}
115
116function ShowMainMenu()
117{
118 global $TranslationTree, $Config;
119
120 $Menu = array
121 (
122 $Config['Web']['BaseURL'].'index.php' => array(LICENCE_ANONYMOUS, 'Hlavní stránka', 'Domů'),
123 'http://wow.zdechov.net/forum/viewforum.php?f=22' => array(LICENCE_ANONYMOUS, 'Diskuze na téma překládání', 'Fórum projektu'),
124 $Config['Web']['BaseURL'].'dictionary.php' => array(LICENCE_ANONYMOUS, 'Slovník WoW výrazů', 'Slovníček'),
125 $Config['Web']['BaseURL'].'statistic.php' => array(LICENCE_ANONYMOUS, 'Stav dokončení překládů', 'Stav dokončení'),
126 $Config['Web']['BaseURL'].'userlist.php?action=nofilter' => array(LICENCE_ANONYMOUS, 'Seznam registrovaných uživatelů', 'Překladatelé'),
127 $Config['Web']['BaseURL'].'team.php?search=' => array(LICENCE_ANONYMOUS, 'Seznam překladatelských týmů', 'Týmy'),
128 $Config['Web']['BaseURL'].'export/' => array(LICENCE_ANONYMOUS, 'Zde si můžete stáhnout přeložené texty', 'Exporty'),
129 $Config['Web']['BaseURL'].'download.php' => array(LICENCE_ANONYMOUS, 'Stahování různých pomocných souborů a programů', 'Soubory'),
130 $Config['Web']['BaseURL'].'info.php' => array(LICENCE_ANONYMOUS, 'Informace k překladu hry', 'Informace'),
131 $Config['Web']['BaseURL'].'TranslationList.php?action=grouplist' => array(LICENCE_ANONYMOUS, 'Informace o překladových skupinách', 'Zdroje dat'),
132 $Config['Web']['BaseURL'].'banners.php' => array(LICENCE_ANONYMOUS, 'Informace k propagaci tohoto projektu', 'Propagace'),
133 $Config['Web']['BaseURL'].'promotion.php' => array(LICENCE_ANONYMOUS, 'Prezentace a motivace překladu', 'Prezentace'),
134 $Config['Web']['BaseURL'].'version.php' => array(LICENCE_ANONYMOUS, 'Seznam verzí herního klienta', 'Verze hry'),
135 $Config['Web']['BaseURL'].'aowow' => array(LICENCE_ANONYMOUS, 'Vyhledávací databáze podobná WoWHead s překlady', 'AoWoW'),
136 $Config['Web']['BaseURL'].'server.php' => array(LICENCE_ANONYMOUS, 'Pomocný WoW server pro překladatele', 'Test server'),
137'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'),
138 $Config['Web']['BaseURL'].'admin.php' => array(LICENCE_ADMIN, 'Volby pro správu', 'Administrace'),
139 );
140
141 echo('<strong>Hlavní menu:</strong>'.
142 '<div class="verticalmenu"><ul>');
143
144 foreach($Menu as $MenuTarget => $MenuItem)
145 {
146 if(isset($MenuItem[3])) $OnClick = ' onclick="'.$MenuItem[3].'"'; else $OnClick = '';
147 if(Licence($MenuItem[0])) echo('<li><a class="verticalmenua" title="'.$MenuItem[1].'" href="'.$MenuTarget.'"'.$OnClick.'>'.$MenuItem[2].'</a></li>');
148 }
149 echo('</ul></div>');
150}
151
152function ShowTranslatedMenu()
153{
154 global $TranslationTree, $Config, $Database;
155
156 echo('<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">');
157 if(Licence(LICENCE_USER))
158 {
159 echo ('<a title="Všechny překlady, které jste přeložil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?user='.$_SESSION['UserID'].'&amp;action=userall">Všechny moje texty</a><br />');
160 echo ('<a title="Všechny překlady, které jste rozepsal a nedokončil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?user='.$_SESSION['UserID'].'&amp;not&amp;action=userall">Rozpracované texty</a>');
161 //TODO: počet nedokončených
162 echo ('<br /><br />');
163 }
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="'.$Config['Web']['BaseURL'].'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="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=notran">Nepřeložené</a><br />
170 &nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=Translate">Přeložené</a><br />');
171 $ID = $Database->SQLCommand('SELECT * FROM connexion WHERE `Group` = '.$Group['Id']);
172 if (mysql_num_rows($ID) > 0)
173 echo('&nbsp;<a title="Vypsání souvislostí" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=connexion_list">Souvislosti</a><br />');
174
175 if(Licence(LICENCE_USER))
176 {
177 echo('&nbsp;<a title="Nedokončené překlady" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=mydevelop">Rozepsané</a><br />
178 &nbsp;<a title="Všechny překlady, které jste přeložil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=my">Vlastní</a><br />');
179 }
180 echo('&nbsp;<a title="Sestavit speciální filtr" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=filter">Filtr</a><br />');
181 echo('</div>');
182 }
183 echo ('</div>');
184}
185
186function ShowOnlineUserList()
187{
188 global $Database, $Moderators;
189
190 echo('Online překladatelé:<br />');
191 $ID = $Database->SQLCommand('SELECT user, GM, ID FROM `user` WHERE LastLogin >= Now() - 300 AND ((LastLogout < LastLogin) OR (ISNULL(LastLogout)))');
192 while ($Line = mysql_fetch_assoc($ID))
193 {
194 if(Licence(LICENCE_MODERATOR)) $Name = '<a href="user.php?user='.$Line['ID'].'">'.$Line['user'].'</a>';
195 else $Name = $Line['user'];
196 //if($Line['GM'] <> 0) $TextGM = '<small>('.$Moderators[$Line['GM']].')</small>';
197 //else
198 $TextGM = '';
199 echo('<strong>'.$Name.'</strong>'.$TextGM.'<br />');
200 }
201}
202
203function CheckLogin()
204{
205 global $Database;
206
207 if(!array_key_exists('UserID', $_SESSION)) $_SESSION['UserID'] = '';
208 if(!array_key_exists('User', $_SESSION)) $_SESSION['User'] = 'NotRegistred';
209 if(!array_key_exists('Pass', $_SESSION)) $_SESSION['Pass'] = '';
210
211 // Přihlášení
212 if(array_key_exists('LoginUser', $_POST))
213 {
214 $_SESSION['User'] = $_POST['LoginUser'];
215 $_SESSION['Pass'] = $_POST['LoginPass'];
216
217 $DbResult = $Database->SQLCommand('SELECT * FROM user WHERE LOWER(user) = LOWER("'.$_SESSION['User'].'") AND pass = sha1(CONCAT(sha1("'.$_SESSION['Pass'].'"), Salt))');
218 if(mysql_num_rows($DbResult) == 0)
219 {
220 echo('<script> alert("Jméno nebo heslo bylo zadáno špatně!"); </script>');
221 $_SESSION['UserID'] = '';
222 $_SESSION['User'] = '';
223 $_SESSION['Pass'] = '';
224 } else
225 {
226 $User = mysql_fetch_assoc($DbResult);
227 $_SESSION['UserID'] = $User['ID'];
228 $_SESSION['User'] = $User['user'];
229 WriteLog('Login: '.$_SESSION['User'], 3);
230 }
231 }
232
233 // Odhlášení
234 if(array_key_exists('Logout', $_GET) and ($_SESSION['User'] != ''))
235 {
236 WriteLog('Odhlášení', 3);
237 if(is_numeric($_SESSION['UserID']))
238 $Database->SQLCommand('UPDATE user SET LastLogout = NOW() WHERE ID = '.$_SESSION['UserID']);
239 $_SESSION['User'] = '';
240 $_SESSION['Pass'] = '';
241 $_SESSION['UserID'] = '';
242 }
243
244 // Záznam o aktivitě
245 if(Licence(0) and array_key_exists('REMOTE_ADDR', $_SERVER))
246 $Database->SQLCommand('UPDATE user SET LastIP = "'.$_SERVER['REMOTE_ADDR'].'", LastLogin = NOW() WHERE ID = '.$_SESSION['UserID']);
247}
248
249function ShowPage()
250{
251 global $Config, $Database, $RSSChannels, $PageFooterRequested;
252
253 echo('<?xml version="1.0" encoding="'.$Config['Web']['Charset'].'"?>
254 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
255<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">'.
256'<head>'.
257'<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.
258'<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" />'.
259'<meta name="description" content="Projekt překládání textů hry World of Warcraft" />'.
260'<meta name="robots" content="all" />'.
261'<link rel="stylesheet" href="'.$Config['Web']['BaseURL'].'style/style.css" type="text/css" media="all" />'.
262'<script type="text/javascript" src="'.$Config['Web']['BaseURL'].'style/global.js"></script>'.
263'<link rel="SHORTCUT ICON" href="'.$Config['Web']['BaseURL'].'images/favicon.ico" />');
264 if(isset($RSSChannels))
265 foreach($RSSChannels as $Channel)
266 echo(' <link rel="alternate" title="'.$Channel['Title'].'" href="'.$Channel['URL'].'" type="application/rss+xml" />');
267 echo('<title>Projekt překládání textů WoW</title>
268</head>
269<body>
270<table id="bannertable"><tr>
271 <td id="banner1"></td>
272 <td id="banner"><div id="bannertitle">Projekt překládání textů WoW</div></td>
273 <td id="banner2"></td></tr>
274</table>');
275
276 CheckLogin();
277 ShowTopBar();
278
279 echo('<table class="page"><tr><td class="menu">');
280 ShowMainMenu();
281
282 // echo('<br />');
283 //ShowLoginBox();
284 //echo('<br />');
285 ShowOnlineUserList();
286 echo('<br />');
287 ShowSearchBox();
288 echo('</td><td id="border-left"></td><td class="content">');
289 $PageFooterRequested = true;
290}
291
292$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
293
294function HumanSize($Value)
295{
296 global $UnitNames;
297
298 $UnitIndex = 0;
299 while($Value > 1024)
300 {
301 $Value = round($Value / 1024, 3);
302 $UnitIndex++;
303 }
304 return($Value.' '.$UnitNames[$UnitIndex]);
305}
306
307function ShowFooter()
308{
309 global $Database, $Config, $ScriptStartTime, $PageFooterRequested;
310
311 if(isset($PageFooterRequested))
312 {
313 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);
314
315 echo('</td>');
316 echo('<td class="menu2">');
317 ShowTranslatedMenu();
318 echo('<br />');
319 ShowShoutBox();
320 echo('</td>'.
321 '</tr><tr>'.
322 '<td colspan="4" class="page-bottom">Autoři: maron, chronos &nbsp; <a href="http://wowpreklad.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> &nbsp; '.
323 '<a href="http://wowpreklad.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> &nbsp; '.
324 '<a href="http://counter.cnw.cz/"><img src="http://counter.cnw.cz/monika.cgi?wowpreklad&amp;5&amp;000000&amp;FFFFFF&amp;on" alt="CNW:Counter" /></a>
325 <script type="text/javascript">
326 <!--
327 document.write("<a href=\"http://counter.cnw.cz\" target=\"_parent\"><img src=\"http://counter.cnw.cz/trackit.cgi?wowpreklad&t3&" + escape(top.document.referrer) + "\" alt=\"CNW:Tracker\" border=\"0\" width=\"1\" height=\"1\"><\/a>");
328 // -->
329 </script>');
330
331 echo('</td></tr>');
332 if($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>');
333 echo('</table>'.
334 '</body>'.
335 '</html>');
336 $Database->Disconnect();
337 }
338}
339
340function GetQueryStringArray($QueryString)
341{
342 $Result = array();
343 $Parts = explode('&', $QueryString);
344 foreach($Parts as $Part)
345 {
346 if($Part != '')
347 {
348 if(!strpos($Part, '=')) $Part .= '=';
349 $Item = explode('=', $Part);
350 $Result[$Item[0]] = $Item[1];
351 }
352 }
353 return($Result);
354}
355
356function SetQueryStringArray($QueryStringArray)
357{
358 $Parts = array();
359 foreach($QueryStringArray as $Index => $Item)
360 {
361 $Parts[] = $Index.'='.$Item;
362 }
363 return(implode('&', $Parts));
364}
365
366?>
Note: See TracBrowser for help on using the repository browser.