source: trunk/inc/html.php@ 682

Last change on this file since 682 was 682, checked in by george, 15 years ago
  • Opraveno: Na dalších stránkách přepracován systém pro načítání údajů z databáze namísto konfiguračního souboru.
  • Přidáno: Skript pro periodickou kontrolu online stavu přihlašovacích serverů a světů. Online stav se načítá nově přímo z databáze a sníží se tak zátěž sítových portů služeb.
File size: 11.5 KB
Line 
1<?php
2
3class Html
4{
5 private $values;
6 private $db;
7
8 public function __construct($values, $db)
9 {
10 $this->db = &$db;
11 // default config
12 $this->html_cfg = array
13 (
14/* "charset" => "utf-8",
15 "author" => "Zork",
16 "copyright" => "(C) 2008 Heroes of Fantasy, All rights reserved.",
17 "favicon" => "imgs/fav",
18 "title" => "Heroes of Fantasy",
19 "description" => "Heroes of Fantasy free WoW server běžící na programu MaNGOS",
20 "keywords" => "wowserver, world of warcraft, free, wow, server, hof, heroes of fantasy, zdechov, mangos"
21*/ );
22
23 if((count($values) > 1) or ($values[0] != 0) and ($values[0] != 0))
24 {
25 $result_cfg = array_merge ($this->html_cfg, $values);
26 foreach($result_cfg as $name => $value)
27 $this->{$name} = $value;
28 } else
29 {
30 foreach($this->html_cfg as $name => $value)
31 $this->{$name} = $value;
32 }
33 }
34
35 private function CfgChck($value)
36 {
37 if(isset($this->{$value}))
38 {
39 return($this->{$value});
40 } else
41 {
42 return('Undefined');
43 }
44 }
45
46 public function Start()
47 {
48 global $Config;
49
50 $code = '<?xml version="1.0" encoding="utf-8"?>'.
51 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'.
52 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">'.
53 '<head>'.
54 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$Config['Web']['Charset'].'" />'.
55 '<meta http-equiv="content-Language" content="cs" />'.
56 '<meta name="robots" content="index,follow" />'.
57 '<meta name="googlebot" content="index,follow,snippet,archive" />'.
58 '<link href="imgs/fav.ico" rel="shortcut icon" />'.
59 '<title>'.$Config['Web']['Title'].'</title>'.
60 '<meta name="description" content="'.$Config['Web']['Description'].'" />'.
61 '<meta name="keywords" content="'.$Config['Web']['Keywords'].'" />'.
62 '<link rel="stylesheet" type="text/css" href="styles/style.css" />'.
63 '<link href="inc/teamspeakdisplay/teamspeakdisplay.css" rel="stylesheet" type="text/css" />'.
64 '<link rel="alternate" title="Články" href="rss.php?category=articles" type="application/rss+xml" />'.
65 '<link rel="alternate" title="Finanční přispěvky" href="rss.php?category=finance" type="application/rss+xml" />'.
66 '<script type="text/javascript" src="styles/global.js"></script>'.
67 '<!--[if IE]><link rel="stylesheet" type="text/css" href="styles/ie.css" /><![endif]-->'.
68 '</head>'.
69 '<body>';
70 $this->TimerStart();
71 echo($code);
72 }
73
74 private function TimerStart()
75 {
76 $time_start = microtime();
77 $time_start = explode(' ', $time_start);
78 $time_start = $time_start[1] + $time_start[0];
79 $this->time_start = $time_start;
80 }
81
82 private function TimerStop()
83 {
84 $round = 100000;
85 $time_start = $this->time_start;
86 $time_stop = microtime();
87 $time_stop = explode(' ', $time_stop);
88 $time_stop = $time_stop[1] + $time_stop[0];
89 $deltatime = $time_stop - $time_start;
90 $deltatime = (round(($deltatime * $round))) / $round;
91 return($deltatime);
92 }
93
94 public function Stop()
95 {
96 $time = $this->TimerStop();
97 $code = '<!-- Vygenerováno za : ".$time." s -->'.
98 '</body></html>';
99 echo($code);
100 }
101
102 public function Pager($get, $dir_pages, $def)
103 {
104 $anti_ref = array
105 (
106 'server' => 5,
107 'events' => 2,
108 'aukce' => 2,
109 'gmlog' => 300,
110 'online' => 2,
111 );
112 $site_show = $dir_pages.'/'.$get.'.php';
113 if(isset($anti_ref[$get]))
114 {
115 if(!$this->Antirefresh($anti_ref[$get], $get))
116 {
117 if(($site_show != '') and is_readable($site_show)) return($site_show);
118 else return('./'.$dir_pages.'/'.$def.'.php');
119 } else
120 {
121 $this->RefreshMsg($this->Antirefresh($anti_ref[$get], $get), $get);
122 return($dir_pages.'/free.php');
123 }
124 } else
125 {
126 if(($site_show != '') and is_readable($site_show)) return($site_show);
127 else return($dir_pages.'/'.$def.'.php');
128 }
129 }
130
131 public function Antirefresh($value, $page)
132 {
133 $hash = md5($page);
134 if(isset($_SESSION['rf'.$hash.'rsh']))
135 {
136 $refresh = $_SESSION['rf'.$hash.'rsh'] + $value;
137 if(time() < $refresh)
138 {
139 $dif = $refresh - time();
140 return($dif);
141 }
142 }
143 $_SESSION['rf'.$hash.'rsh'] = time();
144 }
145
146 public function RefreshMsg($dif, $get)
147 {
148 if($dif != 0)
149 {
150 if($dif > 60)
151 {
152 $dif = round($dif / 60).' min';
153 $refresh = 30;
154 } else
155 {
156 $dif = $dif.' s';
157 $refresh = 2;
158 }
159 echo('<center><h3>Refresh omezení</h3></center>
160 Stránka nepovoluje tak krátký čas pro refresh (znovunačtení).<br />
161 Další načtení stránky <b>?page='.$get.'</b> bude možné za <b>'.$dif.'</b>.<br />
162 Pokud tento čas vyčkáte budete přesměrován automaticky !
163 <meta http-equiv="refresh" content="'.$refresh.';url=">');
164 }
165 }
166
167 public function PrgStart()
168 {
169 echo('<table align="center" width="346" height="417" border="0" style="background-image: url(imgs/web/prg.gif);">
170 <tr height="80">
171 <td width="20"></td>
172 <td align="center">
173 <h3>Správa účtu</h3>
174 </td>
175 <td width="20"></td>
176 </tr>
177 <tr>
178 <td width="20"></td>
179 <td align="center" valign="top">');
180 }
181
182 public function PrgStop()
183 {
184 echo('</td>
185 <td width="20"></td>
186 </tr>
187 <tr height="30">
188 <td width="20"></td>
189 <td></td>
190 <td width="20"></td>
191 </tr>
192 </table>');
193 }
194
195 function HumanDate($Time)
196 {
197 $Date = explode(' ', $Time);
198 $Parts = explode('-', $Date[0]);
199 if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
200 else return('&nbsp;');
201 }
202
203 function ShowNews()
204 {
205 global $Config, $db;
206
207 $db->select_db($Config['Database']['Database']);
208
209 $Output = '<table class="NewsCategoryTable">'.
210 '<tr>';
211 $DbResult = $db->query('SELECT * FROM ArticleCategory');
212 while($Category = $DbResult->fetch_assoc())
213 {
214 $Output .= '<td><a href="?category='.$Category['Id'].'">'.$Category['Name'].'</a></td>';
215 }
216 $Output .= '<td><a href="?">Vše</a></td>'.
217 '</tr></table><br />';
218 $this->QuickNew();
219
220 $db->select_db($Config['Database']['Database']);
221
222 if(array_key_exists('category', $_GET)) $Filter = ' WHERE `category` = '.$_GET['category'];
223 else $Filter = '';
224
225 $this->db->select_db($Config['Database']['Database']);
226 $limit = 5;
227
228 if(array_key_exists('page_index', $_GET)) $Page = $_GET['page_index'];
229 else $Page = 0;
230
231 $DbResult = $db->query('SELECT COUNT(*) FROM `Article`'.$Filter);
232 $DbRow = $DbResult->fetch_row();
233 $TotalCount = $DbRow[0];
234
235 $DbResult = $db->query('SELECT Article.*, ArticleCategory.Name AS CategoryName FROM Article LEFT JOIN ArticleCategory ON ArticleCategory.Id = Article.Category '.$Filter.' ORDER BY Time DESC LIMIT '.($Page * $Config['Web']['TableRowPerPage']).', '.$Config['Web']['TableRowPerPage']);
236 while($Article = $DbResult->fetch_assoc())
237 {
238 $Content = str_replace('&', '&amp;', $Article['Content']);
239 $Content = str_replace('<br>', '<br/>', $Content);
240 $Content = str_replace('</br>', '<br/>', $Content);
241 $Content = str_replace('</ br>', '<br/>', $Content);
242 $Output .= '<table class="NewsQuickInfoTable">'.
243 '<tr>'.
244 '<td><strong>'.$Article['Title'].'</strong></td>'.
245 '<td style="width: 100px">'.$this->HumanDate($Article['Time']).'</td>'.
246 '</tr>'.
247 '<tr>'.
248 '<td colspan="2">'.$Content.'</td>'.
249 '</tr>'.
250 '<tr>'.
251 '<td>Sekce : <a href="category='.$Article['Category'].'">'.$Article['CategoryName'].'</a></td>'.
252 '<td>'.$Article['Author'].'</td>'.
253 '</tr>'.
254 '</table>'.
255 '<br />';
256 }
257 $Output .= '<div class="Center">'.$this->PageList('page_index', $Page, $TotalCount, $Config['Web']['TableRowPerPage'], 10).'</div>';
258
259 return($Output);
260 }
261
262 function QuickNew()
263 {
264 global $server, $Config, $System;
265
266 // Check servers online state.
267 $DbResult = $System->Database->query('SELECT COUNT(*) FROM Logon WHERE Online = 1');
268 $DbRow = $DbResult->fetch_row();
269 $OnlineState = $DbRow[0] > 0; // Report online state if one of all servers is online.
270
271 if(isset($_COOKIE['hof-quick']) AND $_COOKIE['hof-quick'] == 'no')
272 {
273 } else
274 {
275 echo('<table class="NewsQuickInfoTable">'.
276 '<tr>'.
277 '<td><strong>Rychlý přehled</strong></td>'.
278 '<td style="width: 100px;">'.date('d.m.Y', time()).'</td>'.
279 '</tr>'.
280 '<tr>'.
281 '<td colspan="2">'.
282 '<strong>Server : </strong>'.$server->OnlineStateImage($OnlineState).'<b> (<a href="?page=realmlist">'.$server->OnlineCharactersCount().' hráčů celkem</a>) | Patch '.$Config['Mangos']['ClientVersion'].' | <a href="'.$Config['Web']['BaseURL'].'/pages/realmlist.wtf">Realmlist</a> | <a href="?page=server">Server info</a> | <a href="?page=realmlist">Seznam světů</a></b>'.
283 '</td></tr></table><br />');
284 }
285 }
286
287 function GetQueryStringArray()
288 {
289 $Result = array();
290 $Parts = explode('&', $_SERVER['QUERY_STRING']);
291 foreach($Parts as $Part)
292 {
293 if($Part != '')
294 {
295 $Item = explode('=', $Part);
296 $Result[$Item[0]] = $Item[1];
297 }
298 }
299 return($Result);
300 }
301
302 function SetQueryStringArray($QueryStringArray)
303 {
304 $Parts = array();
305 foreach($QueryStringArray as $Index => $Item)
306 {
307 $Parts[] = $Index.'='.$Item;
308 }
309 return(implode('&', $Parts));
310 }
311
312 // Zobrazení číselný seznamu stránek
313 function PageList($QueryStringVar, $Page, $TotalCount, $CountPerPage, $Around = 10)
314 {
315 $QueryStringArray = $this->GetQueryStringArray();
316 $Count = ceil($TotalCount / $CountPerPage);
317 $Result = '';
318 if($Count > 1)
319 {
320 if($Page > 0)
321 {
322 $QueryStringArray[$QueryStringVar] = 0;
323 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&lt;&lt;</a> ';
324 $QueryStringArray[$QueryStringVar] = $Page - 1;
325 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&lt;</a> ';
326 }
327 $PagesMax = $Count - 1;
328 $PagesMin = 0;
329 if($PagesMax > ($Page + $Around)) $PagesMax = $Page + $Around;
330 if($PagesMin < ($Page - $Around))
331 {
332 $Result .= ' .. ';
333 $PagesMin = $Page - $Around;
334 }
335 for($i = $PagesMin; $i <= $PagesMax; $i++)
336 {
337 if($i == $Page) $Result .= '<strong>';
338 $QueryStringArray[$QueryStringVar] = $i;
339 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">'.($i + 1).'</a> ';
340 if($i == $Page) $Result .= '</strong>';
341 }
342 if($PagesMax < ($Count - 1)) $Result .= ' .. ';
343 if($Page < ($Count - 1))
344 {
345 $QueryStringArray[$QueryStringVar] = $Page + 1;
346 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&gt;</a> ';
347 $QueryStringArray[$QueryStringVar] = $Count - 1;
348 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&gt;&gt;</a>';
349 }
350 }
351 return($Result);
352 }
353}
354
355?>
Note: See TracBrowser for help on using the repository browser.