Project

General

Profile

1
<?php
2

    
3
// $Id: frontend.functions.php 740 2008-03-03 18:57:43Z thorn $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
/*
27
	This file is purely for ensuring compatibility with 3rd party
28
	contributions made for WB version 2.5.2 or below
29
*/
30
if(!defined('WB_URL')) {
31
	header('Location: ../index.php');
32
	exit(0);
33
}
34

    
35
// references to objects and variables that changed their names
36

    
37
$admin = &$wb;
38

    
39
$default_link=&$wb->default_link;
40

    
41
$page_trail=&$wb->page_trail;
42
$page_description=&$wb->page_description;
43
$page_keywords=&$wb->page_keywords;
44
$page_link=&$wb->link;
45

    
46
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
47
$extra_sql=&$wb->extra_sql;
48
$extra_where_sql=&$wb->extra_where_sql;
49

    
50
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
51
$query_result=$database->query($query);
52
if ($query_result->numRows()>0) {
53
	while ($row = $query_result->fetchRow()) {
54
		$module_dir = $row['directory'];
55
		if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
56
			include(WB_PATH.'/modules/'.$module_dir.'/include.php');
57
		}
58
	}
59
}
60

    
61
// Frontend functions
62
if (!function_exists('page_link')) {
63
	function page_link($link) {
64
		global $wb;
65
		return $wb->page_link($link);
66
	}
67
}
68

    
69
//function to highlight search results
70
if (!function_exists('search_highlight')) {
71
function search_highlight($foo='', $arr_string=array()) {
72
	require_once(WB_PATH.'/framework/functions.php');
73
	static $string_ul_umlauts=array();
74
	if($string_ul_umlauts == array())
75
		require(WB_PATH.'/search/search_convert.php');
76
	$foo = entities_to_umlauts($foo, 'UTF-8');
77
	array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'/\');'));
78
	$search_string = implode("|", $arr_string);
79
	$string = entities_to_umlauts($search_string, 'UTF-8');
80
	$string = strtr($string, $string_ul_umlauts);
81
	// special-feature: '|' means word-boundary (\b). Searching for 'the|' will find 'the', but not 'thema'.
82
	$string = strtr($string, array('\\|'=>'\b'));
83
	
84
	// the highlighting
85
	// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
86
	// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
87
	// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
88
	$matches = preg_split("/(<style.*<\/style>|<script.*<\/script>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
89
	if(is_array($matches) && $matches != array()) {
90
		$foo = "";
91
		$string = strtr($string, array('&lt;'=>'<', '&gt;'=>'>', '&amp;'=>'&', '&quot;'=>'"', '&#39;'=>'\'', '&nbsp;'=>"\xC2\xA0"));
92
		foreach($matches as $match) {
93
			if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $match)) {
94
				$match = strtr($match, array('&lt;'=>'<', '&gt;'=>'>', '&amp;'=>'&', '&quot;'=>'"', '&#39;'=>'\'', '&nbsp;'=>"\xC2\xA0"));
95
				$match = preg_replace('/('.$string.')/iS', '_span class=_highlight__$1_/span_',$match);
96
				$match = strtr($match, array('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;', '\''=>'&#39;', "\xC2\xA0"=>'&nbsp;'));
97
				$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
98
			}
99
			$foo .= $match;
100
		}
101
	}
102
	
103
	if(DEFAULT_CHARSET != 'utf-8') {
104
		$foo = umlauts_to_entities($foo, 'UTF-8');
105
	}
106
	return $foo;
107
}
108
}
109

    
110
// Old menu call invokes new menu function
111
if (!function_exists('page_menu')) {
112
	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) {
113
		global $wb;
114
		$wb->menu_number=$menu_number;
115
		$wb->menu_item_template=$item_template;
116
		$wb->menu_item_footer='';
117
		$wb->menu_parent = $parent;
118
		$wb->menu_header = $menu_header; 
119
		$wb->menu_footer = $menu_footer;
120
		$wb->menu_default_class = $default_class;
121
		$wb->menu_current_class = $current_class;
122
		$wb->menu_recurse = $recurse+2; 	
123
		$wb->menu();
124
		unset($wb->menu_parent);
125
		unset($wb->menu_number);
126
		unset($wb->menu_item_template);
127
		unset($wb->menu_item_footer);
128
		unset($wb->menu_header);
129
		unset($wb->menu_footer);
130
		unset($wb->menu_default_class);
131
		unset($wb->menu_current_class);
132
		unset($wb->menu_start_level);
133
		unset($wb->menu_collapse);
134
		unset($wb->menu_recurse);
135
	}
136
}
137

    
138
if (!function_exists('show_menu')) {
139
	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) {
140
		global $wb;
141
		if (isset($menu_number))
142
			$wb->menu_number=$menu_number;
143
		if (isset($start_level))
144
			$wb->menu_start_level=$start_level;
145
		if (isset($recurse))
146
			$wb->menu_recurse=$recurse;
147
		if (isset($collapse))
148
			$wb->menu_collapse=$collapse;
149
		if (isset($item_template))
150
			$wb->menu_item_template=$item_template;
151
		if (isset($item_footer))
152
			$wb->menu_item_footer=$item_footer;
153
		if (isset($menu_header))
154
			$wb->menu_header=$menu_header;
155
		if (isset($menu_footer))
156
			$wb->menu_footer=$menu_footer;
157
		if (isset($default_class))
158
			$wb->menu_default_class=$default_class;
159
		if (isset($current_class))
160
			$wb->menu_current_class=$current_class;
161
		if (isset($parent))
162
			$wb->menu_parent=$parent;
163
		$wb->menu();
164
		unset($wb->menu_recurse);
165
		unset($wb->menu_parent);
166
		unset($wb->menu_start_level);
167
	}
168
}
169

    
170
if (!function_exists('page_content')) {
171
	function page_content($block = 1) {
172
		// Get outside objects
173
		global $TEXT,$MENU,$HEADING,$MESSAGE;
174
		global $globals;
175
		global $database;
176
		global $wb;
177
		$admin = & $wb;
178
		if ($wb->page_access_denied==true) {
179
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
180
			exit();
181
		}
182
		if ($wb->page_no_active_sections==true) {
183
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
184
			exit();
185
		}
186
		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
187
		// Make sure block is numeric
188
		if(!is_numeric($block)) { $block = 1; }
189
		// Include page content
190
		if(!defined('PAGE_CONTENT') OR $block!=1) {
191
			$page_id=$wb->page_id;
192
			// First get all sections for this page
193
			$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");
194
			// If none were found, check if default content is supposed to be shown
195
			if($query_sections->numRows() == 0) {
196
				if ($wb->default_block_content=='none') {
197
					return;
198
				}
199
				if (is_numeric($wb->default_block_content)) {
200
					$page_id=$wb->default_block_content;
201
				} else {
202
					$page_id=$wb->default_page_id;
203
				}				
204
				$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");
205
				// Still no cotent found? Give it up, there's just nothing to show!
206
				if($query_sections->numRows() == 0) {
207
					return;
208
				}
209
			}
210
			// Loop through them and include their module file
211
			while($section = $query_sections->fetchRow()) {
212
				// skip this section if it is out of publication-date
213
				$now = time();
214
				if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
215
					continue;
216
				}
217
				$section_id = $section['section_id'];
218
				$module = $section['module'];
219
				// make a anchor for every section. This is for the search_extension
220
				echo "<a id=\"wb_section_$section_id\" name=\"wb_section_$section_id\"></a>";
221
				// highlights searchresults
222
				if (isset($_GET['searchresult']) AND is_numeric($_GET['searchresult']) AND !isset($_GET['nohighlight'])) {
223
					if (isset($_GET['sstring']) AND !empty($_GET['sstring']) ){
224
						$arr_string = explode(" ", $_GET['sstring']);
225
						if($_GET['searchresult'] == 2) {
226
							// exact match
227
							$arr_string[0] = strtr($arr_string[0], "_"," ");
228
						}
229
						ob_start(); //start output buffer
230
						require(WB_PATH.'/modules/'.$module.'/view.php');
231
						$foo = ob_get_contents();    // put outputbuffer in $foo
232
						ob_end_clean();             // clear outputbuffer
233
						echo search_highlight($foo, $arr_string);
234
					}
235
				} else {
236
					require(WB_PATH.'/modules/'.$module.'/view.php');
237
				}
238
			}
239
		} else {
240
			require(PAGE_CONTENT);
241
		}
242
	}
243
}
244

    
245
if (!function_exists('show_content')) {
246
	function show_content($block=1) {
247
		page_content($block);
248
	}
249
}
250

    
251
if (!function_exists('show_breadcrumbs')) {
252
	function show_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
253
		global $wb;
254
		$page_id=$wb->page_id;
255
		if ($page_id!=0)
256
		{
257
	 		global $database;
258
			$bca=$wb->page_trail;
259
			$counter=0;
260
			foreach ($bca as $temp)
261
			{
262
		        if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
263
		        {
264
					if ($counter>=$tier) echo $sep;
265
					$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
266
					$page=$query_menu->fetchRow();
267
					if ($links==true AND $temp!=$page_id)
268
						echo '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
269
					else
270
					    echo $page['menu_title'];
271
		        }
272
	            $counter++;
273
			}
274
		}
275
	}
276
}
277

    
278
// Function for page title
279
if (!function_exists('page_title')) {
280
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
281
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
282
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
283
		echo str_replace($vars, $values, $template);
284
	}
285
}
286

    
287
// Function for page description
288
if (!function_exists('page_description')) {
289
	function page_description() {
290
		global $wb;
291
		if ($wb->page_description!='') {
292
			echo $wb->page_description;
293
		} else {
294
			echo WEBSITE_DESCRIPTION;
295
		}
296
	}
297
}
298

    
299
// Function for page keywords
300
if (!function_exists('page_keywords')) {
301
	function page_keywords() {
302
		global $wb;
303
		if ($wb->page_keywords!='') {
304
			echo $wb->page_keywords;
305
		} else {
306
			echo WEBSITE_KEYWORDS;
307
		}
308
	}
309
}
310

    
311
// Function for page header
312
if (!function_exists('page_header')) {
313
	function page_header($date_format = 'Y') {
314
		echo WEBSITE_HEADER;
315
	}
316
}
317

    
318
// Function for page footer
319
if (!function_exists('page_footer')) {
320
	function page_footer($date_format = 'Y') {
321
		global $starttime;
322
		$vars = array('[YEAR]', '[PROCESS_TIME]');
323
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
324
		$values = array(date($date_format),$processtime);
325
		echo str_replace($vars, $values, WEBSITE_FOOTER);
326
	}
327
}
328

    
329
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
330
if(!function_exists('register_frontend_modfiles')) {
331
	function register_frontend_modfiles($file_id="css") {
332
		// sanity check of parameter passed to the function
333
		$file_id = strtolower($file_id);
334
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { 
335
			return;
336
		}
337

    
338
		global $wb, $database;
339
		// define default baselink and filename for optional module javascript and stylesheet files
340
		$head_links = "";
341
		if($file_id == "css") {
342
      $base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"'; 
343
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
344
			$base_file = "frontend.css";
345
		} else {
346
			$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
347
			$base_file = "frontend.js";
348
		}
349

    
350
  	// gather information for all models embedded on actual page
351
		$page_id = $wb->page_id;
352
    $query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections 
353
			WHERE page_id=$page_id AND module<>'wysiwyg'");
354

    
355
    while($row = $query_modules->fetchRow()) {
356
		// check if page module directory contains a frontend.js or frontend.css file
357
    	if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
358
				// create link with frontend.js or frontend.css source for the current module
359
				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
360

    
361
        // define constant indicating that the register_frontent_files was invoked
362
				if($file_id == 'css') {
363
					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
364
				} else {
365
					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
366
				}
367

    
368
        // ensure that frontend.js or frontend.css is only added once per module type
369
        if(strpos($head_links, $tmp_link) === false) {
370
					$head_links .= $tmp_link ."\n";
371
				}
372
			}
373
    }
374
  	// include the Javascript email protection function
375
  	if($file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js')) {
376
			$head_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/output_filter/js/mdcr.js"></script>' ."\n";
377
		}
378
  		
379
		// write out links with all external module javascript/CSS files, remove last line feed
380
		echo $head_links;
381
	}
382
}
383

    
384
// Begin WB < 2.4.x template compatibility code
385
	// Make extra_sql accessable through private_sql
386
	$private_sql = $extra_sql;
387
	$private_where_sql = $extra_where_sql;
388
	// Query pages for menu
389
	$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");
390
	// Check if current pages is a parent page and if we need its submenu
391
	if(PARENT == 0) {
392
		// Get the pages submenu
393
		$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");
394
	} else {
395
		// Get the pages submenu
396
		$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");
397
	}
398
// End WB < 2.4.x template compatibility code
399
// Include template file
400

    
401

    
402
?>
(9-9/13)