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 1796 2012-10-24 14:12:02Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
|
14
|
* @lastmodified $Date: 2012-10-24 16:12:02 +0200 (Wed, 24 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
|
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_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 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
|
$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
|
// 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
|
// Page position
|
225
|
$this->level=$this->page['position'];
|
226
|
// 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
|
|
244
|
$bCanRedirect = ($this->visibility == 'registered' || $this->visibility == 'privat');
|
245
|
|
246
|
$this->link=$this->page_link($this->page['link']);
|
247
|
|
248
|
$_SESSION['PAGE_ID'] = $this->page_id;
|
249
|
|
250
|
$_SESSION['HTTP_REFERER'] = $bCanRedirect != true ? $this->link : WB_URL;
|
251
|
$_SESSION['HTTP_REFERER'] = !$this->is_authenticated() ? $this->link : $_SESSION['HTTP_REFERER'];
|
252
|
|
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
|
$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
|
301
|
// Set extra private sql code
|
302
|
if($this->is_authenticated()==false) {
|
303
|
// if user is not authenticated, don't show private pages either
|
304
|
$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
|
305
|
// and 'registered' without frontend login doesn't make much sense!
|
306
|
if (FRONTEND_LOGIN==false) {
|
307
|
$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
|
308
|
}
|
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
|
define('SHOW_SEARCH', true);
|
321
|
} 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
|
public function preprocess(&$content)
|
346
|
{
|
347
|
// do nothing
|
348
|
}
|
349
|
|
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
|
|
388
|
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
|
$menu_number = '`menu`='.intval($this->menu_number);
|
405
|
} else {
|
406
|
$menu_number = '1';
|
407
|
}
|
408
|
// Query pages
|
409
|
$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
|
// 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
|
$this->ShowMaintainScreen('new');
|
464
|
exit();
|
465
|
}
|
466
|
}
|
467
|
|