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