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 1702 2012-08-27 15:16:04Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
14
 * @lastmodified    $Date: 2012-08-27 17:16:04 +0200 (Mon, 27 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
			$this->link=$this->page_link($this->page['link']);
194
			$_SESSION['PAGE_ID'] = $this->page_id;
195
            $bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
196
			$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
197

    
198
		// End code to set details as either variables of constants
199
		}
200

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

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

    
232
			}
233
		}
234
		// check if there is at least one active section
235
		if($this->page && $this->page_is_active($this->page) == false) {
236
			$this->page_no_active_sections=true;
237
		}
238
	}
239

    
240
	public function get_website_settings()
241
    {
242
		global $database;
243

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

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

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

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

    
406

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

    
(13-13/25)