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