1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/Database.php');
|
---|
4 | include_once(dirname(__FILE__).'/Base.php');
|
---|
5 | include_once(dirname(__FILE__).'/system.php');
|
---|
6 | include_once(dirname(__FILE__).'/Update.php');
|
---|
7 | include_once(dirname(__FILE__).'/Page.php');
|
---|
8 | if(file_exists(dirname(__FILE__).'/config.php'))
|
---|
9 | include_once(dirname(__FILE__).'/config.php');
|
---|
10 | include_once(dirname(__FILE__).'/Version.php');
|
---|
11 | include_once(dirname(__FILE__).'/AppModule.php');
|
---|
12 | include_once(dirname(__FILE__).'/Locale.php');
|
---|
13 | include_once(dirname(__FILE__).'/UTF8.php');
|
---|
14 | require_once(dirname(__FILE__).'/../HTML/BBCodeParser2.php');
|
---|
15 |
|
---|
16 | // Include application modules
|
---|
17 | // TODO: Make modules configurable
|
---|
18 | include_once(dirname(__FILE__).'/../Modules/Error/Error.php');
|
---|
19 | include_once(dirname(__FILE__).'/../Modules/Log/Log.php');
|
---|
20 | include_once(dirname(__FILE__).'/../Modules/Translation/Translation.php');
|
---|
21 | include_once(dirname(__FILE__).'/../Modules/AoWoW/AoWoW.php');
|
---|
22 | include_once(dirname(__FILE__).'/../Modules/Referrer/Referrer.php');
|
---|
23 | include_once(dirname(__FILE__).'/../Modules/Team/Team.php');
|
---|
24 | include_once(dirname(__FILE__).'/../Modules/User/User.php');
|
---|
25 | include_once(dirname(__FILE__).'/../Modules/Dictionary/Dictionary.php');
|
---|
26 | include_once(dirname(__FILE__).'/../Modules/Import/Import.php');
|
---|
27 | include_once(dirname(__FILE__).'/../Modules/Export/Export.php');
|
---|
28 | include_once(dirname(__FILE__).'/../Modules/Server/Server.php');
|
---|
29 | include_once(dirname(__FILE__).'/../Modules/ClientVersion/ClientVersion.php');
|
---|
30 | include_once(dirname(__FILE__).'/../Modules/ShoutBox/ShoutBox.php');
|
---|
31 | include_once(dirname(__FILE__).'/../Modules/News/News.php');
|
---|
32 | include_once(dirname(__FILE__).'/../Modules/Wiki/Wiki.php');
|
---|
33 | include_once(dirname(__FILE__).'/../Modules/Search/Search.php');
|
---|
34 | include_once(dirname(__FILE__).'/../Modules/FrontPage/FrontPage.php');
|
---|
35 | include_once(dirname(__FILE__).'/../Modules/Download/Download.php');
|
---|
36 | include_once(dirname(__FILE__).'/../Modules/Forum/Forum.php');
|
---|
37 | include_once(dirname(__FILE__).'/../Modules/Redirection/Redirection.php');
|
---|
38 |
|
---|
39 |
|
---|
40 | // Back compatibility, will be removed
|
---|
41 | if(isset($InitSystem) and $InitSystem)
|
---|
42 | {
|
---|
43 | $System = new System();
|
---|
44 | $System->DoNotShowPage = true;
|
---|
45 | $System->Run();
|
---|
46 | $User = $System->User; // Back compatibility, will be removed
|
---|
47 | }
|
---|
48 |
|
---|
49 | class TempPage extends Page
|
---|
50 | {
|
---|
51 | function Show()
|
---|
52 | {
|
---|
53 | global $TempPageContent;
|
---|
54 | return($TempPageContent);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | function ShowPageClass($Page)
|
---|
59 | {
|
---|
60 | global $TempPageContent, $System;
|
---|
61 |
|
---|
62 | $System->Pages['temporary-page'] = get_class($Page);
|
---|
63 | $_SERVER['REDIRECT_QUERY_STRING'] = 'temporary-page';
|
---|
64 | $System->PathItems = ProcessURL();
|
---|
65 | $System->ShowPage();
|
---|
66 | }
|
---|
67 |
|
---|
68 | function ShowPage($Content)
|
---|
69 | {
|
---|
70 | global $TempPageContent, $System;
|
---|
71 |
|
---|
72 | $TempPage = new TempPage($System);
|
---|
73 | $System->Pages['temporary-page'] = 'TempPage';
|
---|
74 | $_SERVER['REDIRECT_QUERY_STRING'] = 'temporary-page';
|
---|
75 | $TempPageContent = $Content;
|
---|
76 | $System->PathItems = ProcessURL();
|
---|
77 | $System->ShowPage();
|
---|
78 | }
|
---|
79 |
|
---|
80 | function GetMicrotime()
|
---|
81 | {
|
---|
82 | list($Usec, $Sec) = explode(' ', microtime());
|
---|
83 | return ((float)$Usec + (float)$Sec);
|
---|
84 | }
|
---|
85 |
|
---|
86 | $UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
|
---|
87 |
|
---|
88 | function HumanSize($Value)
|
---|
89 | {
|
---|
90 | global $UnitNames;
|
---|
91 |
|
---|
92 | $UnitIndex = 0;
|
---|
93 | while($Value > 1024)
|
---|
94 | {
|
---|
95 | $Value = round($Value / 1024, 3);
|
---|
96 | $UnitIndex++;
|
---|
97 | }
|
---|
98 | return($Value.' '.$UnitNames[$UnitIndex]);
|
---|
99 | }
|
---|
100 |
|
---|
101 | function GetQueryStringArray($QueryString)
|
---|
102 | {
|
---|
103 | $Result = array();
|
---|
104 | $Parts = explode('&', $QueryString);
|
---|
105 | foreach($Parts as $Part)
|
---|
106 | {
|
---|
107 | if($Part != '')
|
---|
108 | {
|
---|
109 | if(!strpos($Part, '=')) $Part .= '=';
|
---|
110 | $Item = explode('=', $Part);
|
---|
111 | $Result[$Item[0]] = $Item[1];
|
---|
112 | }
|
---|
113 | }
|
---|
114 | return($Result);
|
---|
115 | }
|
---|
116 |
|
---|
117 | function SetQueryStringArray($QueryStringArray)
|
---|
118 | {
|
---|
119 | $Parts = array();
|
---|
120 | foreach($QueryStringArray as $Index => $Item)
|
---|
121 | {
|
---|
122 | $Parts[] = $Index.'='.$Item;
|
---|
123 | }
|
---|
124 | return(implode('&', $Parts));
|
---|
125 | }
|
---|
126 |
|
---|
127 | function utf2ascii($text)
|
---|
128 | {
|
---|
129 | $return = Str_Replace(
|
---|
130 | Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") ,
|
---|
131 | Array("a","c","d","e","e","i","l","n","o","r","s","t","u","u","y","z","A","C","D","E","E","I","L","N","O","R","S","T","U","U","Y","Z") ,
|
---|
132 | $text);
|
---|
133 | //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami
|
---|
134 | //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"'
|
---|
135 | //$return = StrToLower($return); // velká písmena nahradí malými.
|
---|
136 | return($return);
|
---|
137 | }
|
---|
138 |
|
---|
139 | function getmonthyears($Days)
|
---|
140 | {
|
---|
141 | $month = floor($Days / 30);
|
---|
142 | $year = floor($month / 12);
|
---|
143 | $Days = floor($Days - $month * 30);
|
---|
144 | $month = $month - $year * 12;
|
---|
145 | return($year.'r '.$month.'m '.$Days.'d');
|
---|
146 | }
|
---|
147 |
|
---|
148 | function GetTranslateGoogle($text, $withouttitle = false)
|
---|
149 | {
|
---|
150 | global $System;
|
---|
151 |
|
---|
152 | // $text = 'Balthule\'s letter is dire. This Cult of the Dark Strand is a thorn in my side that must be removed. I have been dealing with some of the Dark Strand scum northeast of here at Ordil\'Aran. One of their number possesses a soul gem that I believe holds the secret to the cult\'s power.$b$bBring it to me, and I will be able to decipher the secrets held within.';
|
---|
153 | // $text = htmlspecialchars($text);
|
---|
154 |
|
---|
155 | $text = str_replace('$B','$B ', $text);
|
---|
156 | $text = urlencode($text);
|
---|
157 | // $text = strtolower($text);
|
---|
158 | // $text = str_replace('&','',$text);
|
---|
159 | // $text = str_replace(' ','%20',$text);
|
---|
160 | $DbResult = $System->Database->select('Language', '`Code`', '`Id`='.$System->User->Language);
|
---|
161 | $DbRow = $DbResult->fetch_assoc();
|
---|
162 | $lang = $DbRow['Code'];
|
---|
163 | $url = 'http://translate.google.cz/?sl=en&tl='.$lang.'&text='.$text;
|
---|
164 |
|
---|
165 | error_reporting(E_ALL ^ E_WARNING);
|
---|
166 | if (($handle = @fopen($url, "r")) === FALSE) return(false);
|
---|
167 |
|
---|
168 | $data = stream_get_contents($handle);
|
---|
169 | $data = substr($data, strpos($data, 'result_box'));
|
---|
170 | $data = substr($data, strpos($data, '>') + 1);
|
---|
171 | $data = substr($data, 0, strpos($data, '</div>'));
|
---|
172 |
|
---|
173 | if ($withouttitle)
|
---|
174 | while ((strpos($data, '>') !== false and (strpos($data, '<') !== false)) and (strpos($data, '>') > strpos($data, '<')))
|
---|
175 | {
|
---|
176 | $partbefore = substr($data, 0, strpos($data, '<'));
|
---|
177 | // echo $partbefore;
|
---|
178 | $partafter = substr($data, strpos($data, '>') + 1);
|
---|
179 | // echo $partafter;
|
---|
180 | $data = $partbefore.' '.$partafter;
|
---|
181 | }
|
---|
182 |
|
---|
183 | $Encoding = new Encoding();
|
---|
184 | $data = $Encoding->ToUTF8($data);
|
---|
185 | //$data = utf8_encode($data);
|
---|
186 |
|
---|
187 | $data = str_replace('$ ', '$',$data);
|
---|
188 | $data = str_replace('$b $b', '$b$b', $data);
|
---|
189 | $data = str_replace('| ', '|', $data);
|
---|
190 |
|
---|
191 | $data = strip_tags($data);
|
---|
192 |
|
---|
193 | return($data);
|
---|
194 | }
|
---|
195 |
|
---|
196 | function GetPageList($TotalCount)
|
---|
197 | {
|
---|
198 | global $System;
|
---|
199 |
|
---|
200 | $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
|
---|
201 |
|
---|
202 | $ItemPerPage = $System->Config['Web']['ItemsPerPage'];
|
---|
203 | $Around = round($System->Config['Web']['VisiblePagingItems'] / 2);
|
---|
204 | $Result = '';
|
---|
205 | $PageCount = floor($TotalCount / $ItemPerPage) + 1;
|
---|
206 |
|
---|
207 | if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
|
---|
208 | if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
|
---|
209 | if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
|
---|
210 | if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
|
---|
211 | $CurrentPage = $_SESSION['Page'];
|
---|
212 |
|
---|
213 |
|
---|
214 | $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> Stránky: ';
|
---|
215 |
|
---|
216 | $Result = '';
|
---|
217 | if($PageCount > 1)
|
---|
218 | {
|
---|
219 | if($CurrentPage > 0)
|
---|
220 | {
|
---|
221 | $QueryItems['page'] = 0;
|
---|
222 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><<</a> ';
|
---|
223 | $QueryItems['page'] = ($CurrentPage - 1);
|
---|
224 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><</a> ';
|
---|
225 | }
|
---|
226 | $PagesMax = $PageCount - 1;
|
---|
227 | $PagesMin = 0;
|
---|
228 | if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
|
---|
229 | if($PagesMin < ($CurrentPage - $Around))
|
---|
230 | {
|
---|
231 | $Result.= ' ... ';
|
---|
232 | $PagesMin = $CurrentPage - $Around;
|
---|
233 | }
|
---|
234 | for($i = $PagesMin; $i <= $PagesMax; $i++)
|
---|
235 | {
|
---|
236 | if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
|
---|
237 | else {
|
---|
238 | $QueryItems['page'] = $i;
|
---|
239 | $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
|
---|
240 | }
|
---|
241 | }
|
---|
242 | if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
|
---|
243 | if($CurrentPage < ($PageCount - 1))
|
---|
244 | {
|
---|
245 | $QueryItems['page'] = ($CurrentPage + 1);
|
---|
246 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">></a> ';
|
---|
247 | $QueryItems['page'] = ($PageCount - 1);
|
---|
248 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">>></a>';
|
---|
249 | }
|
---|
250 | }
|
---|
251 | $Result = '<div style="text-align: center">'.$Result.'</div>';
|
---|
252 | return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
|
---|
253 | 'Page' => $CurrentPage,
|
---|
254 | 'Output' => $Result,
|
---|
255 | ));
|
---|
256 | }
|
---|
257 |
|
---|
258 | $OrderDirSQL = array('ASC', 'DESC');
|
---|
259 | $OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
|
---|
260 |
|
---|
261 | function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
|
---|
262 | {
|
---|
263 | global $OrderDirSQL, $OrderArrowImage, $Config, $System;
|
---|
264 |
|
---|
265 | if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
|
---|
266 | if(array_key_exists('OrderDir', $_GET) and (array_key_exists($_GET['OrderDir'], $OrderArrowImage)))
|
---|
267 | $_SESSION['OrderDir'] = $_GET['OrderDir'];
|
---|
268 | if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
|
---|
269 | if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
|
---|
270 |
|
---|
271 | // Check OrderCol
|
---|
272 | $Found = false;
|
---|
273 | foreach($Columns as $Column)
|
---|
274 | {
|
---|
275 | if($Column['Name'] == $_SESSION['OrderCol'])
|
---|
276 | {
|
---|
277 | $Found = true;
|
---|
278 | break;
|
---|
279 | }
|
---|
280 | }
|
---|
281 | if($Found == false)
|
---|
282 | {
|
---|
283 | $_SESSION['OrderCol'] = $DefaultColumn;
|
---|
284 | $_SESSION['OrderDir'] = $DefaultOrder;
|
---|
285 | }
|
---|
286 | // Check OrderDir
|
---|
287 | if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
|
---|
288 |
|
---|
289 | $Result = '';
|
---|
290 | $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
|
---|
291 | foreach($Columns as $Index => $Column)
|
---|
292 | {
|
---|
293 | $QueryItems['OrderCol'] = $Column['Name'];
|
---|
294 | $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
|
---|
295 | if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.
|
---|
296 | $System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow"/>';
|
---|
297 | else $ArrowImage = '';
|
---|
298 | if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
|
---|
299 | else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>';
|
---|
300 | }
|
---|
301 | return(array(
|
---|
302 | 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
|
---|
303 | 'Output' => '<tr>'.$Result.'</tr>',
|
---|
304 | 'Column' => $_SESSION['OrderCol'],
|
---|
305 | 'Direction' => $_SESSION['OrderDir'],
|
---|
306 | ));
|
---|
307 | }
|
---|
308 |
|
---|
309 | function ClientVersionSelection($Selected)
|
---|
310 | {
|
---|
311 | global $System;
|
---|
312 |
|
---|
313 | $Output = '<select name="ClientVersion">';
|
---|
314 | $DbResult = $System->Database->select('ClientVersion', '`Id`, `Version`', '`Imported` = 1');
|
---|
315 | $Output .= '<option value=""';
|
---|
316 | if($Selected == '')
|
---|
317 | $Output .= ' selected="selected"';
|
---|
318 | $Output .= '>Žádná</option>';
|
---|
319 | while($ClientVersion = $DbResult->fetch_assoc())
|
---|
320 | {
|
---|
321 | $Output .= '<option value="'.$ClientVersion['Id'].'"';
|
---|
322 | if($Selected == $ClientVersion['Id'])
|
---|
323 | $Output .= ' selected="selected"';
|
---|
324 | $Output .= '>'.$ClientVersion['Version'].'</option>';
|
---|
325 | }
|
---|
326 | $Output .= '</select>';
|
---|
327 | return($Output);
|
---|
328 | }
|
---|
329 |
|
---|
330 | function GetLanguageList()
|
---|
331 | {
|
---|
332 | global $System;
|
---|
333 |
|
---|
334 | $Result = array();
|
---|
335 | $DbResult = $System->Database->query('SELECT * FROM `Language` WHERE `Enabled` = 1');
|
---|
336 | while($DbRow = $DbResult->fetch_assoc())
|
---|
337 | $Result[$DbRow['Id']] = $DbRow;
|
---|
338 | return($Result);
|
---|
339 | }
|
---|
340 |
|
---|
341 | function GetTranslationTree()
|
---|
342 | {
|
---|
343 | global $System;
|
---|
344 |
|
---|
345 | $Result = array();
|
---|
346 | $DbResult = $System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`');
|
---|
347 | while($DbRow = $DbResult->fetch_assoc())
|
---|
348 | {
|
---|
349 | $DbRow['Items'] = array();
|
---|
350 | $Result[$DbRow['Id']] = $DbRow;
|
---|
351 | }
|
---|
352 | $DbResult = $System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
|
---|
353 | while($DbRow = $DbResult->fetch_assoc())
|
---|
354 | {
|
---|
355 | $Result[$DbRow['Group']]['Items'][] = $DbRow;
|
---|
356 | }
|
---|
357 | return($Result);
|
---|
358 | }
|
---|
359 |
|
---|
360 | $Moderators = array('Překladatel', 'Moderátor', 'Administrátor');
|
---|
361 |
|
---|
362 | function HumanDate($SQLDateTime)
|
---|
363 | {
|
---|
364 | $DateTimeParts = explode(' ', $SQLDateTime);
|
---|
365 | if($DateTimeParts[0] != '0000-00-00')
|
---|
366 | {
|
---|
367 | $DateParts = explode('-', $DateTimeParts[0]);
|
---|
368 | return(($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1));
|
---|
369 | } else return(' ');
|
---|
370 | }
|
---|
371 |
|
---|
372 | function HumanDateTime($SQLDateTime)
|
---|
373 | {
|
---|
374 | $DateTimeParts = explode(' ', $SQLDateTime);
|
---|
375 | if($DateTimeParts[0] != '0000-00-00' and $SQLDateTime <> '')
|
---|
376 | {
|
---|
377 | $DateParts = explode('-', $DateTimeParts[0]);
|
---|
378 | $Output = ($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1);
|
---|
379 | } else $Output = ' ';
|
---|
380 | if(count($DateTimeParts) > 1)
|
---|
381 | if($DateTimeParts[1] != '00:00:00')
|
---|
382 | {
|
---|
383 | $TimeParts = explode(':', $DateTimeParts[1]);
|
---|
384 | $Output .= ' '.($TimeParts[0] * 1).':'.($TimeParts[1] * 1).':'.($TimeParts[2] * 1);
|
---|
385 | };
|
---|
386 | return($Output);
|
---|
387 | }
|
---|
388 |
|
---|
389 | function FollowingTran($TextID, $Table, $GroupId, $Prev = false)
|
---|
390 | {
|
---|
391 | global $System, $Config;
|
---|
392 |
|
---|
393 | if($Prev)
|
---|
394 | $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
|
---|
395 | '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
|
---|
396 | 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
|
---|
397 | 'AND (`sub`.`entry` = `item`.`entry`)) AND (`ID` < '.$TextID.') ORDER BY `ID` DESC LIMIT 1';
|
---|
398 | else $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
|
---|
399 | '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
|
---|
400 | 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
|
---|
401 | 'AND (`sub`.`entry` = `item`.`entry`)) AND `ID` > '.$TextID.' ORDER BY `ID` LIMIT 1';
|
---|
402 |
|
---|
403 | $DbResult = $System->Database->query($sql);
|
---|
404 | $Next = $DbResult->fetch_assoc();
|
---|
405 | if($Next)
|
---|
406 | {
|
---|
407 | if($Prev) $Output = '<a href="form.php?group='.$GroupId.'&ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> ';
|
---|
408 | else $Output = '<a href="form.php?group='.$GroupId.'&ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> ';
|
---|
409 | return('form.php?group='.$GroupId.'&ID='.$Next['ID']);
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | function GetBuildNumber($Version)
|
---|
414 | {
|
---|
415 | global $System, $BuildNumbers;
|
---|
416 |
|
---|
417 | if(isset($BuildNumbers[$Version]) == false)
|
---|
418 | {
|
---|
419 | $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"';
|
---|
420 | $DbResult = $System->Database->query($sql);
|
---|
421 | $DbRow = $DbResult->fetch_assoc();
|
---|
422 | $BuildNumbers[$Version] = $DbRow['BuildNumber'];
|
---|
423 | }
|
---|
424 | return($BuildNumbers[$Version]);
|
---|
425 | }
|
---|
426 |
|
---|
427 | // TODO: Client version build number should not be used in internal references
|
---|
428 | function GetVersionWOW($BuildNumber)
|
---|
429 | {
|
---|
430 | global $System, $VersionsWOW;
|
---|
431 |
|
---|
432 | if(isset($VersionsWOW[$BuildNumber]) == false)
|
---|
433 | {
|
---|
434 | $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
|
---|
435 | $DbResult = $System->Database->query($sql);
|
---|
436 | $Version = $DbResult->fetch_assoc();
|
---|
437 | $VersionsWOW[$BuildNumber] = $Version['Version'];
|
---|
438 | }
|
---|
439 | return($VersionsWOW[$BuildNumber]);
|
---|
440 | }
|
---|
441 |
|
---|
442 | // TODO: Client version build number should not be used in internal references
|
---|
443 | function GetVersionWOWId($BuildNumber)
|
---|
444 | {
|
---|
445 | global $System, $VersionsWOWId;
|
---|
446 |
|
---|
447 | if(isset($VersionsWOWId[$BuildNumber]) == false)
|
---|
448 | {
|
---|
449 | $sql = 'SELECT `Id` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
|
---|
450 | $DbResult = $System->Database->query($sql);
|
---|
451 | $Version = $DbResult->fetch_assoc();
|
---|
452 | $VersionsWOWId[$BuildNumber] = $Version['Id'];
|
---|
453 | }
|
---|
454 | return($VersionsWOWId[$BuildNumber]);
|
---|
455 | }
|
---|
456 |
|
---|
457 | function LoadGroupIdParameter()
|
---|
458 | {
|
---|
459 | global $TranslationTree;
|
---|
460 |
|
---|
461 | if(array_key_exists('group', $_GET)) $GroupId = $_GET['group'] * 1;
|
---|
462 | else $GroupId = 1;
|
---|
463 |
|
---|
464 | if(isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.');
|
---|
465 | return($GroupId);
|
---|
466 | }
|
---|
467 |
|
---|
468 | function LoadCommandLineParameters()
|
---|
469 | {
|
---|
470 | if(!array_key_exists('REMOTE_ADDR', $_SERVER))
|
---|
471 | {
|
---|
472 | foreach($_SERVER['argv'] as $Parameter)
|
---|
473 | {
|
---|
474 | if(strpos($Parameter, '=') !== false)
|
---|
475 | {
|
---|
476 | $Index = substr($Parameter, 0, strpos($Parameter, '='));
|
---|
477 | $Parameter = substr($Parameter, strpos($Parameter, '=') + 1);
|
---|
478 | //echo($Index.' ---- '.$Parameter);
|
---|
479 | $_GET[$Index] = $Parameter;
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | function ShowTabs($Tabs)
|
---|
486 | {
|
---|
487 | $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
|
---|
488 |
|
---|
489 | if(array_key_exists('Tab', $_GET)) $_SESSION['Tab'] = $_GET['Tab'];
|
---|
490 | if(!array_key_exists('Tab', $_SESSION)) $_SESSION['Tab'] = 0;
|
---|
491 | if(($_SESSION['Tab'] < 0) or ($_SESSION['Tab'] > (count($Tabs) - 1))) $_SESSION['Tab'] = 0;
|
---|
492 | $Output = '<div id="header">'.
|
---|
493 | '<ul>';
|
---|
494 | foreach($Tabs as $Index => $Tab)
|
---|
495 | {
|
---|
496 | $QueryItems['Tab'] = $Index;
|
---|
497 | if($Index == $_SESSION['Tab']) $Selected = ' id="selected"';
|
---|
498 | else $Selected = '';
|
---|
499 | $Output .= '<li'.$Selected.'><a href="?'.SetQueryStringArray($QueryItems).'">'.$Tab.'</a></li>';
|
---|
500 | }
|
---|
501 | $Output .= '</ul></div>';
|
---|
502 | return($Output);
|
---|
503 | }
|
---|
504 |
|
---|
505 | function CheckBox($Name, $Checked = false, $Id = '', $Class = '', $Disabled = false)
|
---|
506 | {
|
---|
507 | if($Id) $Id = ' id="'.$Id.'"'; else $Id = '';
|
---|
508 | if($Class) $Class = ' class="'.$Class.'"'; else $Class = '';
|
---|
509 | if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
|
---|
510 | if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
|
---|
511 | return('<input type="checkbox" value="checked" name="'.$Name.'"'.$Checked.$Disabled.$Id.$Class.' />');
|
---|
512 | }
|
---|
513 |
|
---|
514 | function RadioButton($Name, $Value, $Checked = false, $OnClick = '', $Disabled = false)
|
---|
515 | {
|
---|
516 | if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
|
---|
517 | if($OnClick != '') $OnClick = ' onclick="'.$OnClick.'"'; else $OnClick = '';
|
---|
518 | if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
|
---|
519 | return('<input type="radio" name="'.$Name.'" value="'.$Value.'"'.$Checked.$Disabled.$OnClick.'/>');
|
---|
520 | }
|
---|
521 |
|
---|
522 | function SelectOption($Name, $Text, $Selected = false)
|
---|
523 | {
|
---|
524 | if($Selected) $Selected = ' selected="selected"'; else $Selected = '';
|
---|
525 | return('<option value="'.$Name.'"'.$Selected.'>'.$Text.'</option>');
|
---|
526 | }
|
---|
527 |
|
---|
528 | function DeleteDirectory($dirname)
|
---|
529 | {
|
---|
530 | if(is_dir($dirname))
|
---|
531 | {
|
---|
532 | $dir_handle = opendir($dirname);
|
---|
533 | if(!$dir_handle) return(false);
|
---|
534 | while($file = readdir($dir_handle))
|
---|
535 | {
|
---|
536 | if(($file != '.') and ($file != '..'))
|
---|
537 | {
|
---|
538 | if(!is_dir($dirname.'/'.$file)) unlink($dirname.'/'.$file);
|
---|
539 | else DeleteDirectory($dirname.'/'.$file);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | closedir($dir_handle);
|
---|
543 | rmdir($dirname);
|
---|
544 | }
|
---|
545 | return(true);
|
---|
546 | }
|
---|
547 |
|
---|
548 | function ErrorMessage($Text)
|
---|
549 | {
|
---|
550 | ShowPage($Text);
|
---|
551 | die();
|
---|
552 | }
|
---|
553 |
|
---|
554 | function GetIDbyName($Table)
|
---|
555 | {
|
---|
556 | global $TranslationTree;
|
---|
557 |
|
---|
558 | foreach($TranslationTree as $TableID => $Value)
|
---|
559 | {
|
---|
560 | if($Value['TablePrefix'] == $Table) return $TableID;
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | function GetTranslatNamesArray()
|
---|
565 | {
|
---|
566 | $TablesColumn = array
|
---|
567 | (
|
---|
568 | 'TextGameObject' => 'Name',
|
---|
569 | 'TextCreature' => 'name',
|
---|
570 | 'TextTransport' => 'Name',
|
---|
571 | 'TextAreaTriggerTeleport' => 'Name',
|
---|
572 | 'TextAreaTriggerTavern' => 'Name',
|
---|
573 | 'TextArea' => 'Name',
|
---|
574 | 'TextAreaPOI' => 'Name',
|
---|
575 | 'TextCharacterClass' => 'Name',
|
---|
576 | 'TextCharacterRace' => 'Name1',
|
---|
577 | 'TextItemSubClass' => 'Name',
|
---|
578 | 'TextItemSubClass' => 'Name2',
|
---|
579 | 'TextCreatureType' => 'Name',
|
---|
580 | 'TextItem' => 'Name',
|
---|
581 | 'Dictionary' => 'Text',
|
---|
582 | );
|
---|
583 | return($TablesColumn);
|
---|
584 | }
|
---|
585 |
|
---|
586 | function GetTranslatNames($Text,$mode,$TablesColumn, $FirstBig = True)
|
---|
587 | {
|
---|
588 | global $System, $Config;
|
---|
589 |
|
---|
590 | /* $TablesID = array('gameobject' => 5,
|
---|
591 | 'creature' => 6,
|
---|
592 | 'item' => 4,
|
---|
593 | 'transports' => 'Name',
|
---|
594 | 'areatrigger_teleport' => 'Name',
|
---|
595 | 'areatrigger_tavern' => 'Name',); */
|
---|
596 | $buff = array();
|
---|
597 |
|
---|
598 | //change chars by we want to separate
|
---|
599 | $Text = str_replace('$B$B',' ',$Text);
|
---|
600 | $Text = str_replace('$b$b',' ',$Text);
|
---|
601 | $Text = str_replace('$G',' ',$Text);
|
---|
602 | $Text = str_replace('$I',' ',$Text);
|
---|
603 | $Text = str_replace('$N',' ',$Text);
|
---|
604 | $Text = str_replace('$R',' ',$Text);
|
---|
605 | $Text = str_replace('$g',' ',$Text);
|
---|
606 | $Text = str_replace('$i',' ',$Text);
|
---|
607 | $Text = str_replace('$n',' ',$Text);
|
---|
608 | $Text = str_replace('$r',' ',$Text);
|
---|
609 | $Text = str_replace(':',' ',$Text);
|
---|
610 | $Text = str_replace(';',' ',$Text);
|
---|
611 | $Text = str_replace('!',' ',$Text);
|
---|
612 | $Text = str_replace('?',' ',$Text);
|
---|
613 | $Text = str_replace('.',' ',$Text);
|
---|
614 | $Text = str_replace(',',' ',$Text);
|
---|
615 | $Text = str_replace('\'s',' ',$Text);
|
---|
616 | $Text = str_replace('<',' ',$Text);
|
---|
617 | $Text = str_replace('>',' ',$Text);
|
---|
618 | $ArrStr = explode(' ', $Text);
|
---|
619 | $sqlall = '';
|
---|
620 | foreach($TablesColumn as $Table => $Column)
|
---|
621 | {
|
---|
622 | $orderinby = ' ORDER BY ID DESC ';
|
---|
623 | $sql = 'SELECT `ID`, (SELECT CONCAT( \''.GetIDbyName($Table).'\' )) AS `GoupId`,`'.$Column.'` AS Orig, (SELECT `'.$Column.'` FROM `'.$Table.'` AS `T` WHERE '.
|
---|
624 | '(`O`.`Entry` = `T`.`Entry`) AND (`Language` <> '.$Config['OriginalLanguage'].') '.$orderinby.' LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE ';
|
---|
625 | $groupby = ' GROUP BY `'.$Column.'` ';
|
---|
626 |
|
---|
627 | $where = '(`Language` = '.$Config['OriginalLanguage'].') ';
|
---|
628 | if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
|
---|
629 | if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
|
---|
630 | $where .= ' AND (';
|
---|
631 | if (array_search('the' , $ArrStr)) $where .= '(`O`.`'.$Column.'` LIKE "The %") OR ';
|
---|
632 |
|
---|
633 | $SqlOK = false;
|
---|
634 | if (count($ArrStr) > 0) {
|
---|
635 | for($i = 0; $i < count($ArrStr); $i++)
|
---|
636 | {
|
---|
637 |
|
---|
638 | //find word only if is 3 characters and more, and if starts by upper char, and search only once
|
---|
639 | if ((strlen($ArrStr[$i]) > 3) or ( ((count($ArrStr) < 6) or ($i == 0)) and (strlen($ArrStr[$i]) > 0) ) ) //length
|
---|
640 | if ((!$FirstBig) or (ctype_upper(substr($ArrStr[$i],0,1))) or (count($ArrStr) < 6) ) //first big
|
---|
641 | if (array_search($ArrStr[$i], $ArrStr) == $i) { //first in array
|
---|
642 | $where .= '(`O`.`'.$Column.'` LIKE "'.addslashes($ArrStr[$i]).'%") OR ';
|
---|
643 | $SqlOK = true;
|
---|
644 | }
|
---|
645 | }
|
---|
646 | $where = substr($where, 0, strlen($where) - 4);
|
---|
647 | $where .= ')';
|
---|
648 | }
|
---|
649 | if ($SqlOK) {
|
---|
650 | //$sql.$where.$groupby.$orderby
|
---|
651 | // $buff[] = array($Line['ID'], GetIDbyName($Table), $Line['Orig'], $Line['Tran']);
|
---|
652 | if ($sqlall <> '') { $sqlall .= ' UNION ALL ( '.$sql.$where.$groupby.' )';}
|
---|
653 | else {$sqlall .= ' ( '.$sql.$where.$groupby.' )'; }
|
---|
654 | }
|
---|
655 |
|
---|
656 | }
|
---|
657 | if ($SqlOK) {
|
---|
658 | $orderby = ' ORDER BY LENGTH(Orig) DESC ';
|
---|
659 | // echo $sqlall. $orderby;
|
---|
660 | $DbResult = $System->Database->query($sqlall.$orderby);
|
---|
661 | // echo ($sql.'|'.$where.'|'.$groupby);
|
---|
662 | while($Line = $DbResult->fetch_assoc())
|
---|
663 | {
|
---|
664 | $buff[] = array($Line['ID'], $Line['GoupId'], $Line['Orig'], $Line['Tran']);
|
---|
665 | }
|
---|
666 | }
|
---|
667 | return $buff;
|
---|
668 | }
|
---|
669 |
|
---|
670 | function ProgressBar($Width, $Percent, $Text = '')
|
---|
671 | {
|
---|
672 | $Pixels = $Width * ($Percent / 100);
|
---|
673 | if($Pixels > $Width) $Pixels = $Width;
|
---|
674 | if($Text == '') $Text = $Percent;
|
---|
675 |
|
---|
676 | return('<div class="progressbar" style="width: '.$Width.'px">'.
|
---|
677 | '<div class="bar" style="width: '.$Pixels.'px;"></div>'.
|
---|
678 | '<div class="text" style="width: '.$Width.'px">'.$Text.'</div>'.
|
---|
679 | '</div>');
|
---|
680 | }
|
---|
681 |
|
---|
682 | function GetLevelMinMax($XP)
|
---|
683 | {
|
---|
684 | $IndexLevel = 100;
|
---|
685 |
|
---|
686 | if($XP > 0) $Level = floor(sqrt($XP / $IndexLevel));
|
---|
687 | else $Level = 0;
|
---|
688 | $MinXP = $Level * $Level * $IndexLevel;
|
---|
689 | $MaxXP = ($Level + 1) * ($Level + 1) * $IndexLevel;
|
---|
690 | $MaxXP = $MaxXP - $MinXP;
|
---|
691 | $XP = $XP - $MinXP;
|
---|
692 | return(array('Level' => $Level, 'XP' => $XP, 'MaxXP' => $MaxXP));
|
---|
693 | }
|
---|
694 |
|
---|
695 | function GetParameter($Name, $Default = '', $Numeric = false, $Session = false)
|
---|
696 | {
|
---|
697 | $Result = $Default;
|
---|
698 | if(array_key_exists($Name, $_GET)) $Result = $_GET[$Name];
|
---|
699 | else if(array_key_exists($Name, $_POST)) $Result = $_POST[$Name];
|
---|
700 | else if($Session and array_key_exists($Name, $_SESSION)) $Result = $_SESSION[$Name];
|
---|
701 | if($Numeric and !is_numeric($Result)) $Result = $Default;
|
---|
702 | if($Session) $_SESSION[$Name] = $Result;
|
---|
703 | return($Result);
|
---|
704 | }
|
---|
705 |
|
---|
706 | function MakeActiveLinks($Content)
|
---|
707 | {
|
---|
708 | $Content = htmlspecialchars($Content);
|
---|
709 | $Content = str_replace("\n", ' <br/>', $Content);
|
---|
710 | $Content = str_replace("\r", '', $Content);
|
---|
711 |
|
---|
712 | $Result = '';
|
---|
713 | $I = 0;
|
---|
714 | while((strpos($Content, 'http://') !== false) or (strpos($Content, 'https://') !== false))
|
---|
715 | {
|
---|
716 | if(strpos($Content, 'http://') !== false) $I = strpos($Content, 'http://');
|
---|
717 | if(strpos($Content, 'https://') !== false) $I = strpos($Content, 'https://');
|
---|
718 | $Result .= substr($Content, 0, $I);
|
---|
719 | $Content = substr($Content, $I);
|
---|
720 | $SpacePos = strpos($Content, ' ');
|
---|
721 | if($SpacePos !== false) $URL = substr($Content, 0, strpos($Content, ' '));
|
---|
722 | else $URL = substr($Content, 0);
|
---|
723 |
|
---|
724 | $Result .= '<a href="'.$URL.'">'.$URL.'</a>';
|
---|
725 | $Content = substr($Content, strlen($URL));
|
---|
726 | }
|
---|
727 | $Result .= $Content;
|
---|
728 | return($Result);
|
---|
729 | }
|
---|
730 |
|
---|
731 | define('MESSAGE_WARNING', 0);
|
---|
732 | define('MESSAGE_CRITICAL', 1);
|
---|
733 | define('MESSAGE_INFORMATION', 2);
|
---|
734 |
|
---|
735 | function ShowMessage($Text, $Type = MESSAGE_INFORMATION)
|
---|
736 | {
|
---|
737 | global $System;
|
---|
738 |
|
---|
739 | $IconName = array(
|
---|
740 | MESSAGE_INFORMATION => 'information',
|
---|
741 | MESSAGE_WARNING => 'warning',
|
---|
742 | MESSAGE_CRITICAL => 'critical'
|
---|
743 | );
|
---|
744 | $BackgroundColor = array(
|
---|
745 | MESSAGE_INFORMATION => '#e0e0ff',
|
---|
746 | MESSAGE_WARNING => '#ffffe0',
|
---|
747 | MESSAGE_CRITICAL => '#ffe0e0'
|
---|
748 | );
|
---|
749 |
|
---|
750 | return('<div class="message" style="background-color: '.$BackgroundColor[$Type].
|
---|
751 | ';"><table><tr><td class="icon"><img src="'.
|
---|
752 | $System->Link('/images/message/'.$IconName[$Type].'.png').'" alt="'.
|
---|
753 | $IconName[$Type].'"><td>'.$Text.'</td></tr></table></div>');
|
---|
754 | }
|
---|
755 |
|
---|
756 | function ProcessURL()
|
---|
757 | {
|
---|
758 | if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
|
---|
759 | $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
|
---|
760 | else $PathString = '';
|
---|
761 | if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
|
---|
762 | $PathItems = explode('/', $PathString);
|
---|
763 | if(strpos(GetRequestURI(), '?') !== false)
|
---|
764 | $_SERVER['QUERY_STRING'] = substr(GetRequestURI(), strpos(GetRequestURI(), '?') + 1);
|
---|
765 | else $_SERVER['QUERY_STRING'] = '';
|
---|
766 | parse_str($_SERVER['QUERY_STRING'], $_GET);
|
---|
767 | // SQL injection hack protection
|
---|
768 | foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
|
---|
769 | return($PathItems);
|
---|
770 | }
|
---|
771 |
|
---|
772 | function WriteLanguages($Selected)
|
---|
773 | {
|
---|
774 | global $System;
|
---|
775 |
|
---|
776 | $Output = '<select name="Language">';
|
---|
777 | $DbResult = $System->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1');
|
---|
778 | while($Language = $DbResult->fetch_assoc())
|
---|
779 | {
|
---|
780 | $Output .= '<option value="'.$Language['Id'].'"';
|
---|
781 | if($Selected == $Language['Id'])
|
---|
782 | $Output .= ' selected="selected"';
|
---|
783 | $Output .= '>'.$Language['Name'].'</option>';
|
---|
784 | }
|
---|
785 | $Output .= '</select>';
|
---|
786 | return($Output);
|
---|
787 | }
|
---|
788 |
|
---|
789 | function GetClientProxyAddresses()
|
---|
790 | {
|
---|
791 | if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
---|
792 | else $IP = array();
|
---|
793 | }
|
---|
794 |
|
---|
795 | function GetRemoteAddress()
|
---|
796 | {
|
---|
797 | if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
|
---|
798 | else $IP = '';
|
---|
799 | return($IP);
|
---|
800 | }
|
---|
801 |
|
---|
802 | function GetRequestURI()
|
---|
803 | {
|
---|
804 | if(array_key_exists('REQUEST_URI', $_SERVER)) return($_SERVER['REQUEST_URI']);
|
---|
805 | else return($_SERVER['PHP_SELF']);
|
---|
806 | }
|
---|