source: trunk/includes/global.php@ 577

Last change on this file since 577 was 577, checked in by chronos, 12 years ago
  • Modified: Moved some code from global to system file. System class is now serving as main application class. Now old files which still use ShowPage function need system initialization with $InitSystem = true; before global.php inclusion.
  • Modified: Get rid of some global reference to $System, $Config and $User variables.
  • Modified: Search result functionality moved to application module from action.php file.
File size: 21.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__).'/rss.php');
8include_once(dirname(__FILE__).'/Page.php');
9if(file_exists(dirname(__FILE__).'/config.php'))
10 include_once(dirname(__FILE__).'/config.php');
11include_once(dirname(__FILE__).'/Version.php');
12include_once(dirname(__FILE__).'/AppModule.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');
33
34
35// Back compatibility, will be removed
36if(isset($InitSystem) and $InitSystem)
37{
38 $System = new System();
39 $System->DoNotShowPage = true;
40 $System->Run();
41}
42
43class TempPage extends Page
44{
45 function Show()
46 {
47 global $TempPageContent;
48 return($TempPageContent);
49 }
50}
51function ShowPage($Content)
52{
53 global $TempPageContent, $System;
54
55 $TempPage = new TempPage($System);
56 $System->Pages['temporary-page'] = 'TempPage';
57 $_SERVER['REDIRECT_QUERY_STRING'] = 'temporary-page';
58 $TempPageContent = $Content;
59 $System->PathItems = ProcessURL();
60 $System->ShowPage();
61}
62
63
64function GetMicrotime()
65{
66 list($Usec, $Sec) = explode(' ', microtime());
67 return ((float)$Usec + (float)$Sec);
68}
69
70$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
71
72function HumanSize($Value)
73{
74 global $UnitNames;
75
76 $UnitIndex = 0;
77 while($Value > 1024)
78 {
79 $Value = round($Value / 1024, 3);
80 $UnitIndex++;
81 }
82 return($Value.' '.$UnitNames[$UnitIndex]);
83}
84
85function GetQueryStringArray($QueryString)
86{
87 $Result = array();
88 $Parts = explode('&', $QueryString);
89 foreach($Parts as $Part)
90 {
91 if($Part != '')
92 {
93 if(!strpos($Part, '=')) $Part .= '=';
94 $Item = explode('=', $Part);
95 $Result[$Item[0]] = $Item[1];
96 }
97 }
98 return($Result);
99}
100
101function SetQueryStringArray($QueryStringArray)
102{
103 $Parts = array();
104 foreach($QueryStringArray as $Index => $Item)
105 {
106 $Parts[] = $Index.'='.$Item;
107 }
108 return(implode('&', $Parts));
109}
110
111function utf2ascii($text)
112{
113 $return = Str_Replace(
114 Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") ,
115 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") ,
116 $text);
117 //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami
118 //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"'
119 //$return = StrToLower($return); // velká písmena nahradí malými.
120 return($return);
121}
122
123function getmonthyears($Days)
124{
125 $month = floor($Days / 30);
126 $year = floor($month / 12);
127 $Days = floor($Days - $month * 30);
128 $month = $month - $year * 12;
129 return($year.'r '.$month.'m '.$Days.'d');
130}
131
132function GetPageList($TotalCount)
133{
134 global $System;
135
136 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
137
138 $ItemPerPage = $System->Config['Web']['ItemsPerPage'];
139 $Around = round($System->Config['Web']['VisiblePagingItems'] / 2);
140 $Result = '';
141 $PageCount = floor($TotalCount / $ItemPerPage) + 1;
142
143 if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
144 if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
145 if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
146 if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
147 $CurrentPage = $_SESSION['Page'];
148
149
150 $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> &nbsp; Stránky: ';
151
152 $Result = '';
153 if($PageCount > 1)
154 {
155 if($CurrentPage > 0)
156 {
157 $QueryItems['page'] = 0;
158 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
159 $QueryItems['page'] = ($CurrentPage - 1);
160 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
161 }
162 $PagesMax = $PageCount - 1;
163 $PagesMin = 0;
164 if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
165 if($PagesMin < ($CurrentPage - $Around))
166 {
167 $Result.= ' ... ';
168 $PagesMin = $CurrentPage - $Around;
169 }
170 for($i = $PagesMin; $i <= $PagesMax; $i++)
171 {
172 if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
173 else {
174 $QueryItems['page'] = $i;
175 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
176 }
177 }
178 if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
179 if($CurrentPage < ($PageCount - 1))
180 {
181 $QueryItems['page'] = ($CurrentPage + 1);
182 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
183 $QueryItems['page'] = ($PageCount - 1);
184 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
185 }
186 }
187 $Result = '<div style="text-align: center">'.$Result.'</div>';
188 return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
189 'Page' => $CurrentPage,
190 'Output' => $Result,
191 ));
192}
193
194$OrderDirSQL = array('ASC', 'DESC');
195$OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
196
197function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
198{
199 global $OrderDirSQL, $OrderArrowImage, $Config, $System;
200
201 if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
202 if(array_key_exists('OrderDir', $_GET) and (array_key_exists($_GET['OrderDir'], $OrderArrowImage)))
203 $_SESSION['OrderDir'] = $_GET['OrderDir'];
204 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
205 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
206
207 // Check OrderCol
208 $Found = false;
209 foreach($Columns as $Column)
210 {
211 if($Column['Name'] == $_SESSION['OrderCol'])
212 {
213 $Found = true;
214 break;
215 }
216 }
217 if($Found == false)
218 {
219 $_SESSION['OrderCol'] = $DefaultColumn;
220 $_SESSION['OrderDir'] = $DefaultOrder;
221 }
222 // Check OrderDir
223 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
224
225 $Result = '';
226 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
227 foreach($Columns as $Index => $Column)
228 {
229 $QueryItems['OrderCol'] = $Column['Name'];
230 $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
231 if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.
232 $System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow">';
233 else $ArrowImage = '';
234 if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
235 else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>';
236 }
237 return(array(
238 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
239 'Output' => '<tr>'.$Result.'</tr>',
240 'Column' => $_SESSION['OrderCol'],
241 'Direction' => $_SESSION['OrderDir'],
242 ));
243}
244
245function ClientVersionSelection($Selected)
246{
247 global $System;
248
249 $Output = '<select name="ClientVersion">';
250 $DbResult = $System->Database->select('ClientVersion', '`Id`, `Version`', '`Imported` = 1');
251 $Output .= '<option value=""';
252 if($Selected == '')
253 $Output .= ' selected="selected"';
254 $Output .= '>Žádná</option>';
255 while($ClientVersion = $DbResult->fetch_assoc())
256 {
257 $Output .= '<option value="'.$ClientVersion['Id'].'"';
258 if($Selected == $ClientVersion['Id'])
259 $Output .= ' selected="selected"';
260 $Output .= '>'.$ClientVersion['Version'].'</option>';
261 }
262 $Output .= '</select>';
263 return($Output);
264}
265
266function GetLanguageList()
267{
268 global $System;
269
270 $Result = array();
271 $DbResult = $System->Database->query('SELECT * FROM `Language` WHERE `Enabled` = 1');
272 while($DbRow = $DbResult->fetch_assoc())
273 $Result[$DbRow['Id']] = $DbRow;
274 return($Result);
275}
276
277function GetTranslationTree()
278{
279 global $System;
280
281 $Result = array();
282 $DbResult = $System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`');
283 while($DbRow = $DbResult->fetch_assoc())
284 {
285 $DbRow['Items'] = array();
286 $Result[$DbRow['Id']] = $DbRow;
287 }
288 $DbResult = $System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
289 while($DbRow = $DbResult->fetch_assoc())
290 {
291 $Result[$DbRow['Group']]['Items'][] = $DbRow;
292 }
293 return($Result);
294}
295
296$Moderators = array('Překladatel', 'Moderátor', 'Administrátor');
297
298function HumanDate($SQLDateTime)
299{
300 $DateTimeParts = explode(' ', $SQLDateTime);
301 if($DateTimeParts[0] != '0000-00-00')
302 {
303 $DateParts = explode('-', $DateTimeParts[0]);
304 return(($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1));
305 } else return('&nbsp;');
306}
307
308function HumanDateTime($SQLDateTime)
309{
310 $DateTimeParts = explode(' ', $SQLDateTime);
311 if($DateTimeParts[0] != '0000-00-00')
312 {
313 $DateParts = explode('-', $DateTimeParts[0]);
314 $Output = ($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1);
315 } else $Output = '&nbsp;';
316 if(count($DateTimeParts) > 1)
317 if($DateTimeParts[1] != '00:00:00')
318 {
319 $TimeParts = explode(':', $DateTimeParts[1]);
320 $Output .= ' '.($TimeParts[0] * 1).':'.($TimeParts[1] * 1).':'.($TimeParts[2] * 1);
321 };
322 return($Output);
323}
324
325function FollowingTran($TextID, $Table, $GroupId, $Prev = false)
326{
327 global $System, $Config;
328
329 if($Prev)
330 $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
331 '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
332 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
333 'AND (`sub`.`entry` = `item`.`entry`)) AND (`ID` < '.$TextID.') ORDER BY `ID` DESC LIMIT 1';
334 else $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
335 '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
336 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
337 'AND (`sub`.`entry` = `item`.`entry`)) AND `ID` > '.$TextID.' ORDER BY `ID` LIMIT 1';
338
339 $DbResult = $System->Database->query($sql);
340 $Next = $DbResult->fetch_assoc();
341 if($Next)
342 {
343 if($Prev) $Output = '<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> ';
344 else $Output = '<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> ';
345 return('form.php?group='.$GroupId.'&amp;ID='.$Next['ID']);
346 }
347}
348
349function GetBuildNumber($Version)
350{
351 global $System, $BuildNumbers;
352
353 if(isset($BuildNumbers[$Version]) == false)
354 {
355 $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"';
356 $DbResult = $System->Database->query($sql);
357 $DbRow = $DbResult->fetch_assoc();
358 $BuildNumbers[$Version] = $DbRow['BuildNumber'];
359 }
360 return($BuildNumbers[$Version]);
361}
362
363function GetVersionWOW($BuildNumber)
364{
365 global $System, $VersionsWOW;
366
367 if(isset($VersionsWOW[$BuildNumber]) == false)
368 {
369 $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
370 $DbResult = $System->Database->query($sql);
371 $Version = $DbResult->fetch_assoc();
372 $VersionsWOW[$BuildNumber] = $Version['Version'];
373 }
374 return($VersionsWOW[$BuildNumber]);
375}
376
377function LoadGroupIdParameter()
378{
379 global $TranslationTree;
380
381 if(array_key_exists('group', $_GET)) $GroupId = $_GET['group'] * 1;
382 else $GroupId = 1;
383
384 if(isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.');
385 return($GroupId);
386}
387
388function LoadCommandLineParameters()
389{
390 if(!array_key_exists('REMOTE_ADDR', $_SERVER))
391 {
392 foreach($_SERVER['argv'] as $Parameter)
393 {
394 if(strpos($Parameter, '=') !== false)
395 {
396 $Index = substr($Parameter, 0, strpos($Parameter, '='));
397 $Parameter = substr($Parameter, strpos($Parameter, '=') + 1);
398 //echo($Index.' ---- '.$Parameter);
399 $_GET[$Index] = $Parameter;
400 }
401 }
402 }
403}
404
405function ShowTabs($Tabs)
406{
407 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
408
409 if(array_key_exists('Tab', $_GET)) $_SESSION['Tab'] = $_GET['Tab'];
410 if(!array_key_exists('Tab', $_SESSION)) $_SESSION['Tab'] = 0;
411 if(($_SESSION['Tab'] < 0) or ($_SESSION['Tab'] > (count($Tabs) - 1))) $_SESSION['Tab'] = 0;
412 $Output = '<div id="header">'.
413 '<ul>';
414 foreach($Tabs as $Index => $Tab)
415 {
416 $QueryItems['Tab'] = $Index;
417 if($Index == $_SESSION['Tab']) $Selected = ' id="selected"';
418 else $Selected = '';
419 $Output .= '<li'.$Selected.'><a href="?'.SetQueryStringArray($QueryItems).'">'.$Tab.'</a></li>';
420 }
421 $Output .= '</ul></div>';
422 return($Output);
423}
424
425function CheckBox($Name, $Checked = false, $Id = '', $Class = '', $Disabled = false)
426{
427 if($Id) $Id = ' id="'.$Id.'"'; else $Id = '';
428 if($Class) $Class = ' class="'.$Class.'"'; else $Class = '';
429 if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
430 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
431 return('<input type="checkbox" value="checked" name="'.$Name.'"'.$Checked.$Disabled.$Id.$Class.' />');
432}
433
434function RadioButton($Name, $Value, $Checked = false, $OnClick = '', $Disabled = false)
435{
436 if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
437 if($OnClick != '') $OnClick = ' onclick="'.$OnClick.'"'; else $OnClick = '';
438 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
439 return('<input type="radio" name="'.$Name.'" value="'.$Value.'"'.$Checked.$Disabled.$OnClick.'/>');
440}
441
442function SelectOption($Name, $Text, $Selected = false)
443{
444 if($Selected) $Selected = ' selected="selected"'; else $Selected = '';
445 return('<option value="'.$Name.'"'.$Selected.'>'.$Text.'</option>');
446}
447
448function DeleteDirectory($dirname)
449{
450 if(is_dir($dirname))
451 {
452 $dir_handle = opendir($dirname);
453 if(!$dir_handle) return(false);
454 while($file = readdir($dir_handle))
455 {
456 if(($file != '.') and ($file != '..'))
457 {
458 if(!is_dir($dirname.'/'.$file)) unlink($dirname.'/'.$file);
459 else DeleteDirectory($dirname.'/'.$file);
460 }
461 }
462 closedir($dir_handle);
463 rmdir($dirname);
464 }
465 return(true);
466}
467
468function ErrorMessage($Text)
469{
470 ShowPage($Text);
471 die();
472}
473
474function GetIDbyName($Table)
475{
476 global $TranslationTree;
477
478 foreach($TranslationTree as $TableID => $Value)
479 {
480 if($Value['TablePrefix'] == $Table) return $TableID;
481 }
482}
483
484function GetTranslatNames($Text,$mode,$TablesColumn)
485{
486 global $System, $Config;
487
488 /* $TablesID = array('gameobject' => 5,
489 'creature' => 6,
490 'item' => 4,
491 'transports' => 'Name',
492 'areatrigger_teleport' => 'Name',
493 'areatrigger_tavern' => 'Name',); */
494 $buff = array();
495
496 foreach($TablesColumn as $Table => $Column)
497 {
498 $sql = 'SELECT `ID`,`'.$Column.'`, (SELECT `'.$Column.'` FROM `'.$Table.'` AS `T` WHERE '.
499 '(`O`.`Entry` = `T`.`Entry`) AND (`Language` <> '.$Config['OriginalLanguage'].') LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE ';
500 $groupby = ' GROUP BY `'.$Column.'`';
501
502 $ArrStr = explode(' ', $Text);
503 $where = '(`Language` = '.$Config['OriginalLanguage'].') ';
504 if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
505 if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
506 $where .= ' AND (';
507
508 $SqlOK = false;
509 if (count($ArrStr) > 0) {
510 for($i = 0; $i < count($ArrStr); $i++)
511 {
512 if (strpos($ArrStr[$i],"'s") > 0)
513 $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-2);
514 if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
515 if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
516 if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
517 if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
518
519 if (strlen($ArrStr[$i]) > 4) {
520 $where .= '(`O`.`'.$Column.'` LIKE "%'.addslashes($ArrStr[$i]).'%") OR ';
521 $SqlOK = true;
522 }
523 }
524 $where = substr($where, 0, strlen($where) - 4);
525 $where .= ')';
526 if ($SqlOK) {
527 $DbResult = $System->Database->query($sql.$where.$groupby);
528 // echo ($sql.'|'.$where.'|'.$groupby);
529 while($Line = $DbResult->fetch_assoc())
530 {
531 $buff[] = array($Line['ID'], GetIDbyName($Table), $Line[$Column], $Line['Tran']);
532 }
533 }
534 }
535 }
536 return $buff;
537}
538
539function ProgressBar($Width, $Percent, $Text = '')
540{
541 $Pixels = $Width * ($Percent / 100);
542 if($Pixels > $Width) $Pixels = $Width;
543 if($Text == '') $Text = $Percent;
544
545 return('<div class="progressbar" style="width: '.$Width.'px">'.
546 '<div class="bar" style="width: '.$Pixels.'px;"></div>'.
547 '<div class="text" style="width: '.$Width.'px">'.$Text.'</div>'.
548 '</div>');
549}
550
551function GetLevelMinMax($XP)
552{
553 $IndexLevel = 100;
554
555 if($XP > 0) $Level = floor(sqrt($XP / $IndexLevel));
556 else $Level = 0;
557 $MinXP = $Level * $Level * $IndexLevel;
558 $MaxXP = ($Level + 1) * ($Level + 1) * $IndexLevel;
559 $MaxXP = $MaxXP - $MinXP;
560 $XP = $XP - $MinXP;
561 return(array('Level' => $Level, 'XP' => $XP, 'MaxXP' => $MaxXP));
562}
563
564function GetParameter($Name, $Default = '', $Numeric = false, $Session = false)
565{
566 $Result = $Default;
567 if(array_key_exists($Name, $_GET)) $Result = $_GET[$Name];
568 else if(array_key_exists($Name, $_POST)) $Result = $_POST[$Name];
569 else if($Session and array_key_exists($Name, $_SESSION)) $Result = $_SESSION[$Name];
570 if($Numeric and !is_numeric($Result)) $Result = $Default;
571 if($Session) $_SESSION[$Name] = $Result;
572 return($Result);
573}
574
575function MakeActiveLinks($Content)
576{
577 $Content = htmlspecialchars($Content);
578 $Content = str_replace("\n", ' <br/>', $Content);
579 $Content = str_replace("\r", '', $Content);
580
581 $Result = '';
582 $I = 0;
583 while(strpos($Content, 'http://') !== false)
584 {
585 $I = strpos($Content, 'http://');
586 $Result .= substr($Content, 0, $I);
587 $Content = substr($Content, $I);
588 $SpacePos = strpos($Content, ' ');
589 if($SpacePos !== false) $URL = substr($Content, 0, strpos($Content, ' '));
590 else $URL = substr($Content, 0);
591
592 $Result .= '<a href="'.$URL.'">'.$URL.'</a>';
593 $Content = substr($Content, strlen($URL));
594 }
595 $Result .= $Content;
596 return($Result);
597}
598
599define('MESSAGE_WARNING', 0);
600define('MESSAGE_CRITICAL', 1);
601define('MESSAGE_INFORMATION', 2);
602
603function ShowMessage($Text, $Type = MESSAGE_INFORMATION)
604{
605 global $System;
606
607 $IconName = array(
608 MESSAGE_INFORMATION => 'information',
609 MESSAGE_WARNING => 'warning',
610 MESSAGE_CRITICAL => 'critical'
611 );
612 $BackgroundColor = array(
613 MESSAGE_INFORMATION => '#e0e0ff',
614 MESSAGE_WARNING => '#ffffe0',
615 MESSAGE_CRITICAL => '#ffe0e0'
616 );
617
618 return('<div class="message" style="background-color: '.$BackgroundColor[$Type].
619 ';"><table><tr><td class="icon"><img src="'.
620 $System->Link('/images/message/'.$IconName[$Type].'.png').'" alt="'.
621 $IconName[$Type].'"><td>'.$Text.'</td></tr></table></div>');
622}
623
624function ProcessURL()
625{
626 if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
627 $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
628 else $PathString = '';
629 if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
630 $PathItems = explode('/', $PathString);
631 if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
632 $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
633 else $_SERVER['QUERY_STRING'] = '';
634 parse_str($_SERVER['QUERY_STRING'], $_GET);
635 return($PathItems);
636}
637
638function WriteLanguages($Selected)
639{
640 global $System;
641
642 $Output = '<select name="Language">';
643 $DbResult = $System->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1');
644 while($Language = $DbResult->fetch_assoc())
645 {
646 $Output .= '<option value="'.$Language['Id'].'"';
647 if($Selected == $Language['Id'])
648 $Output .= ' selected="selected"';
649 $Output .= '>'.$Language['Name'].'</option>';
650 }
651 $Output .= '</select>';
652 return($Output);
653}
Note: See TracBrowser for help on using the repository browser.