1
|
<?php
|
2
|
|
3
|
// $Id: frontend.functions.php 881 2008-11-22 15:51:23Z thorn $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, 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
|
This file is purely for ensuring compatibility with 3rd party
|
28
|
contributions made for WB version 2.5.2 or below
|
29
|
*/
|
30
|
if(!defined('WB_URL')) {
|
31
|
header('Location: ../index.php');
|
32
|
exit(0);
|
33
|
}
|
34
|
|
35
|
// references to objects and variables that changed their names
|
36
|
|
37
|
$admin = &$wb;
|
38
|
|
39
|
$default_link=&$wb->default_link;
|
40
|
|
41
|
$page_trail=&$wb->page_trail;
|
42
|
$page_description=&$wb->page_description;
|
43
|
$page_keywords=&$wb->page_keywords;
|
44
|
$page_link=&$wb->link;
|
45
|
|
46
|
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
|
47
|
$extra_sql=&$wb->extra_sql;
|
48
|
$extra_where_sql=&$wb->extra_where_sql;
|
49
|
|
50
|
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
|
51
|
$query_result=$database->query($query);
|
52
|
if ($query_result->numRows()>0) {
|
53
|
while ($row = $query_result->fetchRow()) {
|
54
|
$module_dir = $row['directory'];
|
55
|
if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
|
56
|
include(WB_PATH.'/modules/'.$module_dir.'/include.php');
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
|
61
|
// Frontend functions
|
62
|
if (!function_exists('page_link')) {
|
63
|
function page_link($link) {
|
64
|
global $wb;
|
65
|
return $wb->page_link($link);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
//function to highlight search results
|
70
|
if (!function_exists('search_highlight')) {
|
71
|
function search_highlight($foo='', $arr_string=array()) {
|
72
|
require_once(WB_PATH.'/framework/functions.php');
|
73
|
static $string_ul_umlaut = FALSE;
|
74
|
static $string_ul_regex = FALSE;
|
75
|
if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE)
|
76
|
require(WB_PATH.'/search/search_convert.php');
|
77
|
$foo = entities_to_umlauts($foo, 'UTF-8');
|
78
|
array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'/\');'));
|
79
|
$search_string = implode("|", $arr_string);
|
80
|
$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
|
81
|
// the highlighting
|
82
|
// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
|
83
|
// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
|
84
|
// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
|
85
|
$matches = preg_split("/(<style.*<\/style>|<script.*<\/script>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)/iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
|
86
|
if(is_array($matches) && $matches != array()) {
|
87
|
$foo = "";
|
88
|
foreach($matches as $match) {
|
89
|
if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match)) {
|
90
|
$match = str_replace(array('<', '>', '&', '"', ''', ' '), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
|
91
|
$match = preg_replace('/('.$string.')/ui', '_span class=_highlight__$1_/span_',$match);
|
92
|
$match = str_replace(array('<', '>', '&', '"', '\'', "\xC2\xA0"), array('<', '>', '&', '"', ''', ' '), $match);
|
93
|
$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
|
94
|
}
|
95
|
$foo .= $match;
|
96
|
}
|
97
|
}
|
98
|
|
99
|
if(DEFAULT_CHARSET != 'utf-8') {
|
100
|
$foo = umlauts_to_entities($foo, 'UTF-8');
|
101
|
}
|
102
|
return $foo;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
// Old menu call invokes new menu function
|
107
|
if (!function_exists('page_menu')) {
|
108
|
function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a] [menu_title] [/a]</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
|
109
|
global $wb;
|
110
|
$wb->menu_number=$menu_number;
|
111
|
$wb->menu_item_template=$item_template;
|
112
|
$wb->menu_item_footer='';
|
113
|
$wb->menu_parent = $parent;
|
114
|
$wb->menu_header = $menu_header;
|
115
|
$wb->menu_footer = $menu_footer;
|
116
|
$wb->menu_default_class = $default_class;
|
117
|
$wb->menu_current_class = $current_class;
|
118
|
$wb->menu_recurse = $recurse+2;
|
119
|
$wb->menu();
|
120
|
unset($wb->menu_parent);
|
121
|
unset($wb->menu_number);
|
122
|
unset($wb->menu_item_template);
|
123
|
unset($wb->menu_item_footer);
|
124
|
unset($wb->menu_header);
|
125
|
unset($wb->menu_footer);
|
126
|
unset($wb->menu_default_class);
|
127
|
unset($wb->menu_current_class);
|
128
|
unset($wb->menu_start_level);
|
129
|
unset($wb->menu_collapse);
|
130
|
unset($wb->menu_recurse);
|
131
|
}
|
132
|
}
|
133
|
|
134
|
if (!function_exists('show_menu')) {
|
135
|
function show_menu($menu_number = NULL, $start_level=NULL, $recurse = NULL, $collapse = NULL, $item_template = NULL, $item_footer = NULL, $menu_header = NULL, $menu_footer = NULL, $default_class = NULL, $current_class = NULL, $parent = NULL) {
|
136
|
global $wb;
|
137
|
if (isset($menu_number))
|
138
|
$wb->menu_number=$menu_number;
|
139
|
if (isset($start_level))
|
140
|
$wb->menu_start_level=$start_level;
|
141
|
if (isset($recurse))
|
142
|
$wb->menu_recurse=$recurse;
|
143
|
if (isset($collapse))
|
144
|
$wb->menu_collapse=$collapse;
|
145
|
if (isset($item_template))
|
146
|
$wb->menu_item_template=$item_template;
|
147
|
if (isset($item_footer))
|
148
|
$wb->menu_item_footer=$item_footer;
|
149
|
if (isset($menu_header))
|
150
|
$wb->menu_header=$menu_header;
|
151
|
if (isset($menu_footer))
|
152
|
$wb->menu_footer=$menu_footer;
|
153
|
if (isset($default_class))
|
154
|
$wb->menu_default_class=$default_class;
|
155
|
if (isset($current_class))
|
156
|
$wb->menu_current_class=$current_class;
|
157
|
if (isset($parent))
|
158
|
$wb->menu_parent=$parent;
|
159
|
$wb->menu();
|
160
|
unset($wb->menu_recurse);
|
161
|
unset($wb->menu_parent);
|
162
|
unset($wb->menu_start_level);
|
163
|
}
|
164
|
}
|
165
|
|
166
|
if (!function_exists('page_content')) {
|
167
|
function page_content($block = 1) {
|
168
|
// Get outside objects
|
169
|
global $TEXT,$MENU,$HEADING,$MESSAGE;
|
170
|
global $globals;
|
171
|
global $database;
|
172
|
global $wb;
|
173
|
$admin = & $wb;
|
174
|
if ($wb->page_access_denied==true) {
|
175
|
echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
|
176
|
exit();
|
177
|
}
|
178
|
if ($wb->page_no_active_sections==true) {
|
179
|
echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
|
180
|
exit();
|
181
|
}
|
182
|
if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
|
183
|
// Make sure block is numeric
|
184
|
if(!is_numeric($block)) { $block = 1; }
|
185
|
// Include page content
|
186
|
if(!defined('PAGE_CONTENT') OR $block!=1) {
|
187
|
$page_id=$wb->page_id;
|
188
|
// First get all sections for this page
|
189
|
$query_sections = $database->query("SELECT section_id,module,publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
|
190
|
// If none were found, check if default content is supposed to be shown
|
191
|
if($query_sections->numRows() == 0) {
|
192
|
if ($wb->default_block_content=='none') {
|
193
|
return;
|
194
|
}
|
195
|
if (is_numeric($wb->default_block_content)) {
|
196
|
$page_id=$wb->default_block_content;
|
197
|
} else {
|
198
|
$page_id=$wb->default_page_id;
|
199
|
}
|
200
|
$query_sections = $database->query("SELECT section_id,module,publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
|
201
|
// Still no cotent found? Give it up, there's just nothing to show!
|
202
|
if($query_sections->numRows() == 0) {
|
203
|
return;
|
204
|
}
|
205
|
}
|
206
|
// Loop through them and include their module file
|
207
|
while($section = $query_sections->fetchRow()) {
|
208
|
// skip this section if it is out of publication-date
|
209
|
$now = time();
|
210
|
if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
|
211
|
continue;
|
212
|
}
|
213
|
$section_id = $section['section_id'];
|
214
|
$module = $section['module'];
|
215
|
// make a anchor for every section.
|
216
|
if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
|
217
|
echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
|
218
|
}
|
219
|
|
220
|
// fetch content -- this is where to place possible output-filters (before highlighting)
|
221
|
ob_start(); // fetch original content
|
222
|
require(WB_PATH.'/modules/'.$module.'/view.php');
|
223
|
$content = ob_get_contents();
|
224
|
ob_end_clean();
|
225
|
|
226
|
// highlights searchresults
|
227
|
if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
|
228
|
$arr_string = explode(" ", $_GET['sstring']);
|
229
|
if($_GET['searchresult']==2) { // exact match
|
230
|
$arr_string[0] = str_replace("_", " ", $arr_string[0]);
|
231
|
}
|
232
|
echo search_highlight($content, $arr_string);
|
233
|
} else {
|
234
|
echo $content;
|
235
|
}
|
236
|
}
|
237
|
} else {
|
238
|
require(PAGE_CONTENT);
|
239
|
}
|
240
|
}
|
241
|
}
|
242
|
|
243
|
if (!function_exists('show_content')) {
|
244
|
function show_content($block=1) {
|
245
|
page_content($block);
|
246
|
}
|
247
|
}
|
248
|
|
249
|
if (!function_exists('show_breadcrumbs')) {
|
250
|
function show_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
|
251
|
global $wb;
|
252
|
$page_id=$wb->page_id;
|
253
|
if ($page_id!=0)
|
254
|
{
|
255
|
global $database;
|
256
|
$bca=$wb->page_trail;
|
257
|
$counter=0;
|
258
|
foreach ($bca as $temp)
|
259
|
{
|
260
|
if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
|
261
|
{
|
262
|
if ($counter>=$tier) echo $sep;
|
263
|
$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
|
264
|
$page=$query_menu->fetchRow();
|
265
|
if ($links==true AND $temp!=$page_id)
|
266
|
echo '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
|
267
|
else
|
268
|
echo $page['menu_title'];
|
269
|
}
|
270
|
$counter++;
|
271
|
}
|
272
|
}
|
273
|
}
|
274
|
}
|
275
|
|
276
|
// Function for page title
|
277
|
if (!function_exists('page_title')) {
|
278
|
function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
|
279
|
$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
|
280
|
$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
|
281
|
echo str_replace($vars, $values, $template);
|
282
|
}
|
283
|
}
|
284
|
|
285
|
// Function for page description
|
286
|
if (!function_exists('page_description')) {
|
287
|
function page_description() {
|
288
|
global $wb;
|
289
|
if ($wb->page_description!='') {
|
290
|
echo $wb->page_description;
|
291
|
} else {
|
292
|
echo WEBSITE_DESCRIPTION;
|
293
|
}
|
294
|
}
|
295
|
}
|
296
|
|
297
|
// Function for page keywords
|
298
|
if (!function_exists('page_keywords')) {
|
299
|
function page_keywords() {
|
300
|
global $wb;
|
301
|
if ($wb->page_keywords!='') {
|
302
|
echo $wb->page_keywords;
|
303
|
} else {
|
304
|
echo WEBSITE_KEYWORDS;
|
305
|
}
|
306
|
}
|
307
|
}
|
308
|
|
309
|
// Function for page header
|
310
|
if (!function_exists('page_header')) {
|
311
|
function page_header($date_format = 'Y') {
|
312
|
echo WEBSITE_HEADER;
|
313
|
}
|
314
|
}
|
315
|
|
316
|
// Function for page footer
|
317
|
if (!function_exists('page_footer')) {
|
318
|
function page_footer($date_format = 'Y') {
|
319
|
global $starttime;
|
320
|
$vars = array('[YEAR]', '[PROCESS_TIME]');
|
321
|
$processtime=array_sum(explode(" ",microtime()))-$starttime;
|
322
|
$values = array(date($date_format),$processtime);
|
323
|
echo str_replace($vars, $values, WEBSITE_FOOTER);
|
324
|
}
|
325
|
}
|
326
|
|
327
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
|
328
|
if(!function_exists('register_frontend_modfiles')) {
|
329
|
function register_frontend_modfiles($file_id="css") {
|
330
|
// sanity check of parameter passed to the function
|
331
|
$file_id = strtolower($file_id);
|
332
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
333
|
return;
|
334
|
}
|
335
|
|
336
|
global $wb, $database;
|
337
|
// define default baselink and filename for optional module javascript and stylesheet files
|
338
|
$head_links = "";
|
339
|
if($file_id == "css") {
|
340
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
|
341
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
342
|
$base_file = "frontend.css";
|
343
|
} else {
|
344
|
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
|
345
|
$base_file = "frontend.js";
|
346
|
}
|
347
|
|
348
|
// gather information for all models embedded on actual page
|
349
|
$page_id = $wb->page_id;
|
350
|
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
|
351
|
WHERE page_id=$page_id AND module<>'wysiwyg'");
|
352
|
|
353
|
while($row = $query_modules->fetchRow()) {
|
354
|
// check if page module directory contains a frontend.js or frontend.css file
|
355
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
356
|
// create link with frontend.js or frontend.css source for the current module
|
357
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
358
|
|
359
|
// define constant indicating that the register_frontent_files was invoked
|
360
|
if($file_id == 'css') {
|
361
|
if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
|
362
|
} else {
|
363
|
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
|
364
|
}
|
365
|
|
366
|
// ensure that frontend.js or frontend.css is only added once per module type
|
367
|
if(strpos($head_links, $tmp_link) === false) {
|
368
|
$head_links .= $tmp_link ."\n";
|
369
|
}
|
370
|
}
|
371
|
}
|
372
|
// include the Javascript email protection function
|
373
|
if($file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js')) {
|
374
|
$head_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/output_filter/js/mdcr.js"></script>' ."\n";
|
375
|
}
|
376
|
|
377
|
// write out links with all external module javascript/CSS files, remove last line feed
|
378
|
echo $head_links;
|
379
|
}
|
380
|
}
|
381
|
|
382
|
// Begin WB < 2.4.x template compatibility code
|
383
|
// Make extra_sql accessable through private_sql
|
384
|
$private_sql = $extra_sql;
|
385
|
$private_where_sql = $extra_where_sql;
|
386
|
// Query pages for menu
|
387
|
$menu1 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND $extra_where_sql ORDER BY position ASC");
|
388
|
// Check if current pages is a parent page and if we need its submenu
|
389
|
if(PARENT == 0) {
|
390
|
// Get the pages submenu
|
391
|
$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PAGE_ID."' AND $extra_where_sql ORDER BY position ASC");
|
392
|
} else {
|
393
|
// Get the pages submenu
|
394
|
$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PARENT."' AND $extra_where_sql ORDER BY position ASC");
|
395
|
}
|
396
|
// End WB < 2.4.x template compatibility code
|
397
|
// Include template file
|
398
|
|
399
|
|
400
|
?>
|