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 1782 2012-10-11 12:29:11Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
14
 * @lastmodified    $Date: 2012-10-11 14:29:11 +0200 (Thu, 11 Oct 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

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

    
42
	public $page_access_denied;
43
	public $page_no_active_sections;
44

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

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

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

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

    
63
	public function page_select() {
64
		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
		// We have no page id and are supposed to show the intro page
87
		if((INTRO_PAGE && ($maintance != true) && !isset($no_intro)) && (!isset($page_id) || !is_numeric($page_id)))
88
		{
89
			// Since we have no page id check if we should go to intro page or default page
90
			// Get intro page content
91
			$sIntroFilename = PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
92
			if(file_exists(WB_PATH.$sIntroFilename)) {
93
                // send intro.php as header to allow parsing of php statements
94
				header("Location: ".WB_URL.$sIntroFilename."");
95
				exit();
96
			}
97
		}
98

    
99
		// Check if we should add page language sql code
100
		if(PAGE_LANGUAGES) {
101
			$this->sql_where_language = ' AND `language`=\''.LANGUAGE.'\'';
102
		}
103
		// Get default page
104
		// Check for a page id
105
		$table_p = TABLE_PREFIX.'pages';
106
		$table_s = TABLE_PREFIX.'sections';
107
		$now = time();
108
		$sql  = 'SELECT `p`.`page_id`, `link` ';
109
		$sql .= 'FROM `'.$table_p.'` AS `p` INNER JOIN `'.$table_s.'` USING(`page_id`) ';
110
		$sql .= 'WHERE `parent`=0 AND `visibility`=\'public\' ';
111
		$sql .=     'AND (('.$now.'>=`publ_start` OR `publ_start`=0) ';
112
		$sql .=     'AND ('.$now.'<=`publ_end` OR `publ_end`=0)) ';
113
		if(trim($this->sql_where_language) != '') {
114
			$sql .= trim($this->sql_where_language).' ';
115
		}
116
		$sql .= 'ORDER BY `p`.`position` ASC';
117
		if($get_default = $database->query($sql)) {
118

    
119
    		$default_num_rows = $get_default->numRows();
120
    		if(!isset($page_id) OR !is_numeric($page_id)){
121
    			// Go to or show default page
122
    			if($default_num_rows > 0) {
123
    				$fetch_default = $get_default->fetchRow(MYSQL_ASSOC);
124
    				$this->default_link = $fetch_default['link'];
125
    				$this->default_page_id = $fetch_default['page_id'];
126
    				// Check if we should redirect or include page inline
127
    				if(HOMEPAGE_REDIRECTION) {
128
    					// Redirect to page
129
    //					header("Location: ".$this->page_link($this->default_link));
130
    //					exit();
131
    					$this->send_header($this->page_link($this->default_link));
132
    				} else {
133
    					// Include page inline
134
    					$this->page_id = $this->default_page_id;
135
    				}
136
    			} else {
137
    		   		// No pages have been added, so print under construction page
138
    //				if(trim($this->sql_where_language) == '') {
139
    //					$this->ShowMaintainScreen('new');
140
    //    				exit();
141
    //				}
142
    				$this->ShowMaintainScreen('new');
143
    //				$this->print_under_construction();
144
    				exit();
145
    			}
146
    		} else {
147
    			$this->page_id=$page_id;
148
    		}
149
    		// Get default page link
150
    		if(!isset($fetch_default)) {
151
    		  	$fetch_default = $get_default->fetchRow(MYSQL_ASSOC);
152
    	 		$this->default_link = $fetch_default['link'];
153
    			$this->default_page_id = $fetch_default['page_id'];
154
    		}
155
    		return true;
156

    
157
		} else {
158
			$this->ShowMaintainScreen('new');
159
			exit();
160
    	}
161

    
162
	}
163

    
164
	public function get_page_details() {
165
		global $database;
166
	    if($this->page_id != 0) {
167
			// Query page details
168
			$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
169
			$get_page = $database->query($sql);
170
			// Make sure page was found in database
171
			if($get_page->numRows() == 0) {
172
				// Print page not found message
173
				exit("Page not found");
174
			}
175
			// Fetch page details
176
			$this->page = $get_page->fetchRow(MYSQL_ASSOC);
177

    
178
		//  Check if the page language is also the selected language. If not, send headers again.
179
			if (($this->page['language'] != LANGUAGE) && $this->FrontendLanguage )
180
            {
181
            //  check if there is an query-string
182
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
183
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
184
				} else {
185
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
186
				}
187
				exit();
188
			}
189

    
190
			// Begin code to set details as either variables of constants
191
			// Page ID
192
			if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
193
			// Page Title
194
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
195
			$this->page_title=PAGE_TITLE;
196
			// Menu Title
197
			$menu_title = $this->page['menu_title'];
198
			if($menu_title != '') {
199
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
200
			} else {
201
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
202
			}
203
			$this->menu_title = MENU_TITLE;
204
			$this->page_icon = $this->page['page_icon'];
205
			$this->menu_icon_0 = $this->page['menu_icon_0'];
206
			$this->menu_icon_1 = $this->page['menu_icon_1'];
207
			$this->tooltip = $this->page['tooltip'];
208
			// Page parent
209
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
210
			$this->parent=$this->page['parent'];
211
			// Page root parent
212
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
213
			$this->root_parent=$this->page['root_parent'];
214
			// Page level
215
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
216
			$this->level=$this->page['level'];
217
			// Page position
218
			$this->level=$this->page['position'];
219
			// Page visibility
220
			if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
221
			$this->visibility=$this->page['visibility'];
222
			// Page trail
223
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
224
				$this->page_trail[$pid]=$pid;
225
			}
226
			// Page description
227
			$this->page_description=$this->page['description'];
228
			if($this->page_description != '') {
229
				define('PAGE_DESCRIPTION', $this->page_description);
230
			} else {
231
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
232
			}
233
			// Page keywords
234
			$this->page_keywords=$this->page['keywords'];
235
			// Page link
236

    
237
            $bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
238

    
239
			$this->link=$this->page_link($this->page['link']);
240

    
241
			$_SESSION['PAGE_ID'] = $this->page_id;
242

    
243
			$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
244
            $_SESSION['HTTP_REFERER'] = !$this->is_authenticated() ? $this->link : $_SESSION['HTTP_REFERER'];
245

    
246
		// End code to set details as either variables of constants
247
		}
248

    
249
		// Figure out what template to use
250
		if(!defined('TEMPLATE')) {
251
			if(isset($this->page['template']) AND $this->page['template'] != '') {
252
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
253
					define('TEMPLATE', $this->page['template']);
254
				} else {
255
					define('TEMPLATE', DEFAULT_TEMPLATE);
256
				}
257
			} else {
258
				define('TEMPLATE', DEFAULT_TEMPLATE);
259
			}
260
		}
261
		// Set the template dir
262
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
263

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

    
287
	public function get_website_settings()
288
    {
289
		global $database;
290

    
291
		// set visibility SQL code
292
		// never show no-vis, hidden or deleted pages
293
		$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
294
		// Set extra private sql code
295
		if($this->is_authenticated()==false) {
296
			// if user is not authenticated, don't show private pages either
297
			$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
298
			// and 'registered' without frontend login doesn't make much sense!
299
			if (FRONTEND_LOGIN==false) {
300
				$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
301
			}
302
		}
303
		$this->extra_where_sql .= $this->sql_where_language;
304

    
305
		// Work-out if any possible in-line search boxes should be shown
306
		if(SEARCH == 'public') {
307
			define('SHOW_SEARCH', true);
308
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
309
			define('SHOW_SEARCH', true);
310
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
311
			define('SHOW_SEARCH', true);
312
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
313
			define('SHOW_SEARCH', true);
314
		} else {
315
			define('SHOW_SEARCH', false);
316
		}
317
		// Work-out if menu should be shown
318
		if(!defined('SHOW_MENU')) {
319
			define('SHOW_MENU', true);
320
		}
321
		// Work-out if login menu constants should be set
322
		if(FRONTEND_LOGIN) {
323
			// Set login menu constants
324
			define('LOGIN_URL', WB_URL.'/account/login.php');
325
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
326
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
327
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
328
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
329
		}
330
	}
331

    
332
/*
333
 * replace all "[wblink{page_id}]" with real links
334
 * @param string &$content : reference to global $content
335
 * @return void
336
 * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
337
 */
338
     public function preprocess(&$content)
339
     {
340
    //   do nothing
341
     }
342

    
343
	public function menu() {
344
		global $wb;
345
	   if (!isset($wb->menu_number)) {
346
	   	$wb->menu_number = 1;
347
	   }
348
	   if (!isset($wb->menu_start_level)) {
349
	   	$wb->menu_start_level = 0;
350
	   }
351
	   if (!isset($wb->menu_recurse)) {
352
	   	$wb->menu_recurse = -1;
353
	   }
354
	   if (!isset($wb->menu_collapse)) {
355
	   	$wb->menu_collapse = true;
356
	   }
357
	   if (!isset($wb->menu_item_template)) {
358
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
359
	   }
360
	   if (!isset($wb->menu_item_footer)) {
361
	   	$wb->menu_item_footer = '</li>';
362
	   }
363
	   if (!isset($wb->menu_header)) {
364
	   	$wb->menu_header = '<ul>';
365
	   }
366
	   if (!isset($wb->menu_footer)) {
367
	   	$wb->menu_footer = '</ul>';
368
	   }
369
	   if (!isset($wb->menu_default_class)) {
370
	   	$wb->menu_default_class = ' class="menu_default"';
371
	   }
372
	   if (!isset($wb->menu_current_class)) {
373
	   	$wb->menu_current_class = ' class="menu_current"';
374
	   }
375
	   if (!isset($wb->menu_parent)) {
376
	   	$wb->menu_parent = 0;
377
	   }
378
	   $wb->show_menu();
379
	}
380

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

    
453

    
454
	// Function to show the "Under Construction" page
455
	public function print_under_construction() {
456
		$this->ShowMaintainScreen('new');
457
		exit();
458
	}
459
}
460

    
(13-13/25)