Revision 452
Added by Matthias over 17 years ago
class.frontend.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2007, 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 |
exit(0); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
39 |
|
|
40 |
class frontend extends wb { |
|
41 |
// defaults |
|
42 |
var $default_link,$default_page_id; |
|
43 |
// when multiple blocks are used, show home page blocks on |
|
44 |
// pages where no content is defined (search, login, ...) |
|
45 |
var $default_block_content=true; |
|
46 |
|
|
47 |
// page details |
|
48 |
// page database row |
|
49 |
var $page; |
|
50 |
var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility; |
|
51 |
var $page_description,$page_keywords,$page_link; |
|
52 |
var $page_trail=array(); |
|
53 |
|
|
54 |
var $page_access_denied; |
|
55 |
|
|
56 |
// website settings |
|
57 |
var $website_title,$website_description,$website_keywords,$website_header,$website_footer; |
|
58 |
|
|
59 |
// ugly database stuff |
|
60 |
var $extra_where_sql, $sql_where_language; |
|
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 ($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 |
$this->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: ".$this->page_link($this->default_link)); |
|
98 |
exit(); |
|
99 |
} else { |
|
100 |
// Include page inline |
|
101 |
$this->page_id = $this->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 |
$this->default_page_id = $fetch_default['page_id']; |
|
116 |
} |
|
117 |
return true; |
|
118 |
} |
|
119 |
|
|
120 |
function get_page_details() { |
|
121 |
global $database; |
|
122 |
if($this->page_id != 0) { |
|
123 |
// Query page details |
|
124 |
$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'"; |
|
125 |
$get_page = $database->query($query_page); |
|
126 |
// Make sure page was found in database |
|
127 |
if($get_page->numRows() == 0) { |
|
128 |
// Print page not found message |
|
129 |
exit("Page not found"); |
|
130 |
} |
|
131 |
// Fetch page details |
|
132 |
$this->page = $get_page->fetchRow(); |
|
133 |
// Check if the page language is also the selected language. If not, send headers again. |
|
134 |
if ($this->page['language']!=LANGUAGE) { |
|
135 |
header('Location: '.$this->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 |
// Page Title |
|
142 |
define('PAGE_TITLE', htmlentities(($this->page['page_title']))); |
|
143 |
$this->page_title=PAGE_TITLE; |
|
144 |
// Menu Title |
|
145 |
$menu_title = htmlentities($this->page['menu_title']); |
|
146 |
if($menu_title != '') { |
|
147 |
define('MENU_TITLE', $menu_title); |
|
148 |
} else { |
|
149 |
define('MENU_TITLE', PAGE_TITLE); |
|
150 |
} |
|
151 |
$this->menu_title=MENU_TITLE; |
|
152 |
// Page parent |
|
153 |
define('PARENT', $this->page['parent']); |
|
154 |
$this->parent=$this->page['parent']; |
|
155 |
// Page root parent |
|
156 |
define('ROOT_PARENT', $this->page['root_parent']); |
|
157 |
$this->root_parent=$this->page['root_parent']; |
|
158 |
// Page level |
|
159 |
define('LEVEL', $this->page['level']); |
|
160 |
$this->level=$this->page['level']; |
|
161 |
// Page visibility |
|
162 |
define('VISIBILITY', $this->page['visibility']); |
|
163 |
$this->visibility=$this->page['visibility']; |
|
164 |
// Page trail |
|
165 |
foreach(explode(',', $this->page['page_trail']) AS $pid) { |
|
166 |
$this->page_trail[$pid]=$pid; |
|
167 |
} |
|
168 |
// Page description |
|
169 |
$this->page_description=$this->page['description']; |
|
170 |
if($this->page_description != '') { |
|
171 |
define('PAGE_DESCRIPTION', $this->page_description); |
|
172 |
} else { |
|
173 |
define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION); |
|
174 |
} |
|
175 |
// Page keywords |
|
176 |
$this->page_keywords=$this->page['keywords']; |
|
177 |
// Page link |
|
178 |
$this->link=$this->page_link($this->page['link']); |
|
179 |
|
|
180 |
// End code to set details as either variables of constants |
|
181 |
} |
|
182 |
|
|
183 |
// Figure out what template to use |
|
184 |
if(!defined('TEMPLATE')) { |
|
185 |
if(isset($this->page['template']) AND $this->page['template'] != '') { |
|
186 |
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) { |
|
187 |
define('TEMPLATE', $this->page['template']); |
|
188 |
} else { |
|
189 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
190 |
} |
|
191 |
} else { |
|
192 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
193 |
} |
|
194 |
} |
|
195 |
// Set the template dir |
|
196 |
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE); |
|
197 |
|
|
198 |
// Check if user is allowed to view this page |
|
199 |
if(VISIBILITY == 'private' OR VISIBILITY == 'registered') { |
|
200 |
// Check if the user is authenticated |
|
201 |
if($this->is_authenticated() == false) { |
|
202 |
// User needs to login first |
|
203 |
header("Location: ".WB_URL."/account/login".PAGE_EXTENSION.'?redirect='.$this->link); |
|
204 |
exit(0); |
|
205 |
} |
|
206 |
// Check if we should show this page |
|
207 |
if($this->show_page($this->page) == false) { |
|
208 |
$this->page_access_denied=true; |
|
209 |
} |
|
210 |
} elseif(VISIBILITY == 'deleted' OR VISIBILITY == 'none') { |
|
211 |
// User isnt allowed on this page so tell them |
|
212 |
$this->page_access_denied=true; |
|
213 |
} |
|
214 |
} |
|
215 |
|
|
216 |
function get_website_settings() { |
|
217 |
global $database; |
|
218 |
|
|
219 |
// set visibility SQL code |
|
220 |
// never show no-vis, hidden or deleted pages |
|
221 |
$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'"; |
|
222 |
// Set extra private sql code |
|
223 |
if($this->is_authenticated()==false) { |
|
224 |
// if user is not authenticated, don't show private pages either |
|
225 |
$this->extra_where_sql .= " AND visibility != 'private'"; |
|
226 |
// and 'registered' without frontend login doesn't make much sense! |
|
227 |
if (FRONTEND_LOGIN==false) { |
|
228 |
$this->extra_where_sql .= " AND visibility != 'registered'"; |
|
229 |
} |
|
230 |
} |
|
231 |
$this->extra_where_sql .= $this->sql_where_language; |
|
232 |
|
|
233 |
// Work-out if any possible in-line search boxes should be shown |
|
234 |
if(SEARCH == 'public') { |
|
235 |
define('SHOW_SEARCH', true); |
|
236 |
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') { |
|
237 |
define('SHOW_SEARCH', true); |
|
238 |
} elseif(SEARCH == 'private' AND $wb->is_authenticated() == true) { |
|
239 |
define('SHOW_SEARCH', true); |
|
240 |
} else { |
|
241 |
define('SHOW_SEARCH', false); |
|
242 |
} |
|
243 |
// Work-out if menu should be shown |
|
244 |
if(!defined('SHOW_MENU')) { |
|
245 |
define('SHOW_MENU', true); |
|
246 |
} |
|
247 |
// Work-out if login menu constants should be set |
|
248 |
if(FRONTEND_LOGIN) { |
|
249 |
// Set login menu constants |
|
250 |
define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION); |
|
251 |
define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION); |
|
252 |
define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION); |
|
253 |
define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION); |
|
254 |
define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
function preprocess(&$content) { |
|
259 |
global $database; |
|
260 |
// Replace [wblink--PAGE_ID--] with real link |
|
261 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
262 |
preg_match_all($pattern,$content,$ids); |
|
263 |
foreach($ids[1] AS $page_id) { |
|
264 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
265 |
// Get page link |
|
266 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
267 |
$fetch_link = $get_link->fetchRow(); |
|
268 |
$link = $this->page_link($fetch_link['link']); |
|
269 |
$content = preg_replace($pattern,$link,$content); |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
function menu() { |
|
274 |
global $wb; |
|
275 |
if (!isset($wb->menu_number)) { |
|
276 |
$wb->menu_number = 1; |
|
277 |
} |
|
278 |
if (!isset($wb->menu_start_level)) { |
|
279 |
$wb->menu_start_level = 0; |
|
280 |
} |
|
281 |
if (!isset($wb->menu_recurse)) { |
|
282 |
$wb->menu_recurse = -1; |
|
283 |
} |
|
284 |
if (!isset($wb->menu_collapse)) { |
|
285 |
$wb->menu_collapse = true; |
|
286 |
} |
|
287 |
if (!isset($wb->menu_item_template)) { |
|
288 |
$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>'; |
|
289 |
} |
|
290 |
if (!isset($wb->menu_item_footer)) { |
|
291 |
$wb->menu_item_footer = '</li>'; |
|
292 |
} |
|
293 |
if (!isset($wb->menu_header)) { |
|
294 |
$wb->menu_header = '<ul>'; |
|
295 |
} |
|
296 |
if (!isset($wb->menu_footer)) { |
|
297 |
$wb->menu_footer = '</ul>'; |
|
298 |
} |
|
299 |
if (!isset($wb->menu_default_class)) { |
|
300 |
$wb->menu_default_class = ' class="menu_default"'; |
|
301 |
} |
|
302 |
if (!isset($wb->menu_current_class)) { |
|
303 |
$wb->menu_current_class = ' class="menu_current"'; |
|
304 |
} |
|
305 |
if (!isset($wb->menu_parent)) { |
|
306 |
$wb->menu_parent = 0; |
|
307 |
} |
|
308 |
$wb->show_menu(); |
|
309 |
} |
|
310 |
|
|
311 |
function show_menu() { |
|
312 |
global $database; |
|
313 |
if ($this->menu_start_level>0) { |
|
314 |
$key_array=array_keys($this->page_trail); |
|
315 |
if (isset($key_array[$this->menu_start_level-1])) { |
|
316 |
$real_start=$key_array[$this->menu_start_level-1]; |
|
317 |
$this->menu_parent=$real_start; |
|
318 |
$this->menu_start_level=0; |
|
319 |
} else { |
|
320 |
return; |
|
321 |
} |
|
322 |
} |
|
323 |
if ($this->menu_recurse==0) |
|
324 |
return; |
|
325 |
// Check if we should add menu number check to query |
|
326 |
if($this->menu_parent == 0) { |
|
327 |
$menu_number = "menu = '$this->menu_number'"; |
|
328 |
} else { |
|
329 |
$menu_number = '1'; |
|
330 |
} |
|
331 |
// Query pages |
|
332 |
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility FROM ". |
|
333 |
TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC"); |
|
334 |
// Check if there are any pages to show |
|
335 |
if($query_menu->numRows() > 0) { |
|
336 |
// Print menu header |
|
337 |
echo "\n".$this->menu_header; |
|
338 |
// Loop through pages |
|
339 |
while($page = $query_menu->fetchRow()) { |
|
340 |
// Check if this page should be shown |
|
341 |
// Create vars |
|
342 |
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]'); |
|
343 |
// Work-out class |
|
344 |
if($page['page_id'] == PAGE_ID) { |
|
345 |
$class = $this->menu_current_class; |
|
346 |
} else { |
|
347 |
$class = $this->menu_default_class; |
|
348 |
} |
|
349 |
// Check if link is same as first page link, and if so change to WB URL |
|
350 |
if($page['link'] == $this->default_link AND !INTRO_PAGE) { |
|
351 |
$link = WB_URL; |
|
352 |
} else { |
|
353 |
$link = $this->page_link($page['link']); |
|
354 |
} |
|
355 |
// Create values |
|
356 |
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', htmlentities($page['menu_title']), htmlentities($page['page_title'])); |
|
357 |
// Replace vars with value and print |
|
358 |
echo "\n".str_replace($vars, $values, $this->menu_item_template); |
|
359 |
// Generate sub-menu |
|
360 |
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) { |
|
361 |
$this->menu_recurse--; |
|
362 |
$this->menu_parent=$page['page_id']; |
|
363 |
$this->show_menu(); |
|
364 |
} |
|
365 |
echo "\n".$this->menu_item_footer; |
|
366 |
} |
|
367 |
// Print menu footer |
|
368 |
echo "\n".$this->menu_footer; |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
|
|
373 |
// Function to show the "Under Construction" page |
|
374 |
function print_under_construction() { |
|
375 |
global $MESSAGE; |
|
376 |
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php'); |
|
377 |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
378 |
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title> |
|
379 |
<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif; |
|
380 |
font-size: 12px; color: #000000; background-color: #FFFFFF; margin: 20px; text-align: center; } |
|
381 |
h1 { margin: 0; padding: 0; }--></style></head><body> |
|
382 |
<h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br /> |
|
383 |
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>'; |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2007, 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 |
exit(0); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
39 |
|
|
40 |
class frontend extends wb { |
|
41 |
// defaults |
|
42 |
var $default_link,$default_page_id; |
|
43 |
// when multiple blocks are used, show home page blocks on |
|
44 |
// pages where no content is defined (search, login, ...) |
|
45 |
var $default_block_content=true; |
|
46 |
|
|
47 |
// page details |
|
48 |
// page database row |
|
49 |
var $page; |
|
50 |
var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility; |
|
51 |
var $page_description,$page_keywords,$page_link; |
|
52 |
var $page_trail=array(); |
|
53 |
|
|
54 |
var $page_access_denied; |
|
55 |
|
|
56 |
// website settings |
|
57 |
var $website_title,$website_description,$website_keywords,$website_header,$website_footer; |
|
58 |
|
|
59 |
// ugly database stuff |
|
60 |
var $extra_where_sql, $sql_where_language; |
|
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 |
header("Location: pages/intro.php"); // send intro.php as header to allow parsing of php statements |
|
76 |
echo ($content); |
|
77 |
return false; |
|
78 |
} |
|
79 |
} |
|
80 |
// Check if we should add page language sql code |
|
81 |
if(PAGE_LANGUAGES) { |
|
82 |
$this->sql_where_language = " AND language = '".LANGUAGE."'"; |
|
83 |
} |
|
84 |
// Get default page |
|
85 |
// Check for a page id |
|
86 |
$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"; |
|
87 |
$get_default = $database->query($query_default); |
|
88 |
$default_num_rows = $get_default->numRows(); |
|
89 |
if(!isset($page_id) OR !is_numeric($page_id)){ |
|
90 |
// Go to or show default page |
|
91 |
if($default_num_rows > 0) { |
|
92 |
$fetch_default = $get_default->fetchRow(); |
|
93 |
$this->default_link = $fetch_default['link']; |
|
94 |
$this->default_page_id = $fetch_default['page_id']; |
|
95 |
// Check if we should redirect or include page inline |
|
96 |
if(HOMEPAGE_REDIRECTION) { |
|
97 |
// Redirect to page |
|
98 |
header("Location: ".$this->page_link($this->default_link)); |
|
99 |
exit(); |
|
100 |
} else { |
|
101 |
// Include page inline |
|
102 |
$this->page_id = $this->default_page_id; |
|
103 |
} |
|
104 |
} else { |
|
105 |
// No pages have been added, so print under construction page |
|
106 |
$this->print_under_construction(); |
|
107 |
exit(); |
|
108 |
} |
|
109 |
} else { |
|
110 |
$this->page_id=$page_id; |
|
111 |
} |
|
112 |
// Get default page link |
|
113 |
if(!isset($fetch_default)) { |
|
114 |
$fetch_default = $get_default->fetchRow(); |
|
115 |
$this->default_link = $fetch_default['link']; |
|
116 |
$this->default_page_id = $fetch_default['page_id']; |
|
117 |
} |
|
118 |
return true; |
|
119 |
} |
|
120 |
|
|
121 |
function get_page_details() { |
|
122 |
global $database; |
|
123 |
if($this->page_id != 0) { |
|
124 |
// Query page details |
|
125 |
$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'"; |
|
126 |
$get_page = $database->query($query_page); |
|
127 |
// Make sure page was found in database |
|
128 |
if($get_page->numRows() == 0) { |
|
129 |
// Print page not found message |
|
130 |
exit("Page not found"); |
|
131 |
} |
|
132 |
// Fetch page details |
|
133 |
$this->page = $get_page->fetchRow(); |
|
134 |
// Check if the page language is also the selected language. If not, send headers again. |
|
135 |
if ($this->page['language']!=LANGUAGE) { |
|
136 |
header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']); |
|
137 |
exit(); |
|
138 |
} |
|
139 |
// Begin code to set details as either variables of constants |
|
140 |
// Page ID |
|
141 |
define('PAGE_ID', $this->page['page_id']); |
|
142 |
// Page Title |
|
143 |
define('PAGE_TITLE', $this->page['page_title']); |
|
144 |
$this->page_title=PAGE_TITLE; |
|
145 |
// Menu Title |
|
146 |
$menu_title = $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 |
if($this->page_description != '') { |
|
172 |
define('PAGE_DESCRIPTION', $this->page_description); |
|
173 |
} else { |
|
174 |
define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION); |
|
175 |
} |
|
176 |
// Page keywords |
|
177 |
$this->page_keywords=$this->page['keywords']; |
|
178 |
// Page link |
|
179 |
$this->link=$this->page_link($this->page['link']); |
|
180 |
|
|
181 |
// End code to set details as either variables of constants |
|
182 |
} |
|
183 |
|
|
184 |
// Figure out what template to use |
|
185 |
if(!defined('TEMPLATE')) { |
|
186 |
if(isset($this->page['template']) AND $this->page['template'] != '') { |
|
187 |
if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) { |
|
188 |
define('TEMPLATE', $this->page['template']); |
|
189 |
} else { |
|
190 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
191 |
} |
|
192 |
} else { |
|
193 |
define('TEMPLATE', DEFAULT_TEMPLATE); |
|
194 |
} |
|
195 |
} |
|
196 |
// Set the template dir |
|
197 |
define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE); |
|
198 |
|
|
199 |
// Check if user is allowed to view this page |
|
200 |
if(VISIBILITY == 'private' OR VISIBILITY == 'registered') { |
|
201 |
// Check if the user is authenticated |
|
202 |
if($this->is_authenticated() == false) { |
|
203 |
// User needs to login first |
|
204 |
header("Location: ".WB_URL."/account/login".PAGE_EXTENSION.'?redirect='.$this->link); |
|
205 |
exit(0); |
|
206 |
} |
|
207 |
// Check if we should show this page |
|
208 |
if($this->show_page($this->page) == false) { |
|
209 |
$this->page_access_denied=true; |
|
210 |
} |
|
211 |
} elseif(VISIBILITY == 'deleted' OR VISIBILITY == 'none') { |
|
212 |
// User isnt allowed on this page so tell them |
|
213 |
$this->page_access_denied=true; |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
function get_website_settings() { |
|
218 |
global $database; |
|
219 |
|
|
220 |
// set visibility SQL code |
|
221 |
// never show no-vis, hidden or deleted pages |
|
222 |
$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'"; |
|
223 |
// Set extra private sql code |
|
224 |
if($this->is_authenticated()==false) { |
|
225 |
// if user is not authenticated, don't show private pages either |
|
226 |
$this->extra_where_sql .= " AND visibility != 'private'"; |
|
227 |
// and 'registered' without frontend login doesn't make much sense! |
|
228 |
if (FRONTEND_LOGIN==false) { |
|
229 |
$this->extra_where_sql .= " AND visibility != 'registered'"; |
|
230 |
} |
|
231 |
} |
|
232 |
$this->extra_where_sql .= $this->sql_where_language; |
|
233 |
|
|
234 |
// Work-out if any possible in-line search boxes should be shown |
|
235 |
if(SEARCH == 'public') { |
|
236 |
define('SHOW_SEARCH', true); |
|
237 |
} elseif(SEARCH == 'private' AND VISIBILITY == 'private') { |
|
238 |
define('SHOW_SEARCH', true); |
|
239 |
} elseif(SEARCH == 'private' AND $wb->is_authenticated() == true) { |
|
240 |
define('SHOW_SEARCH', true); |
|
241 |
} else { |
|
242 |
define('SHOW_SEARCH', false); |
|
243 |
} |
|
244 |
// Work-out if menu should be shown |
|
245 |
if(!defined('SHOW_MENU')) { |
|
246 |
define('SHOW_MENU', true); |
|
247 |
} |
|
248 |
// Work-out if login menu constants should be set |
|
249 |
if(FRONTEND_LOGIN) { |
|
250 |
// Set login menu constants |
|
251 |
define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION); |
|
252 |
define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION); |
|
253 |
define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION); |
|
254 |
define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION); |
|
255 |
define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
function preprocess(&$content) { |
|
260 |
global $database; |
|
261 |
// Replace [wblink--PAGE_ID--] with real link |
|
262 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
263 |
preg_match_all($pattern,$content,$ids); |
|
264 |
foreach($ids[1] AS $page_id) { |
|
265 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
266 |
// Get page link |
|
267 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
268 |
$fetch_link = $get_link->fetchRow(); |
|
269 |
$link = $this->page_link($fetch_link['link']); |
|
270 |
$content = preg_replace($pattern,$link,$content); |
|
271 |
} |
|
272 |
} |
|
273 |
|
|
274 |
function menu() { |
|
275 |
global $wb; |
|
276 |
if (!isset($wb->menu_number)) { |
|
277 |
$wb->menu_number = 1; |
|
278 |
} |
|
279 |
if (!isset($wb->menu_start_level)) { |
|
280 |
$wb->menu_start_level = 0; |
|
281 |
} |
|
282 |
if (!isset($wb->menu_recurse)) { |
|
283 |
$wb->menu_recurse = -1; |
|
284 |
} |
|
285 |
if (!isset($wb->menu_collapse)) { |
|
286 |
$wb->menu_collapse = true; |
|
287 |
} |
|
288 |
if (!isset($wb->menu_item_template)) { |
|
289 |
$wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>'; |
|
290 |
} |
|
291 |
if (!isset($wb->menu_item_footer)) { |
|
292 |
$wb->menu_item_footer = '</li>'; |
|
293 |
} |
|
294 |
if (!isset($wb->menu_header)) { |
|
295 |
$wb->menu_header = '<ul>'; |
|
296 |
} |
|
297 |
if (!isset($wb->menu_footer)) { |
|
298 |
$wb->menu_footer = '</ul>'; |
|
299 |
} |
|
300 |
if (!isset($wb->menu_default_class)) { |
|
301 |
$wb->menu_default_class = ' class="menu_default"'; |
|
302 |
} |
|
303 |
if (!isset($wb->menu_current_class)) { |
|
304 |
$wb->menu_current_class = ' class="menu_current"'; |
|
305 |
} |
|
306 |
if (!isset($wb->menu_parent)) { |
|
307 |
$wb->menu_parent = 0; |
|
308 |
} |
|
309 |
$wb->show_menu(); |
|
310 |
} |
|
311 |
|
|
312 |
function show_menu() { |
|
313 |
global $database; |
|
314 |
if ($this->menu_start_level>0) { |
|
315 |
$key_array=array_keys($this->page_trail); |
|
316 |
if (isset($key_array[$this->menu_start_level-1])) { |
|
317 |
$real_start=$key_array[$this->menu_start_level-1]; |
|
318 |
$this->menu_parent=$real_start; |
|
319 |
$this->menu_start_level=0; |
|
320 |
} else { |
|
321 |
return; |
|
322 |
} |
|
323 |
} |
|
324 |
if ($this->menu_recurse==0) |
|
325 |
return; |
|
326 |
// Check if we should add menu number check to query |
|
327 |
if($this->menu_parent == 0) { |
|
328 |
$menu_number = "menu = '$this->menu_number'"; |
|
329 |
} else { |
|
330 |
$menu_number = '1'; |
|
331 |
} |
|
332 |
// Query pages |
|
333 |
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility FROM ". |
|
334 |
TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC"); |
|
335 |
// Check if there are any pages to show |
|
336 |
if($query_menu->numRows() > 0) { |
|
337 |
// Print menu header |
|
338 |
echo "\n".$this->menu_header; |
|
339 |
// Loop through pages |
|
340 |
while($page = $query_menu->fetchRow()) { |
|
341 |
// Check if this page should be shown |
|
342 |
// Create vars |
|
343 |
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]'); |
|
344 |
// Work-out class |
|
345 |
if($page['page_id'] == PAGE_ID) { |
|
346 |
$class = $this->menu_current_class; |
|
347 |
} else { |
|
348 |
$class = $this->menu_default_class; |
|
349 |
} |
|
350 |
// Check if link is same as first page link, and if so change to WB URL |
|
351 |
if($page['link'] == $this->default_link AND !INTRO_PAGE) { |
|
352 |
$link = WB_URL; |
|
353 |
} else { |
|
354 |
$link = $this->page_link($page['link']); |
|
355 |
} |
|
356 |
// Create values |
|
357 |
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']); |
|
358 |
// Replace vars with value and print |
|
359 |
echo "\n".str_replace($vars, $values, $this->menu_item_template); |
|
360 |
// Generate sub-menu |
|
361 |
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) { |
|
362 |
$this->menu_recurse--; |
|
363 |
$this->menu_parent=$page['page_id']; |
|
364 |
$this->show_menu(); |
|
365 |
} |
|
366 |
echo "\n".$this->menu_item_footer; |
|
367 |
} |
|
368 |
// Print menu footer |
|
369 |
echo "\n".$this->menu_footer; |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
|
|
374 |
// Function to show the "Under Construction" page |
|
375 |
function print_under_construction() { |
|
376 |
global $MESSAGE; |
|
377 |
require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php'); |
|
378 |
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
379 |
<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</title> |
|
380 |
<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif; |
|
381 |
font-size: 12px; color: #000000; background-color: #FFFFFF; margin: 20px; text-align: center; } |
|
382 |
h1 { margin: 0; padding: 0; }--></style></head><body> |
|
383 |
<h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONSTRUCTION'].'</h1><br /> |
|
384 |
'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>'; |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
387 | 388 |
?> |
Also available in: Unified diff
again copied all changes for WB 2.6.6 from trunk to branches