Revision 1420
Added by Dietmar almost 14 years ago
class.frontend.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category frontend |
|
5 |
* @package framework |
|
6 |
* @author WebsiteBaker Project |
|
7 |
* @copyright 2004-2009, Ryan Djurovich |
|
8 |
* @copyright 2009-2011, Website Baker Org. e.V. |
|
9 |
* @link http://www.websitebaker2.org/ |
|
10 |
* @license http://www.gnu.org/licenses/gpl.html |
|
11 |
* @platform WebsiteBaker 2.8.x |
|
12 |
* @requirements PHP 5.2.2 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
if(!defined('WB_PATH')) { |
|
20 |
header('Location: ../index.php'); |
|
21 |
exit(0); |
|
22 |
} |
|
23 |
|
|
24 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
25 |
require_once(WB_PATH.'/framework/SecureForm.php'); |
|
26 |
|
|
27 |
class frontend extends wb { |
|
28 |
// defaults |
|
29 |
public $default_link,$default_page_id; |
|
30 |
// when multiple blocks are used, show home page blocks on |
|
31 |
// pages where no content is defined (search, login, ...) |
|
32 |
public $default_block_content=true; |
|
33 |
|
|
34 |
// page details |
|
35 |
// page database row |
|
36 |
public $page; |
|
37 |
public $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility; |
|
38 |
public $page_description,$page_keywords,$page_link; |
|
39 |
public $page_trail=array(); |
|
40 |
|
|
41 |
public $page_access_denied; |
|
42 |
public $page_no_active_sections; |
|
43 |
|
|
44 |
// website settings |
|
45 |
public $website_title,$website_description,$website_keywords,$website_header,$website_footer; |
|
46 |
|
|
47 |
// ugly database stuff |
|
48 |
public $extra_where_sql, $sql_where_language; |
|
49 |
|
|
50 |
public function __construct() { |
|
51 |
parent::__construct(SecureForm::FRONTEND); |
|
52 |
} |
|
53 |
|
|
54 |
public function page_select() { |
|
55 |
global $page_id,$no_intro; |
|
56 |
global $database; |
|
57 |
// We have no page id and are supposed to show the intro page |
|
58 |
if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) { |
|
59 |
// Since we have no page id check if we should go to intro page or default page |
|
60 |
// Get intro page content |
|
61 |
$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION; |
|
62 |
if(file_exists($filename)) { |
|
63 |
$handle = @fopen($filename, "r"); |
|
64 |
$content = @fread($handle, filesize($filename)); |
|
65 |
@fclose($handle); |
|
66 |
$this->preprocess($content); |
|
67 |
header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION.""); // send intro.php as header to allow parsing of php statements |
|
68 |
echo ($content); |
|
69 |
return false; |
|
70 |
} |
|
71 |
} |
|
72 |
// Check if we should add page language sql code |
|
73 |
if(PAGE_LANGUAGES) { |
|
74 |
$this->sql_where_language = " AND language = '".LANGUAGE."'"; |
|
75 |
} |
|
76 |
// Get default page |
|
77 |
// Check for a page id |
|
78 |
$table_p = TABLE_PREFIX.'pages'; |
|
79 |
$table_s = TABLE_PREFIX.'sections'; |
|
80 |
$now = time(); |
|
81 |
$query_default = " |
|
82 |
SELECT `p`.`page_id`, `link` |
|
83 |
FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`) |
|
84 |
WHERE `parent` = '0' AND `visibility` = 'public' |
|
85 |
AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0)) |
|
86 |
$this->sql_where_language |
|
87 |
ORDER BY `p`.`position` ASC LIMIT 1"; |
|
88 |
$get_default = $database->query($query_default); |
|
89 |
$default_num_rows = $get_default->numRows(); |
|
90 |
if(!isset($page_id) OR !is_numeric($page_id)){ |
|
91 |
// Go to or show default page |
|
92 |
if($default_num_rows > 0) { |
|
93 |
$fetch_default = $get_default->fetchRow(); |
|
94 |
$this->default_link = $fetch_default['link']; |
|
95 |
$this->default_page_id = $fetch_default['page_id']; |
|
96 |
// Check if we should redirect or include page inline |
|
97 |
if(HOMEPAGE_REDIRECTION) { |
|
98 |
// Redirect to page |
|
99 |
header("Location: ".$this->page_link($this->default_link)); |
|
100 |
exit(); |
|
101 |
} else { |
|
102 |
// Include page inline |
|
103 |
$this->page_id = $this->default_page_id; |
|
104 |
} |
|
105 |
} else { |
|
106 |
// No pages have been added, so print under construction page |
|
107 |
$this->print_under_construction(); |
|
108 |
exit(); |
|
109 |
} |
|
110 |
} else { |
|
111 |
$this->page_id=$page_id; |
|
112 |
} |
|
113 |
// Get default page link |
|
114 |
if(!isset($fetch_default)) { |
|
115 |
$fetch_default = $get_default->fetchRow(); |
|
116 |
$this->default_link = $fetch_default['link']; |
|
117 |
$this->default_page_id = $fetch_default['page_id']; |
|
118 |
} |
|
119 |
return true; |
|
120 |
} |
|
121 |
|
|
122 |
public function get_page_details() { |
|
123 |
global $database; |
|
124 |
if($this->page_id != 0) { |
|
125 |
// Query page details |
|
126 |
$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'"; |
|
127 |
$get_page = $database->query($query_page); |
|
128 |
// Make sure page was found in database |
|
129 |
if($get_page->numRows() == 0) { |
|
130 |
// Print page not found message |
|
131 |
exit("Page not found"); |
|
132 |
} |
|
133 |
// Fetch page details |
|
134 |
$this->page = $get_page->fetchRow(); |
|
135 |
// Check if the page language is also the selected language. If not, send headers again. |
|
136 |
if ($this->page['language']!=LANGUAGE) { |
|
137 |
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string |
|
138 |
header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']); |
|
139 |
} else { |
|
140 |
header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']); |
|
141 |
} |
|
142 |
exit(); |
|
143 |
} |
|
144 |
// Begin code to set details as either variables of constants |
|
145 |
// Page ID |
|
146 |
if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);} |
|
147 |
// Page Title |
|
148 |
if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);} |
|
149 |
$this->page_title=PAGE_TITLE; |
|
150 |
// Menu Title |
|
151 |
$menu_title = $this->page['menu_title']; |
|
152 |
if($menu_title != '') { |
|
153 |
if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);} |
|
154 |
} else { |
|
155 |
if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);} |
|
156 |
} |
|
157 |
$this->menu_title = MENU_TITLE; |
|
158 |
// Page parent |
|
159 |
if(!defined('PARENT')) {define('PARENT', $this->page['parent']);} |
|
160 |
$this->parent=$this->page['parent']; |
|
161 |
// Page root parent |
|
162 |
if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);} |
|
163 |
$this->root_parent=$this->page['root_parent']; |
|
164 |
// Page level |
|
165 |
if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);} |
|
166 |
$this->level=$this->page['level']; |
|
167 |
// Page visibility |
|
168 |
if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);} |
|
169 |
$this->visibility=$this->page['visibility']; |
|
170 |
// Page trail |
|
171 |
foreach(explode(',', $this->page['page_trail']) AS $pid) { |
|
172 |
$this->page_trail[$pid]=$pid; |
|
173 |
} |
|
174 |
// Page description |
|
175 |
$this->page_description=$this->page['description']; |
|
176 |
if($this->page_description != '') { |
|
177 |
define('PAGE_DESCRIPTION', $this->page_description); |
|
178 |
} else { |
|
179 |
define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION); |
|
180 |
} |
|
181 |
// Page keywords |
|
182 |
$this->page_keywords=$this->page['keywords']; |
|
183 |
// Page link |
|
184 |
$this->link=$this->page_link($this->page['link']); |
|
185 |
|
|
186 |
// End code to set details as either variables of constants |
|
187 |
} |
|
188 |
|
|
189 |
// Figure out what template to use |
|
190 |
if(!defined('TEMPLATE')) { |
|
191 |
if(isset($this->page['template']) AND $this->page['template'] != '') { |
|
192 |
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) { |
|
193 |
define('TEMPLATE', $this->page['template']); |
|
194 |
} else { |
|
195 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
196 |
} |
|
197 |
} else { |
|
198 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
199 |
} |
|
200 |
} |
|
201 |
// Set the template dir |
|
202 |
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE); |
|
203 |
|
|
204 |
// Check if user is allowed to view this page |
|
205 |
if($this->page && $this->page_is_visible($this->page) == false) { |
|
206 |
if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') { |
|
207 |
// User isnt allowed on this page so tell them |
|
208 |
$this->page_access_denied=true; |
|
209 |
} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') { |
|
210 |
// Check if the user is authenticated |
|
211 |
if($this->is_authenticated() == false) { |
|
212 |
// User needs to login first |
|
213 |
header("Location: ".WB_URL."/account/login.php?redirect=".$this->link); |
|
214 |
exit(0); |
|
215 |
} else { |
|
216 |
// User isnt allowed on this page so tell them |
|
217 |
$this->page_access_denied=true; |
|
218 |
} |
|
219 |
|
|
220 |
} |
|
221 |
} |
|
222 |
// check if there is at least one active section |
|
223 |
if($this->page && $this->page_is_active($this->page) == false) { |
|
224 |
$this->page_no_active_sections=true; |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
public function get_website_settings() |
|
229 |
{ |
|
230 |
global $database; |
|
231 |
|
|
232 |
// set visibility SQL code |
|
233 |
// never show no-vis, hidden or deleted pages |
|
234 |
$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'"; |
|
235 |
// Set extra private sql code |
|
236 |
if($this->is_authenticated()==false) { |
|
237 |
// if user is not authenticated, don't show private pages either |
|
238 |
$this->extra_where_sql .= " AND visibility != 'private'"; |
|
239 |
// and 'registered' without frontend login doesn't make much sense! |
|
240 |
if (FRONTEND_LOGIN==false) { |
|
241 |
$this->extra_where_sql .= " AND visibility != 'registered'"; |
|
242 |
} |
|
243 |
} |
|
244 |
$this->extra_where_sql .= $this->sql_where_language; |
|
245 |
|
|
246 |
// Work-out if any possible in-line search boxes should be shown |
|
247 |
if(SEARCH == 'public') { |
|
248 |
define('SHOW_SEARCH', true); |
|
249 |
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') { |
|
250 |
define('SHOW_SEARCH', true); |
|
251 |
} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) { |
|
252 |
define('SHOW_SEARCH', true); |
|
253 |
} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) { |
|
254 |
define('SHOW_SEARCH', true); |
|
255 |
} else { |
|
256 |
define('SHOW_SEARCH', false); |
|
257 |
} |
|
258 |
// Work-out if menu should be shown |
|
259 |
if(!defined('SHOW_MENU')) { |
|
260 |
define('SHOW_MENU', true); |
|
261 |
} |
|
262 |
// Work-out if login menu constants should be set |
|
263 |
if(FRONTEND_LOGIN) { |
|
264 |
// Set login menu constants |
|
265 |
define('LOGIN_URL', WB_URL.'/account/login.php'); |
|
266 |
define('LOGOUT_URL', WB_URL.'/account/logout.php'); |
|
267 |
define('FORGOT_URL', WB_URL.'/account/forgot.php'); |
|
268 |
define('PREFERENCES_URL', WB_URL.'/account/preferences.php'); |
|
269 |
define('SIGNUP_URL', WB_URL.'/account/signup.php'); |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
/* |
|
274 |
* replace all "[wblink{page_id}]" with real links |
|
275 |
* @param string &$content : reference to global $content |
|
276 |
* @return void |
|
277 |
* @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict |
|
278 |
*/ |
|
279 |
public function preprocess(&$content) |
|
280 |
{ |
|
281 |
global $database; |
|
282 |
$replace_list = array(); |
|
283 |
$pattern = '/\[wblink([0-9]+)\]/isU'; |
|
284 |
if(preg_match_all($pattern,$content,$ids)) |
|
285 |
{ |
|
286 |
foreach($ids[1] as $key => $page_id) |
|
287 |
{ |
|
288 |
$replace_list[$page_id] = $ids[0][$key]; |
|
289 |
} |
|
290 |
foreach($replace_list as $page_id => $tag) |
|
291 |
{ |
|
292 |
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id; |
|
293 |
$link = $database->get_one($sql); |
|
294 |
if(!is_null($link)) |
|
295 |
{ |
|
296 |
$link = $this->page_link($link); |
|
297 |
$content = str_replace($tag, $link, $content); |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/* |
|
304 |
function preprocess(&$content) { |
|
305 |
global $database; |
|
306 |
// Replace [wblink--PAGE_ID--] with real link |
|
307 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
308 |
preg_match_all($pattern,$content,$ids); |
|
309 |
foreach($ids[1] AS $page_id) { |
|
310 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
311 |
// Get page link |
|
312 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
313 |
$fetch_link = $get_link->fetchRow(); |
|
314 |
$link = $this->page_link($fetch_link['link']); |
|
315 |
$content = preg_replace($pattern,$link,$content); |
|
316 |
} |
|
317 |
} |
|
318 |
*/ |
|
319 |
public function menu() { |
|
320 |
global $wb; |
|
321 |
if (!isset($wb->menu_number)) { |
|
322 |
$wb->menu_number = 1; |
|
323 |
} |
|
324 |
if (!isset($wb->menu_start_level)) { |
|
325 |
$wb->menu_start_level = 0; |
|
326 |
} |
|
327 |
if (!isset($wb->menu_recurse)) { |
|
328 |
$wb->menu_recurse = -1; |
|
329 |
} |
|
330 |
if (!isset($wb->menu_collapse)) { |
|
331 |
$wb->menu_collapse = true; |
|
332 |
} |
|
333 |
if (!isset($wb->menu_item_template)) { |
|
334 |
$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>'; |
|
335 |
} |
|
336 |
if (!isset($wb->menu_item_footer)) { |
|
337 |
$wb->menu_item_footer = '</li>'; |
|
338 |
} |
|
339 |
if (!isset($wb->menu_header)) { |
|
340 |
$wb->menu_header = '<ul>'; |
|
341 |
} |
|
342 |
if (!isset($wb->menu_footer)) { |
|
343 |
$wb->menu_footer = '</ul>'; |
|
344 |
} |
|
345 |
if (!isset($wb->menu_default_class)) { |
|
346 |
$wb->menu_default_class = ' class="menu_default"'; |
|
347 |
} |
|
348 |
if (!isset($wb->menu_current_class)) { |
|
349 |
$wb->menu_current_class = ' class="menu_current"'; |
|
350 |
} |
|
351 |
if (!isset($wb->menu_parent)) { |
|
352 |
$wb->menu_parent = 0; |
|
353 |
} |
|
354 |
$wb->show_menu(); |
|
355 |
} |
|
356 |
|
|
357 |
public function show_menu() { |
|
358 |
global $database; |
|
359 |
if ($this->menu_start_level>0) { |
|
360 |
$key_array=array_keys($this->page_trail); |
|
361 |
if (isset($key_array[$this->menu_start_level-1])) { |
|
362 |
$real_start=$key_array[$this->menu_start_level-1]; |
|
363 |
$this->menu_parent=$real_start; |
|
364 |
$this->menu_start_level=0; |
|
365 |
} else { |
|
366 |
return; |
|
367 |
} |
|
368 |
} |
|
369 |
if ($this->menu_recurse==0) |
|
370 |
return; |
|
371 |
// Check if we should add menu number check to query |
|
372 |
if($this->menu_parent == 0) { |
|
373 |
$menu_number = "menu = '$this->menu_number'"; |
|
374 |
} else { |
|
375 |
$menu_number = '1'; |
|
376 |
} |
|
377 |
// Query pages |
|
378 |
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility,viewing_groups,viewing_users FROM ".TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC"); |
|
379 |
// Check if there are any pages to show |
|
380 |
if($query_menu->numRows() > 0) { |
|
381 |
// Print menu header |
|
382 |
echo "\n".$this->menu_header; |
|
383 |
// Loop through pages |
|
384 |
while($page = $query_menu->fetchRow()) { |
|
385 |
// check whether to show this menu-link |
|
386 |
if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) { |
|
387 |
continue; // no active sections |
|
388 |
} |
|
389 |
if($this->page_is_visible($page)==false) { |
|
390 |
if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways |
|
391 |
continue; |
|
392 |
} |
|
393 |
// Create vars |
|
394 |
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]'); |
|
395 |
// Work-out class |
|
396 |
if($page['page_id'] == PAGE_ID) { |
|
397 |
$class = $this->menu_current_class; |
|
398 |
} else { |
|
399 |
$class = $this->menu_default_class; |
|
400 |
} |
|
401 |
// Check if link is same as first page link, and if so change to WB URL |
|
402 |
if($page['link'] == $this->default_link AND !INTRO_PAGE) { |
|
403 |
$link = WB_URL; |
|
404 |
} else { |
|
405 |
$link = $this->page_link($page['link']); |
|
406 |
} |
|
407 |
// Create values |
|
408 |
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']); |
|
409 |
// Replace vars with value and print |
|
410 |
echo "\n".str_replace($vars, $values, $this->menu_item_template); |
|
411 |
// Generate sub-menu |
|
412 |
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) { |
|
413 |
$this->menu_recurse--; |
|
414 |
$this->menu_parent=$page['page_id']; |
|
415 |
$this->show_menu(); |
|
416 |
} |
|
417 |
echo "\n".$this->menu_item_footer; |
|
418 |
} |
|
419 |
// Print menu footer |
|
420 |
echo "\n".$this->menu_footer; |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
|
|
425 |
// Function to show the "Under Construction" page |
|
426 |
public function print_under_construction() { |
|
427 |
global $MESSAGE; |
|
428 |
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php'); |
|
429 |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
430 |
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title> |
|
431 |
<style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.ADMIN_URL.'/interface/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; } |
|
432 |
h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase; |
|
433 |
}--></style></head><body> |
|
434 |
<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br /> |
|
435 |
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>'; |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category frontend |
|
5 |
* @package framework |
|
6 |
* @author WebsiteBaker Project |
|
7 |
* @copyright 2004-2009, Ryan Djurovich |
|
8 |
* @copyright 2009-2011, Website Baker Org. e.V. |
|
9 |
* @link http://www.websitebaker2.org/ |
|
10 |
* @license http://www.gnu.org/licenses/gpl.html |
|
11 |
* @platform WebsiteBaker 2.8.x |
|
12 |
* @requirements PHP 5.2.2 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
// Must include code to stop this file being access directly |
|
20 |
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); } |
|
21 |
|
|
22 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
23 |
require_once(WB_PATH.'/framework/SecureForm.php'); |
|
24 |
|
|
25 |
class frontend extends wb { |
|
26 |
// defaults |
|
27 |
public $default_link,$default_page_id; |
|
28 |
// when multiple blocks are used, show home page blocks on |
|
29 |
// pages where no content is defined (search, login, ...) |
|
30 |
public $default_block_content=true; |
|
31 |
|
|
32 |
// page details |
|
33 |
// page database row |
|
34 |
public $page; |
|
35 |
public $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility; |
|
36 |
public $page_description,$page_keywords,$page_link; |
|
37 |
public $page_trail=array(); |
|
38 |
|
|
39 |
public $page_access_denied; |
|
40 |
public $page_no_active_sections; |
|
41 |
|
|
42 |
// website settings |
|
43 |
public $website_title,$website_description,$website_keywords,$website_header,$website_footer; |
|
44 |
|
|
45 |
// ugly database stuff |
|
46 |
public $extra_where_sql, $sql_where_language; |
|
47 |
|
|
48 |
public function __construct() { |
|
49 |
parent::__construct(SecureForm::FRONTEND); |
|
50 |
} |
|
51 |
|
|
52 |
public function page_select() { |
|
53 |
global $page_id,$no_intro; |
|
54 |
global $database; |
|
55 |
// We have no page id and are supposed to show the intro page |
|
56 |
if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) { |
|
57 |
// Since we have no page id check if we should go to intro page or default page |
|
58 |
// Get intro page content |
|
59 |
$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION; |
|
60 |
if(file_exists($filename)) { |
|
61 |
$handle = @fopen($filename, "r"); |
|
62 |
$content = @fread($handle, filesize($filename)); |
|
63 |
@fclose($handle); |
|
64 |
$this->preprocess($content); |
|
65 |
header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION.""); // send intro.php as header to allow parsing of php statements |
|
66 |
echo ($content); |
|
67 |
return false; |
|
68 |
} |
|
69 |
} |
|
70 |
// Check if we should add page language sql code |
|
71 |
if(PAGE_LANGUAGES) { |
|
72 |
$this->sql_where_language = " AND language = '".LANGUAGE."'"; |
|
73 |
} |
|
74 |
// Get default page |
|
75 |
// Check for a page id |
|
76 |
$table_p = TABLE_PREFIX.'pages'; |
|
77 |
$table_s = TABLE_PREFIX.'sections'; |
|
78 |
$now = time(); |
|
79 |
$query_default = " |
|
80 |
SELECT `p`.`page_id`, `link` |
|
81 |
FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`) |
|
82 |
WHERE `parent` = '0' AND `visibility` = 'public' |
|
83 |
AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0)) |
|
84 |
$this->sql_where_language |
|
85 |
ORDER BY `p`.`position` ASC LIMIT 1"; |
|
86 |
$get_default = $database->query($query_default); |
|
87 |
$default_num_rows = $get_default->numRows(); |
|
88 |
if(!isset($page_id) OR !is_numeric($page_id)){ |
|
89 |
// Go to or show default page |
|
90 |
if($default_num_rows > 0) { |
|
91 |
$fetch_default = $get_default->fetchRow(); |
|
92 |
$this->default_link = $fetch_default['link']; |
|
93 |
$this->default_page_id = $fetch_default['page_id']; |
|
94 |
// Check if we should redirect or include page inline |
|
95 |
if(HOMEPAGE_REDIRECTION) { |
|
96 |
// Redirect to page |
|
97 |
header("Location: ".$this->page_link($this->default_link)); |
|
98 |
exit(); |
|
99 |
} else { |
|
100 |
// Include page inline |
|
101 |
$this->page_id = $this->default_page_id; |
|
102 |
} |
|
103 |
} else { |
|
104 |
// No pages have been added, so print under construction page |
|
105 |
$this->print_under_construction(); |
|
106 |
exit(); |
|
107 |
} |
|
108 |
} else { |
|
109 |
$this->page_id=$page_id; |
|
110 |
} |
|
111 |
// Get default page link |
|
112 |
if(!isset($fetch_default)) { |
|
113 |
$fetch_default = $get_default->fetchRow(); |
|
114 |
$this->default_link = $fetch_default['link']; |
|
115 |
$this->default_page_id = $fetch_default['page_id']; |
|
116 |
} |
|
117 |
return true; |
|
118 |
} |
|
119 |
|
|
120 |
public function get_page_details() { |
|
121 |
global $database; |
|
122 |
if($this->page_id != 0) { |
|
123 |
// Query page details |
|
124 |
$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'"; |
|
125 |
$get_page = $database->query($query_page); |
|
126 |
// Make sure page was found in database |
|
127 |
if($get_page->numRows() == 0) { |
|
128 |
// Print page not found message |
|
129 |
exit("Page not found"); |
|
130 |
} |
|
131 |
// Fetch page details |
|
132 |
$this->page = $get_page->fetchRow(); |
|
133 |
// Check if the page language is also the selected language. If not, send headers again. |
|
134 |
if ($this->page['language']!=LANGUAGE) { |
|
135 |
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string |
|
136 |
header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']); |
|
137 |
} else { |
|
138 |
header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']); |
|
139 |
} |
|
140 |
exit(); |
|
141 |
} |
|
142 |
// Begin code to set details as either variables of constants |
|
143 |
// Page ID |
|
144 |
if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);} |
|
145 |
// Page Title |
|
146 |
if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);} |
|
147 |
$this->page_title=PAGE_TITLE; |
|
148 |
// Menu Title |
|
149 |
$menu_title = $this->page['menu_title']; |
|
150 |
if($menu_title != '') { |
|
151 |
if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);} |
|
152 |
} else { |
|
153 |
if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);} |
|
154 |
} |
|
155 |
$this->menu_title = MENU_TITLE; |
|
156 |
// Page parent |
|
157 |
if(!defined('PARENT')) {define('PARENT', $this->page['parent']);} |
|
158 |
$this->parent=$this->page['parent']; |
|
159 |
// Page root parent |
|
160 |
if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);} |
|
161 |
$this->root_parent=$this->page['root_parent']; |
|
162 |
// Page level |
|
163 |
if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);} |
|
164 |
$this->level=$this->page['level']; |
|
165 |
// Page visibility |
|
166 |
if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);} |
|
167 |
$this->visibility=$this->page['visibility']; |
|
168 |
// Page trail |
|
169 |
foreach(explode(',', $this->page['page_trail']) AS $pid) { |
|
170 |
$this->page_trail[$pid]=$pid; |
|
171 |
} |
|
172 |
// Page description |
|
173 |
$this->page_description=$this->page['description']; |
|
174 |
if($this->page_description != '') { |
|
175 |
define('PAGE_DESCRIPTION', $this->page_description); |
|
176 |
} else { |
|
177 |
define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION); |
|
178 |
} |
|
179 |
// Page keywords |
|
180 |
$this->page_keywords=$this->page['keywords']; |
|
181 |
// Page link |
|
182 |
$this->link=$this->page_link($this->page['link']); |
|
183 |
|
|
184 |
// End code to set details as either variables of constants |
|
185 |
} |
|
186 |
|
|
187 |
// Figure out what template to use |
|
188 |
if(!defined('TEMPLATE')) { |
|
189 |
if(isset($this->page['template']) AND $this->page['template'] != '') { |
|
190 |
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) { |
|
191 |
define('TEMPLATE', $this->page['template']); |
|
192 |
} else { |
|
193 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
194 |
} |
|
195 |
} else { |
|
196 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
197 |
} |
|
198 |
} |
|
199 |
// Set the template dir |
|
200 |
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE); |
|
201 |
|
|
202 |
// Check if user is allowed to view this page |
|
203 |
if($this->page && $this->page_is_visible($this->page) == false) { |
|
204 |
if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') { |
|
205 |
// User isnt allowed on this page so tell them |
|
206 |
$this->page_access_denied=true; |
|
207 |
} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') { |
|
208 |
// Check if the user is authenticated |
|
209 |
if($this->is_authenticated() == false) { |
|
210 |
// User needs to login first |
|
211 |
header("Location: ".WB_URL."/account/login.php?redirect=".$this->link); |
|
212 |
exit(0); |
|
213 |
} else { |
|
214 |
// User isnt allowed on this page so tell them |
|
215 |
$this->page_access_denied=true; |
|
216 |
} |
|
217 |
|
|
218 |
} |
|
219 |
} |
|
220 |
// check if there is at least one active section |
|
221 |
if($this->page && $this->page_is_active($this->page) == false) { |
|
222 |
$this->page_no_active_sections=true; |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
public function get_website_settings() |
|
227 |
{ |
|
228 |
global $database; |
|
229 |
|
|
230 |
// set visibility SQL code |
|
231 |
// never show no-vis, hidden or deleted pages |
|
232 |
$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'"; |
|
233 |
// Set extra private sql code |
|
234 |
if($this->is_authenticated()==false) { |
|
235 |
// if user is not authenticated, don't show private pages either |
|
236 |
$this->extra_where_sql .= " AND visibility != 'private'"; |
|
237 |
// and 'registered' without frontend login doesn't make much sense! |
|
238 |
if (FRONTEND_LOGIN==false) { |
|
239 |
$this->extra_where_sql .= " AND visibility != 'registered'"; |
|
240 |
} |
|
241 |
} |
|
242 |
$this->extra_where_sql .= $this->sql_where_language; |
|
243 |
|
|
244 |
// Work-out if any possible in-line search boxes should be shown |
|
245 |
if(SEARCH == 'public') { |
|
246 |
define('SHOW_SEARCH', true); |
|
247 |
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') { |
|
248 |
define('SHOW_SEARCH', true); |
|
249 |
} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) { |
|
250 |
define('SHOW_SEARCH', true); |
|
251 |
} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) { |
|
252 |
define('SHOW_SEARCH', true); |
|
253 |
} else { |
|
254 |
define('SHOW_SEARCH', false); |
|
255 |
} |
|
256 |
// Work-out if menu should be shown |
|
257 |
if(!defined('SHOW_MENU')) { |
|
258 |
define('SHOW_MENU', true); |
|
259 |
} |
|
260 |
// Work-out if login menu constants should be set |
|
261 |
if(FRONTEND_LOGIN) { |
|
262 |
// Set login menu constants |
|
263 |
define('LOGIN_URL', WB_URL.'/account/login.php'); |
|
264 |
define('LOGOUT_URL', WB_URL.'/account/logout.php'); |
|
265 |
define('FORGOT_URL', WB_URL.'/account/forgot.php'); |
|
266 |
define('PREFERENCES_URL', WB_URL.'/account/preferences.php'); |
|
267 |
define('SIGNUP_URL', WB_URL.'/account/signup.php'); |
|
268 |
} |
|
269 |
} |
|
270 |
|
|
271 |
/* |
|
272 |
* replace all "[wblink{page_id}]" with real links |
|
273 |
* @param string &$content : reference to global $content |
|
274 |
* @return void |
|
275 |
* @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict |
|
276 |
*/ |
|
277 |
public function preprocess(&$content) |
|
278 |
{ |
|
279 |
global $database; |
|
280 |
$replace_list = array(); |
|
281 |
$pattern = '/\[wblink([0-9]+)\]/isU'; |
|
282 |
if(preg_match_all($pattern,$content,$ids)) |
|
283 |
{ |
|
284 |
foreach($ids[1] as $key => $page_id) |
|
285 |
{ |
|
286 |
$replace_list[$page_id] = $ids[0][$key]; |
|
287 |
} |
|
288 |
foreach($replace_list as $page_id => $tag) |
|
289 |
{ |
|
290 |
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id; |
|
291 |
$link = $database->get_one($sql); |
|
292 |
if(!is_null($link)) |
|
293 |
{ |
|
294 |
$link = $this->page_link($link); |
|
295 |
$content = str_replace($tag, $link, $content); |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
/* |
|
302 |
function preprocess(&$content) { |
|
303 |
global $database; |
|
304 |
// Replace [wblink--PAGE_ID--] with real link |
|
305 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
306 |
preg_match_all($pattern,$content,$ids); |
|
307 |
foreach($ids[1] AS $page_id) { |
|
308 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
309 |
// Get page link |
|
310 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
311 |
$fetch_link = $get_link->fetchRow(); |
|
312 |
$link = $this->page_link($fetch_link['link']); |
|
313 |
$content = preg_replace($pattern,$link,$content); |
|
314 |
} |
|
315 |
} |
|
316 |
*/ |
|
317 |
public function menu() { |
|
318 |
global $wb; |
|
319 |
if (!isset($wb->menu_number)) { |
|
320 |
$wb->menu_number = 1; |
|
321 |
} |
|
322 |
if (!isset($wb->menu_start_level)) { |
|
323 |
$wb->menu_start_level = 0; |
|
324 |
} |
|
325 |
if (!isset($wb->menu_recurse)) { |
|
326 |
$wb->menu_recurse = -1; |
|
327 |
} |
|
328 |
if (!isset($wb->menu_collapse)) { |
|
329 |
$wb->menu_collapse = true; |
|
330 |
} |
|
331 |
if (!isset($wb->menu_item_template)) { |
|
332 |
$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>'; |
|
333 |
} |
|
334 |
if (!isset($wb->menu_item_footer)) { |
|
335 |
$wb->menu_item_footer = '</li>'; |
|
336 |
} |
|
337 |
if (!isset($wb->menu_header)) { |
|
338 |
$wb->menu_header = '<ul>'; |
|
339 |
} |
|
340 |
if (!isset($wb->menu_footer)) { |
|
341 |
$wb->menu_footer = '</ul>'; |
|
342 |
} |
|
343 |
if (!isset($wb->menu_default_class)) { |
|
344 |
$wb->menu_default_class = ' class="menu_default"'; |
|
345 |
} |
|
346 |
if (!isset($wb->menu_current_class)) { |
|
347 |
$wb->menu_current_class = ' class="menu_current"'; |
|
348 |
} |
|
349 |
if (!isset($wb->menu_parent)) { |
|
350 |
$wb->menu_parent = 0; |
|
351 |
} |
|
352 |
$wb->show_menu(); |
|
353 |
} |
|
354 |
|
|
355 |
public function show_menu() { |
|
356 |
global $database; |
|
357 |
if ($this->menu_start_level>0) { |
|
358 |
$key_array=array_keys($this->page_trail); |
|
359 |
if (isset($key_array[$this->menu_start_level-1])) { |
|
360 |
$real_start=$key_array[$this->menu_start_level-1]; |
|
361 |
$this->menu_parent=$real_start; |
|
362 |
$this->menu_start_level=0; |
|
363 |
} else { |
|
364 |
return; |
|
365 |
} |
|
366 |
} |
|
367 |
if ($this->menu_recurse==0) |
|
368 |
return; |
|
369 |
// Check if we should add menu number check to query |
|
370 |
if($this->menu_parent == 0) { |
|
371 |
$menu_number = "menu = '$this->menu_number'"; |
|
372 |
} else { |
|
373 |
$menu_number = '1'; |
|
374 |
} |
|
375 |
// Query pages |
|
376 |
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility,viewing_groups,viewing_users FROM ".TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC"); |
|
377 |
// Check if there are any pages to show |
|
378 |
if($query_menu->numRows() > 0) { |
|
379 |
// Print menu header |
|
380 |
echo "\n".$this->menu_header; |
|
381 |
// Loop through pages |
|
382 |
while($page = $query_menu->fetchRow()) { |
|
383 |
// check whether to show this menu-link |
|
384 |
if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) { |
|
385 |
continue; // no active sections |
|
386 |
} |
|
387 |
if($this->page_is_visible($page)==false) { |
|
388 |
if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways |
|
389 |
continue; |
|
390 |
} |
|
391 |
// Create vars |
|
392 |
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]'); |
|
393 |
// Work-out class |
|
394 |
if($page['page_id'] == PAGE_ID) { |
|
395 |
$class = $this->menu_current_class; |
|
396 |
} else { |
|
397 |
$class = $this->menu_default_class; |
|
398 |
} |
|
399 |
// Check if link is same as first page link, and if so change to WB URL |
|
400 |
if($page['link'] == $this->default_link AND !INTRO_PAGE) { |
|
401 |
$link = WB_URL; |
|
402 |
} else { |
|
403 |
$link = $this->page_link($page['link']); |
|
404 |
} |
|
405 |
// Create values |
|
406 |
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']); |
|
407 |
// Replace vars with value and print |
|
408 |
echo "\n".str_replace($vars, $values, $this->menu_item_template); |
|
409 |
// Generate sub-menu |
|
410 |
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) { |
|
411 |
$this->menu_recurse--; |
|
412 |
$this->menu_parent=$page['page_id']; |
|
413 |
$this->show_menu(); |
|
414 |
} |
|
415 |
echo "\n".$this->menu_item_footer; |
|
416 |
} |
|
417 |
// Print menu footer |
|
418 |
echo "\n".$this->menu_footer; |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
|
|
423 |
// Function to show the "Under Construction" page |
|
424 |
public function print_under_construction() { |
|
425 |
global $MESSAGE; |
|
426 |
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php'); |
|
427 |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
428 |
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title> |
|
429 |
<style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.ADMIN_URL.'/interface/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; } |
|
430 |
h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase; |
|
431 |
}--></style></head><body> |
|
432 |
<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br /> |
|
433 |
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>'; |
|
434 |
} |
|
435 |
} |
|
436 |
|
|
439 | 437 |
?> |
Also available in: Unified diff
YGN Ethical Hacker Group (2.8.2 / 2.9.0)