Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         framework
6
 * @author          Ryan Djurovich (2004-2009), 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 1840 2012-12-23 15:35:25Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
14
 * @lastmodified    $Date: 2012-12-23 16:35:25 +0100 (Sun, 23 Dec 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
if(!class_exists('wb', false)){ require(WB_PATH.'/framework/class.wb.php'); }
27
if(!class_exists('admin', false)){ require(WB_PATH.'/framework/class.admin.php'); }
28

    
29
class frontend extends wb {
30
	// defaults
31
	public $default_link,$default_page_id;
32
	// when multiple blocks are used, show home page blocks on
33
	// 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
	public $page_id,$page_code,$page_title,$menu_title,$parent,$root_parent,$level,$position,$visibility;
40
	public $page_description,$page_keywords,$page_link, $page_icon, $menu_icon_0, $menu_icon_1, $tooltip;
41
	public $page_trail=array();
42

    
43
	public $page_access_denied;
44
	public $page_no_active_sections;
45

    
46
	// 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

    
52
// do not chnage if working in frontend account
53
    public $FrontendLanguage;
54

    
55
	public function __construct($value=true) {
56
		parent::__construct(SecureForm::FRONTEND);
57
        $this->FrontendLanguage = isset($value) ? $value : true;
58
	}
59

    
60
    public function ChangeFrontendLanguage( $value=true ) {
61
        $this->FrontendLanguage=$value;
62
    }
63

    
64
	public function page_select() {
65
		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

    
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
		// We have no page id and are supposed to show the intro page
94
		if((INTRO_PAGE && ($maintance != true) && !isset($no_intro)) && (!isset($page_id) || !is_numeric($page_id)))
95
		{
96
			// Since we have no page id check if we should go to intro page or default page
97
			// Get intro page content
98
			$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
			}
104
		}
105

    
106
		// Check if we should add page language sql code
107
		if(PAGE_LANGUAGES) {
108
			$this->sql_where_language = ' AND `language`=\''.LANGUAGE.'\'';
109
		}
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
		$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
		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
		} else {
165
			$this->ShowMaintainScreen('new');
166
			exit();
167
    	}
168

    
169
	}
170

    
171
	public function get_page_details() {
172
		global $database;
173
	    if($this->page_id != 0) {
174
			// Query page details
175
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
176
			$get_page = $database->query($sql);
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(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
					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

    
197
			// 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 Code
201
			if(!defined('PAGE_CODE')) {define('PAGE_CODE', $this->page['page_code']);}
202
			$this->page_code = PAGE_CODE;
203
			// Page Title
204
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
205
			$this->page_title=PAGE_TITLE;
206
			// Menu Title
207
			$menu_title = $this->page['menu_title'];
208
			if($menu_title != '') {
209
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
210
			} else {
211
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
212
			}
213
			$this->menu_title = MENU_TITLE;
214
			$this->page_icon = $this->page['page_icon'];
215
			$this->menu_icon_0 = $this->page['menu_icon_0'];
216
			$this->menu_icon_1 = $this->page['menu_icon_1'];
217
			$this->tooltip = $this->page['tooltip'];
218
			// Page parent
219
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
220
			$this->parent=$this->page['parent'];
221
			// Page root parent
222
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
223
			$this->root_parent=$this->page['root_parent'];
224
			// Page level
225
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
226
			$this->level=$this->page['level'];
227
			// Page position
228
			$this->level=$this->page['position'];
229
			// Page visibility
230
			if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
231
			$this->visibility=$this->page['visibility'];
232
			// Page trail
233
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
234
				$this->page_trail[$pid]=$pid;
235
			}
236
			// Page description
237
			$this->page_description=$this->page['description'];
238
			if($this->page_description != '') {
239
				define('PAGE_DESCRIPTION', $this->page_description);
240
			} else {
241
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
242
			}
243
			// Page keywords
244
			$this->page_keywords=$this->page['keywords'];
245
			// Page link
246

    
247
            $bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
248

    
249
			$this->link=$this->page_link($this->page['link']);
250

    
251
			$_SESSION['PAGE_ID'] = $this->page_id;
252

    
253
			$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
254
            $_SESSION['HTTP_REFERER'] = !$this->is_authenticated() ? $this->link : $_SESSION['HTTP_REFERER'];
255

    
256
		// End code to set details as either variables of constants
257
		}
258

    
259
		// Figure out what template to use
260
		if(!defined('TEMPLATE')) {
261
			if(isset($this->page['template']) AND $this->page['template'] != '') {
262
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
263
					define('TEMPLATE', $this->page['template']);
264
				} else {
265
					define('TEMPLATE', DEFAULT_TEMPLATE);
266
				}
267
			} else {
268
				define('TEMPLATE', DEFAULT_TEMPLATE);
269
			}
270
		}
271
		// Set the template dir
272
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
273

    
274
		// Check if user is allowed to view this page
275
		if($this->page && $this->page_is_visible($this->page) == false) {
276
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
277
				// User isnt allowed on this page so tell them
278
				$this->page_access_denied=true;
279
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
280
				// Check if the user is authenticated
281
				if($this->is_authenticated() == false) {
282
					// User needs to login first
283
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
284
					exit(0);
285
				} else {
286
					// User isnt allowed on this page so tell them
287
					$this->page_access_denied=true;
288
				}
289
			}
290
		}
291
		// check if there is at least one active section
292
		if($this->page && $this->page_is_active($this->page) == false) {
293
			$this->page_no_active_sections=true;
294
		}
295
	}
296

    
297
	public function get_website_settings()
298
    {
299
		global $database;
300

    
301
		// set visibility SQL code
302
		// never show no-vis, hidden or deleted pages
303
		$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
304
		// Set extra private sql code
305
		if($this->is_authenticated()==false) {
306
			// if user is not authenticated, don't show private pages either
307
			$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
308
			// and 'registered' without frontend login doesn't make much sense!
309
			if (FRONTEND_LOGIN==false) {
310
				$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
311
			}
312
		}
313
		$this->extra_where_sql .= $this->sql_where_language;
314

    
315
		// Work-out if any possible in-line search boxes should be shown
316
		if(SEARCH == 'public') {
317
			define('SHOW_SEARCH', true);
318
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
319
			define('SHOW_SEARCH', true);
320
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
321
			define('SHOW_SEARCH', true);
322
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
323
			define('SHOW_SEARCH', true);
324
		} else {
325
			define('SHOW_SEARCH', false);
326
		}
327
		// Work-out if menu should be shown
328
		if(!defined('SHOW_MENU')) {
329
			define('SHOW_MENU', true);
330
		}
331
		// Work-out if login menu constants should be set
332
		if(FRONTEND_LOGIN) {
333
			// Set login menu constants
334
			define('LOGIN_URL', WB_URL.'/account/login.php');
335
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
336
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
337
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
338
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
339
		}
340
	}
341

    
342
/*
343
 * replace all "[wblink{page_id}]" with real links
344
 * @param string &$content : reference to global $content
345
 * @return void
346
 * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
347
 */
348
     public function preprocess(&$content)
349
     {
350
    //   do nothing
351
     }
352

    
353
	public function menu() {
354
		global $wb;
355
	   if (!isset($wb->menu_number)) {
356
	   	$wb->menu_number = 1;
357
	   }
358
	   if (!isset($wb->menu_start_level)) {
359
	   	$wb->menu_start_level = 0;
360
	   }
361
	   if (!isset($wb->menu_recurse)) {
362
	   	$wb->menu_recurse = -1;
363
	   }
364
	   if (!isset($wb->menu_collapse)) {
365
	   	$wb->menu_collapse = true;
366
	   }
367
	   if (!isset($wb->menu_item_template)) {
368
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
369
	   }
370
	   if (!isset($wb->menu_item_footer)) {
371
	   	$wb->menu_item_footer = '</li>';
372
	   }
373
	   if (!isset($wb->menu_header)) {
374
	   	$wb->menu_header = '<ul>';
375
	   }
376
	   if (!isset($wb->menu_footer)) {
377
	   	$wb->menu_footer = '</ul>';
378
	   }
379
	   if (!isset($wb->menu_default_class)) {
380
	   	$wb->menu_default_class = ' class="menu_default"';
381
	   }
382
	   if (!isset($wb->menu_current_class)) {
383
	   	$wb->menu_current_class = ' class="menu_current"';
384
	   }
385
	   if (!isset($wb->menu_parent)) {
386
	   	$wb->menu_parent = 0;
387
	   }
388
	   $wb->show_menu();
389
	}
390

    
391
	public function show_menu() {
392
		global $database;
393
		if ($this->menu_start_level>0) {
394
			$key_array=array_keys($this->page_trail);
395
			if (isset($key_array[$this->menu_start_level-1])) {
396
				$real_start=$key_array[$this->menu_start_level-1];
397
				$this->menu_parent=$real_start;
398
				$this->menu_start_level=0;
399
			} else {
400
				return;
401
			}
402
		}
403
		if ($this->menu_recurse==0)
404
	       return;
405
		// Check if we should add menu number check to query
406
		if($this->menu_parent == 0) {
407
			$menu_number = '`menu`='.intval($this->menu_number);
408
		} else {
409
			$menu_number = '1';
410
		}
411
		// Query pages
412
		$sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`level`,';
413
		$sql .=        '`visibility`,viewing_groups,viewing_users ';
414
		$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
415
		$sql .= 'WHERE `parent`='.(int)$this->menu_parent.' AND '.$menu_number.' AND '.$this->extra_where_sql.' ';
416
		$sql .= 'ORDER BY `position` ASC';
417
		$query_menu = $database->query($sql);
418
		// Check if there are any pages to show
419
		if($query_menu->numRows() > 0) {
420
			// Print menu header
421
			echo "\n".$this->menu_header;
422
			// Loop through pages
423
			while($page = $query_menu->fetchRow()) {
424
				// check whether to show this menu-link
425
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
426
					continue; // no active sections
427
				}
428
				if($this->page_is_visible($page)==false) {
429
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
430
						continue;
431
				}
432
				// Create vars
433
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
434
				// Work-out class
435
				if($page['page_id'] == PAGE_ID) {
436
					$class = $this->menu_current_class;
437
				} else {
438
					$class = $this->menu_default_class;
439
				}
440
				// Check if link is same as first page link, and if so change to WB URL
441
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
442
					$link = WB_URL;
443
				} else {
444
					$link = $this->page_link($page['link']);
445
				}
446
				// Create values
447
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
448
				// Replace vars with value and print
449
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
450
				// Generate sub-menu
451
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
452
					$this->menu_recurse--;
453
					$this->menu_parent=$page['page_id'];
454
					$this->show_menu();
455
				}
456
				echo "\n".$this->menu_item_footer;
457
			}
458
			// Print menu footer
459
			echo "\n".$this->menu_footer;
460
		}
461
	}
462

    
463

    
464
	// Function to show the "Under Construction" page
465
	public function print_under_construction() {
466
		$this->ShowMaintainScreen('new');
467
		exit();
468
	}
469
}
470

    
(16-16/28)