Project

General

Profile

1
<?php
2
/****************************************************************************
3
* SVN Version information:
4
*
5
* $Id: frontend.functions.php 1234 2010-01-05 02:20:20Z Luisehahne $
6
*
7
*
8
*
9
*****************************************************************************
10
*                          WebsiteBaker
11
*
12
* WebsiteBaker Project <http://www.websitebaker2.org/>
13
* Copyright (C) 2009, Website Baker Org. e.V.
14
*         http://start.websitebaker2.org/impressum-datenschutz.php
15
* Copyright (C) 2004-2009, Ryan Djurovich
16
*
17
*                        About WebsiteBaker
18
*
19
* Website Baker is a PHP-based Content Management System (CMS)
20
* designed with one goal in mind: to enable its users to produce websites
21
* with ease.
22
*
23
*****************************************************************************
24
*
25
*****************************************************************************
26
*                        LICENSE INFORMATION
27
*
28
* WebsiteBaker is free software; you can redistribute it and/or
29
* modify it under the terms of the GNU General Public License
30
* as published by the Free Software Foundation; either version 2
31
* of the License, or (at your option) any later version.
32
*
33
* WebsiteBaker is distributed in the hope that it will be useful,
34
* but WITHOUT ANY WARRANTY; without even the implied warranty of
35
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36
* See the GNU General Public License for more details.
37
*
38
* You should have received a copy of the GNU General Public License
39
* along with this program; if not, write to the Free Software
40
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
41
****************************************************************************
42
*
43
*                   WebsiteBaker Extra Information
44
*
45
* Version file
46
*
47
*   This file is purely for ensuring compatibility with 3rd party
48
*	contributions made for WB version 2.5.2 or below
49
*
50
*
51
*
52
*****************************************************************************/
53
/**
54
 *
55
 * @category     frontend
56
 * @package      functions
57
 * @author       Ryan Djurovich
58
 * @copyright    2004-2009, Ryan Djurovich
59
 * @copyright    2009-2010, Website Baker Org. e.V.
60
 * @version      $Id: frontend.functions.php 1234 2010-01-05 02:20:20Z Luisehahne $
61
 * @platform     WebsiteBaker 2.8.x
62
 * @requirements >= PHP 4.3.4
63
 * @license      http://www.gnu.org/licenses/gpl.html
64
 *
65
 */
66

    
67
if(!defined('WB_URL')) {
68
	header('Location: ../index.php');
69
	exit(0);
70
}
71

    
72
// references to objects and variables that changed their names
73

    
74
$admin = &$wb;
75

    
76
$default_link=&$wb->default_link;
77

    
78
$page_trail=&$wb->page_trail;
79
$page_description=&$wb->page_description;
80
$page_keywords=&$wb->page_keywords;
81
$page_link=&$wb->link;
82

    
83
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
84
$extra_sql=&$wb->extra_sql;
85
$extra_where_sql=&$wb->extra_where_sql;
86

    
87
$include_head_link_css = '';
88
$include_body_links = '';
89
$include_head_links = '';
90
// workout to included frontend.css, fronten.js and frontend_body.js in snippets
91
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
92
$query_result=$database->query($query);
93
if ($query_result->numRows()>0) {
94
	while ($row = $query_result->fetchRow()) {
95
		$module_dir = $row['directory'];
96
		if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
97
			include(WB_PATH.'/modules/'.$module_dir.'/include.php');
98
			/* check if frontend.css file needs to be included into the <head></head> of index.php
99
			*/
100
			if( file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
101
				$include_head_link_css .= '<link href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css"';
102
				$include_head_link_css .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
103
				$include_head_file = 'frontend.css';
104
			}
105
			// check if frontend.js file needs to be included into the <body></body> of index.php
106
			if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
107
				$include_head_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript"></script>'."\n";
108
				$include_head_file = 'frontend.js';
109
			}
110
			// check if frontend_body.js file needs to be included into the <body></body> of index.php
111
			if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
112
				$include_body_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript"></script>'."\n";
113
				$include_body_file = 'frontend_body.js';
114
			}
115
		}
116
	}
117
}
118

    
119
// Frontend functions
120
if (!function_exists('page_link')) {
121
	function page_link($link) {
122
		global $wb;
123
		return $wb->page_link($link);
124
	}
125
}
126

    
127
//function to highlight search results
128
if(!function_exists('search_highlight')) {
129
function search_highlight($foo='', $arr_string=array()) {
130
	require_once(WB_PATH.'/framework/functions.php');
131
	static $string_ul_umlaut = FALSE;
132
	static $string_ul_regex = FALSE;
133
	if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE)
134
		require(WB_PATH.'/search/search_convert.php');
135
	$foo = entities_to_umlauts($foo, 'UTF-8');
136
	array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
137
	$search_string = implode("|", $arr_string);
138
	$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
139
	// the highlighting
140
	// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
141
	// Also droplet tags are now excluded from highlighting.
142
	// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
143
	// we have to cut <pre> and <code> as well.
144
	// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
145
	$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));
146
	if(is_array($matches) && $matches != array()) {
147
		$foo = "";
148
		foreach($matches as $match) {
149
			if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
150
				$match = str_replace(array('&lt;', '&gt;', '&amp;', '&quot;', '&#039;', '&nbsp;'), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
151
				$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
152
				$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '&nbsp;'), $match);
153
				$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
154
			}
155
			$foo .= $match;
156
		}
157
	}
158
	
159
	if(DEFAULT_CHARSET != 'utf-8') {
160
		$foo = umlauts_to_entities($foo, 'UTF-8');
161
	}
162
	return $foo;
163
}
164
}
165

    
166
// Old menu call invokes new menu function
167
if (!function_exists('page_menu')) {
168
	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) {
169
		global $wb;
170
		$wb->menu_number=$menu_number;
171
		$wb->menu_item_template=$item_template;
172
		$wb->menu_item_footer='';
173
		$wb->menu_parent = $parent;
174
		$wb->menu_header = $menu_header; 
175
		$wb->menu_footer = $menu_footer;
176
		$wb->menu_default_class = $default_class;
177
		$wb->menu_current_class = $current_class;
178
		$wb->menu_recurse = $recurse+2; 	
179
		$wb->menu();
180
		unset($wb->menu_parent);
181
		unset($wb->menu_number);
182
		unset($wb->menu_item_template);
183
		unset($wb->menu_item_footer);
184
		unset($wb->menu_header);
185
		unset($wb->menu_footer);
186
		unset($wb->menu_default_class);
187
		unset($wb->menu_current_class);
188
		unset($wb->menu_start_level);
189
		unset($wb->menu_collapse);
190
		unset($wb->menu_recurse);
191
	}
192
}
193

    
194
if (!function_exists('show_menu')) {
195
	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) {
196
		global $wb;
197
		if (isset($menu_number))
198
			$wb->menu_number=$menu_number;
199
		if (isset($start_level))
200
			$wb->menu_start_level=$start_level;
201
		if (isset($recurse))
202
			$wb->menu_recurse=$recurse;
203
		if (isset($collapse))
204
			$wb->menu_collapse=$collapse;
205
		if (isset($item_template))
206
			$wb->menu_item_template=$item_template;
207
		if (isset($item_footer))
208
			$wb->menu_item_footer=$item_footer;
209
		if (isset($menu_header))
210
			$wb->menu_header=$menu_header;
211
		if (isset($menu_footer))
212
			$wb->menu_footer=$menu_footer;
213
		if (isset($default_class))
214
			$wb->menu_default_class=$default_class;
215
		if (isset($current_class))
216
			$wb->menu_current_class=$current_class;
217
		if (isset($parent))
218
			$wb->menu_parent=$parent;
219
		$wb->menu();
220
		unset($wb->menu_recurse);
221
		unset($wb->menu_parent);
222
		unset($wb->menu_start_level);
223
	}
224
}
225

    
226
if (!function_exists('page_content')) {
227
	function page_content($block = 1) {
228
		// Get outside objects
229
		global $TEXT,$MENU,$HEADING,$MESSAGE;
230
		global $globals;
231
		global $database;
232
		global $wb;
233
		$admin = & $wb;
234
		if ($wb->page_access_denied==true) {
235
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
236
			exit();
237
		}
238
		if ($wb->page_no_active_sections==true) {
239
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
240
			exit();
241
		}
242
		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
243
		// Make sure block is numeric
244
		if(!is_numeric($block)) { $block = 1; }
245
		// Include page content
246
		if(!defined('PAGE_CONTENT') OR $block!=1)
247
        {
248
			$page_id=$wb->page_id;
249
            // set session variable to save page_id only if PAGE_CONTENT is empty
250
            $_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
251
            // set to new value if page_id changed and not 0
252
            if(($page_id != 0) AND ($_SESSION['PAGE_ID'] <> $page_id))
253
            {
254
            $_SESSION['PAGE_ID'] = $page_id;
255
            }
256

    
257
			// First get all sections for this page
258
			$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");
259
			// If none were found, check if default content is supposed to be shown
260
			if($query_sections->numRows() == 0) {
261
				if ($wb->default_block_content=='none') {
262
					return;
263
				}
264
				if (is_numeric($wb->default_block_content)) {
265
					$page_id=$wb->default_block_content;
266
				} else {
267
					$page_id=$wb->default_page_id;
268
				}				
269
				$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");
270
				// Still no cotent found? Give it up, there's just nothing to show!
271
				if($query_sections->numRows() == 0) {
272
					return;
273
				}
274
			}
275
			// Loop through them and include their module file
276
			while($section = $query_sections->fetchRow()) {
277
				// skip this section if it is out of publication-date
278
				$now = time();
279
				if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
280
					continue;
281
				}
282
				$section_id = $section['section_id'];
283
				$module = $section['module'];
284
				// make a anchor for every section.
285
				if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
286
					echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
287
				}
288

    
289
				// fetch content -- this is where to place possible output-filters (before highlighting)
290
				ob_start(); // fetch original content
291
				require(WB_PATH.'/modules/'.$module.'/view.php');
292
				$content = ob_get_contents();
293
				ob_end_clean();
294

    
295
				// highlights searchresults
296
				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
297
					$arr_string = explode(" ", $_GET['sstring']);
298
					if($_GET['searchresult']==2) { // exact match
299
						$arr_string[0] = str_replace("_", " ", $arr_string[0]);
300
					}
301
					echo search_highlight($content, $arr_string);
302
				} else {
303
					echo $content;
304
				}
305
			}
306
		} else {
307
			require(PAGE_CONTENT);
308
		}
309
	}
310
}
311

    
312
if (!function_exists('show_content')) {
313
	function show_content($block=1) {
314
		page_content($block);
315
	}
316
}
317

    
318
if (!function_exists('show_breadcrumbs'))
319
{
320
	function show_breadcrumbs($sep = ' &raquo; ',$level = 0, $links = true, $depth = -1, $title = 'You are here: ')
321
    {
322
		global $wb;
323
		$page_id = $wb->page_id;
324

    
325
		if ($page_id != 0)
326
		{
327
	 		global $database;
328
			$counter = 0;
329
            // get links as array
330
            $bread_crumbs = $wb->page_trail;
331
            $count = sizeof($bread_crumbs);
332
            // level can't be greater than sum of links
333
            $level = ($count <= $level ) ? $count-1 : $level;
334
            // set level from which to show, delete indexes in array
335
			$crumbs = array_slice($bread_crumbs, $level );
336
            // set depth of links -1 or 0 show all links
337
            $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
338
            // if empty array, set orginal links
339
            $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
340
            $total_crumbs = ( ($depth <= 0) OR ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
341
            print '<div class="breadcrumb">'.$title;
342

    
343
			foreach ($crumbs as $temp){
344
                if($counter == $depth) { break; }
345
                    // set separator
346
					$query_menu = $database->query("SELECT menu_title, link FROM ".TABLE_PREFIX."pages WHERE page_id = $temp");
347
					$page = $query_menu->fetchRow();
348
					if ( ($links == true) AND ($temp != $page_id) ) {
349
						print '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
350
					} else {
351
                        print '<span class="crumb">'.$page['menu_title'].'</span>';
352
					}
353
                    if ( ( $counter <> $total_crumbs-1 ) ) {
354
                        print '<span class="separator">'.$sep.'</span>';
355
                    }
356
	            $counter++;
357
                }
358
            print "</div>\n";
359
		}
360
	}
361
}
362

    
363
// Function for page title
364
if (!function_exists('page_title')) {
365
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
366
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
367
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
368
		echo str_replace($vars, $values, $template);
369
	}
370
}
371

    
372
// Function for page description
373
if (!function_exists('page_description')) {
374
	function page_description() {
375
		global $wb;
376
		if ($wb->page_description!='') {
377
			echo $wb->page_description;
378
		} else {
379
			echo WEBSITE_DESCRIPTION;
380
		}
381
	}
382
}
383

    
384
// Function for page keywords
385
if (!function_exists('page_keywords')) {
386
	function page_keywords() {
387
		global $wb;
388
		if ($wb->page_keywords!='') {
389
			echo $wb->page_keywords;
390
		} else {
391
			echo WEBSITE_KEYWORDS;
392
		}
393
	}
394
}
395

    
396
// Function for page header
397
if (!function_exists('page_header')) {
398
	function page_header($date_format = 'Y') {
399
		echo WEBSITE_HEADER;
400
	}
401
}
402

    
403
// Function for page footer
404
if (!function_exists('page_footer')) {
405
	function page_footer($date_format = 'Y') {
406
		global $starttime;
407
		$vars = array('[YEAR]', '[PROCESS_TIME]');
408
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
409
		$values = array(gmdate($date_format),$processtime);
410
		echo str_replace($vars, $values, WEBSITE_FOOTER);
411
	}
412
}
413

    
414
function bind_jquery ($file_id='jquery')
415
{
416
        $jquery_links = '';
417
		/* include the Javascript jquery api  */
418
		if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
419
        {
420
            $wbpath = str_replace('\\','/',WB_PATH);  // fixed localhost problem with ie
421
			$jquery_links .= "<script type=\"text/javascript\">\n"
422
                ."var URL = '".WB_URL."';\n"
423
                ."var WB_PATH = '".$wbpath."';\n"
424
                ."var WB_URL = '".WB_URL."';\n"
425
                ."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
426
                ."</script>\n";
427

    
428
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
429
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-ui-min.js" type="text/javascript"></script>'."\n";
430
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
431
            /* workout to insert ui.css and theme */
432
            $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
433
			$jquery_links .=  file_exists($jquery_theme)
434
                ? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
435
                : '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
436
            /* workout to insert plugins functions, set in templatedir */
437
            $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
438
			$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
439
                ? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
440
                : '';
441
		}
442
    return $jquery_links;
443
}
444

    
445

    
446
// Function to add optional module Javascript into the <body> section of the frontend
447
if(!function_exists('register_frontend_modfiles_body'))
448
{
449
	function register_frontend_modfiles_body($file_id="js")
450
    {
451
		// sanity check of parameter passed to the function
452
		$file_id = strtolower($file_id);
453
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
454
        {
455
			return;
456
		}
457

    
458
       // define constant indicating that the register_frontent_files was invoked
459
       if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
460
		global $wb, $database, $include_body_links;
461
		// define default baselink and filename for optional module javascript files
462
		$body_links = "";
463

    
464
		/* include the Javascript jquery api  */
465
        $body_links .= bind_jquery($file_id);
466

    
467
		if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
468
        {
469
    		$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
470
    		$base_file = "frontend_body.js";
471

    
472
			// ensure that frontend_body.js is only added once per module type
473
    		if(!empty($include_body_links))
474
            {
475
    			if(strpos($body_links, $include_body_links) === false)
476
                {
477
    				$body_links .= $include_body_links;
478
    			}
479
    			$include_body_links = '';
480
    		}
481

    
482
    		// gather information for all models embedded on actual page
483
    		$page_id = $wb->page_id;
484
    		$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
485
    				WHERE page_id=$page_id AND module<>'wysiwyg'");
486

    
487
    		while($row = $query_modules->fetchRow())
488
            {
489
    			// check if page module directory contains a frontend_body.js file
490
    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
491
    			// create link with frontend_body.js source for the current module
492
    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
493

    
494
    				// define constant indicating that the register_frontent_files_body was invoked
495
    					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
496

    
497
    				// ensure that frontend_body.js is only added once per module type
498
    				if(strpos($body_links, $tmp_link) === false) {
499
    					$body_links .= $tmp_link;
500
    				}
501
    			}
502
    		}
503
        }
504

    
505
		print $body_links."\n"; ;
506
	}
507
}
508

    
509

    
510
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
511
if(!function_exists('register_frontend_modfiles'))
512
{
513
	function register_frontend_modfiles($file_id="css")
514
    {
515
		// sanity check of parameter passed to the function
516
		$file_id = strtolower($file_id);
517
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
518
        {
519
			return;
520
		}
521

    
522
		global $wb, $database, $include_head_link_css, $include_head_links;
523
		// define default baselink and filename for optional module javascript and stylesheet files
524
		$head_links = "";
525

    
526
        switch ($file_id)
527
        {
528
            case 'css':
529
			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
530
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
531
			$base_file = "frontend.css";
532
    		if(!empty($include_head_link_css))
533
            {
534
              $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
535
              $include_head_link_css = '';
536
            }
537
            break;
538
            case 'jquery':
539
            $head_links .= bind_jquery($file_id);
540
            break;
541
            case 'js':
542
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
543
			$base_file = "frontend.js";
544
    		if(!empty($include_head_links))
545
            {
546
              $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
547
              $include_head_links = '';
548
            }
549
            break;
550
            default:
551
            break;
552
		}
553

    
554
		if(!empty($include_head_link_css)) {
555
			if(strpos($head_links, $include_head_link_css) === false) {
556
				$head_links .= $include_head_link_css;
557
			}
558
			$include_head_link_css = '';
559
		} else {
560
			if(!empty($include_head_links)) {
561
				if(strpos($head_links, $include_head_links) === false) {
562
					$head_links .= $include_head_links;
563
				}
564
				$include_head_links = '';
565
			}
566
		}
567

    
568
        if( $file_id != 'jquery')
569
        {
570

    
571
    		// gather information for all models embedded on actual page
572
    		$page_id = $wb->page_id;
573
    		$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
574
    				WHERE page_id=$page_id AND module<>'wysiwyg'");
575

    
576
    		while($row = $query_modules->fetchRow())
577
            {
578
    			// check if page module directory contains a frontend.js or frontend.css file
579
    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
580
                {
581
    			// create link with frontend.js or frontend.css source for the current module
582
    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
583

    
584
    				// define constant indicating that the register_frontent_files was invoked
585
    				if($file_id == 'css')
586
                    {
587
    					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
588
    				} else
589
                    {
590
    					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
591
    				}
592
    				// ensure that frontend.js or frontend.css is only added once per module type
593
    				if(strpos($head_links, $tmp_link) === false)
594
                    {
595
    					$head_links .= $tmp_link."\n";
596
    				}
597
    			};
598
    		}
599
        		// include the Javascript email protection function
600
        		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
601
                {
602
        			$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
603
        		}
604
                elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
605
                {
606
        			$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
607
        		}
608
        }
609
        print $head_links;
610
    }
611
}
612

    
613
// Begin WB < 2.4.x template compatibility code
614
	// Make extra_sql accessable through private_sql
615
	$private_sql = $extra_sql;
616
	$private_where_sql = $extra_where_sql;
617
	// Query pages for menu
618
	$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");
619
	// Check if current pages is a parent page and if we need its submenu
620
	if(PARENT == 0) {
621
		// Get the pages submenu
622
		$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");
623
	} else {
624
		// Get the pages submenu
625
		$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");
626
	}
627
// End WB < 2.4.x template compatibility code
628
// Include template file
629

    
630

    
631
?>
(10-10/15)