Project

General

Profile

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