Project

General

Profile

1 5 stefan
<?php
2
3 11 ryan
// $Id$
4
5 5 stefan
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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
28
wb class
29
30
This class is the basis for admin and frontend classes.
31
32
*/
33 59 stefan
require_once(WB_PATH.'/framework/class.database.php');
34
35 5 stefan
36
class wb
37 55 stefan
{
38
	// General initialization function
39
	// performed when frontend or backend is loaded.
40
	function wb() {
41
		// set global database variable
42
		global $database;
43
		// Create database class
44
		$database = new database();
45
		$this->database = $database;
46
47
		// Start a session
48
		if(!defined('SESSION_STARTED')) {
49
			session_name(APP_NAME.'_session_id');
50
			session_start();
51
			define('SESSION_STARTED', true);
52
		}
53
54
		// Get users language
55
		if(isset($_GET['lang']) AND $_GET['lang'] != '' AND !is_numeric($_GET['lang']) AND strlen($_GET['lang']) == 2) {
56
		  	define('LANGUAGE', strtoupper($_GET['lang']));
57
			$_SESSION['LANGUAGE']=LANGUAGE;
58
		} else {
59
			if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
60
				define('LANGUAGE', $_SESSION['LANGUAGE']);
61
			} else {
62
				define('LANGUAGE', DEFAULT_LANGUAGE);
63
			}
64
		}
65
66
		// make language variables globally accessible
67
		global $language_code, $language_name, $language_author, $language_version, $language_designed_for;
68
		global $MENU, $OVERVIEW, $TEXT, $HEADING, $MESSAGE;
69
		// Load Language file
70
		if(!defined('LANGUAGE_LOADED')) {
71
			if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
72
				exit('Error loading language file '.LANGUAGE.', please check configuration');
73
			} else {
74
				require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
75
			}
76
		}
77
78
		// Get users timezone
79
		if(!defined('TIMEZONE')) {
80
			if(isset($_SESSION['TIMEZONE'])) {
81
				define('TIMEZONE', $_SESSION['TIMEZONE']);
82
			} else {
83
				define('TIMEZONE', DEFAULT_TIMEZONE);
84
			}
85
		}
86
		// Get users date format
87
		if(!defined('DATE_FORMAT')) {
88
			if(isset($_SESSION['DATE_FORMAT'])) {
89
				define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
90
			} else {
91
				define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
92
			}
93
		}
94
		// Get users time format
95
		if(!defined('TIME_FORMAT')) {
96
			if(isset($_SESSION['TIME_FORMAT'])) {
97
				define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
98
			} else {
99
				define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
100
			}
101
		}
102
103
		set_magic_quotes_runtime(0);
104 39 stefan
	}
105 38 stefan
106 5 stefan
	// Check whether we should show a page or not (for front-end)
107
	function show_page($page) {
108
		// First check if the page is set to private
109
		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
110
			// Check if the user is logged in
111
			if($this->is_authenticated() == true) {
112
				// Now check if the user has perms to view it
113
				$viewing_groups = explode(',', $page['viewing_groups']);
114
				$viewing_users = explode(',', $page['viewing_users']);
115
				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
116
					return true;
117
				} else {
118
					return false;
119
				}
120
			} else {
121
				return false;
122
			}
123
		} elseif($page['visibility'] == 'public') {
124
			return true;
125
		} else {
126
			return false;
127
		}
128
	}
129
130
	// Check if the user is already authenticated or not
131
	function is_authenticated() {
132
		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
133
			return true;
134
		} else {
135
			return false;
136
		}
137
	}
138 38 stefan
139
	// Modified addslashes function which takes into account magic_quotes
140 40 stefan
	function add_slashes($input) {
141 38 stefan
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
142
			return $input;
143
		}
144 40 stefan
		$output = addslashes($input);
145 38 stefan
		return $output;
146
	}
147 5 stefan
148 38 stefan
	// Ditto for stripslashes
149 40 stefan
	function strip_slashes($input) {
150 36 stefan
		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
151
			return $input;
152
		}
153
		$output = stripslashes($input);
154
		return $output;
155
	}
156
157 42 stefan
	function strip_slashes_dummy($input) {
158
		return $input;
159
	}
160
161 38 stefan
	// Escape backslashes for use with mySQL LIKE strings
162
	function escape_backslashes($input) {
163 42 stefan
		return str_replace("\\","\\\\",$input);
164 38 stefan
	}
165
166 5 stefan
	// Get POST data
167
	function get_post($field) {
168
		if(isset($_POST[$field])) {
169
			return $_POST[$field];
170
		} else {
171
			return null;
172
		}
173
	}
174
175
	// Get GET data
176
	function get_get($field) {
177
		if(isset($_GET[$field])) {
178
			return $_GET[$field];
179
		} else {
180
			return null;
181
		}
182
	}
183
184
	// Get SESSION data
185
	function get_session($field) {
186
		if(isset($_SESSION[$field])) {
187
			return $_SESSION[$field];
188
		} else {
189
			return null;
190
		}
191
	}
192
193
	// Get SERVER data
194
	function get_server($field) {
195
		if(isset($_SERVER[$field])) {
196
			return $_SERVER[$field];
197
		} else {
198
			return null;
199
		}
200
	}
201
202
	// Get the current users id
203
	function get_user_id() {
204
		return $_SESSION['USER_ID'];
205
	}
206
207
	// Get the current users group id
208
	function get_group_id() {
209
		return $_SESSION['GROUP_ID'];
210
	}
211
212
	// Get the current users group name
213
	function get_group_name() {
214
		return $_SESSION['GROUP_NAME'];
215
	}
216
217
	// Get the current users username
218
	function get_username() {
219
		return $_SESSION['USERNAME'];
220
	}
221
222
	// Get the current users display name
223
	function get_display_name() {
224 42 stefan
		return $this->strip_slashes_dummy($_SESSION['DISPLAY_NAME']);
225 5 stefan
	}
226
227
	// Get the current users email address
228
	function get_email() {
229
		return $_SESSION['EMAIL'];
230
	}
231
232
	// Get the current users home folder
233
	function get_home_folder() {
234
		return $_SESSION['HOME_FOLDER'];
235
	}
236
237
	// Get the current users timezone
238
	function get_timezone() {
239
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
240
			return $_SESSION['TIMEZONE'];
241
		} else {
242
			return '-72000';
243
		}
244
	}
245
246
	// Validate supplied email address
247
	function validate_email($email) {
248
		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
249
			return true;
250
		} else {
251
			return false;
252
		}
253
	}
254
255
256
}
257
?>