Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         frontend
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: class.frontend.php 1728 2012-08-30 14:21:31Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
14
 * @lastmodified    $Date: 2012-08-30 16:21:31 +0200 (Thu, 30 Aug 2012) $
15
 *
16
*/
17
/* -------------------------------------------------------- */
18
// Must include code to stop this file being accessed directly
19
if(!defined('WB_PATH')) {
20
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21
	throw new IllegalFileException();
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,$position,$visibility;
38
	public $page_description,$page_keywords,$page_link, $page_icon, $menu_icon_0, $menu_icon_1, $tooltip;
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
		$sql  = 'SELECT `p`.`page_id`, `link` ';
82
		$sql .= 'FROM `'.$table_p.'` AS `p` INNER JOIN `'.$table_s.'` USING(`page_id`) ';
83
		$sql .= 'WHERE `parent`=0 AND `visibility`=\'public\' ';
84
		$sql .=     'AND (('.$now.'>=`publ_start` OR `publ_start`=0) ';
85
		$sql .=     'AND ('.$now.'<=`publ_end` OR `publ_end`=0)) ';
86
		if(trim($this->sql_where_language) != '') {
87
			$sql .= trim($this->sql_where_language).' ';
88
		}
89
		$sql .= 'ORDER BY `p`.`position` ASC';
90
		$get_default = $database->query($sql);
91
		$default_num_rows = $get_default->numRows();
92
		if(!isset($page_id) OR !is_numeric($page_id)){
93
			// Go to or show default page
94
			if($default_num_rows > 0) {
95
				$fetch_default = $get_default->fetchRow();
96
				$this->default_link = $fetch_default['link'];
97
				$this->default_page_id = $fetch_default['page_id'];
98
				// Check if we should redirect or include page inline
99
				if(HOMEPAGE_REDIRECTION) {
100
					// Redirect to page
101
//					header("Location: ".$this->page_link($this->default_link));
102
//					exit();
103
					$this->send_header($this->page_link($this->default_link));
104
				} else {
105
					// Include page inline
106
					$this->page_id = $this->default_page_id;
107
				}
108
			} else {
109
		   		// No pages have been added, so print under construction page
110
				$this->print_under_construction();
111
				exit();
112
			}
113
		} else {
114
			$this->page_id=$page_id;
115
		}
116
		// Get default page link
117
		if(!isset($fetch_default)) {
118
		  	$fetch_default = $get_default->fetchRow();
119
	 		$this->default_link = $fetch_default['link'];
120
			$this->default_page_id = $fetch_default['page_id'];
121
		}
122
		return true;
123
	}
124

    
125
	public function get_page_details() {
126
		global $database;
127
	    if($this->page_id != 0) {
128
			// Query page details
129
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
130
			$get_page = $database->query($sql);
131
			// Make sure page was found in database
132
			if($get_page->numRows() == 0) {
133
				// Print page not found message
134
				exit("Page not found");
135
			}
136
			// Fetch page details
137
			$this->page = $get_page->fetchRow();
138
			// Check if the page language is also the selected language. If not, send headers again.
139
			if ($this->page['language']!=LANGUAGE) {
140
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
141
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
142
				} else {
143
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
144
				}
145
				exit();
146
			}
147
			// Begin code to set details as either variables of constants
148
			// Page ID
149
			if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
150
			// Page Title
151
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
152
			$this->page_title=PAGE_TITLE;
153
			// Menu Title
154
			$menu_title = $this->page['menu_title'];
155
			if($menu_title != '') {
156
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
157
			} else {
158
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
159
			}
160
			$this->menu_title = MENU_TITLE;
161
			$this->page_icon = $this->page['page_icon'];
162
			$this->menu_icon_0 = $this->page['menu_icon_0'];
163
			$this->menu_icon_1 = $this->page['menu_icon_1'];
164
			$this->tooltip = $this->page['tooltip'];
165
			// Page parent
166
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
167
			$this->parent=$this->page['parent'];
168
			// Page root parent
169
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
170
			$this->root_parent=$this->page['root_parent'];
171
			// Page level
172
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
173
			$this->level=$this->page['level'];
174
			// Page position
175
			$this->level=$this->page['position'];
176
			// Page visibility
177
			if(!defined('VISIBILITY')) {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

    
194
            $bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
195

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

    
198
			$_SESSION['PAGE_ID'] = $this->page_id;
199

    
200
			$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
201
            $_SESSION['HTTP_REFERER'] = !$this->is_authenticated() ? $this->link : $_SESSION['HTTP_REFERER'];
202

    
203
		// End code to set details as either variables of constants
204
		}
205

    
206
		// Figure out what template to use
207
		if(!defined('TEMPLATE')) {
208
			if(isset($this->page['template']) AND $this->page['template'] != '') {
209
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
210
					define('TEMPLATE', $this->page['template']);
211
				} else {
212
					define('TEMPLATE', DEFAULT_TEMPLATE);
213
				}
214
			} else {
215
				define('TEMPLATE', DEFAULT_TEMPLATE);
216
			}
217
		}
218
		// Set the template dir
219
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
220

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

    
237
			}
238
		}
239
		// check if there is at least one active section
240
		if($this->page && $this->page_is_active($this->page) == false) {
241
			$this->page_no_active_sections=true;
242
		}
243
	}
244

    
245
	public function get_website_settings()
246
    {
247
		global $database;
248

    
249
		// set visibility SQL code
250
		// never show no-vis, hidden or deleted pages
251
		$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
252
		// Set extra private sql code
253
		if($this->is_authenticated()==false) {
254
			// if user is not authenticated, don't show private pages either
255
			$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
256
			// and 'registered' without frontend login doesn't make much sense!
257
			if (FRONTEND_LOGIN==false) {
258
				$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
259
			}
260
		}
261
		$this->extra_where_sql .= $this->sql_where_language;
262

    
263
		// Work-out if any possible in-line search boxes should be shown
264
		if(SEARCH == 'public') {
265
			define('SHOW_SEARCH', true);
266
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
267
			define('SHOW_SEARCH', true);
268
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
269
			define('SHOW_SEARCH', true);
270
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
271
			define('SHOW_SEARCH', true);
272
		} else {
273
			define('SHOW_SEARCH', false);
274
		}
275
		// Work-out if menu should be shown
276
		if(!defined('SHOW_MENU')) {
277
			define('SHOW_MENU', true);
278
		}
279
		// Work-out if login menu constants should be set
280
		if(FRONTEND_LOGIN) {
281
			// Set login menu constants
282
			define('LOGIN_URL', WB_URL.'/account/login.php');
283
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
284
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
285
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
286
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
287
		}
288
	}
289

    
290
/*
291
 * replace all "[wblink{page_id}]" with real links
292
 * @param string &$content : reference to global $content
293
 * @return void
294
 * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
295
 */
296
     public function preprocess(&$content)
297
     {
298
    //   do nothing
299
     }
300

    
301
	public function menu() {
302
		global $wb;
303
	   if (!isset($wb->menu_number)) {
304
	   	$wb->menu_number = 1;
305
	   }
306
	   if (!isset($wb->menu_start_level)) {
307
	   	$wb->menu_start_level = 0;
308
	   }
309
	   if (!isset($wb->menu_recurse)) {
310
	   	$wb->menu_recurse = -1;
311
	   }
312
	   if (!isset($wb->menu_collapse)) {
313
	   	$wb->menu_collapse = true;
314
	   }
315
	   if (!isset($wb->menu_item_template)) {
316
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
317
	   }
318
	   if (!isset($wb->menu_item_footer)) {
319
	   	$wb->menu_item_footer = '</li>';
320
	   }
321
	   if (!isset($wb->menu_header)) {
322
	   	$wb->menu_header = '<ul>';
323
	   }
324
	   if (!isset($wb->menu_footer)) {
325
	   	$wb->menu_footer = '</ul>';
326
	   }
327
	   if (!isset($wb->menu_default_class)) {
328
	   	$wb->menu_default_class = ' class="menu_default"';
329
	   }
330
	   if (!isset($wb->menu_current_class)) {
331
	   	$wb->menu_current_class = ' class="menu_current"';
332
	   }
333
	   if (!isset($wb->menu_parent)) {
334
	   	$wb->menu_parent = 0;
335
	   }
336
	   $wb->show_menu();
337
	}
338

    
339
	public function show_menu() {
340
		global $database;
341
		if ($this->menu_start_level>0) {
342
			$key_array=array_keys($this->page_trail);
343
			if (isset($key_array[$this->menu_start_level-1])) {
344
				$real_start=$key_array[$this->menu_start_level-1];
345
				$this->menu_parent=$real_start;
346
				$this->menu_start_level=0;
347
			} else {
348
				return;
349
			}
350
		}
351
		if ($this->menu_recurse==0)
352
	       return;
353
		// Check if we should add menu number check to query
354
		if($this->menu_parent == 0) {
355
			$menu_number = '`menu`='.intval($this->menu_number);
356
		} else {
357
			$menu_number = '1';
358
		}
359
		// Query pages
360
		$sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`level`,';
361
		$sql .=        '`visibility`,viewing_groups,viewing_users ';
362
		$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
363
		$sql .= 'WHERE `parent`='.(int)$this->menu_parent.' AND '.$menu_number.' AND '.$this->extra_where_sql.' ';
364
		$sql .= 'ORDER BY `position` ASC';
365
		$query_menu = $database->query($sql);
366
		// Check if there are any pages to show
367
		if($query_menu->numRows() > 0) {
368
			// Print menu header
369
			echo "\n".$this->menu_header;
370
			// Loop through pages
371
			while($page = $query_menu->fetchRow()) {
372
				// check whether to show this menu-link
373
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
374
					continue; // no active sections
375
				}
376
				if($this->page_is_visible($page)==false) {
377
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
378
						continue;
379
				}
380
				// Create vars
381
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
382
				// Work-out class
383
				if($page['page_id'] == PAGE_ID) {
384
					$class = $this->menu_current_class;
385
				} else {
386
					$class = $this->menu_default_class;
387
				}
388
				// Check if link is same as first page link, and if so change to WB URL
389
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
390
					$link = WB_URL;
391
				} else {
392
					$link = $this->page_link($page['link']);
393
				}
394
				// Create values
395
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
396
				// Replace vars with value and print
397
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
398
				// Generate sub-menu
399
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
400
					$this->menu_recurse--;
401
					$this->menu_parent=$page['page_id'];
402
					$this->show_menu();
403
				}
404
				echo "\n".$this->menu_item_footer;
405
			}
406
			// Print menu footer
407
			echo "\n".$this->menu_footer;
408
		}
409
	}
410

    
411

    
412
	// Function to show the "Under Construction" page
413
	public function print_under_construction() {
414
		global $MESSAGE;
415
		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
416
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
417
		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>
418
		<style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.THEME_URL.'/images/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; }
419
		h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
420
}--></style></head><body>
421
		<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
422
		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
423
	}
424
}
425

    
(13-13/25)