source: trunk/includes/global.php@ 758

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