Project

General

Profile

1
<?php
2

    
3
// $Id: class.wb.php 40 2005-09-07 19:22:34Z 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

    
34
class wb
35
{
36
	function wb() {
37
	}
38

    
39
	// 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

    
72
	// Modified addslashes function which takes into account magic_quotes
73
	function add_slashes($input) {
74
		return addslashes($input);		
75
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
76
			return $input;
77
		}
78
		$output = addslashes($input);
79
		return $output;
80
	}
81

    
82
	// Ditto for stripslashes
83
	function strip_slashes($input) {
84
		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
85
			return $input;
86
		}
87
		$output = stripslashes($input);
88
		return $output;
89
	}
90

    
91
	// Escape backslashes for use with mySQL LIKE strings
92
	function escape_backslashes($input) {
93
		return str_replace("\\","\\\\",$output);
94
	}
95

    
96
	// Get POST data
97
	function get_post($field) {
98
		if(isset($_POST[$field])) {
99
			return $_POST[$field];
100
		} else {
101
			return null;
102
		}
103
	}
104

    
105
	// Get GET data
106
	function get_get($field) {
107
		if(isset($_GET[$field])) {
108
			return $_GET[$field];
109
		} else {
110
			return null;
111
		}
112
	}
113

    
114
	// Get SESSION data
115
	function get_session($field) {
116
		if(isset($_SESSION[$field])) {
117
			return $_SESSION[$field];
118
		} else {
119
			return null;
120
		}
121
	}
122

    
123
	// Get SERVER data
124
	function get_server($field) {
125
		if(isset($_SERVER[$field])) {
126
			return $_SERVER[$field];
127
		} else {
128
			return null;
129
		}
130
	}
131

    
132
	// Get the current users id
133
	function get_user_id() {
134
		return $_SESSION['USER_ID'];
135
	}
136

    
137
	// Get the current users group id
138
	function get_group_id() {
139
		return $_SESSION['GROUP_ID'];
140
	}
141

    
142
	// Get the current users group name
143
	function get_group_name() {
144
		return $_SESSION['GROUP_NAME'];
145
	}
146

    
147
	// Get the current users username
148
	function get_username() {
149
		return $_SESSION['USERNAME'];
150
	}
151

    
152
	// Get the current users display name
153
	function get_display_name() {
154
		return $this->strip_slashes($_SESSION['DISPLAY_NAME']);
155
	}
156

    
157
	// Get the current users email address
158
	function get_email() {
159
		return $_SESSION['EMAIL'];
160
	}
161

    
162
	// Get the current users home folder
163
	function get_home_folder() {
164
		return $_SESSION['HOME_FOLDER'];
165
	}
166

    
167
	// Get the current users timezone
168
	function get_timezone() {
169
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
170
			return $_SESSION['TIMEZONE'];
171
		} else {
172
			return '-72000';
173
		}
174
	}
175

    
176
	// Validate supplied email address
177
	function validate_email($email) {
178
		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
179
			return true;
180
		} else {
181
			return false;
182
		}
183
	}
184

    
185
	
186
}
187
?>
(6-6/11)