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 1487 DarkViper
// compatibility mode for versions before 2.8.1
23
	$admin            = $wb;
24
	$default_link     = $wb->default_link;
25
	$page_trail       = $wb->page_trail;
26
	$page_description = $wb->page_description;
27
	$page_keywords    = $wb->page_keywords;
28
	$page_link        = $wb->link;
29
// ---------- //
30 1363 Luisehahne
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
31 1487 DarkViper
	$extra_sql       = $wb->extra_sql;
32
	$extra_where_sql = $wb->extra_where_sql;
33
// ---------- //
34
	$include_head_link_css = '';
35
	$include_body_links    = '';
36
	$include_head_links    = '';
37 1363 Luisehahne
38
// workout to included frontend.css, fronten.js and frontend_body.js in snippets
39 1487 DarkViper
	$sql  = 'SELECT `directory` FROM `'.TABLE_PREFIX.'addons` ';
40
	$sql .= 'WHERE `type`=\'module\' AND `function`=\'snippet\'';
41
	if(($resSnippets = $database->query($sql))) {
42
		while($recSnippet = $resSnippets->fetchRow()) {
43
			$module_dir = $recSnippet['directory'];
44
			if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
45
				include(WB_PATH.'/modules/'.$module_dir.'/include.php');
46
			// check if frontend.css file needs to be included into the <head></head> of index.php
47
				if( file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
48
					$include_head_link_css .= '<link href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css"';
49
					$include_head_link_css .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
50
					$include_head_file = 'frontend.css';
51
				}
52 1363 Luisehahne
			// check if frontend.js file needs to be included into the <body></body> of index.php
53 1487 DarkViper
				if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
54
					$include_head_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript"></script>'."\n";
55
					$include_head_file = 'frontend.js';
56
				}
57 1363 Luisehahne
			// check if frontend_body.js file needs to be included into the <body></body> of index.php
58 1487 DarkViper
				if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
59
					$include_body_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript"></script>'."\n";
60
					$include_body_file = 'frontend_body.js';
61
				}
62 1363 Luisehahne
			}
63
		}
64
	}
65
66
// Frontend functions
67 1487 DarkViper
if(!function_exists('page_link')) {
68
	/**
69
	 * generate full qualified URL from relative link based on pages_dir
70
	 * @param string $link
71
	 * @return string
72
	 */
73 1363 Luisehahne
	function page_link($link) {
74 1487 DarkViper
		return $GLOBALS['wb']->page_link($link);
75 1363 Luisehahne
	}
76
}
77
78 1487 DarkViper
if (!function_exists('get_page_link')) {
79
    /**
80
	 * get relative link from database based on pages_dir
81
	 * @global <type> $database
82
	 * @param <type> $id
83
	 * @return <type>
84
	 */
85
	function get_page_link( $id )
86 1363 Luisehahne
    {
87
        global $database;
88
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
89
        $link = $database->get_one( $sql );
90
        return $link;
91
    }
92
}
93
94
//function to highlight search results
95
if(!function_exists('search_highlight')) {
96 1487 DarkViper
	/**
97
	 *
98
	 * @staticvar boolean $string_ul_umlaut
99
	 * @staticvar boolean $string_ul_regex
100
	 * @param string $foo
101
	 * @param array $arr_string
102
	 * @return string
103
	 */
104
	function search_highlight($foo='', $arr_string=array()) {
105
		require_once(WB_PATH.'/framework/functions.php');
106
		static $string_ul_umlaut = FALSE;
107
		static $string_ul_regex = FALSE;
108
		if($string_ul_umlaut === FALSE || $string_ul_regex === FALSE) {
109
			require(WB_PATH.'/search/search_convert.php');
110
		}
111
		$foo = entities_to_umlauts($foo, 'UTF-8');
112
		array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
113
		$search_string = implode("|", $arr_string);
114
		$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
115
		// the highlighting
116
		// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
117
		// Also droplet tags are now excluded from highlighting.
118
		// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
119
		// we have to cut <pre> and <code> as well.
120
		// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
121
		$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));
122
		if(is_array($matches) && $matches != array()) {
123
			$foo = "";
124
			foreach($matches as $match) {
125
				if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
126
					$match = str_replace(array('&lt;', '&gt;', '&amp;', '&quot;', '&#039;', '&nbsp;'), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
127
					$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
128
					$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '&nbsp;'), $match);
129
					$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
130
				}
131
				$foo .= $match;
132 1363 Luisehahne
			}
133
		}
134
135 1487 DarkViper
		if(DEFAULT_CHARSET != 'utf-8') {
136
			$foo = umlauts_to_entities($foo, 'UTF-8');
137
		}
138
		return $foo;
139 1363 Luisehahne
	}
140
}
141
142
if (!function_exists('page_menu')) {
143 1487 DarkViper
	/**
144
	 * Old menu generator
145
	 * @deprecated from WB 2.9.x and up
146
	 * @global <type> $wb
147
	 * @param <type> $parent
148
	 * @param <type> $menu_number
149
	 * @param <type> $item_template
150
	 * @param <type> $menu_header
151
	 * @param <type> $menu_footer
152
	 * @param <type> $default_class
153
	 * @param <type> $current_class
154
	 * @param <type> $recurse
155
	 */
156 1363 Luisehahne
	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) {
157
		global $wb;
158
		$wb->menu_number=$menu_number;
159
		$wb->menu_item_template=$item_template;
160
		$wb->menu_item_footer='';
161
		$wb->menu_parent = $parent;
162
		$wb->menu_header = $menu_header;
163
		$wb->menu_footer = $menu_footer;
164
		$wb->menu_default_class = $default_class;
165
		$wb->menu_current_class = $current_class;
166
		$wb->menu_recurse = $recurse+2;
167
		$wb->menu();
168
		unset($wb->menu_parent);
169
		unset($wb->menu_number);
170
		unset($wb->menu_item_template);
171
		unset($wb->menu_item_footer);
172
		unset($wb->menu_header);
173
		unset($wb->menu_footer);
174
		unset($wb->menu_default_class);
175
		unset($wb->menu_current_class);
176
		unset($wb->menu_start_level);
177
		unset($wb->menu_collapse);
178
		unset($wb->menu_recurse);
179
	}
180
}
181
182
if (!function_exists('show_menu')) {
183 1487 DarkViper
	/**
184
	 * Old menu generator
185
	 * @deprecated from WB 2.9.x and up
186
	 * @global  $wb
187
	 * @param <type> $menu_number
188
	 * @param <type> $start_level
189
	 * @param <type> $recurse
190
	 * @param <type> $collapse
191
	 * @param <type> $item_template
192
	 * @param <type> $item_footer
193
	 * @param <type> $menu_header
194
	 * @param <type> $menu_footer
195
	 * @param <type> $default_class
196
	 * @param <type> $current_class
197
	 * @param <type> $parent
198
	 */
199 1363 Luisehahne
	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) {
200
		global $wb;
201
		if (isset($menu_number))
202
			$wb->menu_number=$menu_number;
203
		if (isset($start_level))
204
			$wb->menu_start_level=$start_level;
205
		if (isset($recurse))
206
			$wb->menu_recurse=$recurse;
207
		if (isset($collapse))
208
			$wb->menu_collapse=$collapse;
209
		if (isset($item_template))
210
			$wb->menu_item_template=$item_template;
211
		if (isset($item_footer))
212
			$wb->menu_item_footer=$item_footer;
213
		if (isset($menu_header))
214
			$wb->menu_header=$menu_header;
215
		if (isset($menu_footer))
216
			$wb->menu_footer=$menu_footer;
217
		if (isset($default_class))
218
			$wb->menu_default_class=$default_class;
219
		if (isset($current_class))
220
			$wb->menu_current_class=$current_class;
221
		if (isset($parent))
222
			$wb->menu_parent=$parent;
223
		$wb->menu();
224
		unset($wb->menu_recurse);
225
		unset($wb->menu_parent);
226
		unset($wb->menu_start_level);
227
	}
228
}
229
230
if (!function_exists('page_content')) {
231 1487 DarkViper
	/**
232
	 *
233
	 * @global array $TEXT
234
	 * @global array $MENU
235
	 * @global array $HEADING
236
	 * @global array $MESSAGE
237
	 * @global array $globals several global vars
238
	 * @global datadase $database
239
	 * @global wb $wb
240
	 * @global string $global_name
241
	 * @param int $block
242
	 * @return void
243
	 */
244 1363 Luisehahne
	function page_content($block = 1) {
245
		// Get outside objects
246
		global $TEXT,$MENU,$HEADING,$MESSAGE;
247
		global $globals;
248
		global $database;
249
		global $wb;
250 1487 DarkViper
		$admin = $wb;
251
		if ($wb->page_access_denied==true) {
252 1363 Luisehahne
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
253
			return;
254
		}
255 1487 DarkViper
		if ($wb->page_no_active_sections==true) {
256 1363 Luisehahne
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
257
			return;
258
		}
259 1487 DarkViper
		if(isset($globals) AND is_array($globals)) {
260
            foreach($globals AS $global_name) {
261 1363 Luisehahne
                global $$global_name;
262 1487 DarkViper
			}
263 1363 Luisehahne
        }
264
		// Make sure block is numeric
265 1487 DarkViper
		if( ($block = intval($block)) == 0 ) { $block = 1; }
266 1363 Luisehahne
		// Include page content
267
		if(!defined('PAGE_CONTENT') OR $block!=1)
268
        {
269
			$page_id = intval($wb->page_id);
270
            // set session variable to save page_id only if PAGE_CONTENT is empty
271
            $_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
272
            // set to new value if page_id changed and not 0
273
            if(($page_id != 0) && ($_SESSION['PAGE_ID'] <> $page_id))
274
            {
275
            $_SESSION['PAGE_ID'] = $page_id;
276
            }
277 1487 DarkViper
		// First get all sections for this page
278
			$sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
279
			$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
280
			$sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
281
			$sql .= 'ORDER BY `position`';
282
			if( !($query_sections = $database->query($sql)) ) { return; }
283
		// If none were found, check if default content is supposed to be shown
284 1363 Luisehahne
			if($query_sections->numRows() == 0) {
285 1487 DarkViper
				if($wb->default_block_content == 'none') { return; }
286 1363 Luisehahne
				if (is_numeric($wb->default_block_content)) {
287 1487 DarkViper
					$page_id = $wb->default_block_content;
288 1363 Luisehahne
				} else {
289 1487 DarkViper
					$page_id = $wb->default_page_id;
290 1363 Luisehahne
				}
291 1487 DarkViper
				$sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
292
				$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
293
				$sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
294
				$sql .= 'ORDER BY `position`';
295
				if( !($query_sections = $database->query($sql)) ) { return; }
296 1363 Luisehahne
				// Still no cotent found? Give it up, there's just nothing to show!
297 1487 DarkViper
				if($query_sections->numRows() == 0) { return; }
298 1363 Luisehahne
			}
299
			// Loop through them and include their module file
300
			while($section = $query_sections->fetchRow()) {
301
				// skip this section if it is out of publication-date
302
				$now = time();
303
				if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
304
					continue;
305
				}
306
				$section_id = $section['section_id'];
307
				$module = $section['module'];
308
				// make a anchor for every section.
309
				if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
310
					echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
311
				}
312
                // check if module exists - feature: write in errorlog
313
				if(file_exists(WB_PATH.'/modules/'.$module.'/view.php')) {
314
				// fetch content -- this is where to place possible output-filters (before highlighting)
315
					ob_start(); // fetch original content
316
					require(WB_PATH.'/modules/'.$module.'/view.php');
317 1487 DarkViper
					$content = ob_get_clean();
318 1363 Luisehahne
				} else {
319
					continue;
320
				}
321
				// highlights searchresults
322
				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
323
					$arr_string = explode(" ", $_GET['sstring']);
324
					if($_GET['searchresult']==2) { // exact match
325
						$arr_string[0] = str_replace("_", " ", $arr_string[0]);
326
					}
327
					echo search_highlight($content, $arr_string);
328
				} else {
329
					echo $content;
330
				}
331
			}
332
		}
333 1487 DarkViper
        else {
334 1363 Luisehahne
			require(PAGE_CONTENT);
335
		}
336
	}
337
}
338
339
if (!function_exists('show_content')) {
340
	function show_content($block=1) {
341
		page_content($block);
342
	}
343
}
344
345
if (!function_exists('show_breadcrumbs'))
346
{
347
	function show_breadcrumbs($sep = ' &raquo; ',$level = 0, $links = true, $depth = -1, $title = '')
348
    {
349
		global $wb,$database,$MENU;
350
		$page_id = $wb->page_id;
351
        $title = (trim($title) == '') ? $MENU['BREADCRUMB'] : $title;
352
		if ($page_id != 0)
353
		{
354
			$counter = 0;
355
            // get links as array
356
            $bread_crumbs = $wb->page_trail;
357
            $count = sizeof($bread_crumbs);
358
            // level can't be greater than sum of links
359
            $level = ($count <= $level ) ? $count-1 : $level;
360
            // set level from which to show, delete indexes in array
361
			$crumbs = array_slice($bread_crumbs, $level );
362
            $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
363
            // if empty array, set orginal links
364
            $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
365
            $total_crumbs = ( ($depth <= 0) || ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
366
            print '<div class="breadcrumb"><span class="title">'.$title.'</span>';
367
          //  print_r($crumbs);
368
			foreach ($crumbs as $temp)
369
            {
370
                if($counter == $depth) { break; }
371 1487 DarkViper
                // set links and separator
372
					$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$temp;
373
					$query_menu = $database->query($sql);
374 1363 Luisehahne
					$page = $query_menu->fetchRow();
375
                    $show_crumb = (($links == true) && ($temp != $page_id))
376
                            ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'
377
                            : '<span class="crumb">'.$page['menu_title'].'</span>';
378
                    // Permission
379
                    switch ($page['visibility'])
380
                    {
381
                        case 'none' :
382
                        case 'hidden' :
383
                        // if show, you know there is an error in a hidden page
384
                            print $show_crumb.'&nbsp;';
385 1487 DarkViper
	                        break;
386 1363 Luisehahne
                        default :
387
                            print $show_crumb;
388 1487 DarkViper
		                    break;
389 1363 Luisehahne
                    }
390
391
                    if ( ( $counter <> $total_crumbs-1 ) )
392
                    {
393
                        print '<span class="separator">'.$sep.'</span>';
394
                    }
395
	            $counter++;
396
            }
397
            print "</div>\n";
398
		}
399
	}
400
}
401
402
// Function for page title
403
if (!function_exists('page_title')) {
404
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
405
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
406
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
407
		echo str_replace($vars, $values, $template);
408
	}
409
}
410
411
// Function for page description
412
if (!function_exists('page_description')) {
413
	function page_description() {
414
		global $wb;
415
		if ($wb->page_description!='') {
416
			echo $wb->page_description;
417
		} else {
418
			echo WEBSITE_DESCRIPTION;
419
		}
420
	}
421
}
422
423
// Function for page keywords
424
if (!function_exists('page_keywords')) {
425
	function page_keywords() {
426
		global $wb;
427
		if ($wb->page_keywords!='') {
428
			echo $wb->page_keywords;
429
		} else {
430
			echo WEBSITE_KEYWORDS;
431
		}
432
	}
433
}
434
435
// Function for page header
436
if (!function_exists('page_header')) {
437
	function page_header($date_format = 'Y') {
438
		echo WEBSITE_HEADER;
439
	}
440
}
441
442
// Function for page footer
443
if (!function_exists('page_footer')) {
444
	function page_footer($date_format = 'Y') {
445
		global $starttime;
446
		$vars = array('[YEAR]', '[PROCESS_TIME]');
447
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
448
		$values = array(gmdate($date_format),$processtime);
449
		echo str_replace($vars, $values, WEBSITE_FOOTER);
450
	}
451
}
452
453
function bind_jquery ($file_id='jquery')
454
{
455
456
        $jquery_links = '';
457
		/* include the Javascript jquery api  */
458
		if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
459
        {
460
            $wbpath = str_replace('\\','/',WB_PATH);  // fixed localhost problem with ie
461
			$jquery_links .= "<script type=\"text/javascript\">\n"
462
                ."var URL = '".WB_URL."';\n"
463
               /* ."var WB_PATH = '".$wbpath."';\n" */
464
                ."var WB_URL = '".WB_URL."';\n"
465
                ."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
466
                ."</script>\n";
467
468
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
469
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
470 1369 Luisehahne
			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-include.js" type="text/javascript"></script>'."\n";
471 1363 Luisehahne
            /* workout to insert ui.css and theme */
472
            $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
473
			$jquery_links .=  file_exists($jquery_theme)
474
                ? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
475
                : '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
476
            /* workout to insert plugins functions, set in templatedir */
477
            $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
478
			$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
479
                ? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
480
                : '';
481
		}
482
    return $jquery_links;
483
}
484
485
486
// Function to add optional module Javascript into the <body> section of the frontend
487
if(!function_exists('register_frontend_modfiles_body'))
488
{
489
	function register_frontend_modfiles_body($file_id="js")
490
    {
491
		// sanity check of parameter passed to the function
492
		$file_id = strtolower($file_id);
493
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
494
        {
495
			return;
496
		}
497
498
       // define constant indicating that the register_frontent_files was invoked
499
       if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
500
		global $wb, $database, $include_body_links;
501
		// define default baselink and filename for optional module javascript files
502
		$body_links = "";
503
504
		/* include the Javascript jquery api  */
505
        $body_links .= bind_jquery($file_id);
506
507
		if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
508
        {
509
    		$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
510
    		$base_file = "frontend_body.js";
511
512
			// ensure that frontend_body.js is only added once per module type
513
    		if(!empty($include_body_links))
514
            {
515
    			if(strpos($body_links, $include_body_links) === false)
516
                {
517
    				$body_links .= $include_body_links;
518
    			}
519
    			$include_body_links = '';
520
    		}
521
522
    		// gather information for all models embedded on actual page
523
    		$page_id = $wb->page_id;
524 1368 Luisehahne
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
525 1487 DarkViper
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
526 1368 Luisehahne
    		if( ($query_modules = $database->query($sql)) )
527
			{
528
	    		while($row = $query_modules->fetchRow())
529
	            {
530
	    			// check if page module directory contains a frontend_body.js file
531
	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
532
	                {
533
	    			// create link with frontend_body.js source for the current module
534
	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
535 1363 Luisehahne
536 1368 Luisehahne
	    				// define constant indicating that the register_frontent_files_body was invoked
537
	    					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) { define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);}
538 1363 Luisehahne
539 1368 Luisehahne
	    				// ensure that frontend_body.js is only added once per module type
540
	    				if(strpos($body_links, $tmp_link) === false)
541
	                    {
542
	    					$body_links .= $tmp_link;
543
	    				}
544
	    			}
545
	    		}
546
            }
547 1363 Luisehahne
        }
548
549
		print $body_links."\n"; ;
550
	}
551
}
552
553
554
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
555
if(!function_exists('register_frontend_modfiles'))
556
{
557
	function register_frontend_modfiles($file_id="css")
558
    {
559
		// sanity check of parameter passed to the function
560
		$file_id = strtolower($file_id);
561
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
562
        {
563
			return;
564
		}
565
566
		global $wb, $database, $include_head_link_css, $include_head_links;
567
		// define default baselink and filename for optional module javascript and stylesheet files
568
		$head_links = "";
569
570
        switch ($file_id)
571
        {
572
            case 'css':
573
			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
574
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
575
			$base_file = "frontend.css";
576
    		if(!empty($include_head_link_css))
577
            {
578
              $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
579
              $include_head_link_css = '';
580
            }
581
            break;
582
            case 'jquery':
583
            $head_links .= bind_jquery($file_id);
584
            break;
585
            case 'js':
586
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
587
			$base_file = "frontend.js";
588
    		if(!empty($include_head_links))
589
            {
590
              $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
591
              $include_head_links = '';
592
            }
593
            break;
594
            default:
595
            break;
596
		}
597
598
        if( $file_id != 'jquery')
599
        {
600
    		// gather information for all models embedded on actual page
601
    		$page_id = $wb->page_id;
602 1487 DarkViper
			$sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
603
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
604 1368 Luisehahne
    		if( ($query_modules = $database->query($sql)) )
605
			{
606
	    		while($row = $query_modules->fetchRow())
607
	            {
608
	    			// check if page module directory contains a frontend.js or frontend.css file
609
	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
610
	                {
611
	    			// create link with frontend.js or frontend.css source for the current module
612
	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
613 1363 Luisehahne
614 1368 Luisehahne
	    				// define constant indicating that the register_frontent_files was invoked
615
	    				if($file_id == 'css')
616
	                    {
617
	    					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
618
	    				} else
619
	                    {
620
	    					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
621
	    				}
622
	    				// ensure that frontend.js or frontend.css is only added once per module type
623
	    				if(strpos($head_links, $tmp_link) === false)
624
	                    {
625
	    					$head_links .= $tmp_link."\n";
626
	    				}
627
	    			};
628
	    		}
629
			}
630
       		// include the Javascript email protection function
631
       		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
632
               {
633
       			$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
634
       		}
635
               elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
636
               {
637
       			$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
638
       		}
639 1363 Luisehahne
        }
640
        print $head_links;
641
    }
642
}
643
644 1443 Luisehahne
	function moveCssToHead($content) {
645
		// move css definitions into head section
646 1464 DarkViper
		$pattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
647
		$pattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)/si';
648
		while(preg_match($pattern1, $content, $matches)==1) {
649
		// loop through all linked CSS
650
			$insert = $matches[1];
651
			$content = str_replace($insert, '', $content);
652
			$insert = "\n".$insert."\n</head>\n<body";
653
			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
654 1443 Luisehahne
		}
655 1464 DarkViper
		while(preg_match($pattern2, $content, $matches)==1) {
656
		// loop through all inline CSS
657
			$insert = $matches[1];
658
			$content = str_replace($insert, '', $content);
659
			$insert = "\n".$insert."\n</head>\n<body";
660
			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
661 1443 Luisehahne
		}
662
		return $content;
663
	}
664
665 1363 Luisehahne
// Begin WB < 2.4.x template compatibility code
666
	// Make extra_sql accessable through private_sql
667
	$private_sql = $extra_sql;
668
	$private_where_sql = $extra_where_sql;
669
	// Query pages for menu
670 1487 DarkViper
	$sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`visibility`'.$extra_sql.' ';
671
	$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
672
	$sql .= 'WHERE `parent`=0 AND '.$extra_where_sql.' ';
673
	$sql .= 'ORDER BY `position` ASC';
674
	$menu1 = $database->query($sql);
675 1363 Luisehahne
	// Check if current pages is a parent page and if we need its submenu
676 1487 DarkViper
	$tmp = (PARENT == 0 ? PAGE_ID : PARENT);
677
	$sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`visibility`'.$extra_sql.' ';
678
	$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
679
	$sql .= 'WHERE `parent`='.$tmp.' AND '.$extra_where_sql.' ';
680
	$sql .= 'ORDER BY `position` ASC';
681
	$menu2 = $database->query($sql);