Project

General

Profile

1
<?php
2

    
3
// $Id: frontend.functions.php 490 2007-06-23 08:13:53Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2007, 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
function search_highlight($foo='', $arr_string=array()) {
71
	require_once(WB_PATH.'/framework/functions.php');
72
	require(WB_PATH.'/search/search_convert.php');
73
	$foo = entities_to_umlauts($foo, 'UTF-8');
74
	array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'/\');'));
75
	$search_string = implode("|", $arr_string);
76
	$string = entities_to_umlauts($search_string, 'UTF-8');
77
	$string = strtr($string, $string_ul_umlauts);
78
	// do some magic to prevent &lt; &gt; ... from being highlighted
79
	$foo = strtr($foo, array("&lt;"=>"!,,!", "&gt;"=>"!,,,!", "&amp;"=>"!,,,,!", "&quot;"=>"!,,,,,!", "&#39;"=>"!,,,,,,!"));
80
	$string = strtr($string, array("&lt;"=>"!,,!", "&gt;"=>"!,,,!", "&amp;"=>"!,,,,!", "&quot;"=>"!,,,,,!", "&#39;"=>"!,,,,,,!"));
81
	$foo = preg_replace('/('.$string.')(?=[^>]*<)/iUS', '<span class="highlight">$1</span>',$foo);
82
	$pos = strpos($foo, '<');
83
	if ($pos === false) { // "===" means identicaly
84
		$foo = preg_replace('/('.$string.')/i', '<span class="highlight">$1</span>',$foo);
85
	}
86
	$foo = strtr($foo, array("!,,!"=>"&lt;", "!,,,!"=>"&gt;", "!,,,,!"=>"&amp;", "!,,,,,!"=>"&quot;", "!,,,,,,!"=>"&#39;"));
87
	if(DEFAULT_CHARSET != 'utf-8') {
88
		$foo = umlauts_to_defcharset($foo, 'UTF-8');
89
	}
90
	return $foo;
91
}
92

    
93
// Old menu call invokes new menu function
94
if (!function_exists('page_menu')) {
95
	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) {
96
		global $wb;
97
		$wb->menu_number=$menu_number;
98
		$wb->menu_item_template=$item_template;
99
		$wb->menu_item_footer='';
100
		$wb->menu_parent = $parent;
101
		$wb->menu_header = $menu_header; 
102
		$wb->menu_footer = $menu_footer;
103
		$wb->menu_default_class = $default_class;
104
		$wb->menu_current_class = $current_class;
105
		$wb->menu_recurse = $recurse+2; 	
106
		$wb->menu();
107
		unset($wb->menu_parent);
108
		unset($wb->menu_number);
109
		unset($wb->menu_item_template);
110
		unset($wb->menu_item_footer);
111
		unset($wb->menu_header);
112
		unset($wb->menu_footer);
113
		unset($wb->menu_default_class);
114
		unset($wb->menu_current_class);
115
		unset($wb->menu_start_level);
116
		unset($wb->menu_collapse);
117
		unset($wb->menu_recurse);
118
	}
119
}
120

    
121
if (!function_exists('show_menu')) {
122
	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) {
123
		global $wb;
124
		if (isset($menu_number))
125
			$wb->menu_number=$menu_number;
126
		if (isset($start_level))
127
			$wb->menu_start_level=$start_level;
128
		if (isset($recurse))
129
			$wb->menu_recurse=$recurse;
130
		if (isset($collapse))
131
			$wb->menu_collapse=$collapse;
132
		if (isset($item_template))
133
			$wb->menu_item_template=$item_template;
134
		if (isset($item_footer))
135
			$wb->menu_item_footer=$item_footer;
136
		if (isset($menu_header))
137
			$wb->menu_header=$menu_header;
138
		if (isset($menu_footer))
139
			$wb->menu_footer=$menu_footer;
140
		if (isset($default_class))
141
			$wb->menu_default_class=$default_class;
142
		if (isset($current_class))
143
			$wb->menu_current_class=$current_class;
144
		if (isset($parent))
145
			$wb->menu_parent=$parent;
146
		$wb->menu();
147
		unset($wb->menu_recurse);
148
		unset($wb->menu_parent);
149
		unset($wb->menu_start_level);
150
	}
151
}
152

    
153
if (!function_exists('page_content')) {
154
	function page_content($block = 1) {
155
		// Get outside objects
156
		global $TEXT,$MENU,$HEADING,$MESSAGE;
157
		global $globals;
158
		global $database;
159
		global $wb;
160
		$admin = & $wb;
161
		if ($wb->page_access_denied==true) {
162
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
163
			exit();
164
		}
165
		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
166
		// Make sure block is numeric
167
		if(!is_numeric($block)) { $block = 1; }
168
		// Include page content
169
		if(!defined('PAGE_CONTENT') OR $block!=1) {
170
			$page_id=$wb->page_id;
171
			// First get all sections for this page
172
			$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
173
			// If none were found, check if default content is supposed to be shown
174
			if($query_sections->numRows() == 0) {
175
				if ($wb->default_block_content=='none') {
176
					return;
177
				}
178
				if (is_numeric($wb->default_block_content)) {
179
					$page_id=$wb->default_block_content;
180
				} else {
181
					$page_id=$wb->default_page_id;
182
				}				
183
				$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
184
				// Still no cotent found? Give it up, there's just nothing to show!
185
				if($query_sections->numRows() == 0) {
186
					return;
187
				}
188
			}
189
			// Loop through them and include their module file
190
			while($section = $query_sections->fetchRow()) {
191
				$section_id = $section['section_id'];
192
				$module = $section['module'];
193
				// highlights searchresults
194
				if (isset($_GET['searchresult']) AND is_numeric($_GET['searchresult']) ) {
195
					if (isset($_GET['sstring']) AND !empty($_GET['sstring']) ){
196
						$arr_string = explode(" ", $_GET['sstring']);
197
						if($_GET['searchresult'] == 2) {
198
							// exact match
199
							$arr_string[0] = strtr($arr_string[0], "_"," ");
200
						}
201
						ob_start(); //start output buffer
202
						require(WB_PATH.'/modules/'.$module.'/view.php');
203
						$foo = ob_get_contents();    // put outputbuffer in $foo
204
						ob_end_clean();             // clear outputbuffer
205
						echo search_highlight($foo, $arr_string);
206
					}
207
				} else {
208
					require(WB_PATH.'/modules/'.$module.'/view.php');
209
				}
210
			}
211
		} else {
212
			require(PAGE_CONTENT);
213
		}
214
	}
215
}
216

    
217
if (!function_exists('show_content')) {
218
	function show_content($block=1) {
219
		page_content($block);
220
	}
221
}
222

    
223
if (!function_exists('show_breadcrumbs')) {
224
	function show_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
225
		global $wb;
226
		$page_id=$wb->page_id;
227
		if ($page_id!=0)
228
		{
229
	 		global $database;
230
			$bca=$wb->page_trail;
231
			$counter=0;
232
			foreach ($bca as $temp)
233
			{
234
		        if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
235
		        {
236
					if ($counter>=$tier) echo $sep;
237
					$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
238
					$page=$query_menu->fetchRow();
239
					if ($links==true AND $temp!=$page_id)
240
						echo '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
241
					else
242
					    echo $page['menu_title'];
243
		        }
244
	            $counter++;
245
			}
246
		}
247
	}
248
}
249

    
250
// Function for page title
251
if (!function_exists('page_title')) {
252
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
253
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
254
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
255
		echo str_replace($vars, $values, $template);
256
	}
257
}
258

    
259
// Function for page description
260
if (!function_exists('page_description')) {
261
	function page_description() {
262
		global $wb;
263
		if ($wb->page_description!='') {
264
			echo $wb->page_description;
265
		} else {
266
			echo WEBSITE_DESCRIPTION;
267
		}
268
	}
269
}
270

    
271
// Function for page keywords
272
if (!function_exists('page_keywords')) {
273
	function page_keywords() {
274
		global $wb;
275
		if ($wb->page_keywords!='') {
276
			echo $wb->page_keywords;
277
		} else {
278
			echo WEBSITE_KEYWORDS;
279
		}
280
	}
281
}
282

    
283
// Function for page header
284
if (!function_exists('page_header')) {
285
	function page_header($date_format = 'Y') {
286
		echo WEBSITE_HEADER;
287
	}
288
}
289

    
290
// Function for page footer
291
if (!function_exists('page_footer')) {
292
	function page_footer($date_format = 'Y') {
293
		global $starttime;
294
		$vars = array('[YEAR]', '[PROCESS_TIME]');
295
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
296
		$values = array(date($date_format),$processtime);
297
		echo str_replace($vars, $values, WEBSITE_FOOTER);
298
	}
299
}
300

    
301
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
302
if(!function_exists('register_frontend_modfiles')) {
303
	function register_frontend_modfiles($file_id="css") {
304
		// sanity check of parameter passed to the function
305
		$file_id = strtolower($file_id);
306
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { 
307
			return;
308
		}
309

    
310
		global $wb, $database;
311
		// define default baselink and filename for optional module javascript and stylesheet files
312
		$head_links = "";
313
		if($file_id == "css") {
314
      	$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"'; 
315
			$base_link.= 'rel="stylesheet" type="text/css" media="screen" />';
316
			$base_file = "frontend.css";
317
		} else {
318
			$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
319
			$base_file = "frontend.js";
320
		}
321

    
322
  		// gather information for all models embedded on actual page
323
		$page_id = $wb->page_id;
324
    	$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections 
325
			WHERE page_id=$page_id AND module<>'wysiwyg'");
326

    
327
    	while($row = $query_modules->fetchRow()) {
328
			// check if page module directory contains a frontend.js or frontend.css file
329
      	if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
330
				// create link with frontend.js or frontend.css source for the current module
331
				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
332
        		// ensure that frontend.js or frontend.css is only added once per module type
333
        		if(strpos($head_links, $tmp_link) === false) {
334
					$head_links .= $tmp_link ."\n";
335
				}
336
			}
337
    	}
338
  		// write out links with all external module javascript/CSS files, remove last line feed
339
		echo $head_links;
340
	}
341
}
342

    
343
// Begin WB < 2.4.x template compatibility code
344
	// Make extra_sql accessable through private_sql
345
	$private_sql = $extra_sql;
346
	$private_where_sql = $extra_where_sql;
347
	// Query pages for menu
348
	$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");
349
	// Check if current pages is a parent page and if we need its submenu
350
	if(PARENT == 0) {
351
		// Get the pages submenu
352
		$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");
353
	} else {
354
		// Get the pages submenu
355
		$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");
356
	}
357
// End WB < 2.4.x template compatibility code
358
// Include template file
359

    
360

    
361
?>
(9-9/12)