1 | <?php |
---|
2 | class Page |
---|
3 | { |
---|
4 | function Page($title = '', $cachable = true) |
---|
5 | { |
---|
6 | if (config::get('page_pos_home') == '') |
---|
7 | { |
---|
8 | config::set('page_count',0); |
---|
9 | config::set('page_pos_home', 1); |
---|
10 | config::set('page_pos_campaigns',2); |
---|
11 | config::set('page_pos_contracts',3); |
---|
12 | config::set('page_pos_kills',4); |
---|
13 | config::set('page_pos_losses',5); |
---|
14 | config::set('page_pos_post',6); |
---|
15 | config::set('page_pos_stats',7); |
---|
16 | config::set('page_pos_awards',8); |
---|
17 | config::set('page_pos_standings',9); |
---|
18 | config::set('page_pos_search',10); |
---|
19 | config::set('page_pos_admin',11); |
---|
20 | config::set('page_pos_about',12); |
---|
21 | } |
---|
22 | |
---|
23 | $this->title_ = $title; |
---|
24 | $this->admin_ = false; |
---|
25 | |
---|
26 | $this->igb_ = IS_IGB; |
---|
27 | |
---|
28 | $this->timestart_ = strtok(microtime(), ' ') + strtok(''); |
---|
29 | |
---|
30 | $this->killboard_ = new Killboard(KB_SITE); |
---|
31 | |
---|
32 | $this->cachable_ = $cachable; |
---|
33 | $this->cachetime_ = 5; |
---|
34 | } |
---|
35 | |
---|
36 | function setContent($html) |
---|
37 | { |
---|
38 | $this->contenthtml_ = $html; |
---|
39 | } |
---|
40 | |
---|
41 | function addContext($html) |
---|
42 | { |
---|
43 | $this->contexthtml_ .= $html; |
---|
44 | } |
---|
45 | |
---|
46 | function error($message) |
---|
47 | { |
---|
48 | global $smarty; |
---|
49 | |
---|
50 | $smarty->assign('error', $message); |
---|
51 | $this->setContent($smarty->fetch(get_tpl('error'))); |
---|
52 | $this->generate(); |
---|
53 | } |
---|
54 | |
---|
55 | function generate() |
---|
56 | { |
---|
57 | global $smarty; |
---|
58 | |
---|
59 | $smarty->assign('kb_title', KB_TITLE.' Killboard - '.$this->title_); |
---|
60 | |
---|
61 | $style = config::get('style_name'); |
---|
62 | $smarty->assign('style', $style); |
---|
63 | |
---|
64 | $smarty->assign('common_url', COMMON_URL); |
---|
65 | if ($this->onload_) |
---|
66 | { |
---|
67 | $smarty->assign('on_load', ' onload="'.$this->onload_.'"'); |
---|
68 | } |
---|
69 | // header |
---|
70 | |
---|
71 | if (!$this->igb_) |
---|
72 | { |
---|
73 | if (strpos(config::get('mods_active'), 'rss_feed') !== false) |
---|
74 | { |
---|
75 | $smarty->assign('rss_feed', 1); |
---|
76 | } |
---|
77 | if (MAIN_SITE) |
---|
78 | { |
---|
79 | $smarty->assign('banner_link', MAIN_SITE); |
---|
80 | } |
---|
81 | $banner = config::get('style_banner'); |
---|
82 | if ($banner == 'custom') |
---|
83 | { |
---|
84 | $banner = 'kb-banner.jpg'; |
---|
85 | } |
---|
86 | $smarty->assign('banner', $banner); |
---|
87 | |
---|
88 | $menu = $this->generateMenu(); |
---|
89 | $w = floor(100 / count($menu->get())); |
---|
90 | |
---|
91 | $smarty->assign('menu_w',$w.'%'); |
---|
92 | $smarty->assign('menu', $menu->get()); |
---|
93 | } |
---|
94 | $smarty->assign('page_title', $this->title_); |
---|
95 | |
---|
96 | $this->timeend_ = strtok(microtime(), ' ') + strtok(''); |
---|
97 | $this->processingtime_ = $this->timeend_ - $this->timestart_; |
---|
98 | |
---|
99 | $qry = new DBQuery(); |
---|
100 | if (method_exists($qry, 'queryCachedCount')) |
---|
101 | { |
---|
102 | $smarty->assign('profile_sql_cached', $qry->queryCachedCount()); |
---|
103 | } |
---|
104 | $smarty->assign('profile_sql', $qry->queryCount()); |
---|
105 | $smarty->assign('profile_time', $this->processingtime_); |
---|
106 | $smarty->assign('profile', KB_PROFILE); |
---|
107 | $smarty->assign('content_html', $this->contenthtml_); |
---|
108 | if (config::get('user_showmenu')) |
---|
109 | { |
---|
110 | $this->contexthtml_ = user::menu().$this->contexthtml_; |
---|
111 | } |
---|
112 | $smarty->assign('context_html', $this->contexthtml_); |
---|
113 | $smarty->display(get_tpl('index')); |
---|
114 | } |
---|
115 | |
---|
116 | function igb() |
---|
117 | { |
---|
118 | return $this->igb_; |
---|
119 | } |
---|
120 | |
---|
121 | function setOnLoad($onload) |
---|
122 | { |
---|
123 | $this->onload_ = $onload; |
---|
124 | } |
---|
125 | |
---|
126 | function setTitle($title) |
---|
127 | { |
---|
128 | $this->title_ = $title; |
---|
129 | } |
---|
130 | |
---|
131 | function setAdmin() |
---|
132 | { |
---|
133 | if (!Session::isAdmin()) |
---|
134 | { |
---|
135 | header("Location: ?a=login"); |
---|
136 | echo '<a href="?a=login">Login</a>'; |
---|
137 | exit; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | function isAdmin() |
---|
142 | { |
---|
143 | return Session::isAdmin(); |
---|
144 | } |
---|
145 | |
---|
146 | function isSuperAdmin() |
---|
147 | { |
---|
148 | return Session::isSuperAdmin(); |
---|
149 | } |
---|
150 | |
---|
151 | function setSuperAdmin() |
---|
152 | { |
---|
153 | if (!Session::isSuperAdmin()) |
---|
154 | Header("Location: ?a=login"); |
---|
155 | } |
---|
156 | |
---|
157 | function setCachable($cachable) |
---|
158 | { |
---|
159 | $this->cachable_ = $cachable; |
---|
160 | } |
---|
161 | |
---|
162 | function setCacheTime($cachetime) |
---|
163 | { |
---|
164 | $this->cachetime_ = $cachetime; |
---|
165 | } |
---|
166 | |
---|
167 | function generateMenu(){ |
---|
168 | $menu = new Menu(); |
---|
169 | $contracts = $this->killboard_->hasContracts(); |
---|
170 | $campaigns = $this->killboard_->hasCampaigns(); |
---|
171 | $layout = array(); |
---|
172 | |
---|
173 | // Check which stat page should be schown |
---|
174 | if (config::get('public_stats')=='do nothing') |
---|
175 | { |
---|
176 | if (CORP_ID) |
---|
177 | { |
---|
178 | $statlink = 'corp_detail&crp_id='.CORP_ID; |
---|
179 | } |
---|
180 | elseif (ALLIANCE_ID) |
---|
181 | { |
---|
182 | $link = 'alliance_detail&all_id='.ALLIANCE_ID; |
---|
183 | } |
---|
184 | } |
---|
185 | if (config::get('public_stats')=='replace') |
---|
186 | { |
---|
187 | // Public Stats Page not rdy yet. |
---|
188 | $statlink = ''; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | //preparing default pages |
---|
193 | $layout[config::get('page_pos_home')] = array('Home','?a=home'); |
---|
194 | if ($campaigns) |
---|
195 | $layout[config::get('page_pos_campaigns')] = array('Campaigns','?a=campaigns'); |
---|
196 | if ($contracts) |
---|
197 | $layout[config::get('page_pos_contracts')] = array('Contracts','?a=contracts'); |
---|
198 | $layout[config::get('page_pos_kills')] = array('Kills','?a=kills'); |
---|
199 | if (!config::get('public_losses')) |
---|
200 | $layout[config::get('page_pos_losses')] = array('Losses','?a=losses'); |
---|
201 | $layout[config::get('page_pos_awards')] = array('Awards','?a=awards'); |
---|
202 | if (config::get('show_standings')) |
---|
203 | $layout[config::get('page_pos_standings')] = array('Standings','?a=standings'); |
---|
204 | $layout[config::get('page_pos_search')] = array('Search','?a=search'); |
---|
205 | $layout[config::get('page_pos_admin')] = array('Admin','?a=admin'); |
---|
206 | $layout[config::get('page_pos_stats')] = array('Stats',$statlink); |
---|
207 | $layout[config::get('page_pos_admin')] = array('Admin','?a=admin'); |
---|
208 | $layout[config::get('page_pos_post')] = array('Post mail','?a=post'); |
---|
209 | $layout[config::get('page_pos_about')] = array('About','?a=about'); |
---|
210 | |
---|
211 | //preparing custom pages |
---|
212 | for ($i = 1; $i <= config::get('page_count');$i++) |
---|
213 | { |
---|
214 | $layout[config::get('page_pos_'.$i)] = array(config::get('page_descr_'.$i),config::get('page_url_'.$i).'" target="_blank"'); |
---|
215 | } |
---|
216 | |
---|
217 | //sorting menu |
---|
218 | ksort($layout,SORT_NUMERIC); |
---|
219 | |
---|
220 | //building menu |
---|
221 | foreach ($layout as $item){ |
---|
222 | $menu->add($item[1] , $item[0]); |
---|
223 | } |
---|
224 | |
---|
225 | return $menu; |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | class Menu |
---|
230 | { |
---|
231 | function Menu() |
---|
232 | { |
---|
233 | $this->menu_ = array(); |
---|
234 | } |
---|
235 | |
---|
236 | function get() |
---|
237 | { |
---|
238 | return $this->menu_; |
---|
239 | } |
---|
240 | |
---|
241 | function add($link, $text) |
---|
242 | { |
---|
243 | $this->menu_[] = array('link' => $link, 'text' => $text); |
---|
244 | } |
---|
245 | } |
---|
246 | ?> |
---|