Project

General

Profile

1 1363 Luisehahne
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         frontend.functions
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
13 1363 Luisehahne
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
*/
18
19 1420 Luisehahne
// Must include code to stop this file being access directly
20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
21 1363 Luisehahne
22
// references to objects and variables that changed their names
23
24
$admin = &$wb;
25
26
$default_link=&$wb->default_link;
27
28
$page_trail=&$wb->page_trail;
29
$page_description=&$wb->page_description;
30
$page_keywords=&$wb->page_keywords;
31
$page_link=&$wb->link;
32
33
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
34
$extra_sql=&$wb->extra_sql;
35
$extra_where_sql=&$wb->extra_where_sql;
36
37
$include_head_link_css = '';
38
$include_body_links = '';
39
$include_head_links = '';
40
// workout to included frontend.css, fronten.js and frontend_body.js in snippets
41
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
42
$query_result=$database->query($query);
43
if ($query_result->numRows()>0) {
44
	while ($row = $query_result->fetchRow()) {
45
		$module_dir = $row['directory'];
46
		if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
47
			include(WB_PATH.'/modules/'.$module_dir.'/include.php');
48
			/* check if frontend.css file needs to be included into the <head></head> of index.php
49
			*/
50
			if( file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
51
				$include_head_link_css .= '<link href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css"';
52
				$include_head_link_css .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
53
				$include_head_file = 'frontend.css';
54
			}
55
			// check if frontend.js file needs to be included into the <body></body> of index.php
56
			if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
57
				$include_head_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript"></script>'."\n";
58
				$include_head_file = 'frontend.js';
59
			}
60
			// check if frontend_body.js file needs to be included into the <body></body> of index.php
61
			if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
62
				$include_body_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript"></script>'."\n";
63
				$include_body_file = 'frontend_body.js';
64
			}
65
		}
66
	}
67
}
68
69
// Frontend functions
70
if (!function_exists('page_link'))
71
{
72
	function page_link($link) {
73
		global $wb;
74
		return $wb->page_link($link);
75
	}
76
}
77
78
if (!function_exists('get_page_link'))
79
{
80
    function get_page_link( $id )
81
    {
82
        global $database;
83
        // Get link
84
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
85
        $link = $database->get_one( $sql );
86
        return $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('&lt;', '&gt;', '&amp;', '&quot;', '&#039;', '&nbsp;'), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
114
				$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
115
				$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '&nbsp;'), $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
        {
199
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
200
			return;
201
		}
202
		if ($wb->page_no_active_sections==true)
203
        {
204
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
205
			return;
206
		}
207
		if(isset($globals) AND is_array($globals))
208
        {
209
            foreach($globals AS $global_name)
210
            {
211
                global $$global_name;
212
                }
213
        }
214
		// Make sure block is numeric
215
		if(!is_numeric($block)) { $block = 1; }
216
		// Include page content
217
		if(!defined('PAGE_CONTENT') OR $block!=1)
218
        {
219
			$page_id = intval($wb->page_id);
220
            // set session variable to save page_id only if PAGE_CONTENT is empty
221
            $_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
222
            // set to new value if page_id changed and not 0
223
            if(($page_id != 0) && ($_SESSION['PAGE_ID'] <> $page_id))
224
            {
225
            $_SESSION['PAGE_ID'] = $page_id;
226
            }
227
228
			// First get all sections for this page
229
			$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");
230
			// If none were found, check if default content is supposed to be shown
231
			if($query_sections->numRows() == 0) {
232
				if ($wb->default_block_content=='none') {
233
					return;
234
				}
235
				if (is_numeric($wb->default_block_content)) {
236
					$page_id=$wb->default_block_content;
237
				} else {
238
					$page_id=$wb->default_page_id;
239
				}
240
				$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");
241
				// Still no cotent found? Give it up, there's just nothing to show!
242
				if($query_sections->numRows() == 0) {
243
					return;
244
				}
245
			}
246
			// Loop through them and include their module file
247
			while($section = $query_sections->fetchRow()) {
248
				// skip this section if it is out of publication-date
249
				$now = time();
250
				if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
251
					continue;
252
				}
253
				$section_id = $section['section_id'];
254
				$module = $section['module'];
255
				// make a anchor for every section.
256
				if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
257
					echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
258
				}
259
                // check if module exists - feature: write in errorlog
260
				if(file_exists(WB_PATH.'/modules/'.$module.'/view.php')) {
261
				// fetch content -- this is where to place possible output-filters (before highlighting)
262
					ob_start(); // fetch original content
263
					require(WB_PATH.'/modules/'.$module.'/view.php');
264
					$content = ob_get_contents();
265
					ob_end_clean();
266
				} else {
267
					continue;
268
				}
269
270
				// highlights searchresults
271
				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
272
					$arr_string = explode(" ", $_GET['sstring']);
273
					if($_GET['searchresult']==2) { // exact match
274
						$arr_string[0] = str_replace("_", " ", $arr_string[0]);
275
					}
276
					echo search_highlight($content, $arr_string);
277
				} else {
278
					echo $content;
279
				}
280
			}
281
		}
282
        else
283
        {
284
285
			require(PAGE_CONTENT);
286
		}
287
	}
288
}
289
290
if (!function_exists('show_content')) {
291
	function show_content($block=1) {
292
		page_content($block);
293
	}
294
}
295
296
if (!function_exists('show_breadcrumbs'))
297
{
298
	function show_breadcrumbs($sep = ' &raquo; ',$level = 0, $links = true, $depth = -1, $title = '')
299
    {
300
		global $wb,$database,$MENU;
301
		$page_id = $wb->page_id;
302
        $title = (trim($title) == '') ? $MENU['BREADCRUMB'] : $title;
303
		if ($page_id != 0)
304
		{
305
			$counter = 0;
306
            // get links as array
307
            $bread_crumbs = $wb->page_trail;
308
            $count = sizeof($bread_crumbs);
309
            // level can't be greater than sum of links
310
            $level = ($count <= $level ) ? $count-1 : $level;
311
            // set level from which to show, delete indexes in array
312
			$crumbs = array_slice($bread_crumbs, $level );
313
            $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
314
            // if empty array, set orginal links
315
            $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
316
            $total_crumbs = ( ($depth <= 0) || ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
317
            print '<div class="breadcrumb"><span class="title">'.$title.'</span>';
318
          //  print_r($crumbs);
319
			foreach ($crumbs as $temp)
320
            {
321
                if($counter == $depth) { break; }
322
                    // set links and separator
323
					$query_menu = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = $temp");
324
					$page = $query_menu->fetchRow();
325
326
                    $show_crumb = (($links == true) && ($temp != $page_id))
327
                            ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'
328
                            : '<span class="crumb">'.$page['menu_title'].'</span>';
329
330
                    // Permission
331
                    switch ($page['visibility'])
332
                    {
333
                        case 'none' :
334
                        case 'hidden' :
335
                        // if show, you know there is an error in a hidden page
336
                            print $show_crumb.'&nbsp;';
337
                        break;
338
                        default :
339
                            print $show_crumb;
340
                        break;
341
                    }
342
343
                    if ( ( $counter <> $total_crumbs-1 ) )
344
                    {
345
                        print '<span class="separator">'.$sep.'</span>';
346
                    }
347
	            $counter++;
348
            }
349
            print "</div>\n";
350
		}
351
	}
352
}
353
354
// Function for page title
355
if (!function_exists('page_title')) {
356
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
357
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
358
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
359
		echo str_replace($vars, $values, $template);
360
	}
361
}
362
363
// Function for page description
364
if (!function_exists('page_description')) {
365
	function page_description() {
366
		global $wb;
367
		if ($wb->page_description!='') {
368
			echo $wb->page_description;
369
		} else {
370
			echo WEBSITE_DESCRIPTION;
371
		}
372
	}
373
}
374
375
// Function for page keywords
376
if (!function_exists('page_keywords')) {
377
	function page_keywords() {
378
		global $wb;
379
		if ($wb->page_keywords!='') {
380
			echo $wb->page_keywords;
381
		} else {
382
			echo WEBSITE_KEYWORDS;
383
		}
384
	}
385
}
386
387
// Function for page header
388
if (!function_exists('page_header')) {
389
	function page_header($date_format = 'Y') {
390
		echo WEBSITE_HEADER;
391
	}
392
}
393
394
// Function for page footer
395
if (!function_exists('page_footer')) {
396
	function page_footer($date_format = 'Y') {
397
		global $starttime;
398
		$vars = array('[YEAR]', '[PROCESS_TIME]');
399
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
400
		$values = array(gmdate($date_format),$processtime);
401
		echo str_replace($vars, $values, WEBSITE_FOOTER);
402
	}
403
}
404
405
function bind_jquery ($file_id='jquery')
406
{
407
408
        $jquery_links = '';
409
		/* include the Javascript jquery api  */
410
		if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
411
        {
412
            $wbpath = str_replace('\\','/',WB_PATH);  // fixed localhost problem with ie
413
			$jquery_links .= "<script type=\"text/javascript\">\n"
414
                ."var URL = '".WB_URL."';\n"
415
               /* ."var WB_PATH = '".$wbpath."';\n" */
416
                ."var WB_URL = '".WB_URL."';\n"
417
                ."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
418
                ."</script>\n";
419
420
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
421
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
422 1369 Luisehahne
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-include.js" type="text/javascript"></script>'."\n";
423 1363 Luisehahne
            /* workout to insert ui.css and theme */
424
            $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
425
			$jquery_links .=  file_exists($jquery_theme)
426
                ? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
427
                : '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
428
            /* workout to insert plugins functions, set in templatedir */
429
            $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
430
			$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
431
                ? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
432
                : '';
433
		}
434
    return $jquery_links;
435
}
436
437
438
// Function to add optional module Javascript into the <body> section of the frontend
439
if(!function_exists('register_frontend_modfiles_body'))
440
{
441
	function register_frontend_modfiles_body($file_id="js")
442
    {
443
		// sanity check of parameter passed to the function
444
		$file_id = strtolower($file_id);
445
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
446
        {
447
			return;
448
		}
449
450
       // define constant indicating that the register_frontent_files was invoked
451
       if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
452
		global $wb, $database, $include_body_links;
453
		// define default baselink and filename for optional module javascript files
454
		$body_links = "";
455
456
		/* include the Javascript jquery api  */
457
        $body_links .= bind_jquery($file_id);
458
459
		if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
460
        {
461
    		$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
462
    		$base_file = "frontend_body.js";
463
464
			// ensure that frontend_body.js is only added once per module type
465
    		if(!empty($include_body_links))
466
            {
467
    			if(strpos($body_links, $include_body_links) === false)
468
                {
469
    				$body_links .= $include_body_links;
470
    			}
471
    			$include_body_links = '';
472
    		}
473
474
    		// gather information for all models embedded on actual page
475
    		$page_id = $wb->page_id;
476 1368 Luisehahne
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
477
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module` <> \'wysiwyg\'';
478
    		if( ($query_modules = $database->query($sql)) )
479
			{
480
	    		while($row = $query_modules->fetchRow())
481
	            {
482
	    			// check if page module directory contains a frontend_body.js file
483
	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
484
	                {
485
	    			// create link with frontend_body.js source for the current module
486
	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
487 1363 Luisehahne
488 1368 Luisehahne
	    				// define constant indicating that the register_frontent_files_body was invoked
489
	    					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) { define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);}
490 1363 Luisehahne
491 1368 Luisehahne
	    				// ensure that frontend_body.js is only added once per module type
492
	    				if(strpos($body_links, $tmp_link) === false)
493
	                    {
494
	    					$body_links .= $tmp_link;
495
	    				}
496
	    			}
497
	    		}
498
            }
499 1363 Luisehahne
        }
500
501
		print $body_links."\n"; ;
502
	}
503
}
504
505
506
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
507
if(!function_exists('register_frontend_modfiles'))
508
{
509
	function register_frontend_modfiles($file_id="css")
510
    {
511
		// sanity check of parameter passed to the function
512
		$file_id = strtolower($file_id);
513
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
514
        {
515
			return;
516
		}
517
518
		global $wb, $database, $include_head_link_css, $include_head_links;
519
		// define default baselink and filename for optional module javascript and stylesheet files
520
		$head_links = "";
521
522
        switch ($file_id)
523
        {
524
            case 'css':
525
			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
526
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
527
			$base_file = "frontend.css";
528
    		if(!empty($include_head_link_css))
529
            {
530
              $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
531
              $include_head_link_css = '';
532
            }
533
            break;
534
            case 'jquery':
535
            $head_links .= bind_jquery($file_id);
536
            break;
537
            case 'js':
538
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
539
			$base_file = "frontend.js";
540
    		if(!empty($include_head_links))
541
            {
542
              $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
543
              $include_head_links = '';
544
            }
545
            break;
546
            default:
547
            break;
548
		}
549
550
        if( $file_id != 'jquery')
551
        {
552
    		// gather information for all models embedded on actual page
553
    		$page_id = $wb->page_id;
554 1368 Luisehahne
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
555
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module` <> \'wysiwyg\'';
556
    		if( ($query_modules = $database->query($sql)) )
557
			{
558
	    		while($row = $query_modules->fetchRow())
559
	            {
560
	    			// check if page module directory contains a frontend.js or frontend.css file
561
	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
562
	                {
563
	    			// create link with frontend.js or frontend.css source for the current module
564
	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
565 1363 Luisehahne
566 1368 Luisehahne
	    				// define constant indicating that the register_frontent_files was invoked
567
	    				if($file_id == 'css')
568
	                    {
569
	    					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
570
	    				} else
571
	                    {
572
	    					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
573
	    				}
574
	    				// ensure that frontend.js or frontend.css is only added once per module type
575
	    				if(strpos($head_links, $tmp_link) === false)
576
	                    {
577
	    					$head_links .= $tmp_link."\n";
578
	    				}
579
	    			};
580
	    		}
581
			}
582
       		// include the Javascript email protection function
583
       		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
584
               {
585
       			$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
586
       		}
587
               elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
588
               {
589
       			$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
590
       		}
591 1363 Luisehahne
        }
592
        print $head_links;
593
    }
594
}
595
596 1443 Luisehahne
	function moveCssToHead($content) {
597
		// move css definitions into head section
598
		$pattern1 = '/(?:.*?<body.*?)(<link[^>]*?\"text\/css\".*?\/>)(?:.*)/si';
599
		$pattern2 = '/(?:.*?<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)(?:.*)/si';
600
		$insert1 = array();
601
		$insert2 = array();
602
		if(preg_match_all($pattern1, $content, $matches)) {
603
			$insert1 = $matches[1];
604
			$content = str_replace($insert1, '', $content);
605
		}
606
		if(preg_match_all($pattern2, $content, $matches)) {
607
			$insert2 = $matches[1];
608
			$content = str_replace($insert2, '', $content);
609
		}
610
		$insert = array_merge($insert1, $insert2);
611
		$insert = "\n".implode("\n", $insert)."\n</head>\n<body";
612
		$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
613
		return $content;
614
	}
615
616 1363 Luisehahne
// Begin WB < 2.4.x template compatibility code
617
	// Make extra_sql accessable through private_sql
618
	$private_sql = $extra_sql;
619
	$private_where_sql = $extra_where_sql;
620
	// Query pages for menu
621
	$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");
622
	// Check if current pages is a parent page and if we need its submenu
623
	if(PARENT == 0) {
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 = '".PAGE_ID."' AND $extra_where_sql ORDER BY position ASC");
626
	} else {
627
		// Get the pages submenu
628
		$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");
629
	}
630
// End WB < 2.4.x template compatibility code
631
// Include template file