1
|
<?php
|
2
|
|
3
|
// $Id: frontend.functions.php 1181 2009-11-24 18:42:19Z Luisehahne $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2009, 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
|
$include_head_link_css = '';
|
51
|
$include_body_links = '';
|
52
|
$include_head_links = '';
|
53
|
// workout to included frontend.css, fronten.js and frontend_body.js in snippets
|
54
|
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
|
55
|
$query_result=$database->query($query);
|
56
|
if ($query_result->numRows()>0) {
|
57
|
while ($row = $query_result->fetchRow()) {
|
58
|
$module_dir = $row['directory'];
|
59
|
if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
|
60
|
include(WB_PATH.'/modules/'.$module_dir.'/include.php');
|
61
|
/* check if frontend.css file needs to be included into the <head></head> of index.php
|
62
|
*/
|
63
|
if( file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
|
64
|
$include_head_link_css .= '<link href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css"';
|
65
|
$include_head_link_css .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
|
66
|
$include_head_file = 'frontend.css';
|
67
|
}
|
68
|
// check if frontend.js file needs to be included into the <body></body> of index.php
|
69
|
if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
|
70
|
$include_head_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript"></script>'."\n";
|
71
|
$include_head_file = 'frontend.js';
|
72
|
}
|
73
|
// check if frontend_body.js file needs to be included into the <body></body> of index.php
|
74
|
if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
|
75
|
$include_body_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript"></script>'."\n";
|
76
|
$include_body_file = 'frontend_body.js';
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
// Frontend functions
|
83
|
if (!function_exists('page_link')) {
|
84
|
function page_link($link) {
|
85
|
global $wb;
|
86
|
return $wb->page_link($link);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
//function to highlight search results
|
91
|
if(!function_exists('search_highlight')) {
|
92
|
function search_highlight($foo='', $arr_string=array()) {
|
93
|
require_once(WB_PATH.'/framework/functions.php');
|
94
|
static $string_ul_umlaut = FALSE;
|
95
|
static $string_ul_regex = FALSE;
|
96
|
if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE)
|
97
|
require(WB_PATH.'/search/search_convert.php');
|
98
|
$foo = entities_to_umlauts($foo, 'UTF-8');
|
99
|
array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
|
100
|
$search_string = implode("|", $arr_string);
|
101
|
$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
|
102
|
// the highlighting
|
103
|
// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
|
104
|
// Also droplet tags are now excluded from highlighting.
|
105
|
// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
|
106
|
// we have to cut <pre> and <code> as well.
|
107
|
// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
|
108
|
$matches = preg_split("~(\[\[.*\]\]|<style.*</style>|<script.*</script>|<pre.*</pre>|<code.*</code>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)~iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
|
109
|
if(is_array($matches) && $matches != array()) {
|
110
|
$foo = "";
|
111
|
foreach($matches as $match) {
|
112
|
if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
|
113
|
$match = str_replace(array('<', '>', '&', '"', ''', ' '), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
|
114
|
$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
|
115
|
$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&', '<', '>', '"', ''', ' '), $match);
|
116
|
$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
|
117
|
}
|
118
|
$foo .= $match;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
if(DEFAULT_CHARSET != 'utf-8') {
|
123
|
$foo = umlauts_to_entities($foo, 'UTF-8');
|
124
|
}
|
125
|
return $foo;
|
126
|
}
|
127
|
}
|
128
|
|
129
|
// Old menu call invokes new menu function
|
130
|
if (!function_exists('page_menu')) {
|
131
|
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) {
|
132
|
global $wb;
|
133
|
$wb->menu_number=$menu_number;
|
134
|
$wb->menu_item_template=$item_template;
|
135
|
$wb->menu_item_footer='';
|
136
|
$wb->menu_parent = $parent;
|
137
|
$wb->menu_header = $menu_header;
|
138
|
$wb->menu_footer = $menu_footer;
|
139
|
$wb->menu_default_class = $default_class;
|
140
|
$wb->menu_current_class = $current_class;
|
141
|
$wb->menu_recurse = $recurse+2;
|
142
|
$wb->menu();
|
143
|
unset($wb->menu_parent);
|
144
|
unset($wb->menu_number);
|
145
|
unset($wb->menu_item_template);
|
146
|
unset($wb->menu_item_footer);
|
147
|
unset($wb->menu_header);
|
148
|
unset($wb->menu_footer);
|
149
|
unset($wb->menu_default_class);
|
150
|
unset($wb->menu_current_class);
|
151
|
unset($wb->menu_start_level);
|
152
|
unset($wb->menu_collapse);
|
153
|
unset($wb->menu_recurse);
|
154
|
}
|
155
|
}
|
156
|
|
157
|
if (!function_exists('show_menu')) {
|
158
|
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) {
|
159
|
global $wb;
|
160
|
if (isset($menu_number))
|
161
|
$wb->menu_number=$menu_number;
|
162
|
if (isset($start_level))
|
163
|
$wb->menu_start_level=$start_level;
|
164
|
if (isset($recurse))
|
165
|
$wb->menu_recurse=$recurse;
|
166
|
if (isset($collapse))
|
167
|
$wb->menu_collapse=$collapse;
|
168
|
if (isset($item_template))
|
169
|
$wb->menu_item_template=$item_template;
|
170
|
if (isset($item_footer))
|
171
|
$wb->menu_item_footer=$item_footer;
|
172
|
if (isset($menu_header))
|
173
|
$wb->menu_header=$menu_header;
|
174
|
if (isset($menu_footer))
|
175
|
$wb->menu_footer=$menu_footer;
|
176
|
if (isset($default_class))
|
177
|
$wb->menu_default_class=$default_class;
|
178
|
if (isset($current_class))
|
179
|
$wb->menu_current_class=$current_class;
|
180
|
if (isset($parent))
|
181
|
$wb->menu_parent=$parent;
|
182
|
$wb->menu();
|
183
|
unset($wb->menu_recurse);
|
184
|
unset($wb->menu_parent);
|
185
|
unset($wb->menu_start_level);
|
186
|
}
|
187
|
}
|
188
|
|
189
|
if (!function_exists('page_content')) {
|
190
|
function page_content($block = 1) {
|
191
|
// Get outside objects
|
192
|
global $TEXT,$MENU,$HEADING,$MESSAGE;
|
193
|
global $globals;
|
194
|
global $database;
|
195
|
global $wb;
|
196
|
$admin = & $wb;
|
197
|
if ($wb->page_access_denied==true) {
|
198
|
echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
|
199
|
exit();
|
200
|
}
|
201
|
if ($wb->page_no_active_sections==true) {
|
202
|
echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
|
203
|
exit();
|
204
|
}
|
205
|
if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
|
206
|
// Make sure block is numeric
|
207
|
if(!is_numeric($block)) { $block = 1; }
|
208
|
// Include page content
|
209
|
if(!defined('PAGE_CONTENT') OR $block!=1)
|
210
|
{
|
211
|
$page_id=$wb->page_id;
|
212
|
// set session variable to save page_id only if PAGE_CONTENT is empty
|
213
|
$_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
|
214
|
// set to new value if page_id changed and not 0
|
215
|
if(($page_id != 0) AND ($_SESSION['PAGE_ID'] <> $page_id))
|
216
|
{
|
217
|
$_SESSION['PAGE_ID'] = $page_id;
|
218
|
}
|
219
|
|
220
|
// First get all sections for this page
|
221
|
$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");
|
222
|
// If none were found, check if default content is supposed to be shown
|
223
|
if($query_sections->numRows() == 0) {
|
224
|
if ($wb->default_block_content=='none') {
|
225
|
return;
|
226
|
}
|
227
|
if (is_numeric($wb->default_block_content)) {
|
228
|
$page_id=$wb->default_block_content;
|
229
|
} else {
|
230
|
$page_id=$wb->default_page_id;
|
231
|
}
|
232
|
$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");
|
233
|
// Still no cotent found? Give it up, there's just nothing to show!
|
234
|
if($query_sections->numRows() == 0) {
|
235
|
return;
|
236
|
}
|
237
|
}
|
238
|
// Loop through them and include their module file
|
239
|
while($section = $query_sections->fetchRow()) {
|
240
|
// skip this section if it is out of publication-date
|
241
|
$now = time();
|
242
|
if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
|
243
|
continue;
|
244
|
}
|
245
|
$section_id = $section['section_id'];
|
246
|
$module = $section['module'];
|
247
|
// make a anchor for every section.
|
248
|
if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
|
249
|
echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
|
250
|
}
|
251
|
|
252
|
// fetch content -- this is where to place possible output-filters (before highlighting)
|
253
|
ob_start(); // fetch original content
|
254
|
require(WB_PATH.'/modules/'.$module.'/view.php');
|
255
|
$content = ob_get_contents();
|
256
|
ob_end_clean();
|
257
|
|
258
|
// highlights searchresults
|
259
|
if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
|
260
|
$arr_string = explode(" ", $_GET['sstring']);
|
261
|
if($_GET['searchresult']==2) { // exact match
|
262
|
$arr_string[0] = str_replace("_", " ", $arr_string[0]);
|
263
|
}
|
264
|
echo search_highlight($content, $arr_string);
|
265
|
} else {
|
266
|
echo $content;
|
267
|
}
|
268
|
}
|
269
|
} else {
|
270
|
require(PAGE_CONTENT);
|
271
|
}
|
272
|
}
|
273
|
}
|
274
|
|
275
|
if (!function_exists('show_content')) {
|
276
|
function show_content($block=1) {
|
277
|
page_content($block);
|
278
|
}
|
279
|
}
|
280
|
|
281
|
if (!function_exists('show_breadcrumbs'))
|
282
|
{
|
283
|
function show_breadcrumbs($sep=' » ',$tier=1,$links=true,$depth=-1, $title='You are here: ')
|
284
|
{
|
285
|
global $wb;
|
286
|
$page_id=$wb->page_id;
|
287
|
if ($page_id!=0)
|
288
|
{
|
289
|
global $database;
|
290
|
$bca=$wb->page_trail;
|
291
|
$counter=0;
|
292
|
print '<div class="breadcrumb">'.$title;
|
293
|
|
294
|
foreach ($bca as $temp)
|
295
|
{
|
296
|
if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
|
297
|
{
|
298
|
if ($counter>=$tier) print '<span class="separator">'.$sep.'</span>';
|
299
|
$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
|
300
|
$page=$query_menu->fetchRow();
|
301
|
if ($links==true AND $temp!=$page_id)
|
302
|
print '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
|
303
|
else
|
304
|
print '<span class="crumb">'.$page['menu_title'].'</span>';
|
305
|
}
|
306
|
$counter++;
|
307
|
}
|
308
|
print "</div>\n";
|
309
|
}
|
310
|
}
|
311
|
}
|
312
|
|
313
|
// Function for page title
|
314
|
if (!function_exists('page_title')) {
|
315
|
function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
|
316
|
$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
|
317
|
$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
|
318
|
echo str_replace($vars, $values, $template);
|
319
|
}
|
320
|
}
|
321
|
|
322
|
// Function for page description
|
323
|
if (!function_exists('page_description')) {
|
324
|
function page_description() {
|
325
|
global $wb;
|
326
|
if ($wb->page_description!='') {
|
327
|
echo $wb->page_description;
|
328
|
} else {
|
329
|
echo WEBSITE_DESCRIPTION;
|
330
|
}
|
331
|
}
|
332
|
}
|
333
|
|
334
|
// Function for page keywords
|
335
|
if (!function_exists('page_keywords')) {
|
336
|
function page_keywords() {
|
337
|
global $wb;
|
338
|
if ($wb->page_keywords!='') {
|
339
|
echo $wb->page_keywords;
|
340
|
} else {
|
341
|
echo WEBSITE_KEYWORDS;
|
342
|
}
|
343
|
}
|
344
|
}
|
345
|
|
346
|
// Function for page header
|
347
|
if (!function_exists('page_header')) {
|
348
|
function page_header($date_format = 'Y') {
|
349
|
echo WEBSITE_HEADER;
|
350
|
}
|
351
|
}
|
352
|
|
353
|
// Function for page footer
|
354
|
if (!function_exists('page_footer')) {
|
355
|
function page_footer($date_format = 'Y') {
|
356
|
global $starttime;
|
357
|
$vars = array('[YEAR]', '[PROCESS_TIME]');
|
358
|
$processtime=array_sum(explode(" ",microtime()))-$starttime;
|
359
|
$values = array(gmdate($date_format),$processtime);
|
360
|
echo str_replace($vars, $values, WEBSITE_FOOTER);
|
361
|
}
|
362
|
}
|
363
|
|
364
|
function bind_jquery ($file_id='jquery')
|
365
|
{
|
366
|
$jquery_links = '';
|
367
|
/* include the Javascript jquery api */
|
368
|
if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
|
369
|
{
|
370
|
$wbpath = str_replace('\\','/',WB_PATH); // fixed localhost problem with ie
|
371
|
$jquery_links .= "<script type=\"text/javascript\">\n"
|
372
|
."var URL = '".WB_URL."';\n"
|
373
|
."var WB_PATH = '".$wbpath."';\n"
|
374
|
."var WB_URL = '".WB_URL."';\n"
|
375
|
."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
|
376
|
."</script>\n";
|
377
|
|
378
|
$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
|
379
|
$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-ui-min.js" type="text/javascript"></script>'."\n";
|
380
|
$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
|
381
|
/* workout to insert ui.css and theme */
|
382
|
$jquery_theme = WB_PATH.'/modules/jquery/jquery_theme.js';
|
383
|
$jquery_links .= file_exists($jquery_theme)
|
384
|
? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
|
385
|
: '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
|
386
|
/* workout to insert plugins functions, set in templatedir */
|
387
|
$jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
|
388
|
$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
|
389
|
? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
|
390
|
: '';
|
391
|
}
|
392
|
return $jquery_links;
|
393
|
}
|
394
|
|
395
|
|
396
|
// Function to add optional module Javascript into the <body> section of the frontend
|
397
|
if(!function_exists('register_frontend_modfiles_body'))
|
398
|
{
|
399
|
function register_frontend_modfiles_body($file_id="js")
|
400
|
{
|
401
|
// sanity check of parameter passed to the function
|
402
|
$file_id = strtolower($file_id);
|
403
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
|
404
|
{
|
405
|
return;
|
406
|
}
|
407
|
|
408
|
// define constant indicating that the register_frontent_files was invoked
|
409
|
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
|
410
|
global $wb, $database, $include_body_links;
|
411
|
// define default baselink and filename for optional module javascript files
|
412
|
$body_links = "";
|
413
|
|
414
|
/* include the Javascript jquery api */
|
415
|
$body_links .= bind_jquery($file_id);
|
416
|
|
417
|
if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
|
418
|
{
|
419
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
|
420
|
$base_file = "frontend_body.js";
|
421
|
|
422
|
// ensure that frontend_body.js is only added once per module type
|
423
|
if(!empty($include_body_links))
|
424
|
{
|
425
|
if(strpos($body_links, $include_body_links) === false)
|
426
|
{
|
427
|
$body_links .= $include_body_links;
|
428
|
}
|
429
|
$include_body_links = '';
|
430
|
}
|
431
|
|
432
|
// gather information for all models embedded on actual page
|
433
|
$page_id = $wb->page_id;
|
434
|
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
|
435
|
WHERE page_id=$page_id AND module<>'wysiwyg'");
|
436
|
|
437
|
while($row = $query_modules->fetchRow())
|
438
|
{
|
439
|
// check if page module directory contains a frontend_body.js file
|
440
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
441
|
// create link with frontend_body.js source for the current module
|
442
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
443
|
|
444
|
// define constant indicating that the register_frontent_files_body was invoked
|
445
|
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
|
446
|
|
447
|
// ensure that frontend_body.js is only added once per module type
|
448
|
if(strpos($body_links, $tmp_link) === false) {
|
449
|
$body_links .= $tmp_link;
|
450
|
}
|
451
|
}
|
452
|
}
|
453
|
}
|
454
|
|
455
|
print $body_links."\n"; ;
|
456
|
}
|
457
|
}
|
458
|
|
459
|
|
460
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
|
461
|
if(!function_exists('register_frontend_modfiles'))
|
462
|
{
|
463
|
function register_frontend_modfiles($file_id="css")
|
464
|
{
|
465
|
// sanity check of parameter passed to the function
|
466
|
$file_id = strtolower($file_id);
|
467
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
|
468
|
{
|
469
|
return;
|
470
|
}
|
471
|
|
472
|
global $wb, $database, $include_head_link_css, $include_head_links;
|
473
|
// define default baselink and filename for optional module javascript and stylesheet files
|
474
|
$head_links = "";
|
475
|
|
476
|
switch ($file_id)
|
477
|
{
|
478
|
case 'css':
|
479
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
|
480
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
481
|
$base_file = "frontend.css";
|
482
|
if(!empty($include_head_link_css))
|
483
|
{
|
484
|
$head_links .= !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
|
485
|
$include_head_link_css = '';
|
486
|
}
|
487
|
break;
|
488
|
case 'jquery':
|
489
|
$head_links .= bind_jquery($file_id);
|
490
|
break;
|
491
|
case 'js':
|
492
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
|
493
|
$base_file = "frontend.js";
|
494
|
if(!empty($include_head_links))
|
495
|
{
|
496
|
$head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
|
497
|
$include_head_links = '';
|
498
|
}
|
499
|
break;
|
500
|
default:
|
501
|
break;
|
502
|
}
|
503
|
|
504
|
if(!empty($include_head_link_css)) {
|
505
|
if(strpos($head_links, $include_head_link_css) === false) {
|
506
|
$head_links .= $include_head_link_css;
|
507
|
}
|
508
|
$include_head_link_css = '';
|
509
|
} else {
|
510
|
if(!empty($include_head_links)) {
|
511
|
if(strpos($head_links, $include_head_links) === false) {
|
512
|
$head_links .= $include_head_links;
|
513
|
}
|
514
|
$include_head_links = '';
|
515
|
}
|
516
|
}
|
517
|
|
518
|
if( $file_id != 'jquery')
|
519
|
{
|
520
|
|
521
|
// gather information for all models embedded on actual page
|
522
|
$page_id = $wb->page_id;
|
523
|
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
|
524
|
WHERE page_id=$page_id AND module<>'wysiwyg'");
|
525
|
|
526
|
while($row = $query_modules->fetchRow())
|
527
|
{
|
528
|
// check if page module directory contains a frontend.js or frontend.css file
|
529
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
|
530
|
{
|
531
|
// create link with frontend.js or frontend.css source for the current module
|
532
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
533
|
|
534
|
// define constant indicating that the register_frontent_files was invoked
|
535
|
if($file_id == 'css')
|
536
|
{
|
537
|
if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
|
538
|
} else
|
539
|
{
|
540
|
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
|
541
|
}
|
542
|
// ensure that frontend.js or frontend.css is only added once per module type
|
543
|
if(strpos($head_links, $tmp_link) === false)
|
544
|
{
|
545
|
$head_links .= $tmp_link."\n";
|
546
|
}
|
547
|
};
|
548
|
}
|
549
|
// include the Javascript email protection function
|
550
|
if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
|
551
|
{
|
552
|
$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
|
553
|
}
|
554
|
elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
|
555
|
{
|
556
|
$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
|
557
|
}
|
558
|
}
|
559
|
print $head_links;
|
560
|
}
|
561
|
}
|
562
|
|
563
|
// Begin WB < 2.4.x template compatibility code
|
564
|
// Make extra_sql accessable through private_sql
|
565
|
$private_sql = $extra_sql;
|
566
|
$private_where_sql = $extra_where_sql;
|
567
|
// Query pages for menu
|
568
|
$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");
|
569
|
// Check if current pages is a parent page and if we need its submenu
|
570
|
if(PARENT == 0) {
|
571
|
// Get the pages submenu
|
572
|
$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");
|
573
|
} else {
|
574
|
// Get the pages submenu
|
575
|
$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");
|
576
|
}
|
577
|
// End WB < 2.4.x template compatibility code
|
578
|
// Include template file
|
579
|
|
580
|
|
581
|
?>
|