1
|
<?php
|
2
|
|
3
|
// $Id: class.wb.php 38 2005-09-07 14:56:51Z 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(!defined('WB_URL')) {
|
34
|
header('Location: ../index.php');
|
35
|
}
|
36
|
|
37
|
|
38
|
class wb
|
39
|
{
|
40
|
|
41
|
// Check whether we should show a page or not (for front-end)
|
42
|
function show_page($page) {
|
43
|
// First check if the page is set to private
|
44
|
if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
|
45
|
// Check if the user is logged in
|
46
|
if($this->is_authenticated() == true) {
|
47
|
// Now check if the user has perms to view it
|
48
|
$viewing_groups = explode(',', $page['viewing_groups']);
|
49
|
$viewing_users = explode(',', $page['viewing_users']);
|
50
|
if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
|
51
|
return true;
|
52
|
} else {
|
53
|
return false;
|
54
|
}
|
55
|
} else {
|
56
|
return false;
|
57
|
}
|
58
|
} elseif($page['visibility'] == 'public') {
|
59
|
return true;
|
60
|
} else {
|
61
|
return false;
|
62
|
}
|
63
|
}
|
64
|
|
65
|
// Check if the user is already authenticated or not
|
66
|
function is_authenticated() {
|
67
|
if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
|
68
|
return true;
|
69
|
} else {
|
70
|
return false;
|
71
|
}
|
72
|
}
|
73
|
|
74
|
// Modified addslashes function which takes into account magic_quotes
|
75
|
function addslashes($input) {
|
76
|
if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
77
|
return $input;
|
78
|
}
|
79
|
$output = stripslashes($input);
|
80
|
return $output;
|
81
|
}
|
82
|
|
83
|
// Ditto for stripslashes
|
84
|
function stripslashes($input) {
|
85
|
if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
86
|
return $input;
|
87
|
}
|
88
|
$output = stripslashes($input);
|
89
|
return $output;
|
90
|
}
|
91
|
|
92
|
// Escape backslashes for use with mySQL LIKE strings
|
93
|
function escape_backslashes($input) {
|
94
|
return str_replace("\\","\\\\",$output);
|
95
|
}
|
96
|
|
97
|
// Get POST data
|
98
|
function get_post($field) {
|
99
|
if(isset($_POST[$field])) {
|
100
|
return $_POST[$field];
|
101
|
} else {
|
102
|
return null;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
// Get GET data
|
107
|
function get_get($field) {
|
108
|
if(isset($_GET[$field])) {
|
109
|
return $_GET[$field];
|
110
|
} else {
|
111
|
return null;
|
112
|
}
|
113
|
}
|
114
|
|
115
|
// Get SESSION data
|
116
|
function get_session($field) {
|
117
|
if(isset($_SESSION[$field])) {
|
118
|
return $_SESSION[$field];
|
119
|
} else {
|
120
|
return null;
|
121
|
}
|
122
|
}
|
123
|
|
124
|
// Get SERVER data
|
125
|
function get_server($field) {
|
126
|
if(isset($_SERVER[$field])) {
|
127
|
return $_SERVER[$field];
|
128
|
} else {
|
129
|
return null;
|
130
|
}
|
131
|
}
|
132
|
|
133
|
// Get the current users id
|
134
|
function get_user_id() {
|
135
|
return $_SESSION['USER_ID'];
|
136
|
}
|
137
|
|
138
|
// Get the current users group id
|
139
|
function get_group_id() {
|
140
|
return $_SESSION['GROUP_ID'];
|
141
|
}
|
142
|
|
143
|
// Get the current users group name
|
144
|
function get_group_name() {
|
145
|
return $_SESSION['GROUP_NAME'];
|
146
|
}
|
147
|
|
148
|
// Get the current users username
|
149
|
function get_username() {
|
150
|
return $_SESSION['USERNAME'];
|
151
|
}
|
152
|
|
153
|
// Get the current users display name
|
154
|
function get_display_name() {
|
155
|
return $this->stripslashes($_SESSION['DISPLAY_NAME']);
|
156
|
}
|
157
|
|
158
|
// Get the current users email address
|
159
|
function get_email() {
|
160
|
return $_SESSION['EMAIL'];
|
161
|
}
|
162
|
|
163
|
// Get the current users home folder
|
164
|
function get_home_folder() {
|
165
|
return $_SESSION['HOME_FOLDER'];
|
166
|
}
|
167
|
|
168
|
// Get the current users timezone
|
169
|
function get_timezone() {
|
170
|
if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
|
171
|
return $_SESSION['TIMEZONE'];
|
172
|
} else {
|
173
|
return '-72000';
|
174
|
}
|
175
|
}
|
176
|
|
177
|
// Validate supplied email address
|
178
|
function validate_email($email) {
|
179
|
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
|
180
|
return true;
|
181
|
} else {
|
182
|
return false;
|
183
|
}
|
184
|
}
|
185
|
|
186
|
|
187
|
}
|
188
|
?>
|