Project

General

Profile

1
<?php
2
/****************************************************************************
3
* SVN Version information:
4
*
5
* $Id: class.frontend.php 1248 2010-01-14 04:49:19Z Luisehahne $
6
*
7
*
8
*
9
*****************************************************************************
10
*                          WebsiteBaker
11
*
12
* WebsiteBaker Project <http://www.websitebaker2.org/>
13
* Copyright (C) 2009, Website Baker Org. e.V.
14
*         http://start.websitebaker2.org/impressum-datenschutz.php
15
* Copyright (C) 2004-2009, Ryan Djurovich
16
*
17
*                        About WebsiteBaker
18
*
19
* Website Baker is a PHP-based Content Management System (CMS)
20
* designed with one goal in mind: to enable its users to produce websites
21
* with ease.
22
*
23
*****************************************************************************
24
*
25
*****************************************************************************
26
*                        LICENSE INFORMATION
27
*
28
* WebsiteBaker is free software; you can redistribute it and/or
29
* modify it under the terms of the GNU General Public License
30
* as published by the Free Software Foundation; either version 2
31
* of the License, or (at your option) any later version.
32
*
33
* WebsiteBaker is distributed in the hope that it will be useful,
34
* but WITHOUT ANY WARRANTY; without even the implied warranty of
35
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36
* See the GNU General Public License for more details.
37
*
38
* You should have received a copy of the GNU General Public License
39
* along with this program; if not, write to the Free Software
40
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
41
****************************************************************************
42
*
43
*                   WebsiteBaker Extra Information
44
*
45
*
46
*
47
*
48
*
49
*
50
*
51
*****************************************************************************/
52
/**
53
 *
54
 * @category     frontend
55
 * @package      framework
56
 * @author       Ryan Djurovich
57
 * @copyright    2004-2009, Ryan Djurovich
58
 * @copyright    2009-2010, Website Baker Org. e.V.
59
 * @version      $Id: class.frontend.php 1248 2010-01-14 04:49:19Z Luisehahne $
60
 * @platform     WebsiteBaker 2.8.x
61
 * @requirements >= PHP 4.3.4
62
 * @license      http://www.gnu.org/licenses/gpl.html
63
 *
64
 */
65

    
66
/*
67

    
68
Frontend class
69

    
70
*/
71

    
72
if(!defined('WB_PATH')) {
73
	header('Location: ../index.php');
74
	exit(0);
75
}
76

    
77

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

    
80
class frontend extends wb {
81
	// defaults
82
	var $default_link,$default_page_id;
83
	// when multiple blocks are used, show home page blocks on 
84
	// pages where no content is defined (search, login, ...)
85
	var $default_block_content=true;
86

    
87
	// page details
88
	// page database row
89
	var $page;
90
	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
91
	var $page_description,$page_keywords,$page_link;
92
	var $page_trail=array();
93
	
94
	var $page_access_denied;
95
	var $page_no_active_sections;
96
	
97
	// website settings
98
	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
99

    
100
	// ugly database stuff
101
	var $extra_where_sql, $sql_where_language;
102

    
103
	function page_select() {
104
		global $page_id,$no_intro;
105
		global $database;
106
		// We have no page id and are supposed to show the intro page
107
		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
108
			// Since we have no page id check if we should go to intro page or default page
109
			// Get intro page content
110
			$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
111
			if(file_exists($filename)) {
112
				$handle = @fopen($filename, "r");
113
				$content = @fread($handle, filesize($filename));
114
				@fclose($handle);
115
				$this->preprocess($content);
116
				header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION."");   // send intro.php as header to allow parsing of php statements
117
				echo ($content);
118
				return false;
119
			}
120
		}
121
		// Check if we should add page language sql code
122
		if(PAGE_LANGUAGES) {
123
			$this->sql_where_language = " AND language = '".LANGUAGE."'";
124
		}
125
		// Get default page
126
		// Check for a page id
127
		$table_p = TABLE_PREFIX.'pages';
128
		$table_s = TABLE_PREFIX.'sections';
129
		$now = time();
130
		$query_default = "
131
			SELECT `p`.`page_id`, `link`
132
			FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`)
133
			WHERE `parent` = '0' AND `visibility` = 'public'
134
			AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0))
135
			$this->sql_where_language
136
			ORDER BY `p`.`position` ASC LIMIT 1";
137
		$get_default = $database->query($query_default);
138
		$default_num_rows = $get_default->numRows();
139
		if(!isset($page_id) OR !is_numeric($page_id)){
140
			// Go to or show default page
141
			if($default_num_rows > 0) {
142
				$fetch_default = $get_default->fetchRow();
143
				$this->default_link = $fetch_default['link'];
144
				$this->default_page_id = $fetch_default['page_id'];
145
				// Check if we should redirect or include page inline
146
				if(HOMEPAGE_REDIRECTION) {
147
					// Redirect to page
148
					header("Location: ".$this->page_link($this->default_link));
149
					exit();
150
				} else {
151
					// Include page inline
152
					$this->page_id = $this->default_page_id;
153
				}
154
			} else {
155
		   		// No pages have been added, so print under construction page
156
				$this->print_under_construction();
157
				exit();
158
			}
159
		} else {
160
			$this->page_id=$page_id;
161
		}
162
		// Get default page link
163
		if(!isset($fetch_default)) {
164
		  	$fetch_default = $get_default->fetchRow();
165
	 		$this->default_link = $fetch_default['link'];
166
			$this->default_page_id = $fetch_default['page_id'];
167
		}
168
		return true;
169
	}
170

    
171
	function get_page_details() {
172
		global $database;
173
	    if($this->page_id != 0) {
174
			// Query page details
175
			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
176
			$get_page = $database->query($query_page);
177
			// Make sure page was found in database
178
			if($get_page->numRows() == 0) {
179
				// Print page not found message
180
				exit("Page not found");
181
			}
182
			// Fetch page details
183
			$this->page = $get_page->fetchRow();
184
			// Check if the page language is also the selected language. If not, send headers again.
185
			if ($this->page['language']!=LANGUAGE) {
186
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
187
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
188
				} else {
189
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
190
				}
191
				exit();
192
			}
193
			// Begin code to set details as either variables of constants
194
			// Page ID
195
			if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
196
			// Page Title
197
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
198
			$this->page_title=PAGE_TITLE;
199
			// Menu Title
200
			$menu_title = $this->page['menu_title'];
201
			if($menu_title != '') {
202
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
203
			} else {
204
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
205
			}
206
			$this->menu_title = MENU_TITLE;
207
			// Page parent
208
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
209
			$this->parent=$this->page['parent'];
210
			// Page root parent
211
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
212
			$this->root_parent=$this->page['root_parent'];
213
			// Page level
214
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
215
			$this->level=$this->page['level'];
216
			// Page visibility
217
			if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
218
			$this->visibility=$this->page['visibility'];
219
			// Page trail
220
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
221
				$this->page_trail[$pid]=$pid;
222
			}
223
			// Page description
224
			$this->page_description=$this->page['description'];
225
			if($this->page_description != '') {
226
				define('PAGE_DESCRIPTION', $this->page_description);
227
			} else {
228
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
229
			}
230
			// Page keywords
231
			$this->page_keywords=$this->page['keywords'];
232
			// Page link
233
			$this->link=$this->page_link($this->page['link']);
234

    
235
		// End code to set details as either variables of constants
236
		}
237

    
238
		// Figure out what template to use
239
		if(!defined('TEMPLATE')) {
240
			if(isset($this->page['template']) AND $this->page['template'] != '') {
241
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
242
					define('TEMPLATE', $this->page['template']);
243
				} else {
244
					define('TEMPLATE', DEFAULT_TEMPLATE);
245
				}
246
			} else {
247
				define('TEMPLATE', DEFAULT_TEMPLATE);
248
			}
249
		}
250
		// Set the template dir
251
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
252

    
253
		// Check if user is allowed to view this page
254
		if($this->page && $this->page_is_visible($this->page) == false) {
255
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
256
				// User isnt allowed on this page so tell them
257
				$this->page_access_denied=true;
258
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
259
				// Check if the user is authenticated
260
				if($this->is_authenticated() == false) {
261
					// User needs to login first
262
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
263
					exit(0);
264
				} else {
265
					// User isnt allowed on this page so tell them
266
					$this->page_access_denied=true;
267
				}
268
				
269
			}
270
		}
271
		// check if there is at least one active section
272
		if($this->page && $this->page_is_active($this->page) == false) {
273
			$this->page_no_active_sections=true;
274
		}
275
	}
276

    
277
	function get_website_settings() {
278
		global $database;
279

    
280
		// set visibility SQL code
281
		// never show no-vis, hidden or deleted pages
282
		$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
283
		// Set extra private sql code
284
		if($this->is_authenticated()==false) {
285
			// if user is not authenticated, don't show private pages either
286
			$this->extra_where_sql .= " AND visibility != 'private'";
287
			// and 'registered' without frontend login doesn't make much sense!
288
			if (FRONTEND_LOGIN==false) {
289
				$this->extra_where_sql .= " AND visibility != 'registered'";
290
			}
291
		}
292
		$this->extra_where_sql .= $this->sql_where_language;
293

    
294
		// Work-out if any possible in-line search boxes should be shown
295
		if(SEARCH == 'public') {
296
			define('SHOW_SEARCH', true);
297
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
298
			define('SHOW_SEARCH', true);
299
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
300
			define('SHOW_SEARCH', true);
301
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
302
			define('SHOW_SEARCH', true);	
303
		} else {
304
			define('SHOW_SEARCH', false);
305
		}
306
		// Work-out if menu should be shown
307
		if(!defined('SHOW_MENU')) {
308
			define('SHOW_MENU', true);
309
		}
310
		// Work-out if login menu constants should be set
311
		if(FRONTEND_LOGIN) {
312
			// Set login menu constants
313
			define('LOGIN_URL', WB_URL.'/account/login.php');
314
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
315
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
316
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
317
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
318
		}
319
	}
320
	
321
	function preprocess(&$content) {
322
		global $database;
323
		// Replace [wblink--PAGE_ID--] with real link
324
		$pattern = '/\[wblink(.+?)\]/s';
325
		preg_match_all($pattern,$content,$ids);
326
		foreach($ids[1] AS $page_id) {
327
			$pattern = '/\[wblink'.$page_id.'\]/s';
328
			// Get page link
329
			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
330
			$fetch_link = $get_link->fetchRow();
331
			$link = $this->page_link($fetch_link['link']);
332
			$content = preg_replace($pattern,$link,$content);
333
		}
334
	}
335
	
336
	function menu() {
337
		global $wb;
338
	   if (!isset($wb->menu_number)) {
339
	   	$wb->menu_number = 1;
340
	   }
341
	   if (!isset($wb->menu_start_level)) {
342
	   	$wb->menu_start_level = 0;
343
	   }
344
	   if (!isset($wb->menu_recurse)) {
345
	   	$wb->menu_recurse = -1;
346
	   }
347
	   if (!isset($wb->menu_collapse)) {
348
	   	$wb->menu_collapse = true;
349
	   }
350
	   if (!isset($wb->menu_item_template)) {
351
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
352
	   }
353
	   if (!isset($wb->menu_item_footer)) {
354
	   	$wb->menu_item_footer = '</li>';
355
	   }
356
	   if (!isset($wb->menu_header)) {
357
	   	$wb->menu_header = '<ul>';
358
	   }
359
	   if (!isset($wb->menu_footer)) {
360
	   	$wb->menu_footer = '</ul>';
361
	   }
362
	   if (!isset($wb->menu_default_class)) {
363
	   	$wb->menu_default_class = ' class="menu_default"';
364
	   }
365
	   if (!isset($wb->menu_current_class)) {
366
	   	$wb->menu_current_class = ' class="menu_current"';
367
	   }
368
	   if (!isset($wb->menu_parent)) {
369
	   	$wb->menu_parent = 0;
370
	   }
371
	   $wb->show_menu();
372
	}
373
	
374
	function show_menu() {
375
		global $database;
376
		if ($this->menu_start_level>0) {
377
			$key_array=array_keys($this->page_trail);
378
			if (isset($key_array[$this->menu_start_level-1])) {
379
				$real_start=$key_array[$this->menu_start_level-1];
380
				$this->menu_parent=$real_start;
381
				$this->menu_start_level=0;
382
			} else {
383
				return;
384
			}
385
		}
386
		if ($this->menu_recurse==0)
387
	       return;
388
		// Check if we should add menu number check to query
389
		if($this->menu_parent == 0) {
390
			$menu_number = "menu = '$this->menu_number'";
391
		} else {
392
			$menu_number = '1';
393
		}
394
		// Query pages
395
		$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");
396
		// Check if there are any pages to show
397
		if($query_menu->numRows() > 0) {
398
			// Print menu header
399
			echo "\n".$this->menu_header;
400
			// Loop through pages
401
			while($page = $query_menu->fetchRow()) {
402
				// check whether to show this menu-link
403
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
404
					continue; // no active sections
405
				}
406
				if($this->page_is_visible($page)==false) {
407
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
408
						continue;
409
				}
410
				// Create vars
411
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
412
				// Work-out class
413
				if($page['page_id'] == PAGE_ID) {
414
					$class = $this->menu_current_class;
415
				} else {
416
					$class = $this->menu_default_class;
417
				}
418
				// Check if link is same as first page link, and if so change to WB URL
419
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
420
					$link = WB_URL;
421
				} else {
422
					$link = $this->page_link($page['link']);
423
				}
424
				// Create values
425
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
426
				// Replace vars with value and print
427
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
428
				// Generate sub-menu
429
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
430
					$this->menu_recurse--;
431
					$this->menu_parent=$page['page_id'];
432
					$this->show_menu();
433
				}
434
				echo "\n".$this->menu_item_footer;
435
			}
436
			// Print menu footer
437
			echo "\n".$this->menu_footer;
438
		}
439
	}
440

    
441

    
442
	// Function to show the "Under Construction" page
443
	function print_under_construction() {
444
		global $MESSAGE;
445
		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
446
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
447
		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>
448
		<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; }
449
		h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
450
}--></style></head><body>
451
		<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
452
		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
453
	}
454
}
455

    
456
?>
(5-5/15)