Project

General

Profile

1
<?php
2

    
3
// $Id: frontend.functions.php 438 2007-03-04 09:07:47Z 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
	$last_string="";
72
	foreach($arr_string as $string) {
73
		// filter meta-characters
74
		$string=preg_quote($string, '/');
75
		if ($string!=$last_string ) {
76
			$foo=preg_replace('/('.$string.')(?=[^>;]*(&|<))/iUS', '<span class="highlight">$1</span>',$foo);
77
			$last_string=$string;
78
		}
79
	}
80
	return $foo;
81
}  
82

    
83
// Old menu call invokes new menu function
84
if (!function_exists('page_menu')) {
85
	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) {
86
		global $wb;
87
		$wb->menu_number=$menu_number;
88
		$wb->menu_item_template=$item_template;
89
		$wb->menu_item_footer='';
90
		$wb->menu_parent = $parent;
91
		$wb->menu_header = $menu_header; 
92
		$wb->menu_footer = $menu_footer;
93
		$wb->menu_default_class = $default_class;
94
		$wb->menu_current_class = $current_class;
95
		$wb->menu_recurse = $recurse+2; 	
96
		$wb->menu();
97
		unset($wb->menu_parent);
98
		unset($wb->menu_number);
99
		unset($wb->menu_item_template);
100
		unset($wb->menu_item_footer);
101
		unset($wb->menu_header);
102
		unset($wb->menu_footer);
103
		unset($wb->menu_default_class);
104
		unset($wb->menu_current_class);
105
		unset($wb->menu_start_level);
106
		unset($wb->menu_collapse);
107
		unset($wb->menu_recurse);
108
	}
109
}
110

    
111
if (!function_exists('show_menu')) {
112
	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) {
113
		global $wb;
114
		if (isset($menu_number))
115
			$wb->menu_number=$menu_number;
116
		if (isset($start_level))
117
			$wb->menu_start_level=$start_level;
118
		if (isset($recurse))
119
			$wb->menu_recurse=$recurse;
120
		if (isset($collapse))
121
			$wb->menu_collapse=$collapse;
122
		if (isset($item_template))
123
			$wb->menu_item_template=$item_template;
124
		if (isset($item_footer))
125
			$wb->menu_item_footer=$item_footer;
126
		if (isset($menu_header))
127
			$wb->menu_header=$menu_header;
128
		if (isset($menu_footer))
129
			$wb->menu_footer=$menu_footer;
130
		if (isset($default_class))
131
			$wb->menu_default_class=$default_class;
132
		if (isset($current_class))
133
			$wb->menu_current_class=$current_class;
134
		if (isset($parent))
135
			$wb->menu_parent=$parent;
136
		$wb->menu();
137
		unset($wb->menu_recurse);
138
		unset($wb->menu_parent);
139
		unset($wb->menu_start_level);
140
	}
141
}
142

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

    
203
if (!function_exists('show_content')) {
204
	function show_content($block=1) {
205
		page_content($block);
206
	}
207
}
208

    
209
if (!function_exists('show_breadcrumbs')) {
210
	function show_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
211
		global $wb;
212
		$page_id=$wb->page_id;
213
		if ($page_id!=0)
214
		{
215
	 		global $database;
216
			$bca=$wb->page_trail;
217
			$counter=0;
218
			foreach ($bca as $temp)
219
			{
220
		        if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
221
		        {
222
					if ($counter>=$tier) echo $sep;
223
					$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
224
					$page=$query_menu->fetchRow();
225
					if ($links==true AND $temp!=$page_id)
226
						echo '<a href="'.page_link($page['link']).'">'.htmlentities($page['menu_title']).'</a>';
227
					else
228
					    echo htmlentities($page['menu_title']);
229
		        }
230
	            $counter++;
231
			}
232
		}
233
	}
234
}
235

    
236
// Function for page title
237
if (!function_exists('page_title')) {
238
	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
239
		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
240
		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
241
		echo str_replace($vars, $values, $template);
242
	}
243
}
244

    
245
// Function for page description
246
if (!function_exists('page_description')) {
247
	function page_description() {
248
		global $wb;
249
		if ($wb->page_description!='') {
250
			echo $wb->page_description;
251
		} else {
252
			echo WEBSITE_DESCRIPTION;
253
		}
254
	}
255
}
256

    
257
// Function for page keywords
258
if (!function_exists('page_keywords')) {
259
	function page_keywords() {
260
		global $wb;
261
		if ($wb->page_keywords!='') {
262
			echo $wb->page_keywords;
263
		} else {
264
			echo WEBSITE_KEYWORDS;
265
		}
266
	}
267
}
268

    
269
// Function for page header
270
if (!function_exists('page_header')) {
271
	function page_header($date_format = 'Y') {
272
		echo WEBSITE_HEADER;
273
	}
274
}
275

    
276
// Function for page footer
277
if (!function_exists('page_footer')) {
278
	function page_footer($date_format = 'Y') {
279
		global $starttime;
280
		$vars = array('[YEAR]', '[PROCESS_TIME]');
281
		$processtime=array_sum(explode(" ",microtime()))-$starttime;
282
		$values = array(date($date_format),$processtime);
283
		echo str_replace($vars, $values, WEBSITE_FOOTER);
284
	}
285
}
286

    
287
// Function to include optional module CSS stylesheets (module.css) into the <head> section
288
if (!function_exists('page_css')) {
289
	function page_css() {
290
    global $wb, $database;
291
    $css_head = "";
292

    
293
    // obtain list of modules used for actual displayed page
294
		$page_id=$wb->page_id;
295
    $query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections WHERE page_id=$page_id AND module<>'wysiwyg'");
296
    while($row = $query_modules->fetchRow()) {
297
      if(file_exists(WB_PATH .'/modules/' .$row['module'] .'/module.css')) {
298
        // build css link for current module.css
299
        $css_link = "<link href=\"" .WB_URL ."/modules/" .$row['module'];
300
        $css_link .= "/module.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />\n";
301
        // ensure that module.css is not added twice (e.g. if 2 sections include the same module)
302
        $css_head = str_replace($css_link, "", $css_head);
303
        $css_head .= $css_link;
304
      }
305
    }
306
    // write out links to all external module stylesheets (module.css)
307
    if($css_head != "") {
308
      $css_head = "<!-- Include external module CSS stylesheets -->\n" .$css_head;
309
      echo $css_head;
310
    }
311
	}
312
}
313

    
314
// Function to include optional module javascript files (module.js) into the <head> section
315
if (!function_exists('page_javascript')) {
316
	function page_javascript() {
317
    global $wb, $database;
318
    $js_head = "";
319

    
320
    // obtain list of modules used for actual displayed page
321
		$page_id=$wb->page_id;
322
    $query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections WHERE page_id=$page_id AND module<>'wysiwyg'");
323
    while($row = $query_modules->fetchRow()) {
324
      if(file_exists(WB_PATH .'/modules/' .$row['module'] .'/module.js')) {
325
        // build javascript link for current module.js
326
        $js_link = "<script type=\"text/javascript\" src=\"" .WB_URL ."/modules/" .$row['module'];
327
        $js_link .= "/module.js\"></script>\n";
328
        // ensure that module.js is not added twice (e.g. if 2 sections include the same module)
329
        $js_head = str_replace($js_link, "", $js_head);
330
        $js_head .= $js_link;
331
      }
332
    }
333
    // write out links to all external module javascript files (module.js)
334
    if($js_head != "") {
335
      $js_head = "<!-- Include external module javascript files -->\n" .$js_head;
336
      echo $js_head;
337
    }
338
	}
339
}
340

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

    
358

    
359
?>
(9-9/12)