Project

General

Profile

« Previous | Next » 

Revision 1152

Added by Dietmar over 14 years ago

View differences:

class.frontend.php
1
<?php
2

  
3
// $Id$
4

  
5
/*
6

  
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

  
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

  
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

  
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

  
24
*/
25

  
26
/*
27

  
28
Frontend class
29

  
30
*/
31

  
32
if(!defined('WB_PATH')) {
33
	header('Location: ../index.php');
34
	exit(0);
35
}
36

  
37

  
38
require_once(WB_PATH.'/framework/class.wb.php');
39

  
40
class frontend extends wb {
41
	// defaults
42
	var $default_link,$default_page_id;
43
	// when multiple blocks are used, show home page blocks on 
44
	// pages where no content is defined (search, login, ...)
45
	var $default_block_content=true;
46

  
47
	// page details
48
	// page database row
49
	var $page;
50
	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
51
	var $page_description,$page_keywords,$page_link;
52
	var $page_trail=array();
53
	
54
	var $page_access_denied;
55
	var $page_no_active_sections;
56
	
57
	// website settings
58
	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
59

  
60
	// ugly database stuff
61
	var $extra_where_sql, $sql_where_language;
62

  
63
	function page_select() {
64
		global $page_id,$no_intro;
65
		global $database;
66
		// We have no page id and are supposed to show the intro page
67
		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
68
			// Since we have no page id check if we should go to intro page or default page
69
			// Get intro page content
70
			$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
71
			if(file_exists($filename)) {
72
				$handle = @fopen($filename, "r");
73
				$content = @fread($handle, filesize($filename));
74
				@fclose($handle);
75
				$this->preprocess($content);
76
				header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION."");   // send intro.php as header to allow parsing of php statements
77
				echo ($content);
78
				return false;
79
			}
80
		}
81
		// Check if we should add page language sql code
82
		if(PAGE_LANGUAGES) {
83
			$this->sql_where_language = " AND language = '".LANGUAGE."'";
84
		}
85
		// Get default page
86
		// Check for a page id
87
		$table_p = TABLE_PREFIX.'pages';
88
		$table_s = TABLE_PREFIX.'sections';
89
		$now = time();
90
		$query_default = "
91
			SELECT `p`.`page_id`, `link`
92
			FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`)
93
			WHERE `parent` = '0' AND `visibility` = 'public'
94
			AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0))
95
			$this->sql_where_language
96
			ORDER BY `p`.`position` ASC LIMIT 1";
97
		$get_default = $database->query($query_default);
98
		$default_num_rows = $get_default->numRows();
99
		if(!isset($page_id) OR !is_numeric($page_id)){
100
			// Go to or show default page
101
			if($default_num_rows > 0) {
102
				$fetch_default = $get_default->fetchRow();
103
				$this->default_link = $fetch_default['link'];
104
				$this->default_page_id = $fetch_default['page_id'];
105
				// Check if we should redirect or include page inline
106
				if(HOMEPAGE_REDIRECTION) {
107
					// Redirect to page
108
					header("Location: ".$this->page_link($this->default_link));
109
					exit();
110
				} else {
111
					// Include page inline
112
					$this->page_id = $this->default_page_id;
113
				}
114
			} else {
115
		   		// No pages have been added, so print under construction page
116
				$this->print_under_construction();
117
				exit();
118
			}
119
		} else {
120
			$this->page_id=$page_id;
121
		}
122
		// Get default page link
123
		if(!isset($fetch_default)) {
124
		  	$fetch_default = $get_default->fetchRow();
125
	 		$this->default_link = $fetch_default['link'];
126
			$this->default_page_id = $fetch_default['page_id'];
127
		}
128
		return true;
129
	}
130

  
131
	function get_page_details() {
132
		global $database;
133
	    if($this->page_id != 0) {
134
			// Query page details
135
			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
136
			$get_page = $database->query($query_page);
137
			// Make sure page was found in database
138
			if($get_page->numRows() == 0) {
139
				// Print page not found message
140
				exit("Page not found");
141
			}
142
			// Fetch page details
143
			$this->page = $get_page->fetchRow();
144
			// Check if the page language is also the selected language. If not, send headers again.
145
			if ($this->page['language']!=LANGUAGE) {
146
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
147
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
148
				} else {
149
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
150
				}
151
				exit();
152
			}
153
			// Begin code to set details as either variables of constants
154
			// Page ID
155
			define('PAGE_ID', $this->page['page_id']);
156
			// Page Title
157
			define('PAGE_TITLE', $this->page['page_title']);
158
			$this->page_title=PAGE_TITLE;
159
			// Menu Title
160
			$menu_title = $this->page['menu_title'];
161
			if($menu_title != '') {
162
				define('MENU_TITLE', $menu_title);
163
			} else {
164
				define('MENU_TITLE', PAGE_TITLE);
165
			}
166
			$this->menu_title=MENU_TITLE;
167
			// Page parent
168
			define('PARENT', $this->page['parent']);
169
			$this->parent=$this->page['parent'];
170
			// Page root parent
171
			define('ROOT_PARENT', $this->page['root_parent']);
172
			$this->root_parent=$this->page['root_parent'];
173
			// Page level
174
			define('LEVEL', $this->page['level']);
175
			$this->level=$this->page['level'];
176
			// Page visibility
177
			define('VISIBILITY', $this->page['visibility']);
178
			$this->visibility=$this->page['visibility'];
179
			// Page trail
180
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
181
				$this->page_trail[$pid]=$pid;
182
			}
183
			// Page description
184
			$this->page_description=$this->page['description'];
185
			if($this->page_description != '') {
186
				define('PAGE_DESCRIPTION', $this->page_description);
187
			} else {
188
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
189
			}
190
			// Page keywords
191
			$this->page_keywords=$this->page['keywords'];
192
			// Page link
193
			$this->link=$this->page_link($this->page['link']);
194

  
195
		// End code to set details as either variables of constants
196
		}
197

  
198
		// Figure out what template to use
199
		if(!defined('TEMPLATE')) {
200
			if(isset($this->page['template']) AND $this->page['template'] != '') {
201
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
202
					define('TEMPLATE', $this->page['template']);
203
				} else {
204
					define('TEMPLATE', DEFAULT_TEMPLATE);
205
				}
206
			} else {
207
				define('TEMPLATE', DEFAULT_TEMPLATE);
208
			}
209
		}
210
		// Set the template dir
211
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
212

  
213
		// Check if user is allowed to view this page
214
		if($this->page && $this->page_is_visible($this->page) == false) {
215
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
216
				// User isnt allowed on this page so tell them
217
				$this->page_access_denied=true;
218
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
219
				// Check if the user is authenticated
220
				if($this->is_authenticated() == false) {
221
					// User needs to login first
222
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
223
					exit(0);
224
				} else {
225
					// User isnt allowed on this page so tell them
226
					$this->page_access_denied=true;
227
				}
228
				
229
			}
230
		}
231
		// check if there is at least one active section
232
		if($this->page && $this->page_is_active($this->page) == false) {
233
			$this->page_no_active_sections=true;
234
		}
235
	}
236

  
237
	function get_website_settings() {
238
		global $database;
239

  
240
		// set visibility SQL code
241
		// never show no-vis, hidden or deleted pages
242
		$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
243
		// Set extra private sql code
244
		if($this->is_authenticated()==false) {
245
			// if user is not authenticated, don't show private pages either
246
			$this->extra_where_sql .= " AND visibility != 'private'";
247
			// and 'registered' without frontend login doesn't make much sense!
248
			if (FRONTEND_LOGIN==false) {
249
				$this->extra_where_sql .= " AND visibility != 'registered'";
250
			}
251
		}
252
		$this->extra_where_sql .= $this->sql_where_language;
253

  
254
		// Work-out if any possible in-line search boxes should be shown
255
		if(SEARCH == 'public') {
256
			define('SHOW_SEARCH', true);
257
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
258
			define('SHOW_SEARCH', true);
259
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
260
			define('SHOW_SEARCH', true);
261
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
262
			define('SHOW_SEARCH', true);	
263
		} else {
264
			define('SHOW_SEARCH', false);
265
		}
266
		// Work-out if menu should be shown
267
		if(!defined('SHOW_MENU')) {
268
			define('SHOW_MENU', true);
269
		}
270
		// Work-out if login menu constants should be set
271
		if(FRONTEND_LOGIN) {
272
			// Set login menu constants
273
			define('LOGIN_URL', WB_URL.'/account/login.php');
274
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
275
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
276
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
277
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
278
		}
279
	}
280
	
281
	function preprocess(&$content) {
282
		global $database;
283
		// Replace [wblink--PAGE_ID--] with real link
284
		$pattern = '/\[wblink(.+?)\]/s';
285
		preg_match_all($pattern,$content,$ids);
286
		foreach($ids[1] AS $page_id) {
287
			$pattern = '/\[wblink'.$page_id.'\]/s';
288
			// Get page link
289
			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
290
			$fetch_link = $get_link->fetchRow();
291
			$link = $this->page_link($fetch_link['link']);
292
			$content = preg_replace($pattern,$link,$content);
293
		}
294
	}
295
	
296
	function menu() {
297
		global $wb;
298
	   if (!isset($wb->menu_number)) {
299
	   	$wb->menu_number = 1;
300
	   }
301
	   if (!isset($wb->menu_start_level)) {
302
	   	$wb->menu_start_level = 0;
303
	   }
304
	   if (!isset($wb->menu_recurse)) {
305
	   	$wb->menu_recurse = -1;
306
	   }
307
	   if (!isset($wb->menu_collapse)) {
308
	   	$wb->menu_collapse = true;
309
	   }
310
	   if (!isset($wb->menu_item_template)) {
311
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
312
	   }
313
	   if (!isset($wb->menu_item_footer)) {
314
	   	$wb->menu_item_footer = '</li>';
315
	   }
316
	   if (!isset($wb->menu_header)) {
317
	   	$wb->menu_header = '<ul>';
318
	   }
319
	   if (!isset($wb->menu_footer)) {
320
	   	$wb->menu_footer = '</ul>';
321
	   }
322
	   if (!isset($wb->menu_default_class)) {
323
	   	$wb->menu_default_class = ' class="menu_default"';
324
	   }
325
	   if (!isset($wb->menu_current_class)) {
326
	   	$wb->menu_current_class = ' class="menu_current"';
327
	   }
328
	   if (!isset($wb->menu_parent)) {
329
	   	$wb->menu_parent = 0;
330
	   }
331
	   $wb->show_menu();
332
	}
333
	
334
	function show_menu() {
335
		global $database;
336
		if ($this->menu_start_level>0) {
337
			$key_array=array_keys($this->page_trail);
338
			if (isset($key_array[$this->menu_start_level-1])) {
339
				$real_start=$key_array[$this->menu_start_level-1];
340
				$this->menu_parent=$real_start;
341
				$this->menu_start_level=0;
342
			} else {
343
				return;
344
			}
345
		}
346
		if ($this->menu_recurse==0)
347
	       return;
348
		// Check if we should add menu number check to query
349
		if($this->menu_parent == 0) {
350
			$menu_number = "menu = '$this->menu_number'";
351
		} else {
352
			$menu_number = '1';
353
		}
354
		// Query pages
355
		$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");
356
		// Check if there are any pages to show
357
		if($query_menu->numRows() > 0) {
358
			// Print menu header
359
			echo "\n".$this->menu_header;
360
			// Loop through pages
361
			while($page = $query_menu->fetchRow()) {
362
				// check whether to show this menu-link
363
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
364
					continue; // no active sections
365
				}
366
				if($this->page_is_visible($page)==false) {
367
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
368
						continue;
369
				}
370
				// Create vars
371
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
372
				// Work-out class
373
				if($page['page_id'] == PAGE_ID) {
374
					$class = $this->menu_current_class;
375
				} else {
376
					$class = $this->menu_default_class;
377
				}
378
				// Check if link is same as first page link, and if so change to WB URL
379
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
380
					$link = WB_URL;
381
				} else {
382
					$link = $this->page_link($page['link']);
383
				}
384
				// Create values
385
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
386
				// Replace vars with value and print
387
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
388
				// Generate sub-menu
389
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
390
					$this->menu_recurse--;
391
					$this->menu_parent=$page['page_id'];
392
					$this->show_menu();
393
				}
394
				echo "\n".$this->menu_item_footer;
395
			}
396
			// Print menu footer
397
			echo "\n".$this->menu_footer;
398
		}
399
	}
400

  
401

  
402
	// Function to show the "Under Construction" page
403
	function print_under_construction() {
404
		global $MESSAGE;
405
		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
406
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
407
		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>
408
		<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; }
409
		h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
410
}--></style></head><body>
411
		<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
412
		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
413
	}
414
}
415

  
416
?>
1
<?php

2

  
3
// $Id$

4

  
5
/*

6

  
7
 Website Baker Project <http://www.websitebaker.org/>

8
 Copyright (C) 2004-2009, Ryan Djurovich

9

  
10
 Website Baker is free software; you can redistribute it and/or modify

11
 it under the terms of the GNU General Public License as published by

12
 the Free Software Foundation; either version 2 of the License, or

13
 (at your option) any later version.

14

  
15
 Website Baker is distributed in the hope that it will be useful,

16
 but WITHOUT ANY WARRANTY; without even the implied warranty of

17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

18
 GNU General Public License for more details.

19

  
20
 You should have received a copy of the GNU General Public License

21
 along with Website Baker; if not, write to the Free Software

22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

23

  
24
*/

25

  
26
/*

27

  
28
Frontend class

29

  
30
*/

31

  
32
if(!defined('WB_PATH')) {

33
	header('Location: ../index.php');

34
	exit(0);

35
}

36

  
37

  
38
require_once(WB_PATH.'/framework/class.wb.php');

39

  
40
class frontend extends wb {

41
	// defaults

42
	var $default_link,$default_page_id;

43
	// when multiple blocks are used, show home page blocks on 

44
	// pages where no content is defined (search, login, ...)

45
	var $default_block_content=true;

46

  
47
	// page details

48
	// page database row

49
	var $page;

50
	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;

51
	var $page_description,$page_keywords,$page_link;

52
	var $page_trail=array();

53
	
54
	var $page_access_denied;

55
	var $page_no_active_sections;

56
	
57
	// website settings

58
	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;

59

  
60
	// ugly database stuff

61
	var $extra_where_sql, $sql_where_language;

62

  
63
	function page_select() {

64
		global $page_id,$no_intro;

65
		global $database;

66
		// We have no page id and are supposed to show the intro page

67
		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {

68
			// Since we have no page id check if we should go to intro page or default page

69
			// Get intro page content

70
			$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;

71
			if(file_exists($filename)) {

72
				$handle = @fopen($filename, "r");

73
				$content = @fread($handle, filesize($filename));

74
				@fclose($handle);

75
				$this->preprocess($content);

76
				header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION."");   // send intro.php as header to allow parsing of php statements

77
				echo ($content);

78
				return false;

79
			}

80
		}

81
		// Check if we should add page language sql code

82
		if(PAGE_LANGUAGES) {

83
			$this->sql_where_language = " AND language = '".LANGUAGE."'";

84
		}

85
		// Get default page

86
		// Check for a page id

87
		$table_p = TABLE_PREFIX.'pages';

88
		$table_s = TABLE_PREFIX.'sections';

89
		$now = time();

90
		$query_default = "

91
			SELECT `p`.`page_id`, `link`

92
			FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`)

93
			WHERE `parent` = '0' AND `visibility` = 'public'

94
			AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0))

95
			$this->sql_where_language

96
			ORDER BY `p`.`position` ASC LIMIT 1";

97
		$get_default = $database->query($query_default);

98
		$default_num_rows = $get_default->numRows();

99
		if(!isset($page_id) OR !is_numeric($page_id)){

100
			// Go to or show default page

101
			if($default_num_rows > 0) {

102
				$fetch_default = $get_default->fetchRow();

103
				$this->default_link = $fetch_default['link'];

104
				$this->default_page_id = $fetch_default['page_id'];

105
				// Check if we should redirect or include page inline

106
				if(HOMEPAGE_REDIRECTION) {

107
					// Redirect to page

108
					header("Location: ".$this->page_link($this->default_link));

109
					exit();

110
				} else {

111
					// Include page inline

112
					$this->page_id = $this->default_page_id;

113
				}

114
			} else {

115
		   		// No pages have been added, so print under construction page

116
				$this->print_under_construction();

117
				exit();

118
			}

119
		} else {

120
			$this->page_id=$page_id;

121
		}

122
		// Get default page link

123
		if(!isset($fetch_default)) {

124
		  	$fetch_default = $get_default->fetchRow();

125
	 		$this->default_link = $fetch_default['link'];

126
			$this->default_page_id = $fetch_default['page_id'];

127
		}

128
		return true;

129
	}

130

  
131
	function get_page_details() {

132
		global $database;

133
	    if($this->page_id != 0) {

134
			// Query page details

135
			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";

136
			$get_page = $database->query($query_page);

137
			// Make sure page was found in database

138
			if($get_page->numRows() == 0) {

139
				// Print page not found message

140
				exit("Page not found");

141
			}

142
			// Fetch page details

143
			$this->page = $get_page->fetchRow();

144
			// Check if the page language is also the selected language. If not, send headers again.

145
			if ($this->page['language']!=LANGUAGE) {

146
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string

147
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);

148
				} else {

149
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);

150
				}

151
				exit();

152
			}

153
			// Begin code to set details as either variables of constants

154
			// Page ID

155
			define('PAGE_ID', $this->page['page_id']);

156
			// Page Title

157
			define('PAGE_TITLE', $this->page['page_title']);

158
			$this->page_title=PAGE_TITLE;

159
			// Menu Title

160
			$menu_title = $this->page['menu_title'];

161
			if($menu_title != '') {

162
				define('MENU_TITLE', $menu_title);

163
			} else {

164
				define('MENU_TITLE', PAGE_TITLE);

165
			}

166
			$this->menu_title=MENU_TITLE;

167
			// Page parent

168
			define('PARENT', $this->page['parent']);

169
			$this->parent=$this->page['parent'];

170
			// Page root parent

171
			define('ROOT_PARENT', $this->page['root_parent']);

172
			$this->root_parent=$this->page['root_parent'];

173
			// Page level

174
			define('LEVEL', $this->page['level']);

175
			$this->level=$this->page['level'];

176
			// Page visibility

177
			define('VISIBILITY', $this->page['visibility']);

178
			$this->visibility=$this->page['visibility'];

179
			// Page trail

180
			foreach(explode(',', $this->page['page_trail']) AS $pid) {

181
				$this->page_trail[$pid]=$pid;

182
			}

183
			// Page description

184
			$this->page_description=$this->page['description'];

185
			if($this->page_description != '') {

186
				define('PAGE_DESCRIPTION', $this->page_description);

187
			} else {

188
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);

189
			}

190
			// Page keywords

191
			$this->page_keywords=$this->page['keywords'];

192
			// Page link

193
			$this->link=$this->page_link($this->page['link']);

194

  
195
		// End code to set details as either variables of constants

196
		}

197

  
198
		// Figure out what template to use

199
		if(!defined('TEMPLATE')) {

200
			if(isset($this->page['template']) AND $this->page['template'] != '') {

201
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {

202
					define('TEMPLATE', $this->page['template']);

203
				} else {

204
					define('TEMPLATE', DEFAULT_TEMPLATE);

205
				}

206
			} else {

207
				define('TEMPLATE', DEFAULT_TEMPLATE);

208
			}

209
		}

210
		// Set the template dir

211
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);

212

  
213
		// Check if user is allowed to view this page

214
		if($this->page && $this->page_is_visible($this->page) == false) {

215
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {

216
				// User isnt allowed on this page so tell them

217
				$this->page_access_denied=true;

218
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {

219
				// Check if the user is authenticated

220
				if($this->is_authenticated() == false) {

221
					// User needs to login first

222
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);

223
					exit(0);

224
				} else {

225
					// User isnt allowed on this page so tell them

226
					$this->page_access_denied=true;

227
				}

228
				
229
			}

230
		}

231
		// check if there is at least one active section

232
		if($this->page && $this->page_is_active($this->page) == false) {

233
			$this->page_no_active_sections=true;

234
		}

235
	}

236

  
237
	function get_website_settings() {

238
		global $database;

239

  
240
		// set visibility SQL code

241
		// never show no-vis, hidden or deleted pages

242
		$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";

243
		// Set extra private sql code

244
		if($this->is_authenticated()==false) {

245
			// if user is not authenticated, don't show private pages either

246
			$this->extra_where_sql .= " AND visibility != 'private'";

247
			// and 'registered' without frontend login doesn't make much sense!

248
			if (FRONTEND_LOGIN==false) {

249
				$this->extra_where_sql .= " AND visibility != 'registered'";

250
			}

251
		}

252
		$this->extra_where_sql .= $this->sql_where_language;

253

  
254
		// Work-out if any possible in-line search boxes should be shown

255
		if(SEARCH == 'public') {

256
			define('SHOW_SEARCH', true);

257
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {

258
			define('SHOW_SEARCH', true);

259
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {

260
			define('SHOW_SEARCH', true);

261
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {

262
			define('SHOW_SEARCH', true);	

263
		} else {

264
			define('SHOW_SEARCH', false);

265
		}

266
		// Work-out if menu should be shown

267
		if(!defined('SHOW_MENU')) {

268
			define('SHOW_MENU', true);

269
		}

270
		// Work-out if login menu constants should be set

271
		if(FRONTEND_LOGIN) {

272
			// Set login menu constants

273
			define('LOGIN_URL', WB_URL.'/account/login.php');

274
			define('LOGOUT_URL', WB_URL.'/account/logout.php');

275
			define('FORGOT_URL', WB_URL.'/account/forgot.php');

276
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');

277
			define('SIGNUP_URL', WB_URL.'/account/signup.php');

278
		}

279
	}

280
	
281
	function preprocess(&$content) {

282
		global $database;

283
		// Replace [wblink--PAGE_ID--] with real link

284
		$pattern = '/\[wblink(.+?)\]/s';

285
		preg_match_all($pattern,$content,$ids);

286
		foreach($ids[1] AS $page_id) {

287
			$pattern = '/\[wblink'.$page_id.'\]/s';

288
			// Get page link

289
			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");

290
			$fetch_link = $get_link->fetchRow();

291
			$link = $this->page_link($fetch_link['link']);

292
			$content = preg_replace($pattern,$link,$content);

293
		}

294
	}

295
	
296
	function menu() {

297
		global $wb;

298
	   if (!isset($wb->menu_number)) {

299
	   	$wb->menu_number = 1;

300
	   }

301
	   if (!isset($wb->menu_start_level)) {

302
	   	$wb->menu_start_level = 0;

303
	   }

304
	   if (!isset($wb->menu_recurse)) {

305
	   	$wb->menu_recurse = -1;

306
	   }

307
	   if (!isset($wb->menu_collapse)) {

308
	   	$wb->menu_collapse = true;

309
	   }

310
	   if (!isset($wb->menu_item_template)) {

311
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';

312
	   }

313
	   if (!isset($wb->menu_item_footer)) {

314
	   	$wb->menu_item_footer = '</li>';

315
	   }

316
	   if (!isset($wb->menu_header)) {

317
	   	$wb->menu_header = '<ul>';

318
	   }

319
	   if (!isset($wb->menu_footer)) {

320
	   	$wb->menu_footer = '</ul>';

321
	   }

322
	   if (!isset($wb->menu_default_class)) {

323
	   	$wb->menu_default_class = ' class="menu_default"';

324
	   }

325
	   if (!isset($wb->menu_current_class)) {

326
	   	$wb->menu_current_class = ' class="menu_current"';

327
	   }

328
	   if (!isset($wb->menu_parent)) {

329
	   	$wb->menu_parent = 0;

330
	   }

331
	   $wb->show_menu();

332
	}

333
	
334
	function show_menu() {

335
		global $database;

336
		if ($this->menu_start_level>0) {

337
			$key_array=array_keys($this->page_trail);

338
			if (isset($key_array[$this->menu_start_level-1])) {

339
				$real_start=$key_array[$this->menu_start_level-1];

340
				$this->menu_parent=$real_start;

341
				$this->menu_start_level=0;

342
			} else {

343
				return;

344
			}

345
		}

346
		if ($this->menu_recurse==0)

347
	       return;

348
		// Check if we should add menu number check to query

349
		if($this->menu_parent == 0) {

350
			$menu_number = "menu = '$this->menu_number'";

351
		} else {

352
			$menu_number = '1';

353
		}

354
		// Query pages

355
		$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");

356
		// Check if there are any pages to show

357
		if($query_menu->numRows() > 0) {

358
			// Print menu header

359
			echo "\n".$this->menu_header;

360
			// Loop through pages

361
			while($page = $query_menu->fetchRow()) {

362
				// check whether to show this menu-link

363
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {

364
					continue; // no active sections

365
				}

366
				if($this->page_is_visible($page)==false) {

367
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways

368
						continue;

369
				}

370
				// Create vars

371
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');

372
				// Work-out class

373
				if($page['page_id'] == PAGE_ID) {

374
					$class = $this->menu_current_class;

375
				} else {

376
					$class = $this->menu_default_class;

377
				}

378
				// Check if link is same as first page link, and if so change to WB URL

379
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {

380
					$link = WB_URL;

381
				} else {

382
					$link = $this->page_link($page['link']);

383
				}

384
				// Create values

385
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);

386
				// Replace vars with value and print

387
				echo "\n".str_replace($vars, $values, $this->menu_item_template);

388
				// Generate sub-menu

389
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {

390
					$this->menu_recurse--;

391
					$this->menu_parent=$page['page_id'];

392
					$this->show_menu();

393
				}

394
				echo "\n".$this->menu_item_footer;

395
			}

396
			// Print menu footer

397
			echo "\n".$this->menu_footer;

398
		}

399
	}

400

  
401

  
402
	// Function to show the "Under Construction" page

403
	function print_under_construction() {

404
		global $MESSAGE;

405
		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');

406
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

407
		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>

408
		<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; }

409
		h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;

410
}--></style></head><body>

411
		<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />

412
		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';

413
	}

414
}

415

  
416
?>

Also available in: Unified diff