Project

General

Profile

1
<?php
2

    
3
// $Id: class.wb.php 364 2006-08-22 09:35:31Z stefan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2006, 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
// Include PHPLIB template class
35
require_once(WB_PATH."/include/phplib/template.inc");
36

    
37
require_once(WB_PATH.'/framework/class.database.php');
38

    
39
class wb
40
{
41
	// General initialization function 
42
	// performed when frontend or backend is loaded.
43
	function wb() {
44
	}
45

    
46
	// 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
	// Modified addslashes function which takes into account magic_quotes
79
	function add_slashes($input) {
80
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
81
			return $input;
82
		}
83
		$output = addslashes($input);
84
		return $output;
85
	}
86

    
87
	// Ditto for stripslashes
88
	function strip_slashes($input) {
89
		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
90
			return $input;
91
		}
92
		$output = stripslashes($input);
93
		return $output;
94
	}
95

    
96
	// Escape backslashes for use with mySQL LIKE strings
97
	function escape_backslashes($input) {
98
		return str_replace("\\","\\\\",$input);
99
	}
100

    
101
	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
	// 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 POST data and escape it
120
	function get_post_escaped($field) {
121
		$result = $this->get_post($field);
122
		return (is_null($result)) ? null : $this->add_slashes($result);
123
	}
124
	
125
	// Get GET data
126
	function get_get($field) {
127
		if(isset($_GET[$field])) {
128
			return $_GET[$field];
129
		} else {
130
			return null;
131
		}
132
	}
133

    
134
	// Get SESSION data
135
	function get_session($field) {
136
		if(isset($_SESSION[$field])) {
137
			return $_SESSION[$field];
138
		} else {
139
			return null;
140
		}
141
	}
142

    
143
	// Get SERVER data
144
	function get_server($field) {
145
		if(isset($_SERVER[$field])) {
146
			return $_SERVER[$field];
147
		} else {
148
			return null;
149
		}
150
	}
151

    
152
	// Get the current users id
153
	function get_user_id() {
154
		return $_SESSION['USER_ID'];
155
	}
156

    
157
	// Get the current users group id
158
	function get_group_id() {
159
		return $_SESSION['GROUP_ID'];
160
	}
161

    
162
	// Get the current users group name
163
	function get_group_name() {
164
		return $_SESSION['GROUP_NAME'];
165
	}
166

    
167
	// Get the current users username
168
	function get_username() {
169
		return $_SESSION['USERNAME'];
170
	}
171

    
172
	// Get the current users display name
173
	function get_display_name() {
174
		return ($_SESSION['DISPLAY_NAME']);
175
	}
176

    
177
	// Get the current users email address
178
	function get_email() {
179
		return $_SESSION['EMAIL'];
180
	}
181

    
182
	// Get the current users home folder
183
	function get_home_folder() {
184
		return $_SESSION['HOME_FOLDER'];
185
	}
186

    
187
	// Get the current users timezone
188
	function get_timezone() {
189
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
190
			return $_SESSION['TIMEZONE'];
191
		} else {
192
			return '-72000';
193
		}
194
	}
195

    
196
	// Validate supplied email address
197
	function validate_email($email) {
198
		if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $email)) {
199
			return true;
200
		} else {
201
			return false;
202
		}
203
	}
204

    
205
	// Print a success message which then automatically redirects the user to another page
206
	function print_success($message, $redirect = 'index.php') {
207
		global $TEXT;
208
		$success_template = new Template(ADMIN_PATH.'/interface');
209
		$success_template->set_file('page', 'success.html');
210
		$success_template->set_block('page', 'main_block', 'main');
211
		$success_template->set_var('MESSAGE', $message);
212
		$success_template->set_var('REDIRECT', $redirect);
213
		$success_template->set_var('NEXT', $TEXT['NEXT']);
214
		$success_template->parse('main', 'main_block', false);
215
		$success_template->pparse('output', 'page');
216
	}
217
	
218
	// Print an error message
219
	function print_error($message, $link = 'index.php', $auto_footer = true) {
220
		global $TEXT;
221
		$success_template = new Template(ADMIN_PATH.'/interface');
222
		$success_template->set_file('page', 'error.html');
223
		$success_template->set_block('page', 'main_block', 'main');
224
		$success_template->set_var('MESSAGE', $message);
225
		$success_template->set_var('LINK', $link);
226
		$success_template->set_var('BACK', $TEXT['BACK']);
227
		$success_template->parse('main', 'main_block', false);
228
		$success_template->pparse('output', 'page');
229
		if($auto_footer == true) {
230
			$this->print_footer();
231
		}
232
		exit();
233
	}
234
	// Validate send email
235
	function mail($fromaddress, $toaddress, $subject, $message) {
236
		$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
237
		$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
238
		$subject = preg_replace('/[\r\n]/', '', $subject);
239
		if ($fromaddress=='') {
240
			$fromaddress = SERVER_EMAIL;
241
		}
242
		if(defined('DEFAULT_CHARSET')) { 
243
			$charset = DEFAULT_CHARSET; 
244
		} else {
245
			$charset='utf-8';
246
		}
247
		$headers  = "MIME-Version: 1.0\n";
248
		$headers .= "Content-type: text/plain; charset=".$charset."\n";
249
		$headers .= "X-Priority: 3\n";
250
		$headers .= "X-MSMail-Priority: Normal\n";
251
		$headers .= "X-Mailer: Website Baker\n";
252
		$headers .= "From: ".$fromaddress."\n";
253
		$headers .= "Return-Path: ".$fromaddress."\n";
254
		$headers .= "Reply-To: ".$fromaddress."\n";
255
		$headers .= "\n"; // extra empty line needed??
256
		if (OPERATING_SYSTEM=='windows') {
257
			str_replace("\n","\r\n",$headers);
258
			str_replace("\n","\r\n",$message);
259
		}	
260
		if(mail($toaddress, $subject, $message, $headers)) {
261
			return true;
262
		} else {
263
			return false;
264
		}
265
	}
266

    
267
}
268
?>
(6-6/11)