Project

General

Profile

1 1420 Luisehahne
<?php
2
/**
3
 *
4 1782 Luisehahne
 * @category        frontend
5
 * @package         framework
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7 1702 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1420 Luisehahne
 * @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$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16 1782 Luisehahne
 */
17 1496 DarkViper
/* -------------------------------------------------------- */
18
// Must include code to stop this file being accessed directly
19 1499 DarkViper
if(!defined('WB_PATH')) {
20
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21
	throw new IllegalFileException();
22
}
23 1496 DarkViper
/* -------------------------------------------------------- */
24 1782 Luisehahne
//require_once(WB_PATH.'/framework/class.wb.php');
25 1462 DarkViper
//require_once(WB_PATH.'/framework/SecureForm.php');
26 1782 Luisehahne
if(!class_exists('wb', false)){ require(WB_PATH.'/framework/class.wb.php'); }
27 1796 Luisehahne
if(!class_exists('admin', false)){ require(WB_PATH.'/framework/class.admin.php'); }
28 1420 Luisehahne
29
class frontend extends wb {
30
	// defaults
31
	public $default_link,$default_page_id;
32 1431 Luisehahne
	// when multiple blocks are used, show home page blocks on
33 1420 Luisehahne
	// pages where no content is defined (search, login, ...)
34
	public $default_block_content=true;
35
36
	// page details
37
	// page database row
38
	public $page;
39 1431 Luisehahne
	public $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$position,$visibility;
40 1685 darkviper
	public $page_description,$page_keywords,$page_link, $page_icon, $menu_icon_0, $menu_icon_1, $tooltip;
41 1420 Luisehahne
	public $page_trail=array();
42 1685 darkviper
43 1420 Luisehahne
	public $page_access_denied;
44
	public $page_no_active_sections;
45 1702 Luisehahne
46 1420 Luisehahne
	// website settings
47
	public $website_title,$website_description,$website_keywords,$website_header,$website_footer;
48
49
	// ugly database stuff
50
	public $extra_where_sql, $sql_where_language;
51 1702 Luisehahne
52 1782 Luisehahne
// do not chnage if working in frontend account
53
    public $FrontendLanguage;
54
55
	public function __construct($value=true) {
56 1420 Luisehahne
		parent::__construct(SecureForm::FRONTEND);
57 1782 Luisehahne
        $this->FrontendLanguage = isset($value) ? $value : true;
58 1420 Luisehahne
	}
59
60 1782 Luisehahne
    public function ChangeFrontendLanguage( $value=true ) {
61
        $this->FrontendLanguage=$value;
62
    }
63
64 1420 Luisehahne
	public function page_select() {
65 1782 Luisehahne
		global $database, $page_id,$no_intro;
66
/*
67
		// set by user statusflag and maintance enabled select in options
68
		// if maintance flag is set registered user can see normal pages
69
		// otherwise show show maintance message
70
71
		if($maintance == true)
72
		{
73
			$this->print_under_construction();
74
			return false;
75
		}
76
*/
77
78
/**
79
 * Store installed languages in SESSION
80
 */
81
82
        if( $this->get_session('session_started') ) {
83
            $_SESSION['USED_LANGUAGES'] = $this->GetLanguagesInUsed();
84
        }
85
86
		$maintance = ( defined('SYSTEM_LOCKED') && (SYSTEM_LOCKED==true) ? true : false );
87 1783 Luisehahne
88
		if( ($maintance==true) || $this->get_session('USER_ID')!= 1 )
89
		{
90
       	//  check for show maintenance screen and terminate if needed
91
    		$this->ShowMaintainScreen('locked');
92
        }
93 1420 Luisehahne
		// We have no page id and are supposed to show the intro page
94 1782 Luisehahne
		if((INTRO_PAGE && ($maintance != true) && !isset($no_intro)) && (!isset($page_id) || !is_numeric($page_id)))
95
		{
96 1420 Luisehahne
			// Since we have no page id check if we should go to intro page or default page
97
			// Get intro page content
98 1782 Luisehahne
			$sIntroFilename = PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
99
			if(file_exists(WB_PATH.$sIntroFilename)) {
100
                // send intro.php as header to allow parsing of php statements
101
				header("Location: ".WB_URL.$sIntroFilename."");
102
				exit();
103 1420 Luisehahne
			}
104
		}
105 1782 Luisehahne
106 1420 Luisehahne
		// Check if we should add page language sql code
107
		if(PAGE_LANGUAGES) {
108 1486 DarkViper
			$this->sql_where_language = ' AND `language`=\''.LANGUAGE.'\'';
109 1420 Luisehahne
		}
110
		// Get default page
111
		// Check for a page id
112
		$table_p = TABLE_PREFIX.'pages';
113
		$table_s = TABLE_PREFIX.'sections';
114
		$now = time();
115 1486 DarkViper
		$sql  = 'SELECT `p`.`page_id`, `link` ';
116
		$sql .= 'FROM `'.$table_p.'` AS `p` INNER JOIN `'.$table_s.'` USING(`page_id`) ';
117
		$sql .= 'WHERE `parent`=0 AND `visibility`=\'public\' ';
118
		$sql .=     'AND (('.$now.'>=`publ_start` OR `publ_start`=0) ';
119
		$sql .=     'AND ('.$now.'<=`publ_end` OR `publ_end`=0)) ';
120
		if(trim($this->sql_where_language) != '') {
121
			$sql .= trim($this->sql_where_language).' ';
122
		}
123
		$sql .= 'ORDER BY `p`.`position` ASC';
124 1782 Luisehahne
		if($get_default = $database->query($sql)) {
125
126
    		$default_num_rows = $get_default->numRows();
127
    		if(!isset($page_id) OR !is_numeric($page_id)){
128
    			// Go to or show default page
129
    			if($default_num_rows > 0) {
130
    				$fetch_default = $get_default->fetchRow(MYSQL_ASSOC);
131
    				$this->default_link = $fetch_default['link'];
132
    				$this->default_page_id = $fetch_default['page_id'];
133
    				// Check if we should redirect or include page inline
134
    				if(HOMEPAGE_REDIRECTION) {
135
    					// Redirect to page
136
    //					header("Location: ".$this->page_link($this->default_link));
137
    //					exit();
138
    					$this->send_header($this->page_link($this->default_link));
139
    				} else {
140
    					// Include page inline
141
    					$this->page_id = $this->default_page_id;
142
    				}
143
    			} else {
144
    		   		// No pages have been added, so print under construction page
145
    //				if(trim($this->sql_where_language) == '') {
146
    //					$this->ShowMaintainScreen('new');
147
    //    				exit();
148
    //				}
149
    				$this->ShowMaintainScreen('new');
150
    //				$this->print_under_construction();
151
    				exit();
152
    			}
153
    		} else {
154
    			$this->page_id=$page_id;
155
    		}
156
    		// Get default page link
157
    		if(!isset($fetch_default)) {
158
    		  	$fetch_default = $get_default->fetchRow(MYSQL_ASSOC);
159
    	 		$this->default_link = $fetch_default['link'];
160
    			$this->default_page_id = $fetch_default['page_id'];
161
    		}
162
    		return true;
163
164 1420 Luisehahne
		} else {
165 1782 Luisehahne
			$this->ShowMaintainScreen('new');
166
			exit();
167
    	}
168
169 1420 Luisehahne
	}
170
171
	public function get_page_details() {
172
		global $database;
173
	    if($this->page_id != 0) {
174
			// Query page details
175 1486 DarkViper
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
176
			$get_page = $database->query($sql);
177 1420 Luisehahne
			// 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 1782 Luisehahne
			$this->page = $get_page->fetchRow(MYSQL_ASSOC);
184
185
		//  Check if the page language is also the selected language. If not, send headers again.
186
			if (($this->page['language'] != LANGUAGE) && $this->FrontendLanguage )
187
            {
188
            //  check if there is an query-string
189
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
190 1420 Luisehahne
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
191
				} else {
192
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
193
				}
194
				exit();
195
			}
196 1782 Luisehahne
197 1420 Luisehahne
			// Begin code to set details as either variables of constants
198
			// Page ID
199
			if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
200
			// Page Title
201
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
202
			$this->page_title=PAGE_TITLE;
203
			// Menu Title
204
			$menu_title = $this->page['menu_title'];
205
			if($menu_title != '') {
206
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
207
			} else {
208
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
209
			}
210
			$this->menu_title = MENU_TITLE;
211 1685 darkviper
			$this->page_icon = $this->page['page_icon'];
212
			$this->menu_icon_0 = $this->page['menu_icon_0'];
213
			$this->menu_icon_1 = $this->page['menu_icon_1'];
214
			$this->tooltip = $this->page['tooltip'];
215 1420 Luisehahne
			// Page parent
216
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
217
			$this->parent=$this->page['parent'];
218
			// Page root parent
219
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
220
			$this->root_parent=$this->page['root_parent'];
221
			// Page level
222
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
223
			$this->level=$this->page['level'];
224 1431 Luisehahne
			// Page position
225
			$this->level=$this->page['position'];
226 1420 Luisehahne
			// Page visibility
227
			if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
228
			$this->visibility=$this->page['visibility'];
229
			// Page trail
230
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
231
				$this->page_trail[$pid]=$pid;
232
			}
233
			// Page description
234
			$this->page_description=$this->page['description'];
235
			if($this->page_description != '') {
236
				define('PAGE_DESCRIPTION', $this->page_description);
237
			} else {
238
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
239
			}
240
			// Page keywords
241
			$this->page_keywords=$this->page['keywords'];
242
			// Page link
243 1728 Luisehahne
244
            $bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
245
246 1420 Luisehahne
			$this->link=$this->page_link($this->page['link']);
247 1728 Luisehahne
248 1598 Luisehahne
			$_SESSION['PAGE_ID'] = $this->page_id;
249 1728 Luisehahne
250 1702 Luisehahne
			$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
251 1728 Luisehahne
            $_SESSION['HTTP_REFERER'] = !$this->is_authenticated() ? $this->link : $_SESSION['HTTP_REFERER'];
252 1420 Luisehahne
253
		// End code to set details as either variables of constants
254
		}
255
256
		// Figure out what template to use
257
		if(!defined('TEMPLATE')) {
258
			if(isset($this->page['template']) AND $this->page['template'] != '') {
259
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
260
					define('TEMPLATE', $this->page['template']);
261
				} else {
262
					define('TEMPLATE', DEFAULT_TEMPLATE);
263
				}
264
			} else {
265
				define('TEMPLATE', DEFAULT_TEMPLATE);
266
			}
267
		}
268
		// Set the template dir
269
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
270
271
		// Check if user is allowed to view this page
272
		if($this->page && $this->page_is_visible($this->page) == false) {
273
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
274
				// User isnt allowed on this page so tell them
275
				$this->page_access_denied=true;
276
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
277
				// Check if the user is authenticated
278
				if($this->is_authenticated() == false) {
279
					// User needs to login first
280
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
281
					exit(0);
282
				} else {
283
					// User isnt allowed on this page so tell them
284
					$this->page_access_denied=true;
285
				}
286
			}
287
		}
288
		// check if there is at least one active section
289
		if($this->page && $this->page_is_active($this->page) == false) {
290
			$this->page_no_active_sections=true;
291
		}
292
	}
293
294
	public function get_website_settings()
295
    {
296
		global $database;
297
298
		// set visibility SQL code
299
		// never show no-vis, hidden or deleted pages
300 1486 DarkViper
		$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
301 1420 Luisehahne
		// Set extra private sql code
302
		if($this->is_authenticated()==false) {
303
			// if user is not authenticated, don't show private pages either
304 1486 DarkViper
			$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
305 1420 Luisehahne
			// and 'registered' without frontend login doesn't make much sense!
306
			if (FRONTEND_LOGIN==false) {
307 1486 DarkViper
				$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
308 1420 Luisehahne
			}
309
		}
310
		$this->extra_where_sql .= $this->sql_where_language;
311
312
		// Work-out if any possible in-line search boxes should be shown
313
		if(SEARCH == 'public') {
314
			define('SHOW_SEARCH', true);
315
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
316
			define('SHOW_SEARCH', true);
317
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
318
			define('SHOW_SEARCH', true);
319
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
320 1702 Luisehahne
			define('SHOW_SEARCH', true);
321 1420 Luisehahne
		} else {
322
			define('SHOW_SEARCH', false);
323
		}
324
		// Work-out if menu should be shown
325
		if(!defined('SHOW_MENU')) {
326
			define('SHOW_MENU', true);
327
		}
328
		// Work-out if login menu constants should be set
329
		if(FRONTEND_LOGIN) {
330
			// Set login menu constants
331
			define('LOGIN_URL', WB_URL.'/account/login.php');
332
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
333
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
334
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
335
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
336
		}
337
	}
338
339
/*
340
 * replace all "[wblink{page_id}]" with real links
341
 * @param string &$content : reference to global $content
342
 * @return void
343
 * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
344
 */
345 1702 Luisehahne
     public function preprocess(&$content)
346
     {
347
    //   do nothing
348
     }
349 1420 Luisehahne
350
	public function menu() {
351
		global $wb;
352
	   if (!isset($wb->menu_number)) {
353
	   	$wb->menu_number = 1;
354
	   }
355
	   if (!isset($wb->menu_start_level)) {
356
	   	$wb->menu_start_level = 0;
357
	   }
358
	   if (!isset($wb->menu_recurse)) {
359
	   	$wb->menu_recurse = -1;
360
	   }
361
	   if (!isset($wb->menu_collapse)) {
362
	   	$wb->menu_collapse = true;
363
	   }
364
	   if (!isset($wb->menu_item_template)) {
365
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
366
	   }
367
	   if (!isset($wb->menu_item_footer)) {
368
	   	$wb->menu_item_footer = '</li>';
369
	   }
370
	   if (!isset($wb->menu_header)) {
371
	   	$wb->menu_header = '<ul>';
372
	   }
373
	   if (!isset($wb->menu_footer)) {
374
	   	$wb->menu_footer = '</ul>';
375
	   }
376
	   if (!isset($wb->menu_default_class)) {
377
	   	$wb->menu_default_class = ' class="menu_default"';
378
	   }
379
	   if (!isset($wb->menu_current_class)) {
380
	   	$wb->menu_current_class = ' class="menu_current"';
381
	   }
382
	   if (!isset($wb->menu_parent)) {
383
	   	$wb->menu_parent = 0;
384
	   }
385
	   $wb->show_menu();
386
	}
387 1702 Luisehahne
388 1420 Luisehahne
	public function show_menu() {
389
		global $database;
390
		if ($this->menu_start_level>0) {
391
			$key_array=array_keys($this->page_trail);
392
			if (isset($key_array[$this->menu_start_level-1])) {
393
				$real_start=$key_array[$this->menu_start_level-1];
394
				$this->menu_parent=$real_start;
395
				$this->menu_start_level=0;
396
			} else {
397
				return;
398
			}
399
		}
400
		if ($this->menu_recurse==0)
401
	       return;
402
		// Check if we should add menu number check to query
403
		if($this->menu_parent == 0) {
404 1486 DarkViper
			$menu_number = '`menu`='.intval($this->menu_number);
405 1420 Luisehahne
		} else {
406
			$menu_number = '1';
407
		}
408
		// Query pages
409 1486 DarkViper
		$sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`level`,';
410
		$sql .=        '`visibility`,viewing_groups,viewing_users ';
411
		$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
412
		$sql .= 'WHERE `parent`='.(int)$this->menu_parent.' AND '.$menu_number.' AND '.$this->extra_where_sql.' ';
413
		$sql .= 'ORDER BY `position` ASC';
414
		$query_menu = $database->query($sql);
415 1420 Luisehahne
		// Check if there are any pages to show
416
		if($query_menu->numRows() > 0) {
417
			// Print menu header
418
			echo "\n".$this->menu_header;
419
			// Loop through pages
420
			while($page = $query_menu->fetchRow()) {
421
				// check whether to show this menu-link
422
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
423
					continue; // no active sections
424
				}
425
				if($this->page_is_visible($page)==false) {
426
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
427
						continue;
428
				}
429
				// Create vars
430
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
431
				// Work-out class
432
				if($page['page_id'] == PAGE_ID) {
433
					$class = $this->menu_current_class;
434
				} else {
435
					$class = $this->menu_default_class;
436
				}
437
				// Check if link is same as first page link, and if so change to WB URL
438
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
439
					$link = WB_URL;
440
				} else {
441
					$link = $this->page_link($page['link']);
442
				}
443
				// Create values
444
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
445
				// Replace vars with value and print
446
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
447
				// Generate sub-menu
448
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
449
					$this->menu_recurse--;
450
					$this->menu_parent=$page['page_id'];
451
					$this->show_menu();
452
				}
453
				echo "\n".$this->menu_item_footer;
454
			}
455
			// Print menu footer
456
			echo "\n".$this->menu_footer;
457
		}
458
	}
459
460
461
	// Function to show the "Under Construction" page
462
	public function print_under_construction() {
463 1782 Luisehahne
		$this->ShowMaintainScreen('new');
464
		exit();
465 1420 Luisehahne
	}
466
}