Project

General

Profile

« Previous | Next » 

Revision 1487

Added by DarkViper over 13 years ago

class.order completely recoded to reduce SQL requests
all other files: fix SQL-statements to SQL-strict

View differences:

frontend.functions.php
19 19
// Must include code to stop this file being access directly
20 20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
21 21

  
22
// references to objects and variables that changed their names
23

  
24
$admin = &$wb;
25

  
26
$default_link=&$wb->default_link;
27

  
28
$page_trail=&$wb->page_trail;
29
$page_description=&$wb->page_description;
30
$page_keywords=&$wb->page_keywords;
31
$page_link=&$wb->link;
32

  
22
// 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
// ---------- //
33 30
// extra_sql is not used anymore - this is basically a register_globals exploit prevention...
34
$extra_sql=&$wb->extra_sql;
35
$extra_where_sql=&$wb->extra_where_sql;
31
	$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    = '';
36 37

  
37
$include_head_link_css = '';
38
$include_body_links = '';
39
$include_head_links = '';
40 38
// workout to included frontend.css, fronten.js and frontend_body.js in snippets
41
$query="SELECT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'snippet'";
42
$query_result=$database->query($query);
43
if ($query_result->numRows()>0) {
44
	while ($row = $query_result->fetchRow()) {
45
		$module_dir = $row['directory'];
46
		if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
47
			include(WB_PATH.'/modules/'.$module_dir.'/include.php');
48
			/* check if frontend.css file needs to be included into the <head></head> of index.php
49
			*/
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
			}
39
	$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
				}
55 52
			// check if frontend.js file needs to be included into the <body></body> of index.php
56
			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
			}
53
				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
				}
60 57
			// check if frontend_body.js file needs to be included into the <body></body> of index.php
61
			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';
58
				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
				}
64 62
			}
65 63
		}
66 64
	}
67
}
68 65

  
69 66
// Frontend functions
70
if (!function_exists('page_link'))
71
{
67
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
	 */
72 73
	function page_link($link) {
73
		global $wb;
74
		return $wb->page_link($link);
74
		return $GLOBALS['wb']->page_link($link);
75 75
	}
76 76
}
77 77

  
78
if (!function_exists('get_page_link'))
79
{
80
    function get_page_link( $id )
78
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 )
81 86
    {
82 87
        global $database;
83
        // Get link
84 88
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
85 89
        $link = $database->get_one( $sql );
86 90
        return $link;
......
89 93

  
90 94
//function to highlight search results
91 95
if(!function_exists('search_highlight')) {
92
function search_highlight($foo='', $arr_string=array()) {
93
	require_once(WB_PATH.'/framework/functions.php');
94
	static $string_ul_umlaut = FALSE;
95
	static $string_ul_regex = FALSE;
96
	if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE)
97
		require(WB_PATH.'/search/search_convert.php');
98
	$foo = entities_to_umlauts($foo, 'UTF-8');
99
	array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
100
	$search_string = implode("|", $arr_string);
101
	$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
102
	// the highlighting
103
	// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
104
	// Also droplet tags are now excluded from highlighting.
105
	// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
106
	// we have to cut <pre> and <code> as well.
107
	// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
108
	$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));
109
	if(is_array($matches) && $matches != array()) {
110
		$foo = "";
111
		foreach($matches as $match) {
112
			if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
113
				$match = str_replace(array('&lt;', '&gt;', '&amp;', '&quot;', '&#039;', '&nbsp;'), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
114
				$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
115
				$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '&nbsp;'), $match);
116
				$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
96
	/**
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;
117 132
			}
118
			$foo .= $match;
119 133
		}
120
	}
121 134

  
122
	if(DEFAULT_CHARSET != 'utf-8') {
123
		$foo = umlauts_to_entities($foo, 'UTF-8');
135
		if(DEFAULT_CHARSET != 'utf-8') {
136
			$foo = umlauts_to_entities($foo, 'UTF-8');
137
		}
138
		return $foo;
124 139
	}
125
	return $foo;
126 140
}
127
}
128 141

  
129
// Old menu call invokes new menu function
130 142
if (!function_exists('page_menu')) {
143
	/**
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
	 */
131 156
	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) {
132 157
		global $wb;
133 158
		$wb->menu_number=$menu_number;
......
155 180
}
156 181

  
157 182
if (!function_exists('show_menu')) {
183
	/**
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
	 */
158 199
	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) {
159 200
		global $wb;
160 201
		if (isset($menu_number))
......
187 228
}
188 229

  
189 230
if (!function_exists('page_content')) {
231
	/**
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
	 */
190 244
	function page_content($block = 1) {
191 245
		// Get outside objects
192 246
		global $TEXT,$MENU,$HEADING,$MESSAGE;
193 247
		global $globals;
194 248
		global $database;
195 249
		global $wb;
196
		$admin = & $wb;
197
		if ($wb->page_access_denied==true)
198
        {
250
		$admin = $wb;
251
		if ($wb->page_access_denied==true) {
199 252
	        echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
200 253
			return;
201 254
		}
202
		if ($wb->page_no_active_sections==true)
203
        {
255
		if ($wb->page_no_active_sections==true) {
204 256
	        echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'];
205 257
			return;
206 258
		}
207
		if(isset($globals) AND is_array($globals))
208
        {
209
            foreach($globals AS $global_name)
210
            {
259
		if(isset($globals) AND is_array($globals)) {
260
            foreach($globals AS $global_name) {
211 261
                global $$global_name;
212
                }
262
			}
213 263
        }
214 264
		// Make sure block is numeric
215
		if(!is_numeric($block)) { $block = 1; }
265
		if( ($block = intval($block)) == 0 ) { $block = 1; }
216 266
		// Include page content
217 267
		if(!defined('PAGE_CONTENT') OR $block!=1)
218 268
        {
......
224 274
            {
225 275
            $_SESSION['PAGE_ID'] = $page_id;
226 276
            }
227

  
228
			// First get all sections for this page
229
			$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");
230
			// If none were found, check if default content is supposed to be shown
277
		// 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
231 284
			if($query_sections->numRows() == 0) {
232
				if ($wb->default_block_content=='none') {
233
					return;
234
				}
285
				if($wb->default_block_content == 'none') { return; }
235 286
				if (is_numeric($wb->default_block_content)) {
236
					$page_id=$wb->default_block_content;
287
					$page_id = $wb->default_block_content;
237 288
				} else {
238
					$page_id=$wb->default_page_id;
289
					$page_id = $wb->default_page_id;
239 290
				}				
240
				$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");
291
				$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; }
241 296
				// Still no cotent found? Give it up, there's just nothing to show!
242
				if($query_sections->numRows() == 0) {
243
					return;
244
				}
297
				if($query_sections->numRows() == 0) { return; }
245 298
			}
246 299
			// Loop through them and include their module file
247 300
			while($section = $query_sections->fetchRow()) {
......
261 314
				// fetch content -- this is where to place possible output-filters (before highlighting)
262 315
					ob_start(); // fetch original content
263 316
					require(WB_PATH.'/modules/'.$module.'/view.php');
264
					$content = ob_get_contents();
265
					ob_end_clean();
317
					$content = ob_get_clean();
266 318
				} else {
267 319
					continue;
268 320
				}
269

  
270 321
				// highlights searchresults
271 322
				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
272 323
					$arr_string = explode(" ", $_GET['sstring']);
......
279 330
				}
280 331
			}
281 332
		}
282
        else
283
        {
284

  
333
        else {
285 334
			require(PAGE_CONTENT);
286 335
		}
287 336
	}
......
319 368
			foreach ($crumbs as $temp)
320 369
            {
321 370
                if($counter == $depth) { break; }
322
                    // set links and separator
323
					$query_menu = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = $temp");
371
                // set links and separator
372
					$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$temp;
373
					$query_menu = $database->query($sql);
324 374
					$page = $query_menu->fetchRow();
325

  
326 375
                    $show_crumb = (($links == true) && ($temp != $page_id))
327 376
                            ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'
328 377
                            : '<span class="crumb">'.$page['menu_title'].'</span>';
329

  
330 378
                    // Permission
331 379
                    switch ($page['visibility'])
332 380
                    {
......
334 382
                        case 'hidden' :
335 383
                        // if show, you know there is an error in a hidden page
336 384
                            print $show_crumb.'&nbsp;';
337
                        break;
385
	                        break;
338 386
                        default :
339 387
                            print $show_crumb;
340
                        break;
388
		                    break;
341 389
                    }
342 390

  
343 391
                    if ( ( $counter <> $total_crumbs-1 ) )
......
474 522
    		// gather information for all models embedded on actual page
475 523
    		$page_id = $wb->page_id;
476 524
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
477
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module` <> \'wysiwyg\'';
525
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
478 526
    		if( ($query_modules = $database->query($sql)) )
479 527
			{
480 528
	    		while($row = $query_modules->fetchRow())
......
551 599
        {
552 600
    		// gather information for all models embedded on actual page
553 601
    		$page_id = $wb->page_id;
554
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
555
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module` <> \'wysiwyg\'';
602
			$sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
603
			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
556 604
    		if( ($query_modules = $database->query($sql)) )
557 605
			{
558 606
	    		while($row = $query_modules->fetchRow())
......
619 667
	$private_sql = $extra_sql;
620 668
	$private_where_sql = $extra_where_sql;
621 669
	// Query pages for menu
622
	$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");
670
	$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);
623 675
	// Check if current pages is a parent page and if we need its submenu
624
	if(PARENT == 0) {
625
		// Get the pages submenu
626
		$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");
627
	} else {
628
		// Get the pages submenu
629
		$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");
630
	}
631

  
676
	$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);

Also available in: Unified diff