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