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:

branches/2.8.x/CHANGELOG
12 12

  
13 13
=============================== FEATURES FREEZE ================================
14 14
----------------------------------- Fixes 2.8.2 --------------------------------
15
10 Aug-2011 Build 1487 Werner v.d.Decken(DarkViper)
16
# class.order completely recoded to reduce SQL requests
17
# all other files: fix SQL-statements to SQL-strict
15 18
08 Aug-2011 Build 1486 Werner v.d.Decken(DarkViper)
16 19
# database::field_modify() there was a bug to fix
17 20
# all other files: fix SQL-statements to SQL-strict
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.2');
55
if(!defined('REVISION')) define('REVISION', '1486');
55
if(!defined('REVISION')) define('REVISION', '1487');
branches/2.8.x/wb/framework/initialize.php
16 16
 *
17 17
 */
18 18

  
19
// Must include code to stop this file being access directly
20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
19
//require_once(dirname(__FILE__).'/globalExceptionHandler.php');
20
//// Must include code to stop this file being access directly
21
//if(!defined('WB_PATH')) { throw new Exception('Illegaler Aufruf!'); }
22

  
23
require_once('globalExceptionHandler.php');
24
if(!defined('WB_PATH')) { throw new IllegalFileException(); }
25
//if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
26

  
21 27
//set_include_path(get_include_path() . PATH_SEPARATOR . WB_PATH);
22 28

  
23 29
if (file_exists(WB_PATH.'/framework/class.database.php')) {
branches/2.8.x/wb/framework/class.wb.php
138 138
		$has_active_sections = false;
139 139
		$page_id = $page['page_id'];
140 140
		$now = time();
141
		$query_sections = $database->query("SELECT publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
142
		if($query_sections->numRows() != 0)
143
        {
144
			while($section = $query_sections->fetchRow())
145
            {
146
				if($now<$section['publ_end'] && ($now>$section['publ_start'] || $section['publ_start']==0) || $now>$section['publ_start'] && $section['publ_end']==0)
147
                {
141
		$sql  = 'SELECT `publ_start`, `publ_end` ';
142
		$sql .= 'FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
143
		$query_sections = $database->query($sql);
144
		if($query_sections->numRows() != 0) {
145
			while($section = $query_sections->fetchRow()) {
146
				if( $now<$section['publ_end'] &&
147
					($now>$section['publ_start'] || $section['publ_start']==0) ||
148
					$now>$section['publ_start'] && $section['publ_end']==0)
149
				{
148 150
					$has_active_sections = true;
149 151
					break;
150 152
				}
......
156 158
	// Check whether we should show a page or not (for front-end)
157 159
	function show_page($page)
158 160
    {
159
		if($this->page_is_visible($page) && $this->page_is_active($page))
160
        {
161
			return true;
162
		} else {
163
			return false;
164
		}
161
		$retval = ($this->page_is_visible($page) && $this->page_is_active($page));
162
		return $retval;
165 163
	}
166 164

  
167 165
	// Check if the user is already authenticated or not
168 166
	function is_authenticated() {
169
		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID']))
170
        {
171
			return true;
172
		} else {
173
			return false;
174
		}
167
		$retval = ( isset($_SESSION['USER_ID']) AND
168
		            $_SESSION['USER_ID'] != "" AND
169
		            is_numeric($_SESSION['USER_ID']));
170
        return $retval;
175 171
	}
176 172

  
177 173
	// Modified addslashes function which takes into account magic_quotes
178 174
	function add_slashes($input) {
179
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
175
		if( get_magic_quotes_gpc() || (!is_string($input)) ) {
180 176
			return $input;
181 177
		}
182
		$output = addslashes($input);
183
		return $output;
178
		return addslashes($input);
184 179
	}
185 180

  
186 181
	// Ditto for stripslashes
......
191 186
		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
192 187
			return $input;
193 188
		}
194
		$output = stripslashes($input);
195
		return $output;
189
		return stripslashes($input);
196 190
	}
197 191

  
198 192
	// Escape backslashes for use with mySQL LIKE strings
......
211 205
	
212 206
	// Get POST data
213 207
	function get_post($field) {
214
		if(isset($_POST[$field])) {
215
			return $_POST[$field];
216
		} else {
217
			return null;
218
		}
208
		return (isset($_POST[$field]) ? $_POST[$field] : null);
219 209
	}
220 210

  
221 211
	// Get POST data and escape it
......
226 216
	
227 217
	// Get GET data
228 218
	function get_get($field) {
229
		if(isset($_GET[$field])) {
230
			return $_GET[$field];
231
		} else {
232
			return null;
233
		}
219
		return (isset($_GET[$field]) ? $_GET[$field] : null);
234 220
	}
235 221

  
236 222
	// Get SESSION data
237 223
	function get_session($field) {
238
		if(isset($_SESSION[$field])) {
239
			return $_SESSION[$field];
240
		} else {
241
			return null;
242
		}
224
		return (isset($_SESSION[$field]) ? $_SESSION[$field] : null);
243 225
	}
244 226

  
245 227
	// Get SERVER data
246 228
	function get_server($field) {
247
		if(isset($_SERVER[$field])) {
248
			return $_SERVER[$field];
249
		} else {
250
			return null;
251
		}
229
		return (isset($_SERVER[$field]) ? $_SERVER[$field] : null);
252 230
	}
253 231

  
254 232
	// Get the current users id
......
298 276

  
299 277
	// Get the current users timezone
300 278
	function get_timezone() {
301
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
302
			return $_SESSION['TIMEZONE'];
303
		} else {
304
			return '-72000';
305
		}
279
		return (isset($_SESSION['USE_DEFAULT_TIMEZONE']) ? '-72000' : $_SESSION['TIMEZONE']);
306 280
	}
307 281

  
308 282
	// Validate supplied email address
......
425 399

  
426 400
	// Validate send email
427 401
	function mail($fromaddress, $toaddress, $subject, $message, $fromname='') {
428
		/* 
429
			INTEGRATED OPEN SOURCE PHPMAILER CLASS FOR SMTP SUPPORT AND MORE
430
			SOME SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION
431
			NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE (C. Sommer)
402
/* 
403
	INTEGRATED OPEN SOURCE PHPMAILER CLASS FOR SMTP SUPPORT AND MORE
404
	SOME SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION
405
	NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE (C. Sommer)
432 406

  
433
			NOTE:
434
			To use SMTP for sending out mails, you have to specify the SMTP host of your domain
435
			via the Settings panel in the backend of Website Baker
436
		*/ 
407
	NOTE:
408
	To use SMTP for sending out mails, you have to specify the SMTP host of your domain
409
	via the Settings panel in the backend of Website Baker
410
*/ 
437 411

  
438 412
		$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
439 413
		$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
......
443 417

  
444 418
		// create PHPMailer object and define default settings
445 419
		$myMail = new wbmailer();
446

  
447 420
		// set user defined from address
448 421
		if ($fromaddress!='') {
449
			if($fromname!='') $myMail->FromName = $fromname;         // FROM-NAME
450
			$myMail->From = $fromaddress;                            // FROM:
451
			$myMail->AddReplyTo($fromaddress);                       // REPLY TO:
422
			if($fromname!='') $myMail->FromName = $fromname;  // FROM-NAME
423
			$myMail->From = $fromaddress;                     // FROM:
424
			$myMail->AddReplyTo($fromaddress);                // REPLY TO:
452 425
		}
453
		
454 426
		// define recepient and information to send out
455
		$myMail->AddAddress($toaddress);                            // TO:
456
		$myMail->Subject = $subject;                                // SUBJECT
457
		$myMail->Body = nl2br($message);                                   // CONTENT (HTML)
458
		$myMail->AltBody = strip_tags($message);				// CONTENT (TEXT)
459

  
427
		$myMail->AddAddress($toaddress);                      // TO:
428
		$myMail->Subject = $subject;                          // SUBJECT
429
		$myMail->Body = nl2br($message);                      // CONTENT (HTML)
430
		$myMail->AltBody = strip_tags($message);              // CONTENT (TEXT)
460 431
		// check if there are any send mail errors, otherwise say successful
461 432
		if (!$myMail->Send()) {
462 433
			return false;
branches/2.8.x/wb/framework/class.order.php
1 1
<?php
2
/**
3
 * @category        WebsiteBaker
4
 * @package         WebsiteBaker_core
5
 * @author          Werner v.d.Decken
6
 * @copyright       WebsiteBaker.org e.V.
7
 * @link            http://websitebaker2.org
8
 * @license         http://www.gnu.org/licenses/gpl.html
9
 * @version         $Id$
10
 * @filesource		$HeadURL$
11
 * Ordering class
12
 * This class will be used to change the order of an item in a table
13
 * which contains a special order field (type must be integer)
14
 */
15
/*******************************************************************************
16
 * abstract factory for application
17
 */
18
// Must include code to stop this file being access directly
19
	if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
20
	define('ORDERING_CLASS_LOADED', true);
21
// Load the other required class files if they are not already loaded
22
	require_once(WB_PATH."/framework/class.database.php");
2 23

  
3
// $Id$
24
class order {
4 25

  
5
/*
26
	const MOVE_UP   = 0;
27
	const MOVE_DOWN = 1;
6 28

  
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
29
	private $_Table      = '';
30
	private $_FieldOrder = '';
31
	private $_FieldId    = '';
32
	private $_FieldGroup = '';
33
	private $_DB         = null;
9 34

  
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

  
28
Ordering class
29

  
30
This class will be used to change the order of an item in a table
31
which contains a special order field (type must be integer)
32

  
33
*/
34

  
35
// Must include code to stop this file being access directly
36
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
37

  
38
define('ORDERING_CLASS_LOADED', true);
39

  
40
// Load the other required class files if they are not already loaded
41
require_once(WB_PATH."/framework/class.database.php");
42

  
43
class order {
44
	
45
	// Get the db values
46
	function order($table, $order_field, $id_field = 'id', $common_field) {
47
		$this->table = $table;
48
		$this->order_field = $order_field;
49
		$this->id_field = $id_field;
50
		$this->common_field = $common_field;
35
	/**
36
	 * Constructor
37
	 * @param string $Table
38
	 * @param string $FieldOrder
39
	 * @param string $FieldId
40
	 * @param string $FieldGroup
41
	 * use $GLOBALS['database']
42
	 */
43
	public function __construct($Table, $FieldOrder, $FieldId, $FieldGroup) {
44
		$this->_DB         = $GLOBALS['database'];
45
		$this->_Table      = $Table;
46
		$this->_FieldOrder = $FieldOrder;
47
		$this->_FieldId    = $FieldId;
48
		$this->_FieldGroup = $FieldGroup;
51 49
	}
52
	
53
	// Move a row up
54
	function move_up($id) {
55
		global $database;
56
		// Get current order
57
		$query_order = "SELECT ".$this->order_field.",".$this->common_field." FROM ".$this->table." WHERE ".$this->id_field." = '$id'";
58
		$get_order = $database->query($query_order);
59
		$fetch_order = $get_order->fetchRow();
60
		$order = $fetch_order[$this->order_field];
61
		$parent = $fetch_order[$this->common_field];
62
		// Find out what row is before current one
63
		$query_previous = "SELECT ".$this->id_field.",".$this->order_field." FROM ".$this->table." WHERE ".$this->order_field." < '$order' AND ".$this->common_field." = '$parent' ORDER BY ".$this->order_field." DESC LIMIT 1";
64
		$get_previous = $database->query($query_previous);
65
		if($get_previous->numRows() > 0) {
66
			// Change the previous row to the current order
67
			$fetch_previous = $get_previous->fetchRow();
68
			$previous_id = $fetch_previous[$this->id_field];
69
			$decremented_order = $fetch_previous[$this->order_field];
70
			$query = "UPDATE ".$this->table." SET ".$this->order_field." = '$order' WHERE ".$this->id_field." = '$previous_id' LIMIT 1";
71
			$database->query($query);
72
			// Change the row we want to the decremented order
73
			$query = "UPDATE ".$this->table." SET ".$this->order_field." = '$decremented_order' WHERE ".$this->id_field." = '$id' LIMIT 1";
74
			$database->query($query);
75
			
76
			if($database->is_error()) {
77
				return false;
78
			} else {
79
				return true;
50
	/**
51
	 *
52
	 * @param string|int $id
53
	 * @param int $direction
54
	 * @return bool
55
	 */
56
	public function move($id, $direction = self::MOVE_UP)
57
	{
58
		$retval = false;
59
		$sql  = 'SELECT `'.$this->_FieldOrder.'` `order`, `'.$this->_FieldGroup.'` `group` ';
60
		$sql .= 'FROM `'.$this->_Table.'` WHERE `'.$this->_FieldId.'`=\''.$id.'\'';
61
		if(($res1 = $this->_DB->query($sql))) {
62
			if(($rec1 = $res1->fetchRow())) {
63
				$sql  = 'SELECT `'.$this->_FieldId.'` `id`, `'.$this->_FieldOrder.'` `order` ';
64
				$sql .= 'FROM `'.$this->_Table.'` ';
65
				$sql .= 'WHERE `'.$this->_FieldGroup.'`=\''.$rec1['group'].'\' ';
66
				if($direction == self::MOVE_UP) {
67
					$sql .=     'AND `'.$this->_FieldOrder.'`>\''.$rec1['order'].'\' ';
68
					$sql .= 'ORDER BY `'.$this->_FieldOrder.'` ASC';
69
				}else {
70
					$sql .=     'AND `'.$this->_FieldOrder.'`<\''.$rec1['order'].'\' ';
71
					$sql .= 'ORDER BY `'.$this->_FieldOrder.'` DESC';
72
				}
73
				if(($res2 = $this->_DB->query($sql))) {
74
					if(($rec2 = $res2->fetchRow())) {
75
						$sql  = 'UPDATE `'.$this->_Table.'` ';
76
						$sql .= 'SET `'.$this->_FieldOrder.'`=\''.$rec1['order'].'\' ';
77
						$sql .= 'WHERE `'.$this->_FieldId.'`=\''.$rec2['id'].'\'';
78
						if($this->_DB->query($sql)) {
79
							$sql  = 'UPDATE `'.$this->_Table.'` ';
80
							$sql .= 'SET `'.$this->_FieldOrder.'`=\''.$rec2['order'].'\' ';
81
							$sql .= 'WHERE `'.$this->_FieldId.'`=\''.$id.'\'';
82
							$retval = $this->_DB->query($sql);
83
						}
84
					}
85
				}
80 86
			}
81
		} else {
82
			return false;
83 87
		}
88
		return $retval;
84 89
	}
85
	// Move a row up
86
	function move_down($id) {
87
		global $database;
90

  
91
	/**
92
	 * Move a row up
93
	 * @param string|int $id
94
	 * @return bool
95
	 */
96
	public function move_up($id) {
88 97
		// Get current order
89
		$query_order = "SELECT ".$this->order_field.",".$this->common_field." FROM ".$this->table." WHERE ".$this->id_field." = '$id'";
90
		$get_order = $database->query($query_order);
91
		$fetch_order = $get_order->fetchRow();
92
		$order = $fetch_order[$this->order_field];
93
		$parent = $fetch_order[$this->common_field];
94
		// Find out what row is before current one
95
		$query_next = "SELECT $this->id_field,".$this->order_field." FROM ".$this->table." WHERE ".$this->order_field." > '$order' AND ".$this->common_field." = '$parent' ORDER BY ".$this->order_field." ASC LIMIT 1";
96
		$get_next = $database->query($query_next);
97
		if($get_next->numRows() > 0) {
98
			// Change the previous row to the current order
99
			$fetch_next = $get_next->fetchRow();
100
			$next_id = $fetch_next[$this->id_field];
101
			$incremented_order = $fetch_next[$this->order_field];
102
			$query = "UPDATE ".$this->table." SET ".$this->order_field." = '$order' WHERE ".$this->id_field." = '$next_id' LIMIT 1";
103
			$database->query($query);
104
			// Change the row we want to the decremented order
105
			$query = "UPDATE ".$this->table." SET ".$this->order_field." = '$incremented_order' WHERE ".$this->id_field." = '$id' LIMIT 1";
106
			$database->query($query);
107
			if($database->is_error()) {
108
				return false;
109
			} else {
110
				return true;
111
			}
112
		} else {
113
			return false;
114
		}
98
		return $this->move($id, self::MOVE_UP);
115 99
	}
100

  
101
	/**
102
	 * Move a row down
103
	 * @param string|int $id
104
	 * @return bool
105
	 */
106
	public function move_down($id) {
107
		// Get current order
108
		return $this->move($id, self::MOVE_DOWN);
109
	}
116 110
	
117
	// Get new number for order
118
	function get_new($cf_value) {
119
		global $database;
120
		// $database = new database();
111
	/**
112
	 * Get next free number for order
113
	 * @param string|int $group
114
	 * @return integer
115
	 */
116
	public function get_new($group) {
121 117
		// Get last order
122
		$query_last = "SELECT ".$this->order_field." FROM ".$this->table." WHERE ".$this->common_field." = '$cf_value' ORDER BY ".$this->order_field." DESC LIMIT 1";
123
		$get_last = $database->query($query_last);
124
		if($get_last->numRows() > 0) {
125
			$fetch_last = $get_last->fetchRow();
126
			$last_order = $fetch_last[$this->order_field];
127
			return $last_order+1;
128
		} else {
129
			return 1;
130
		}
118
		$sql  = 'SELECT MAX(`'.$this->_FieldOrder.'`) FROM `'.$this->_Table.'` ';
119
		$sql .= 'WHERE `'.$this->_FieldGroup.'`=\''.$group.'\' ';
120
		$max = intval($this->_DB->get_one($sql)) + 1;
121
		return $max;
131 122
	}
132 123
	
133
	// Clean ordering (should be called if a row in the middle has been deleted)
134
	function clean($cf_value) {
135
		global $database;
124
	/**
125
	 * Renumbering a group from 1 to n (should be called if a row in the middle has been deleted)
126
	 * @param string|int $group
127
	 * @return bool
128
	 */
129
	public function clean($group) {
136 130
		// Loop through all records and give new order
137
		$query_all = "SELECT * FROM ".$this->table." WHERE ".$this->common_field." = '$cf_value' ORDER BY ".$this->order_field." ASC";
138
		$get_all = $database->query($query_all);
139
		if($get_all->numRows() > 0) {
140
			$count = 1;
141
			while($row = $get_all->fetchRow()) {
142
				// Update row with new order
143
				$database->query("UPDATE ".$this->table." SET ".$this->order_field." = '$count' WHERE ".$this->id_field." = '".$row[$this->id_field]."'");
144
				$count = $count+1;
145
			}
146
		} else {
147
			 return true;
148
		}
131
		$sql  = 'SET @c := 0; ';
132
		$sql .= 'UPDATE `'.$this->_Table.'` SET `'.$this->_FieldOrder.'`=( SELECT @c := @c + 1 ) ';
133
		$sql .= 'WHERE `'.$this->_FieldGroup.'`=\''.$group.'\' ';
134
		$sql .= 'ORDER BY `'.$this->_FieldOrder.'` ASC;';
135
		return $this->_DB->query($sql);
149 136
	}
150 137
	
151
}
152

  
153
?>
138
} // end of class
154 139

  
branches/2.8.x/wb/framework/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