Project

General

Profile

1
<?php
2
/****************************************************************************
3
* SVN Version information:
4
*
5
* $Id: frontend.functions.php 1242 2010-01-13 06:34:48Z 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
*
46
*
47
*
48
*
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 1242 2010-01-13 06:34:48Z 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
        {
236
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
237
			exit();
238
		}
239
		if ($wb->page_no_active_sections==true)
240
        {
241
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
242
			exit();
243
		}
244
		if(isset($globals) AND is_array($globals))
245
        {
246
            foreach($globals AS $global_name)
247
            {
248
                global $$global_name;
249
                }
250
        }
251
		// Make sure block is numeric
252
		if(!is_numeric($block)) { $block = 1; }
253
		// Include page content
254
		if(!defined('PAGE_CONTENT') OR $block!=1)
255
        {
256
			$page_id=$wb->page_id;
257
            // set session variable to save page_id only if PAGE_CONTENT is empty
258
            $_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
259
            // set to new value if page_id changed and not 0
260
            if(($page_id != 0) AND ($_SESSION['PAGE_ID'] <> $page_id))
261
            {
262
            $_SESSION['PAGE_ID'] = $page_id;
263
            }
264

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

    
297
				// fetch content -- this is where to place possible output-filters (before highlighting)
298
				ob_start(); // fetch original content
299
				require(WB_PATH.'/modules/'.$module.'/view.php');
300
				$content = ob_get_contents();
301
				ob_end_clean();
302

    
303
				// highlights searchresults
304
				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
305
					$arr_string = explode(" ", $_GET['sstring']);
306
					if($_GET['searchresult']==2) { // exact match
307
						$arr_string[0] = str_replace("_", " ", $arr_string[0]);
308
					}
309
					echo search_highlight($content, $arr_string);
310
				} else {
311
					echo $content;
312
				}
313
			}
314
		}
315
        else
316
        {
317

    
318
			require(PAGE_CONTENT);
319
		}
320
	}
321
}
322

    
323
if (!function_exists('show_content')) {
324
	function show_content($block=1) {
325
		page_content($block);
326
	}
327
}
328

    
329
if (!function_exists('show_breadcrumbs'))
330
{
331
	function show_breadcrumbs($sep = ' &raquo; ',$level = 0, $links = true, $depth = -1, $title = 'You are here: ')
332
    {
333
		global $wb;
334
		$page_id = $wb->page_id;
335

    
336
		if ($page_id != 0)
337
		{
338
	 		global $database;
339
			$counter = 0;
340
            // get links as array
341
            $bread_crumbs = $wb->page_trail;
342
            $count = sizeof($bread_crumbs);
343
            // level can't be greater than sum of links
344
            $level = ($count <= $level ) ? $count-1 : $level;
345
            // set level from which to show, delete indexes in array
346
			$crumbs = array_slice($bread_crumbs, $level );
347
            $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
348
            // if empty array, set orginal links
349
            $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
350
            $total_crumbs = ( ($depth <= 0) OR ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
351
            print '<div class="breadcrumb"><span class="title">'.$title.'</span>';
352
          //  print_r($crumbs);
353
			foreach ($crumbs as $temp)
354
            {
355
                if($counter == $depth) { break; }
356
                    // set links and separator
357
					$query_menu = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = $temp");
358
					$page = $query_menu->fetchRow();
359

    
360
                    $show_crumb = (($links == true) AND ($temp != $page_id))
361
                            ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'
362
                            : '<span class="crumb">'.MENU_TITLE.'</span>';
363

    
364
                    // Permission
365
                    switch ($page['visibility'])
366
                    {
367
                        case 'none' :
368
                        case 'hidden' :
369
                        // if show, you know there is an error in a hidden page
370
                            print $show_crumb.'&nbsp;';
371
                        break;
372
                        default :
373
                            print $show_crumb;
374
                        break;
375
                    }
376

    
377
                    if ( ( $counter <> $total_crumbs-1 ) )
378
                    {
379
                        print '<span class="separator">'.$sep.'</span>';
380
                    }
381
	            $counter++;
382
            }
383
            print "</div>\n";
384
		}
385
	}
386
}
387

    
388
// Function for page title
389
if (!function_exists('page_title')) {
390
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
391
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
392
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
393
		echo str_replace($vars, $values, $template);
394
	}
395
}
396

    
397
// Function for page description
398
if (!function_exists('page_description')) {
399
	function page_description() {
400
		global $wb;
401
		if ($wb->page_description!='') {
402
			echo $wb->page_description;
403
		} else {
404
			echo WEBSITE_DESCRIPTION;
405
		}
406
	}
407
}
408

    
409
// Function for page keywords
410
if (!function_exists('page_keywords')) {
411
	function page_keywords() {
412
		global $wb;
413
		if ($wb->page_keywords!='') {
414
			echo $wb->page_keywords;
415
		} else {
416
			echo WEBSITE_KEYWORDS;
417
		}
418
	}
419
}
420

    
421
// Function for page header
422
if (!function_exists('page_header')) {
423
	function page_header($date_format = 'Y') {
424
		echo WEBSITE_HEADER;
425
	}
426
}
427

    
428
// Function for page footer
429
if (!function_exists('page_footer')) {
430
	function page_footer($date_format = 'Y') {
431
		global $starttime;
432
		$vars = array('[YEAR]', '[PROCESS_TIME]');
433
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
434
		$values = array(gmdate($date_format),$processtime);
435
		echo str_replace($vars, $values, WEBSITE_FOOTER);
436
	}
437
}
438

    
439
function bind_jquery ($file_id='jquery')
440
{
441
        $jquery_links = '';
442
		/* include the Javascript jquery api  */
443
		if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
444
        {
445
            $wbpath = str_replace('\\','/',WB_PATH);  // fixed localhost problem with ie
446
			$jquery_links .= "<script type=\"text/javascript\">\n"
447
                ."var URL = '".WB_URL."';\n"
448
                ."var WB_PATH = '".$wbpath."';\n"
449
                ."var WB_URL = '".WB_URL."';\n"
450
                ."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
451
                ."</script>\n";
452

    
453
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
454
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-ui-min.js" type="text/javascript"></script>'."\n";
455
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
456
            /* workout to insert ui.css and theme */
457
            $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
458
			$jquery_links .=  file_exists($jquery_theme)
459
                ? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
460
                : '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
461
            /* workout to insert plugins functions, set in templatedir */
462
            $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
463
			$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
464
                ? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
465
                : '';
466
		}
467
    return $jquery_links;
468
}
469

    
470

    
471
// Function to add optional module Javascript into the <body> section of the frontend
472
if(!function_exists('register_frontend_modfiles_body'))
473
{
474
	function register_frontend_modfiles_body($file_id="js")
475
    {
476
		// sanity check of parameter passed to the function
477
		$file_id = strtolower($file_id);
478
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
479
        {
480
			return;
481
		}
482

    
483
       // define constant indicating that the register_frontent_files was invoked
484
       if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
485
		global $wb, $database, $include_body_links;
486
		// define default baselink and filename for optional module javascript files
487
		$body_links = "";
488

    
489
		/* include the Javascript jquery api  */
490
        $body_links .= bind_jquery($file_id);
491

    
492
		if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
493
        {
494
    		$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
495
    		$base_file = "frontend_body.js";
496

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

    
507
    		// gather information for all models embedded on actual page
508
    		$page_id = $wb->page_id;
509
    		$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
510
    				WHERE page_id=$page_id AND module<>'wysiwyg'");
511

    
512
    		while($row = $query_modules->fetchRow())
513
            {
514
    			// check if page module directory contains a frontend_body.js file
515
    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
516
    			// create link with frontend_body.js source for the current module
517
    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
518

    
519
    				// define constant indicating that the register_frontent_files_body was invoked
520
    					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
521

    
522
    				// ensure that frontend_body.js is only added once per module type
523
    				if(strpos($body_links, $tmp_link) === false) {
524
    					$body_links .= $tmp_link;
525
    				}
526
    			}
527
    		}
528
        }
529

    
530
		print $body_links."\n"; ;
531
	}
532
}
533

    
534

    
535
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
536
if(!function_exists('register_frontend_modfiles'))
537
{
538
	function register_frontend_modfiles($file_id="css")
539
    {
540
		// sanity check of parameter passed to the function
541
		$file_id = strtolower($file_id);
542
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
543
        {
544
			return;
545
		}
546

    
547
		global $wb, $database, $include_head_link_css, $include_head_links;
548
		// define default baselink and filename for optional module javascript and stylesheet files
549
		$head_links = "";
550

    
551
        switch ($file_id)
552
        {
553
            case 'css':
554
			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
555
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
556
			$base_file = "frontend.css";
557
    		if(!empty($include_head_link_css))
558
            {
559
              $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
560
              $include_head_link_css = '';
561
            }
562
            break;
563
            case 'jquery':
564
            $head_links .= bind_jquery($file_id);
565
            break;
566
            case 'js':
567
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
568
			$base_file = "frontend.js";
569
    		if(!empty($include_head_links))
570
            {
571
              $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
572
              $include_head_links = '';
573
            }
574
            break;
575
            default:
576
            break;
577
		}
578

    
579
		if(!empty($include_head_link_css)) {
580
			if(strpos($head_links, $include_head_link_css) === false) {
581
				$head_links .= $include_head_link_css;
582
			}
583
			$include_head_link_css = '';
584
		} else {
585
			if(!empty($include_head_links)) {
586
				if(strpos($head_links, $include_head_links) === false) {
587
					$head_links .= $include_head_links;
588
				}
589
				$include_head_links = '';
590
			}
591
		}
592

    
593
        if( $file_id != 'jquery')
594
        {
595

    
596
    		// gather information for all models embedded on actual page
597
    		$page_id = $wb->page_id;
598
    		$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
599
    				WHERE page_id=$page_id AND module<>'wysiwyg'");
600

    
601
    		while($row = $query_modules->fetchRow())
602
            {
603
    			// check if page module directory contains a frontend.js or frontend.css file
604
    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
605
                {
606
    			// create link with frontend.js or frontend.css source for the current module
607
    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
608

    
609
    				// define constant indicating that the register_frontent_files was invoked
610
    				if($file_id == 'css')
611
                    {
612
    					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
613
    				} else
614
                    {
615
    					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
616
    				}
617
    				// ensure that frontend.js or frontend.css is only added once per module type
618
    				if(strpos($head_links, $tmp_link) === false)
619
                    {
620
    					$head_links .= $tmp_link."\n";
621
    				}
622
    			};
623
    		}
624
        		// include the Javascript email protection function
625
        		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
626
                {
627
        			$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
628
        		}
629
                elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
630
                {
631
        			$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
632
        		}
633
        }
634
        print $head_links;
635
    }
636
}
637

    
638
// Begin WB < 2.4.x template compatibility code
639
	// Make extra_sql accessable through private_sql
640
	$private_sql = $extra_sql;
641
	$private_where_sql = $extra_where_sql;
642
	// Query pages for menu
643
	$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");
644
	// Check if current pages is a parent page and if we need its submenu
645
	if(PARENT == 0) {
646
		// Get the pages submenu
647
		$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");
648
	} else {
649
		// Get the pages submenu
650
		$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");
651
	}
652
// End WB < 2.4.x template compatibility code
653
// Include template file
654

    
655

    
656
?>
(10-10/15)