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 275 stefan
// Include PHPLIB template class
35
require_once(WB_PATH."/include/phplib/template.inc");
36
37 106 stefan
require_once(WB_PATH.'/framework/class.database.php');
38
39 5 stefan
class wb
40 95 stefan
{
41 55 stefan
	// General initialization function
42 238 stefan
	// performed when frontend or backend is loaded.
43 55 stefan
	function wb() {
44 238 stefan
	}
45
46 5 stefan
	// Check whether we should show a page or not (for front-end)
47
	function show_page($page) {
48
		// First check if the page is set to private
49
		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
50
			// Check if the user is logged in
51
			if($this->is_authenticated() == true) {
52
				// Now check if the user has perms to view it
53
				$viewing_groups = explode(',', $page['viewing_groups']);
54
				$viewing_users = explode(',', $page['viewing_users']);
55
				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
56
					return true;
57
				} else {
58
					return false;
59
				}
60
			} else {
61
				return false;
62
			}
63
		} elseif($page['visibility'] == 'public') {
64
			return true;
65
		} else {
66
			return false;
67
		}
68
	}
69
70
	// Check if the user is already authenticated or not
71
	function is_authenticated() {
72
		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
73
			return true;
74
		} else {
75
			return false;
76
		}
77
	}
78 238 stefan
	// Modified addslashes function which takes into account magic_quotes
79
	function add_slashes($input) {
80 38 stefan
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
81
			return $input;
82
		}
83 40 stefan
		$output = addslashes($input);
84 38 stefan
		return $output;
85
	}
86 5 stefan
87 238 stefan
	// Ditto for stripslashes
88 40 stefan
	function strip_slashes($input) {
89 36 stefan
		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
90
			return $input;
91
		}
92
		$output = stripslashes($input);
93
		return $output;
94
	}
95
96 238 stefan
	// Escape backslashes for use with mySQL LIKE strings
97 38 stefan
	function escape_backslashes($input) {
98 42 stefan
		return str_replace("\\","\\\\",$input);
99 38 stefan
	}
100
101 242 stefan
	function page_link($link){
102
		// Check for :// in the link (used in URL's) as well as mailto:
103
		if(strstr($link, '://') == '' AND substr($link, 0, 7) != 'mailto:') {
104
			return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
105
		} else {
106
			return $link;
107
		}
108
	}
109
110 5 stefan
	// Get POST data
111
	function get_post($field) {
112
		if(isset($_POST[$field])) {
113
			return $_POST[$field];
114
		} else {
115
			return null;
116
		}
117
	}
118
119
	// Get GET data
120
	function get_get($field) {
121
		if(isset($_GET[$field])) {
122
			return $_GET[$field];
123
		} else {
124
			return null;
125
		}
126
	}
127
128
	// Get SESSION data
129
	function get_session($field) {
130
		if(isset($_SESSION[$field])) {
131
			return $_SESSION[$field];
132
		} else {
133
			return null;
134
		}
135
	}
136
137
	// Get SERVER data
138
	function get_server($field) {
139
		if(isset($_SERVER[$field])) {
140
			return $_SERVER[$field];
141
		} else {
142
			return null;
143
		}
144
	}
145
146
	// Get the current users id
147
	function get_user_id() {
148
		return $_SESSION['USER_ID'];
149
	}
150
151
	// Get the current users group id
152
	function get_group_id() {
153
		return $_SESSION['GROUP_ID'];
154
	}
155
156
	// Get the current users group name
157
	function get_group_name() {
158
		return $_SESSION['GROUP_NAME'];
159
	}
160
161
	// Get the current users username
162
	function get_username() {
163
		return $_SESSION['USERNAME'];
164
	}
165
166
	// Get the current users display name
167
	function get_display_name() {
168 106 stefan
		return ($_SESSION['DISPLAY_NAME']);
169 5 stefan
	}
170
171
	// Get the current users email address
172
	function get_email() {
173
		return $_SESSION['EMAIL'];
174
	}
175
176
	// Get the current users home folder
177
	function get_home_folder() {
178
		return $_SESSION['HOME_FOLDER'];
179
	}
180
181
	// Get the current users timezone
182
	function get_timezone() {
183
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
184
			return $_SESSION['TIMEZONE'];
185
		} else {
186
			return '-72000';
187
		}
188
	}
189
190
	// Validate supplied email address
191
	function validate_email($email) {
192 295 stefan
		if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $email)) {
193 5 stefan
			return true;
194
		} else {
195
			return false;
196
		}
197
	}
198
199 275 stefan
	// Print a success message which then automatically redirects the user to another page
200
	function print_success($message, $redirect = 'index.php') {
201
		global $TEXT;
202
		$success_template = new Template(ADMIN_PATH.'/interface');
203
		$success_template->set_file('page', 'success.html');
204
		$success_template->set_block('page', 'main_block', 'main');
205
		$success_template->set_var('MESSAGE', $message);
206
		$success_template->set_var('REDIRECT', $redirect);
207
		$success_template->set_var('NEXT', $TEXT['NEXT']);
208
		$success_template->parse('main', 'main_block', false);
209
		$success_template->pparse('output', 'page');
210
	}
211 5 stefan
212 275 stefan
	// Print an error message
213
	function print_error($message, $link = 'index.php', $auto_footer = true) {
214
		global $TEXT;
215
		$success_template = new Template(ADMIN_PATH.'/interface');
216
		$success_template->set_file('page', 'error.html');
217
		$success_template->set_block('page', 'main_block', 'main');
218
		$success_template->set_var('MESSAGE', $message);
219
		$success_template->set_var('LINK', $link);
220
		$success_template->set_var('BACK', $TEXT['BACK']);
221
		$success_template->parse('main', 'main_block', false);
222
		$success_template->pparse('output', 'page');
223
		if($auto_footer == true) {
224
			$this->print_footer();
225
		}
226
		exit();
227
	}
228 295 stefan
	// Validate send email
229
	function mail($fromaddress, $toaddress, $subject, $message) {
230
		$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
231
		$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
232
		$subject = preg_replace('/[\r\n]/', '', $subject);
233
		if ($fromaddress=='') {
234
			$fromaddress = SERVER_EMAIL;
235
		}
236 296 stefan
		if(defined('DEFAULT_CHARSET')) {
237
			$charset = DEFAULT_CHARSET;
238 295 stefan
		} else {
239
			$charset='utf-8';
240
		}
241
		$headers  = "MIME-Version: 1.0\n";
242
		$headers .= "Content-type: text/plain; charset=".$charset."\n";
243
		$headers .= "X-Priority: 3\n";
244
		$headers .= "X-MSMail-Priority: Normal\n";
245
		$headers .= "X-Mailer: Website Baker\n";
246
		$headers .= "From: ".$fromaddress."\n";
247
		$headers .= "Return-Path: ".$fromaddress."\n";
248
		$headers .= "Reply-To: ".$fromaddress."\n";
249
		$headers .= "\n"; // extra empty line needed??
250
		if (OPERATING_SYSTEM=='windows') {
251
			str_replace("\n","\r\n",$headers);
252
			str_replace("\n","\r\n",$message);
253
		}
254
		if(mail($toaddress, $subject, $message, $headers, "-f $fromaddress")) {
255
			return true;
256
		} else {
257
			return false;
258
		}
259
	}
260 275 stefan
261 5 stefan
}
262 242 stefan
?>