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