1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category frontend
|
5
|
* @package framework
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, 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 5.2.2 and higher
|
13
|
* @version $Id: class.frontend.php 1496 2011-08-11 16:15:31Z DarkViper $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.frontend.php $
|
15
|
* @lastmodified $Date: 2011-08-11 18:15:31 +0200 (Thu, 11 Aug 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
/* -------------------------------------------------------- */
|
20
|
// Must include code to stop this file being accessed directly
|
21
|
require_once('globalExceptionHandler.php');
|
22
|
if(!defined('WB_PATH')) { throw new IllegalFileException(); }
|
23
|
/* -------------------------------------------------------- */
|
24
|
require_once(WB_PATH.'/framework/class.wb.php');
|
25
|
//require_once(WB_PATH.'/framework/SecureForm.php');
|
26
|
|
27
|
class frontend extends wb {
|
28
|
// defaults
|
29
|
public $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
|
public $default_block_content=true;
|
33
|
|
34
|
// page details
|
35
|
// page database row
|
36
|
public $page;
|
37
|
public $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$position,$visibility;
|
38
|
public $page_description,$page_keywords,$page_link;
|
39
|
public $page_trail=array();
|
40
|
|
41
|
public $page_access_denied;
|
42
|
public $page_no_active_sections;
|
43
|
|
44
|
// website settings
|
45
|
public $website_title,$website_description,$website_keywords,$website_header,$website_footer;
|
46
|
|
47
|
// ugly database stuff
|
48
|
public $extra_where_sql, $sql_where_language;
|
49
|
|
50
|
public function __construct() {
|
51
|
parent::__construct(SecureForm::FRONTEND);
|
52
|
}
|
53
|
|
54
|
public function page_select() {
|
55
|
global $page_id,$no_intro;
|
56
|
global $database;
|
57
|
// We have no page id and are supposed to show the intro page
|
58
|
if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
|
59
|
// Since we have no page id check if we should go to intro page or default page
|
60
|
// Get intro page content
|
61
|
$filename = WB_PATH.PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
|
62
|
if(file_exists($filename)) {
|
63
|
$handle = @fopen($filename, "r");
|
64
|
$content = @fread($handle, filesize($filename));
|
65
|
@fclose($handle);
|
66
|
$this->preprocess($content);
|
67
|
header("Location: ".WB_URL.PAGES_DIRECTORY."/intro".PAGE_EXTENSION.""); // send intro.php as header to allow parsing of php statements
|
68
|
echo ($content);
|
69
|
return false;
|
70
|
}
|
71
|
}
|
72
|
// Check if we should add page language sql code
|
73
|
if(PAGE_LANGUAGES) {
|
74
|
$this->sql_where_language = ' AND `language`=\''.LANGUAGE.'\'';
|
75
|
}
|
76
|
// Get default page
|
77
|
// Check for a page id
|
78
|
$table_p = TABLE_PREFIX.'pages';
|
79
|
$table_s = TABLE_PREFIX.'sections';
|
80
|
$now = time();
|
81
|
$sql = 'SELECT `p`.`page_id`, `link` ';
|
82
|
$sql .= 'FROM `'.$table_p.'` AS `p` INNER JOIN `'.$table_s.'` USING(`page_id`) ';
|
83
|
$sql .= 'WHERE `parent`=0 AND `visibility`=\'public\' ';
|
84
|
$sql .= 'AND (('.$now.'>=`publ_start` OR `publ_start`=0) ';
|
85
|
$sql .= 'AND ('.$now.'<=`publ_end` OR `publ_end`=0)) ';
|
86
|
if(trim($this->sql_where_language) != '') {
|
87
|
$sql .= trim($this->sql_where_language).' ';
|
88
|
}
|
89
|
$sql .= 'ORDER BY `p`.`position` ASC';
|
90
|
$get_default = $database->query($sql);
|
91
|
$default_num_rows = $get_default->numRows();
|
92
|
if(!isset($page_id) OR !is_numeric($page_id)){
|
93
|
// Go to or show default page
|
94
|
if($default_num_rows > 0) {
|
95
|
$fetch_default = $get_default->fetchRow();
|
96
|
$this->default_link = $fetch_default['link'];
|
97
|
$this->default_page_id = $fetch_default['page_id'];
|
98
|
// Check if we should redirect or include page inline
|
99
|
if(HOMEPAGE_REDIRECTION) {
|
100
|
// Redirect to page
|
101
|
header("Location: ".$this->page_link($this->default_link));
|
102
|
exit();
|
103
|
} else {
|
104
|
// Include page inline
|
105
|
$this->page_id = $this->default_page_id;
|
106
|
}
|
107
|
} else {
|
108
|
// No pages have been added, so print under construction page
|
109
|
$this->print_under_construction();
|
110
|
exit();
|
111
|
}
|
112
|
} else {
|
113
|
$this->page_id=$page_id;
|
114
|
}
|
115
|
// Get default page link
|
116
|
if(!isset($fetch_default)) {
|
117
|
$fetch_default = $get_default->fetchRow();
|
118
|
$this->default_link = $fetch_default['link'];
|
119
|
$this->default_page_id = $fetch_default['page_id'];
|
120
|
}
|
121
|
return true;
|
122
|
}
|
123
|
|
124
|
public function get_page_details() {
|
125
|
global $database;
|
126
|
if($this->page_id != 0) {
|
127
|
// Query page details
|
128
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
|
129
|
$get_page = $database->query($sql);
|
130
|
// Make sure page was found in database
|
131
|
if($get_page->numRows() == 0) {
|
132
|
// Print page not found message
|
133
|
exit("Page not found");
|
134
|
}
|
135
|
// Fetch page details
|
136
|
$this->page = $get_page->fetchRow();
|
137
|
// Check if the page language is also the selected language. If not, send headers again.
|
138
|
if ($this->page['language']!=LANGUAGE) {
|
139
|
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
|
140
|
header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
|
141
|
} else {
|
142
|
header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
|
143
|
}
|
144
|
exit();
|
145
|
}
|
146
|
// Begin code to set details as either variables of constants
|
147
|
// Page ID
|
148
|
if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
|
149
|
// Page Title
|
150
|
if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
|
151
|
$this->page_title=PAGE_TITLE;
|
152
|
// Menu Title
|
153
|
$menu_title = $this->page['menu_title'];
|
154
|
if($menu_title != '') {
|
155
|
if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
|
156
|
} else {
|
157
|
if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
|
158
|
}
|
159
|
$this->menu_title = MENU_TITLE;
|
160
|
// Page parent
|
161
|
if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
|
162
|
$this->parent=$this->page['parent'];
|
163
|
// Page root parent
|
164
|
if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
|
165
|
$this->root_parent=$this->page['root_parent'];
|
166
|
// Page level
|
167
|
if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
|
168
|
$this->level=$this->page['level'];
|
169
|
// Page position
|
170
|
$this->level=$this->page['position'];
|
171
|
// Page visibility
|
172
|
if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
|
173
|
$this->visibility=$this->page['visibility'];
|
174
|
// Page trail
|
175
|
foreach(explode(',', $this->page['page_trail']) AS $pid) {
|
176
|
$this->page_trail[$pid]=$pid;
|
177
|
}
|
178
|
// Page description
|
179
|
$this->page_description=$this->page['description'];
|
180
|
if($this->page_description != '') {
|
181
|
define('PAGE_DESCRIPTION', $this->page_description);
|
182
|
} else {
|
183
|
define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
|
184
|
}
|
185
|
// Page keywords
|
186
|
$this->page_keywords=$this->page['keywords'];
|
187
|
// Page link
|
188
|
$this->link=$this->page_link($this->page['link']);
|
189
|
|
190
|
// End code to set details as either variables of constants
|
191
|
}
|
192
|
|
193
|
// Figure out what template to use
|
194
|
if(!defined('TEMPLATE')) {
|
195
|
if(isset($this->page['template']) AND $this->page['template'] != '') {
|
196
|
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
|
197
|
define('TEMPLATE', $this->page['template']);
|
198
|
} else {
|
199
|
define('TEMPLATE', DEFAULT_TEMPLATE);
|
200
|
}
|
201
|
} else {
|
202
|
define('TEMPLATE', DEFAULT_TEMPLATE);
|
203
|
}
|
204
|
}
|
205
|
// Set the template dir
|
206
|
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
|
207
|
|
208
|
// Check if user is allowed to view this page
|
209
|
if($this->page && $this->page_is_visible($this->page) == false) {
|
210
|
if(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
|
211
|
// User isnt allowed on this page so tell them
|
212
|
$this->page_access_denied=true;
|
213
|
} elseif(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
|
214
|
// Check if the user is authenticated
|
215
|
if($this->is_authenticated() == false) {
|
216
|
// User needs to login first
|
217
|
header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
|
218
|
exit(0);
|
219
|
} else {
|
220
|
// User isnt allowed on this page so tell them
|
221
|
$this->page_access_denied=true;
|
222
|
}
|
223
|
|
224
|
}
|
225
|
}
|
226
|
// check if there is at least one active section
|
227
|
if($this->page && $this->page_is_active($this->page) == false) {
|
228
|
$this->page_no_active_sections=true;
|
229
|
}
|
230
|
}
|
231
|
|
232
|
public function get_website_settings()
|
233
|
{
|
234
|
global $database;
|
235
|
|
236
|
// set visibility SQL code
|
237
|
// never show no-vis, hidden or deleted pages
|
238
|
$this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
|
239
|
// Set extra private sql code
|
240
|
if($this->is_authenticated()==false) {
|
241
|
// if user is not authenticated, don't show private pages either
|
242
|
$this->extra_where_sql .= ' AND `visibility`!=\'private\'';
|
243
|
// and 'registered' without frontend login doesn't make much sense!
|
244
|
if (FRONTEND_LOGIN==false) {
|
245
|
$this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
|
246
|
}
|
247
|
}
|
248
|
$this->extra_where_sql .= $this->sql_where_language;
|
249
|
|
250
|
// Work-out if any possible in-line search boxes should be shown
|
251
|
if(SEARCH == 'public') {
|
252
|
define('SHOW_SEARCH', true);
|
253
|
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
|
254
|
define('SHOW_SEARCH', true);
|
255
|
} elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
|
256
|
define('SHOW_SEARCH', true);
|
257
|
} elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
|
258
|
define('SHOW_SEARCH', true);
|
259
|
} else {
|
260
|
define('SHOW_SEARCH', false);
|
261
|
}
|
262
|
// Work-out if menu should be shown
|
263
|
if(!defined('SHOW_MENU')) {
|
264
|
define('SHOW_MENU', true);
|
265
|
}
|
266
|
// Work-out if login menu constants should be set
|
267
|
if(FRONTEND_LOGIN) {
|
268
|
// Set login menu constants
|
269
|
define('LOGIN_URL', WB_URL.'/account/login.php');
|
270
|
define('LOGOUT_URL', WB_URL.'/account/logout.php');
|
271
|
define('FORGOT_URL', WB_URL.'/account/forgot.php');
|
272
|
define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
|
273
|
define('SIGNUP_URL', WB_URL.'/account/signup.php');
|
274
|
}
|
275
|
}
|
276
|
|
277
|
/*
|
278
|
* replace all "[wblink{page_id}]" with real links
|
279
|
* @param string &$content : reference to global $content
|
280
|
* @return void
|
281
|
* @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
|
282
|
*/
|
283
|
public function preprocess(&$content)
|
284
|
{
|
285
|
global $database;
|
286
|
$replace_list = array();
|
287
|
$pattern = '/\[wblink([0-9]+)\]/isU';
|
288
|
if(preg_match_all($pattern,$content,$ids))
|
289
|
{
|
290
|
foreach($ids[1] as $key => $page_id)
|
291
|
{
|
292
|
$replace_list[$page_id] = $ids[0][$key];
|
293
|
}
|
294
|
foreach($replace_list as $page_id => $tag)
|
295
|
{
|
296
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id;
|
297
|
$link = $database->get_one($sql);
|
298
|
if(!is_null($link))
|
299
|
{
|
300
|
$link = $this->page_link($link);
|
301
|
$content = str_replace($tag, $link, $content);
|
302
|
}
|
303
|
}
|
304
|
}
|
305
|
}
|
306
|
|
307
|
/*
|
308
|
function preprocess(&$content) {
|
309
|
global $database;
|
310
|
// Replace [wblink--PAGE_ID--] with real link
|
311
|
$pattern = '/\[wblink(.+?)\]/s';
|
312
|
preg_match_all($pattern,$content,$ids);
|
313
|
foreach($ids[1] AS $page_id) {
|
314
|
$pattern = '/\[wblink'.$page_id.'\]/s';
|
315
|
// Get page link
|
316
|
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
317
|
$fetch_link = $get_link->fetchRow();
|
318
|
$link = $this->page_link($fetch_link['link']);
|
319
|
$content = preg_replace($pattern,$link,$content);
|
320
|
}
|
321
|
}
|
322
|
*/
|
323
|
public function menu() {
|
324
|
global $wb;
|
325
|
if (!isset($wb->menu_number)) {
|
326
|
$wb->menu_number = 1;
|
327
|
}
|
328
|
if (!isset($wb->menu_start_level)) {
|
329
|
$wb->menu_start_level = 0;
|
330
|
}
|
331
|
if (!isset($wb->menu_recurse)) {
|
332
|
$wb->menu_recurse = -1;
|
333
|
}
|
334
|
if (!isset($wb->menu_collapse)) {
|
335
|
$wb->menu_collapse = true;
|
336
|
}
|
337
|
if (!isset($wb->menu_item_template)) {
|
338
|
$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
|
339
|
}
|
340
|
if (!isset($wb->menu_item_footer)) {
|
341
|
$wb->menu_item_footer = '</li>';
|
342
|
}
|
343
|
if (!isset($wb->menu_header)) {
|
344
|
$wb->menu_header = '<ul>';
|
345
|
}
|
346
|
if (!isset($wb->menu_footer)) {
|
347
|
$wb->menu_footer = '</ul>';
|
348
|
}
|
349
|
if (!isset($wb->menu_default_class)) {
|
350
|
$wb->menu_default_class = ' class="menu_default"';
|
351
|
}
|
352
|
if (!isset($wb->menu_current_class)) {
|
353
|
$wb->menu_current_class = ' class="menu_current"';
|
354
|
}
|
355
|
if (!isset($wb->menu_parent)) {
|
356
|
$wb->menu_parent = 0;
|
357
|
}
|
358
|
$wb->show_menu();
|
359
|
}
|
360
|
|
361
|
public function show_menu() {
|
362
|
global $database;
|
363
|
if ($this->menu_start_level>0) {
|
364
|
$key_array=array_keys($this->page_trail);
|
365
|
if (isset($key_array[$this->menu_start_level-1])) {
|
366
|
$real_start=$key_array[$this->menu_start_level-1];
|
367
|
$this->menu_parent=$real_start;
|
368
|
$this->menu_start_level=0;
|
369
|
} else {
|
370
|
return;
|
371
|
}
|
372
|
}
|
373
|
if ($this->menu_recurse==0)
|
374
|
return;
|
375
|
// Check if we should add menu number check to query
|
376
|
if($this->menu_parent == 0) {
|
377
|
$menu_number = '`menu`='.intval($this->menu_number);
|
378
|
} else {
|
379
|
$menu_number = '1';
|
380
|
}
|
381
|
// Query pages
|
382
|
$sql = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`level`,';
|
383
|
$sql .= '`visibility`,viewing_groups,viewing_users ';
|
384
|
$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
|
385
|
$sql .= 'WHERE `parent`='.(int)$this->menu_parent.' AND '.$menu_number.' AND '.$this->extra_where_sql.' ';
|
386
|
$sql .= 'ORDER BY `position` ASC';
|
387
|
$query_menu = $database->query($sql);
|
388
|
// Check if there are any pages to show
|
389
|
if($query_menu->numRows() > 0) {
|
390
|
// Print menu header
|
391
|
echo "\n".$this->menu_header;
|
392
|
// Loop through pages
|
393
|
while($page = $query_menu->fetchRow()) {
|
394
|
// check whether to show this menu-link
|
395
|
if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
|
396
|
continue; // no active sections
|
397
|
}
|
398
|
if($this->page_is_visible($page)==false) {
|
399
|
if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
|
400
|
continue;
|
401
|
}
|
402
|
// Create vars
|
403
|
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
|
404
|
// Work-out class
|
405
|
if($page['page_id'] == PAGE_ID) {
|
406
|
$class = $this->menu_current_class;
|
407
|
} else {
|
408
|
$class = $this->menu_default_class;
|
409
|
}
|
410
|
// Check if link is same as first page link, and if so change to WB URL
|
411
|
if($page['link'] == $this->default_link AND !INTRO_PAGE) {
|
412
|
$link = WB_URL;
|
413
|
} else {
|
414
|
$link = $this->page_link($page['link']);
|
415
|
}
|
416
|
// Create values
|
417
|
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
|
418
|
// Replace vars with value and print
|
419
|
echo "\n".str_replace($vars, $values, $this->menu_item_template);
|
420
|
// Generate sub-menu
|
421
|
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
|
422
|
$this->menu_recurse--;
|
423
|
$this->menu_parent=$page['page_id'];
|
424
|
$this->show_menu();
|
425
|
}
|
426
|
echo "\n".$this->menu_item_footer;
|
427
|
}
|
428
|
// Print menu footer
|
429
|
echo "\n".$this->menu_footer;
|
430
|
}
|
431
|
}
|
432
|
|
433
|
|
434
|
// Function to show the "Under Construction" page
|
435
|
public function print_under_construction() {
|
436
|
global $MESSAGE;
|
437
|
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
|
438
|
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
439
|
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title>
|
440
|
<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; }
|
441
|
h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
|
442
|
}--></style></head><body>
|
443
|
<br /><h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
|
444
|
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
|
445
|
}
|
446
|
}
|
447
|
|
448
|
?>
|