1
|
<?php
|
2
|
|
3
|
// $Id: class.frontend.php 40 2005-09-07 19:22:34Z stefan $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2005, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
|
26
|
/*
|
27
|
|
28
|
Frontend class
|
29
|
|
30
|
*/
|
31
|
|
32
|
if(!defined('WB_PATH')) {
|
33
|
header('Location: ../index.php');
|
34
|
}
|
35
|
|
36
|
|
37
|
require_once(WB_PATH.'/framework/class.wb.php');
|
38
|
|
39
|
class frontend extends wb {
|
40
|
// defaults
|
41
|
var $default_link,$default_page_id;
|
42
|
|
43
|
// page details
|
44
|
// page database row
|
45
|
var $page;
|
46
|
var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
|
47
|
var $page_description,$page_keywords,$page_link_original,$page_link;
|
48
|
var $page_trail=array();
|
49
|
|
50
|
var $page_access_denied;
|
51
|
|
52
|
// website settings
|
53
|
var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
|
54
|
|
55
|
// ugly database stuff
|
56
|
var $extra_where_sql;
|
57
|
|
58
|
function frontend() {
|
59
|
$this->wb();
|
60
|
}
|
61
|
|
62
|
function page_select() {
|
63
|
global $page_id,$no_intro;
|
64
|
global $database;
|
65
|
// We have no page id and are supposed to show the intro page
|
66
|
if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
|
67
|
// Since we have no page id check if we should go to intro page or default page
|
68
|
// Get intro page content
|
69
|
$filename = WB_PATH.PAGES_DIRECTORY.'/intro.php';
|
70
|
if(file_exists($filename)) {
|
71
|
$handle = fopen($filename, "r");
|
72
|
$content = fread($handle, filesize($filename));
|
73
|
fclose($handle);
|
74
|
$this->preprocess($content);
|
75
|
echo $this->strip_slashes($content);
|
76
|
return false;
|
77
|
}
|
78
|
}
|
79
|
// Check if we should add page language sql code
|
80
|
if(PAGE_LANGUAGES) {
|
81
|
$this->sql_where_language = " AND language = '".LANGUAGE."'";
|
82
|
}
|
83
|
// Get default page
|
84
|
// Check for a page id
|
85
|
$query_default = "SELECT page_id,link FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND visibility = 'public'$this->sql_where_language ORDER BY position ASC LIMIT 1";
|
86
|
$get_default = $database->query($query_default);
|
87
|
$default_num_rows = $get_default->numRows();
|
88
|
if(!isset($page_id) OR !is_numeric($page_id)){
|
89
|
// Go to or show default page
|
90
|
if($default_num_rows > 0) {
|
91
|
$fetch_default = $get_default->fetchRow();
|
92
|
$this->default_link = $fetch_default['link'];
|
93
|
$default_page_id = $fetch_default['page_id'];
|
94
|
// Check if we should redirect or include page inline
|
95
|
if(HOMEPAGE_REDIRECTION) {
|
96
|
// Redirect to page
|
97
|
header("Location: ".page_link($this->default_link));
|
98
|
exit();
|
99
|
} else {
|
100
|
// Include page inline
|
101
|
$this->page_id = $default_page_id;
|
102
|
}
|
103
|
} else {
|
104
|
// No pages have been added, so print under construction page
|
105
|
$this->print_under_construction();
|
106
|
exit();
|
107
|
}
|
108
|
} else {
|
109
|
$this->page_id=$page_id;
|
110
|
}
|
111
|
// Get default page link
|
112
|
if(!isset($fetch_default)) {
|
113
|
$fetch_default = $get_default->fetchRow();
|
114
|
$this->default_link = $fetch_default['link'];
|
115
|
}
|
116
|
return true;
|
117
|
}
|
118
|
|
119
|
function get_page_details() {
|
120
|
global $database;
|
121
|
if($this->page_id != 0) {
|
122
|
// Query page details
|
123
|
$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
|
124
|
$get_page = $database->query($query_page);
|
125
|
// Make sure page was found in database
|
126
|
if($get_page->numRows() == 0) {
|
127
|
// Print page not found message
|
128
|
exit("Page not found");
|
129
|
}
|
130
|
// Fetch page details
|
131
|
$this->page = $get_page->fetchRow();
|
132
|
// Check if the page language is also the selected language. If not, send headers again.
|
133
|
if ($this->page['language']!=LANGUAGE) {
|
134
|
require_once(WB_PATH.'/framework/functions.php');
|
135
|
header('Location: '.page_link($this->page['link']).'?lang='.$this->page['language']);
|
136
|
exit();
|
137
|
}
|
138
|
// Begin code to set details as either variables of constants
|
139
|
// Page ID
|
140
|
define('PAGE_ID', $this->page['page_id']);
|
141
|
$this->page_id=$this->page['page_id'];
|
142
|
// Page Title
|
143
|
define('PAGE_TITLE', $this->strip_slashes($this->page['page_title']));
|
144
|
$this->page_title=PAGE_TITLE;
|
145
|
// Menu Title
|
146
|
$menu_title = $this->strip_slashes($this->page['menu_title']);
|
147
|
if($menu_title != '') {
|
148
|
define('MENU_TITLE', $menu_title);
|
149
|
} else {
|
150
|
define('MENU_TITLE', PAGE_TITLE);
|
151
|
}
|
152
|
$this->menu_title=MENU_TITLE;
|
153
|
// Page parent
|
154
|
define('PARENT', $this->page['parent']);
|
155
|
$this->parent=$this->page['parent'];
|
156
|
// Page root parent
|
157
|
define('ROOT_PARENT', $this->page['root_parent']);
|
158
|
$this->root_parent=$this->page['root_parent'];
|
159
|
// Page level
|
160
|
define('LEVEL', $this->page['level']);
|
161
|
$this->level=$this->page['level'];
|
162
|
// Page visibility
|
163
|
define('VISIBILITY', $this->page['visibility']);
|
164
|
$this->visibility=$this->page['visibility'];
|
165
|
// Page trail
|
166
|
foreach(explode(',', $this->page['page_trail']) AS $pid) {
|
167
|
$this->page_trail[$pid]=$pid;
|
168
|
}
|
169
|
// Page description
|
170
|
$this->page_description=$this->page['description'];
|
171
|
// Page keywords
|
172
|
$this->page_keywords=$this->page['keywords'];
|
173
|
// Page link
|
174
|
$this->link=$this->page_link($this->page['link']);
|
175
|
|
176
|
// End code to set details as either variables of constants
|
177
|
}
|
178
|
|
179
|
// Work-out if any possible in-line search boxes should be shown
|
180
|
if(SEARCH == 'public') {
|
181
|
define('SHOW_SEARCH', true);
|
182
|
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
|
183
|
define('SHOW_SEARCH', true);
|
184
|
} elseif(SEARCH == 'private' AND $wb->is_authenticated() == true) {
|
185
|
define('SHOW_SEARCH', true);
|
186
|
} else {
|
187
|
define('SHOW_SEARCH', false);
|
188
|
}
|
189
|
// Work-out if menu should be shown
|
190
|
if(!defined('SHOW_MENU')) {
|
191
|
define('SHOW_MENU', true);
|
192
|
}
|
193
|
// Work-out if login menu constants should be set
|
194
|
if(FRONTEND_LOGIN) {
|
195
|
// Set login menu constants
|
196
|
define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION);
|
197
|
define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION);
|
198
|
define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION);
|
199
|
define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION);
|
200
|
define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION);
|
201
|
}
|
202
|
|
203
|
// Figure out what template to use
|
204
|
if(!defined('TEMPLATE')) {
|
205
|
if(isset($this->page['template']) AND $this->page['template'] != '') {
|
206
|
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
|
207
|
define('TEMPLATE', $this->page['template']);
|
208
|
} else {
|
209
|
define('TEMPLATE', DEFAULT_TEMPLATE);
|
210
|
}
|
211
|
} else {
|
212
|
define('TEMPLATE', DEFAULT_TEMPLATE);
|
213
|
}
|
214
|
}
|
215
|
// Set the template dir
|
216
|
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
|
217
|
|
218
|
// Check if user is allow to view this page
|
219
|
if(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
|
220
|
// Check if the user is authenticated
|
221
|
if($this->is_authenticated() == false) {
|
222
|
// User needs to login first
|
223
|
header("Location: ".WB_URL."/account/login".PAGE_EXTENSION);
|
224
|
}
|
225
|
// Check if we should show this page
|
226
|
if($this->show_page($this->page) == false) {
|
227
|
$this->page_access_denied=true;
|
228
|
}
|
229
|
} elseif(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
|
230
|
// User isnt allowed on this page so tell them
|
231
|
$this->page_access_denied=true;
|
232
|
}
|
233
|
// never show no-vis, hidden or deleted pages
|
234
|
$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
|
235
|
// Set extra private sql code
|
236
|
if($this->is_authenticated()==false) {
|
237
|
// if user is not authenticated, don't show private pages either
|
238
|
$this->extra_where_sql .= " AND visibility != 'private'";
|
239
|
// and 'registered' without frontend login doesn't make much sense!
|
240
|
if (FRONTEND_LOGIN==false) {
|
241
|
$this->extra_where_sql .= " AND visibility != 'registered'";
|
242
|
}
|
243
|
}
|
244
|
$this->extra_where_sql .= $this->sql_where_language;
|
245
|
}
|
246
|
|
247
|
function get_website_settings() {
|
248
|
global $database;
|
249
|
// Get website settings (title, keywords, description, header, and footer)
|
250
|
$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
|
251
|
$get_settings = $database->query($query_settings);
|
252
|
while($setting = $get_settings->fetchRow()) {
|
253
|
switch($setting['name']) {
|
254
|
case 'title':
|
255
|
define('WEBSITE_TITLE', $this->strip_slashes($setting['value']));
|
256
|
$this->website_title=WEBSITE_TITLE;
|
257
|
break;
|
258
|
case 'description':
|
259
|
if($page_description != '') {
|
260
|
define('WEBSITE_DESCRIPTION', $page_description);
|
261
|
} else {
|
262
|
define('WEBSITE_DESCRIPTION', $this->strip_slashes($setting['value']));
|
263
|
}
|
264
|
$this->website_description=WEBSITE_DESCRIPTION;
|
265
|
break;
|
266
|
case 'keywords':
|
267
|
if($page_keywords != '') {
|
268
|
define('WEBSITE_KEYWORDS', $this->strip_slashes($setting['value']).' '.$page_keywords);
|
269
|
} else {
|
270
|
define('WEBSITE_KEYWORDS', $this->strip_slashes($setting['value']));
|
271
|
}
|
272
|
$this->website_keywords=WEBSITE_KEYWORDS;
|
273
|
break;
|
274
|
case 'header':
|
275
|
define('WEBSITE_HEADER', $this->strip_slashes($setting['value']));
|
276
|
$this->website_header=WEBSITE_HEADER;
|
277
|
break;
|
278
|
case 'footer':
|
279
|
define('WEBSITE_FOOTER', $this->strip_slashes($setting['value']));
|
280
|
$this->website_footer=WEBSITE_FOOTER;
|
281
|
break;
|
282
|
}
|
283
|
}
|
284
|
}
|
285
|
|
286
|
function page_link($link){
|
287
|
// Check for :// in the link (used in URL's)
|
288
|
if(strstr($link, '://') == '') {
|
289
|
return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
290
|
} else {
|
291
|
return $link;
|
292
|
}
|
293
|
}
|
294
|
|
295
|
function preprocess(&$content) {
|
296
|
global $database;
|
297
|
// Replace [wblink--PAGE_ID--] with real link
|
298
|
$pattern = '/\[wblink(.+?)\]/s';
|
299
|
preg_match_all($pattern,$content,$ids);
|
300
|
foreach($ids[1] AS $page_id) {
|
301
|
$pattern = '/\[wblink'.$page_id.'\]/s';
|
302
|
// Get page link
|
303
|
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
304
|
$fetch_link = $get_link->fetchRow();
|
305
|
$link = page_link($fetch_link['link']);
|
306
|
$content = preg_replace($pattern,$link,$content);
|
307
|
}
|
308
|
}
|
309
|
|
310
|
function menu() {
|
311
|
if (!isset($this->menu_number)) {
|
312
|
$this->menu_number = 1;
|
313
|
}
|
314
|
if (!isset($this->menu_start_level)) {
|
315
|
$this->menu_start_level = 0;
|
316
|
}
|
317
|
if (!isset($this->menu_recurse)) {
|
318
|
$this->menu_recurse = -1;
|
319
|
}
|
320
|
if (!isset($this->menu_collapse)) {
|
321
|
$this->menu_collapse = true;
|
322
|
}
|
323
|
if (!isset($this->menu_item_template)) {
|
324
|
$this->menu_item_template = '<li><span[class]>[a][menu_title][/a]</span>';
|
325
|
}
|
326
|
if (!isset($this->menu_item_footer)) {
|
327
|
$this->menu_item_footer = '</li>';
|
328
|
}
|
329
|
if (!isset($this->menu_header)) {
|
330
|
$this->menu_header = '<ul>';
|
331
|
}
|
332
|
if (!isset($this->menu_footer)) {
|
333
|
$this->menu_footer = '<ul>';
|
334
|
}
|
335
|
if (!isset($this->menu_default_class)) {
|
336
|
$this->menu_default_class = ' class="menu_default"';
|
337
|
}
|
338
|
if (!isset($this->menu_current_class)) {
|
339
|
$this->menu_current_class = ' class="menu_current"';
|
340
|
}
|
341
|
if (!isset($this->menu_parent)) {
|
342
|
$this->menu_parent = 0;
|
343
|
}
|
344
|
$this->show_menu();
|
345
|
if ($start_level>0) {
|
346
|
$key_array=array_keys($this->page_trail);
|
347
|
$real_start=$key_array[$start_level-1];
|
348
|
if (isset($real_start))
|
349
|
{
|
350
|
$this->menu_parent=$real_start;
|
351
|
$this->show_menu();
|
352
|
}
|
353
|
return;
|
354
|
}
|
355
|
|
356
|
}
|
357
|
|
358
|
function show_menu() {
|
359
|
global $database;
|
360
|
if ($this->menu_recurse==0)
|
361
|
return;
|
362
|
// Check if we should add menu number check to query
|
363
|
if($menu_parent == 0) {
|
364
|
$menu_number = "menu = '$this->menu_number'";
|
365
|
} else {
|
366
|
$menu_number = '1';
|
367
|
}
|
368
|
// Query pages
|
369
|
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility FROM ".
|
370
|
TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC");
|
371
|
// Check if there are any pages to show
|
372
|
if($query_menu->numRows() > 0) {
|
373
|
// Print menu header
|
374
|
echo "\n".$this->menu_header;
|
375
|
// Loop through pages
|
376
|
while($page = $query_menu->fetchRow()) {
|
377
|
// Check if this page should be shown
|
378
|
// Create vars
|
379
|
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
|
380
|
// Work-out class
|
381
|
if($page['page_id'] == PAGE_ID) {
|
382
|
$class = $this->menu_current_class;
|
383
|
} else {
|
384
|
$class = $this->menu_default_class;
|
385
|
}
|
386
|
// Check if link is same as first page link, and if so change to WB URL
|
387
|
if($page['link'] == $this->default_link AND !INTRO_PAGE) {
|
388
|
$link = WB_URL;
|
389
|
} else {
|
390
|
$link = $this->page_link($page['link']);
|
391
|
}
|
392
|
// Create values
|
393
|
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $this->strip_slashes($page['menu_title']), $this->strip_slashes($page['page_title']));
|
394
|
// Replace vars with value and print
|
395
|
echo "\n".str_replace($vars, $values, $this->menu_item_template);
|
396
|
// Generate sub-menu
|
397
|
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
|
398
|
$this->menu_recurse--;
|
399
|
$this->menu_parent=$page['page_id'];
|
400
|
$this->show_menu();
|
401
|
}
|
402
|
echo "\n".$this->menu_item_footer;
|
403
|
}
|
404
|
// Print menu footer
|
405
|
echo "\n".$this->menu_footer;
|
406
|
}
|
407
|
}
|
408
|
|
409
|
function page_content($block = 1) {
|
410
|
// Get outside objects
|
411
|
global $database,$admin,$TEXT,$MENU,$HEADING,$MESSAGE;
|
412
|
global $globals;
|
413
|
if ($this->page_access_denied==true) {
|
414
|
echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
|
415
|
exit();
|
416
|
}
|
417
|
if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
|
418
|
// Make sure block is numeric
|
419
|
if(!is_numeric($block)) { $block = 1; }
|
420
|
// Include page content
|
421
|
if(!defined('PAGE_CONTENT')) {
|
422
|
// First get all sections for this page
|
423
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".PAGE_ID."' AND block = '$block' ORDER BY position");
|
424
|
if($query_sections->numRows() > 0) {
|
425
|
// Loop through them and include there modules file
|
426
|
while($section = $query_sections->fetchRow()) {
|
427
|
$section_id = $section['section_id'];
|
428
|
$module = $section['module'];
|
429
|
require(WB_PATH.'/modules/'.$module.'/view.php');
|
430
|
}
|
431
|
}
|
432
|
} else {
|
433
|
if($block == 1) {
|
434
|
require(PAGE_CONTENT);
|
435
|
}
|
436
|
}
|
437
|
}
|
438
|
|
439
|
// Function for page title
|
440
|
function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
|
441
|
$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
|
442
|
$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
|
443
|
echo str_replace($vars, $values, $template);
|
444
|
}
|
445
|
|
446
|
// Function for page description
|
447
|
function page_description() {
|
448
|
echo WEBSITE_DESCRIPTION;
|
449
|
}
|
450
|
// Function for page keywords
|
451
|
function page_keywords() {
|
452
|
echo WEBSITE_KEYWORDS;
|
453
|
}
|
454
|
// Function for page header
|
455
|
function page_header($date_format = 'Y') {
|
456
|
echo WEBSITE_HEADER;
|
457
|
}
|
458
|
|
459
|
// Function for page footer
|
460
|
function page_footer($date_format = 'Y') {
|
461
|
global $starttime;
|
462
|
$vars = array('[YEAR]', '[PROCESSTIME]');
|
463
|
$processtime=(microtime()>$starttime)?microtime()-$starttime:microtime()-$starttime+1;
|
464
|
$values = array(date($date_format),$processtime);
|
465
|
echo str_replace($vars, $values, WEBSITE_FOOTER);
|
466
|
}
|
467
|
|
468
|
// Function to show the "Under Construction" page
|
469
|
function print_under_construction() {
|
470
|
global $MESSAGE;
|
471
|
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
|
472
|
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
473
|
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'].'</title>
|
474
|
<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif;
|
475
|
font-size: 12px; color: #000000; background-color: #FFFFFF; margin: 20px; text-align: center; }
|
476
|
h1 { margin: 0; padding: 0; }--></style></head><body>
|
477
|
<h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'];'.</h1><br />
|
478
|
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
|
479
|
}
|
480
|
}
|
481
|
|
482
|
?>
|