source: branches/posledni/inc/html.php

Last change on this file was 711, checked in by george, 15 years ago
  • Zkopírováno: Větev trunk do branches jako posledni.
File size: 10.2 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 function Link($Path)
36 {
37 global $Config;
38
39 if(substr($Path, 0, 1) == '/') return($Config['Web']['BaseURL'].$Path);
40 return($Path);
41 }
42
43 private function CfgChck($value)
44 {
45 if(isset($this->{$value}))
46 {
47 return($this->{$value});
48 } else
49 {
50 return('Undefined');
51 }
52 }
53
54 public function Start()
55 {
56 global $Config;
57
58 $code = '<?xml version="1.0" encoding="utf-8"?>'.
59 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'.
60 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">'.
61 '<head>'.
62 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$Config['Web']['Charset'].'" />'.
63 '<meta http-equiv="content-Language" content="cs" />'.
64 '<meta name="robots" content="index,follow" />'.
65 '<meta name="googlebot" content="index,follow,snippet,archive" />'.
66 '<link href="imgs/fav.ico" rel="shortcut icon" />'.
67 '<title>'.$Config['Web']['Title'].'</title>'.
68 '<meta name="description" content="'.$Config['Web']['Description'].'" />'.
69 '<meta name="keywords" content="'.$Config['Web']['Keywords'].'" />'.
70 '<link rel="stylesheet" type="text/css" href="'.$this->Link('/styles/style.css.php').'" />'.
71 '<link href="'.$this->Link('/inc/teamspeakdisplay/teamspeakdisplay.css').'" rel="stylesheet" type="text/css" />'.
72 '<link rel="alternate" title="Články" href="'.$this->Link('/rss.php?category=articles').'" type="application/rss+xml" />'.
73 '<link rel="alternate" title="Finanční přispěvky" href="'.$this->Link('rss.php?category=finance').'" type="application/rss+xml" />'.
74 '<script type="text/javascript" src="'.$this->Link('/styles/global.js').'"></script>'.
75 '<!--[if IE]><link rel="stylesheet" type="text/css" href="'.$this->Link('styles/ie.css').'" /><![endif]-->'.
76 '</head>'.
77 '<body>';
78 $this->TimerStart();
79 echo($code);
80 }
81
82 private function TimerStart()
83 {
84 $time_start = microtime();
85 $time_start = explode(' ', $time_start);
86 $time_start = $time_start[1] + $time_start[0];
87 $this->time_start = $time_start;
88 }
89
90 private function TimerStop()
91 {
92 $round = 100000;
93 $time_start = $this->time_start;
94 $time_stop = microtime();
95 $time_stop = explode(' ', $time_stop);
96 $time_stop = $time_stop[1] + $time_stop[0];
97 $deltatime = $time_stop - $time_start;
98 $deltatime = (round(($deltatime * $round))) / $round;
99 return($deltatime);
100 }
101
102 public function Stop()
103 {
104 $time = $this->TimerStop();
105 $code = '<!-- Vygenerováno za : ".$time." s -->'.
106 '</body></html>';
107 echo($code);
108 }
109
110 public function PrgStart()
111 {
112 global $html;
113
114 echo('<table align="center" width="346" height="417" border="0" style="background-image: url('.$html->Link('/imgs/web/prg.gif').');">
115 <tr height="80">
116 <td width="20"></td>
117 <td align="center">
118 <h3>Správa účtu</h3>
119 </td>
120 <td width="20"></td>
121 </tr>
122 <tr>
123 <td width="20"></td>
124 <td align="center" valign="top">');
125 }
126
127 public function PrgStop()
128 {
129 echo('</td>
130 <td width="20"></td>
131 </tr>
132 <tr height="30">
133 <td width="20"></td>
134 <td></td>
135 <td width="20"></td>
136 </tr>
137 </table>');
138 }
139
140 function HumanDate($Time)
141 {
142 $Date = explode(' ', $Time);
143 $Parts = explode('-', $Date[0]);
144 if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
145 else return('&nbsp;');
146 }
147
148 function ShowNews()
149 {
150 global $Config, $db;
151
152 $db->select_db($Config['Database']['Database']);
153 $Output = '';
154
155 /*$Output = '<table class="NewsCategoryTable">'.
156 '<tr>';
157 $DbResult = $db->query('SELECT * FROM ArticleCategory');
158 while($Category = $DbResult->fetch_assoc())
159 {
160 $Output .= '<td><a href="?category='.$Category['Id'].'">'.$Category['Name'].'</a></td>';
161 }
162 $Output .= '<td><a href="?">Vše</a></td>'.
163 '</tr></table><br />';
164 */
165 $this->QuickNew();
166
167 $db->select_db($Config['Database']['Database']);
168
169 if(array_key_exists('category', $_GET)) $Filter = ' WHERE `category` = '.$_GET['category'];
170 else $Filter = '';
171
172 $this->db->select_db($Config['Database']['Database']);
173 $limit = 5;
174
175 if(array_key_exists('page_index', $_GET)) $Page = $_GET['page_index'];
176 else $Page = 0;
177
178 $DbResult = $db->query('SELECT COUNT(*) FROM `Article`'.$Filter);
179 $DbRow = $DbResult->fetch_row();
180 $TotalCount = $DbRow[0];
181
182 $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']);
183 while($Article = $DbResult->fetch_assoc())
184 {
185 $Content = str_replace('&', '&amp;', $Article['Content']);
186 $Content = str_replace('<br>', '<br/>', $Content);
187 $Content = str_replace('</br>', '<br/>', $Content);
188 $Content = str_replace('</ br>', '<br/>', $Content);
189 $Output .= '<table class="NewsQuickInfoTable">'.
190 '<tr>'.
191 '<td><strong>'.$Article['Title'].'</strong></td>'.
192 '<td style="width: 100px">'.$this->HumanDate($Article['Time']).'</td>'.
193 '</tr>'.
194 '<tr>'.
195 '<td colspan="2">'.$Content.'</td>'.
196 '</tr>'.
197 /*'<tr>'.
198 '<td>Sekce : <a href="category='.$Article['Category'].'">'.$Article['CategoryName'].'</a></td>'.
199 '<td>'.$Article['Author'].'</td>'.
200 '</tr>'.*/
201 '</table>'.
202 '<br />';
203 }
204 $Output .= '<div class="Center">'.$this->PageList('page_index', $Page, $TotalCount, $Config['Web']['TableRowPerPage'], 10).'</div>';
205
206 return($Output);
207 }
208
209 function QuickNew()
210 {
211 global $server, $Config, $System, $html;
212
213 // Check servers online state.
214 $DbResult = $System->Database->query('SELECT COUNT(*) FROM Logon WHERE Online = 1 AND Enabled=1');
215 $DbRow = $DbResult->fetch_row();
216 $OnlineState = $DbRow[0] > 0; // Report online state if one of all servers is online.
217
218 if(isset($_COOKIE['hof-quick']) AND $_COOKIE['hof-quick'] == 'no')
219 {
220 } else
221 {
222 echo('<table class="NewsQuickInfoTable">'.
223 '<tr>'.
224 '<td><strong>Rychlý přehled</strong></td>'.
225 '<td style="width: 100px;">'.date('d.m.Y', time()).'</td>'.
226 '</tr>'.
227 '<tr>'.
228 '<td colspan="2">'.
229 '<strong>Server : </strong>'.$server->OnlineStateImage($OnlineState).'<b> (<a href="'.$html->Link('/online-hraci/').'">'.$server->OnlineCharactersCount().' hráčů celkem</a>) | Patch '.$Config['Mangos']['ClientVersion'].' | <a href="'.$html->Link('/pages/realmlist.wtf').'">Realmlist</a> | <a href="'.$html->Link('/server/').'">Server</a> | <a href="'.$html->Link('/svety/').'">Světy</a></b>'.
230 '</td></tr></table><br />');
231 }
232 }
233
234 function GetQueryStringArray()
235 {
236 $Result = array();
237 $Parts = explode('&', $_SERVER['QUERY_STRING']);
238 foreach($Parts as $Part)
239 {
240 if($Part != '')
241 {
242 $Item = explode('=', $Part);
243 if(count($Item) > 1) $Result[$Item[0]] = $Item[1];
244 else $Result[$Item[0]] = '';
245 }
246 }
247 return($Result);
248 }
249
250 function SetQueryStringArray($QueryStringArray)
251 {
252 $Parts = array();
253 foreach($QueryStringArray as $Index => $Item)
254 {
255 $Parts[] = $Index.'='.$Item;
256 }
257 return(implode('&', $Parts));
258 }
259
260 // Zobrazení číselný seznamu stránek
261 function PageList($QueryStringVar, $Page, $TotalCount, $CountPerPage, $Around = 10)
262 {
263 $QueryStringArray = $this->GetQueryStringArray();
264 $Count = ceil($TotalCount / $CountPerPage);
265 $Result = '';
266 if($Count > 1)
267 {
268 if($Page > 0)
269 {
270 $QueryStringArray[$QueryStringVar] = 0;
271 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&lt;&lt;</a> ';
272 $QueryStringArray[$QueryStringVar] = $Page - 1;
273 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&lt;</a> ';
274 }
275 $PagesMax = $Count - 1;
276 $PagesMin = 0;
277 if($PagesMax > ($Page + $Around)) $PagesMax = $Page + $Around;
278 if($PagesMin < ($Page - $Around))
279 {
280 $Result .= ' .. ';
281 $PagesMin = $Page - $Around;
282 }
283 for($i = $PagesMin; $i <= $PagesMax; $i++)
284 {
285 if($i == $Page) $Result .= '<strong>';
286 $QueryStringArray[$QueryStringVar] = $i;
287 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">'.($i + 1).'</a> ';
288 if($i == $Page) $Result .= '</strong>';
289 }
290 if($PagesMax < ($Count - 1)) $Result .= ' .. ';
291 if($Page < ($Count - 1))
292 {
293 $QueryStringArray[$QueryStringVar] = $Page + 1;
294 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&gt;</a> ';
295 $QueryStringArray[$QueryStringVar] = $Count - 1;
296 $Result .= '<a href="?'.$this->SetQueryStringArray($QueryStringArray).'">&gt;&gt;</a>';
297 }
298 }
299 return($Result);
300 }
301}
302
303?>
Note: See TracBrowser for help on using the repository browser.