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