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