Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         framework
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id: class.frontend.php 1277 2010-01-28 05:18:18Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
15
 * @lastmodified    $Date: 2010-01-28 06:18:18 +0100 (Thu, 28 Jan 2010) $
16
 *
17
*/
18

    
19
if(!defined('WB_PATH')) {
20
	header('Location: ../index.php');
21
	exit(0);
22
}
23

    
24

    
25
require_once(WB_PATH.'/framework/class.wb.php');
26

    
27
class frontend extends wb {
28
	// defaults
29
	var $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
	var $default_block_content=true;
33

    
34
	// page details
35
	// page database row
36
	var $page;
37
	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
38
	var $page_description,$page_keywords,$page_link;
39
	var $page_trail=array();
40
	
41
	var $page_access_denied;
42
	var $page_no_active_sections;
43
	
44
	// website settings
45
	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
46

    
47
	// ugly database stuff
48
	var $extra_where_sql, $sql_where_language;
49

    
50
	function page_select() {
51
		global $page_id,$no_intro;
52
		global $database;
53
		// We have no page id and are supposed to show the intro page
54
		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
55
			// Since we have no page id check if we should go to intro page or default page
56
			// Get intro page content
57
			$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
58
			if(file_exists($filename)) {
59
				$handle = @fopen($filename, "r");
60
				$content = @fread($handle, filesize($filename));
61
				@fclose($handle);
62
				$this->preprocess($content);
63
				header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION."");   // send intro.php as header to allow parsing of php statements
64
				echo ($content);
65
				return false;
66
			}
67
		}
68
		// Check if we should add page language sql code
69
		if(PAGE_LANGUAGES) {
70
			$this->sql_where_language = " AND language = '".LANGUAGE."'";
71
		}
72
		// Get default page
73
		// Check for a page id
74
		$table_p = TABLE_PREFIX.'pages';
75
		$table_s = TABLE_PREFIX.'sections';
76
		$now = time();
77
		$query_default = "
78
			SELECT `p`.`page_id`, `link`
79
			FROM `$table_p` AS `p` INNER JOIN `$table_s` USING(`page_id`)
80
			WHERE `parent` = '0' AND `visibility` = 'public'
81
			AND (($now>=`publ_start` OR `publ_start`=0) AND ($now<=`publ_end` OR `publ_end`=0))
82
			$this->sql_where_language
83
			ORDER BY `p`.`position` ASC LIMIT 1";
84
		$get_default = $database->query($query_default);
85
		$default_num_rows = $get_default->numRows();
86
		if(!isset($page_id) OR !is_numeric($page_id)){
87
			// Go to or show default page
88
			if($default_num_rows > 0) {
89
				$fetch_default = $get_default->fetchRow();
90
				$this->default_link = $fetch_default['link'];
91
				$this->default_page_id = $fetch_default['page_id'];
92
				// Check if we should redirect or include page inline
93
				if(HOMEPAGE_REDIRECTION) {
94
					// Redirect to page
95
					header("Location: ".$this->page_link($this->default_link));
96
					exit();
97
				} else {
98
					// Include page inline
99
					$this->page_id = $this->default_page_id;
100
				}
101
			} else {
102
		   		// No pages have been added, so print under construction page
103
				$this->print_under_construction();
104
				exit();
105
			}
106
		} else {
107
			$this->page_id=$page_id;
108
		}
109
		// Get default page link
110
		if(!isset($fetch_default)) {
111
		  	$fetch_default = $get_default->fetchRow();
112
	 		$this->default_link = $fetch_default['link'];
113
			$this->default_page_id = $fetch_default['page_id'];
114
		}
115
		return true;
116
	}
117

    
118
	function get_page_details() {
119
		global $database;
120
	    if($this->page_id != 0) {
121
			// Query page details
122
			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
123
			$get_page = $database->query($query_page);
124
			// Make sure page was found in database
125
			if($get_page->numRows() == 0) {
126
				// Print page not found message
127
				exit("Page not found");
128
			}
129
			// Fetch page details
130
			$this->page = $get_page->fetchRow();
131
			// Check if the page language is also the selected language. If not, send headers again.
132
			if ($this->page['language']!=LANGUAGE) {
133
				if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
134
					header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
135
				} else {
136
					header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
137
				}
138
				exit();
139
			}
140
			// Begin code to set details as either variables of constants
141
			// Page ID
142
			if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
143
			// Page Title
144
			if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
145
			$this->page_title=PAGE_TITLE;
146
			// Menu Title
147
			$menu_title = $this->page['menu_title'];
148
			if($menu_title != '') {
149
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
150
			} else {
151
				if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
152
			}
153
			$this->menu_title = MENU_TITLE;
154
			// Page parent
155
			if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
156
			$this->parent=$this->page['parent'];
157
			// Page root parent
158
			if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
159
			$this->root_parent=$this->page['root_parent'];
160
			// Page level
161
			if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
162
			$this->level=$this->page['level'];
163
			// Page visibility
164
			if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
165
			$this->visibility=$this->page['visibility'];
166
			// Page trail
167
			foreach(explode(',', $this->page['page_trail']) AS $pid) {
168
				$this->page_trail[$pid]=$pid;
169
			}
170
			// Page description
171
			$this->page_description=$this->page['description'];
172
			if($this->page_description != '') {
173
				define('PAGE_DESCRIPTION', $this->page_description);
174
			} else {
175
				define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
176
			}
177
			// Page keywords
178
			$this->page_keywords=$this->page['keywords'];
179
			// Page link
180
			$this->link=$this->page_link($this->page['link']);
181

    
182
		// End code to set details as either variables of constants
183
		}
184

    
185
		// Figure out what template to use
186
		if(!defined('TEMPLATE')) {
187
			if(isset($this->page['template']) AND $this->page['template'] != '') {
188
				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
189
					define('TEMPLATE', $this->page['template']);
190
				} else {
191
					define('TEMPLATE', DEFAULT_TEMPLATE);
192
				}
193
			} else {
194
				define('TEMPLATE', DEFAULT_TEMPLATE);
195
			}
196
		}
197
		// Set the template dir
198
		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
199

    
200
		// Check if user is allowed to view this page
201
		if($this->page && $this->page_is_visible($this->page) == false) {
202
			if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
203
				// User isnt allowed on this page so tell them
204
				$this->page_access_denied=true;
205
			} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
206
				// Check if the user is authenticated
207
				if($this->is_authenticated() == false) {
208
					// User needs to login first
209
					header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
210
					exit(0);
211
				} else {
212
					// User isnt allowed on this page so tell them
213
					$this->page_access_denied=true;
214
				}
215
				
216
			}
217
		}
218
		// check if there is at least one active section
219
		if($this->page && $this->page_is_active($this->page) == false) {
220
			$this->page_no_active_sections=true;
221
		}
222
	}
223

    
224
	function get_website_settings() {
225
		global $database;
226

    
227
		// set visibility SQL code
228
		// never show no-vis, hidden or deleted pages
229
		$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
230
		// Set extra private sql code
231
		if($this->is_authenticated()==false) {
232
			// if user is not authenticated, don't show private pages either
233
			$this->extra_where_sql .= " AND visibility != 'private'";
234
			// and 'registered' without frontend login doesn't make much sense!
235
			if (FRONTEND_LOGIN==false) {
236
				$this->extra_where_sql .= " AND visibility != 'registered'";
237
			}
238
		}
239
		$this->extra_where_sql .= $this->sql_where_language;
240

    
241
		// Work-out if any possible in-line search boxes should be shown
242
		if(SEARCH == 'public') {
243
			define('SHOW_SEARCH', true);
244
		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
245
			define('SHOW_SEARCH', true);
246
		} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
247
			define('SHOW_SEARCH', true);
248
		} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
249
			define('SHOW_SEARCH', true);	
250
		} else {
251
			define('SHOW_SEARCH', false);
252
		}
253
		// Work-out if menu should be shown
254
		if(!defined('SHOW_MENU')) {
255
			define('SHOW_MENU', true);
256
		}
257
		// Work-out if login menu constants should be set
258
		if(FRONTEND_LOGIN) {
259
			// Set login menu constants
260
			define('LOGIN_URL', WB_URL.'/account/login.php');
261
			define('LOGOUT_URL', WB_URL.'/account/logout.php');
262
			define('FORGOT_URL', WB_URL.'/account/forgot.php');
263
			define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
264
			define('SIGNUP_URL', WB_URL.'/account/signup.php');
265
		}
266
	}
267
	
268
	function preprocess(&$content) {
269
		global $database;
270
		// Replace [wblink--PAGE_ID--] with real link
271
		$pattern = '/\[wblink(.+?)\]/s';
272
		preg_match_all($pattern,$content,$ids);
273
		foreach($ids[1] AS $page_id) {
274
			$pattern = '/\[wblink'.$page_id.'\]/s';
275
			// Get page link
276
			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
277
			$fetch_link = $get_link->fetchRow();
278
			$link = $this->page_link($fetch_link['link']);
279
			$content = preg_replace($pattern,$link,$content);
280
		}
281
	}
282
	
283
	function menu() {
284
		global $wb;
285
	   if (!isset($wb->menu_number)) {
286
	   	$wb->menu_number = 1;
287
	   }
288
	   if (!isset($wb->menu_start_level)) {
289
	   	$wb->menu_start_level = 0;
290
	   }
291
	   if (!isset($wb->menu_recurse)) {
292
	   	$wb->menu_recurse = -1;
293
	   }
294
	   if (!isset($wb->menu_collapse)) {
295
	   	$wb->menu_collapse = true;
296
	   }
297
	   if (!isset($wb->menu_item_template)) {
298
	   	$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
299
	   }
300
	   if (!isset($wb->menu_item_footer)) {
301
	   	$wb->menu_item_footer = '</li>';
302
	   }
303
	   if (!isset($wb->menu_header)) {
304
	   	$wb->menu_header = '<ul>';
305
	   }
306
	   if (!isset($wb->menu_footer)) {
307
	   	$wb->menu_footer = '</ul>';
308
	   }
309
	   if (!isset($wb->menu_default_class)) {
310
	   	$wb->menu_default_class = ' class="menu_default"';
311
	   }
312
	   if (!isset($wb->menu_current_class)) {
313
	   	$wb->menu_current_class = ' class="menu_current"';
314
	   }
315
	   if (!isset($wb->menu_parent)) {
316
	   	$wb->menu_parent = 0;
317
	   }
318
	   $wb->show_menu();
319
	}
320
	
321
	function show_menu() {
322
		global $database;
323
		if ($this->menu_start_level>0) {
324
			$key_array=array_keys($this->page_trail);
325
			if (isset($key_array[$this->menu_start_level-1])) {
326
				$real_start=$key_array[$this->menu_start_level-1];
327
				$this->menu_parent=$real_start;
328
				$this->menu_start_level=0;
329
			} else {
330
				return;
331
			}
332
		}
333
		if ($this->menu_recurse==0)
334
	       return;
335
		// Check if we should add menu number check to query
336
		if($this->menu_parent == 0) {
337
			$menu_number = "menu = '$this->menu_number'";
338
		} else {
339
			$menu_number = '1';
340
		}
341
		// Query pages
342
		$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility,viewing_groups,viewing_users FROM ".TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC");
343
		// Check if there are any pages to show
344
		if($query_menu->numRows() > 0) {
345
			// Print menu header
346
			echo "\n".$this->menu_header;
347
			// Loop through pages
348
			while($page = $query_menu->fetchRow()) {
349
				// check whether to show this menu-link
350
				if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
351
					continue; // no active sections
352
				}
353
				if($this->page_is_visible($page)==false) {
354
					if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
355
						continue;
356
				}
357
				// Create vars
358
				$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
359
				// Work-out class
360
				if($page['page_id'] == PAGE_ID) {
361
					$class = $this->menu_current_class;
362
				} else {
363
					$class = $this->menu_default_class;
364
				}
365
				// Check if link is same as first page link, and if so change to WB URL
366
				if($page['link'] == $this->default_link AND !INTRO_PAGE) {
367
					$link = WB_URL;
368
				} else {
369
					$link = $this->page_link($page['link']);
370
				}
371
				// Create values
372
				$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
373
				// Replace vars with value and print
374
				echo "\n".str_replace($vars, $values, $this->menu_item_template);
375
				// Generate sub-menu
376
				if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
377
					$this->menu_recurse--;
378
					$this->menu_parent=$page['page_id'];
379
					$this->show_menu();
380
				}
381
				echo "\n".$this->menu_item_footer;
382
			}
383
			// Print menu footer
384
			echo "\n".$this->menu_footer;
385
		}
386
	}
387

    
388

    
389
	// Function to show the "Under Construction" page
390
	function print_under_construction() {
391
		global $MESSAGE;
392
		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
393
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
394
		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>
395
		<style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.ADMIN_URL.'/interface/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; }
396
		h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
397
}--></style></head><body>
398
		<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
399
		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
400
	}
401
}
402

    
403
?>
(5-5/15)