source: trunk/includes/global.php@ 798

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