1
|
<?php
|
2
|
|
3
|
// $Id: class.wb.php 386 2006-12-20 21:43:17Z Ruebenwurzel $
|
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
|
// Include new wbmailer class (subclass of PHPmailer)
|
40
|
require_once(WB_PATH."/framework/class.wbmailer.php");
|
41
|
|
42
|
class wb
|
43
|
{
|
44
|
// General initialization function
|
45
|
// performed when frontend or backend is loaded.
|
46
|
function wb() {
|
47
|
}
|
48
|
|
49
|
// Check whether we should show a page or not (for front-end)
|
50
|
function show_page($page) {
|
51
|
// First check if the page is set to private
|
52
|
if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
|
53
|
// Check if the user is logged in
|
54
|
if($this->is_authenticated() == true) {
|
55
|
// Now check if the user has perms to view it
|
56
|
$viewing_groups = explode(',', $page['viewing_groups']);
|
57
|
$viewing_users = explode(',', $page['viewing_users']);
|
58
|
if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
|
59
|
return true;
|
60
|
} else {
|
61
|
return false;
|
62
|
}
|
63
|
} else {
|
64
|
return false;
|
65
|
}
|
66
|
} elseif($page['visibility'] == 'public') {
|
67
|
return true;
|
68
|
} else {
|
69
|
return false;
|
70
|
}
|
71
|
}
|
72
|
|
73
|
// Check if the user is already authenticated or not
|
74
|
function is_authenticated() {
|
75
|
if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
|
76
|
return true;
|
77
|
} else {
|
78
|
return false;
|
79
|
}
|
80
|
}
|
81
|
// Modified addslashes function which takes into account magic_quotes
|
82
|
function add_slashes($input) {
|
83
|
if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
84
|
return $input;
|
85
|
}
|
86
|
$output = addslashes($input);
|
87
|
return $output;
|
88
|
}
|
89
|
|
90
|
// Ditto for stripslashes
|
91
|
function strip_slashes($input) {
|
92
|
if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
93
|
return $input;
|
94
|
}
|
95
|
$output = stripslashes($input);
|
96
|
return $output;
|
97
|
}
|
98
|
|
99
|
// Escape backslashes for use with mySQL LIKE strings
|
100
|
function escape_backslashes($input) {
|
101
|
return str_replace("\\","\\\\",$input);
|
102
|
}
|
103
|
|
104
|
function page_link($link){
|
105
|
// Check for :// in the link (used in URL's) as well as mailto:
|
106
|
if(strstr($link, '://') == '' AND substr($link, 0, 7) != 'mailto:') {
|
107
|
return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
108
|
} else {
|
109
|
return $link;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
// Get POST data
|
114
|
function get_post($field) {
|
115
|
if(isset($_POST[$field])) {
|
116
|
return $_POST[$field];
|
117
|
} else {
|
118
|
return null;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
// Get POST data and escape it
|
123
|
function get_post_escaped($field) {
|
124
|
$result = $this->get_post($field);
|
125
|
return (is_null($result)) ? null : $this->add_slashes($result);
|
126
|
}
|
127
|
|
128
|
// Get GET data
|
129
|
function get_get($field) {
|
130
|
if(isset($_GET[$field])) {
|
131
|
return $_GET[$field];
|
132
|
} else {
|
133
|
return null;
|
134
|
}
|
135
|
}
|
136
|
|
137
|
// Get SESSION data
|
138
|
function get_session($field) {
|
139
|
if(isset($_SESSION[$field])) {
|
140
|
return $_SESSION[$field];
|
141
|
} else {
|
142
|
return null;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
// Get SERVER data
|
147
|
function get_server($field) {
|
148
|
if(isset($_SERVER[$field])) {
|
149
|
return $_SERVER[$field];
|
150
|
} else {
|
151
|
return null;
|
152
|
}
|
153
|
}
|
154
|
|
155
|
// Get the current users id
|
156
|
function get_user_id() {
|
157
|
return $_SESSION['USER_ID'];
|
158
|
}
|
159
|
|
160
|
// Get the current users group id
|
161
|
function get_group_id() {
|
162
|
return $_SESSION['GROUP_ID'];
|
163
|
}
|
164
|
|
165
|
// Get the current users group name
|
166
|
function get_group_name() {
|
167
|
return $_SESSION['GROUP_NAME'];
|
168
|
}
|
169
|
|
170
|
// Get the current users username
|
171
|
function get_username() {
|
172
|
return $_SESSION['USERNAME'];
|
173
|
}
|
174
|
|
175
|
// Get the current users display name
|
176
|
function get_display_name() {
|
177
|
return ($_SESSION['DISPLAY_NAME']);
|
178
|
}
|
179
|
|
180
|
// Get the current users email address
|
181
|
function get_email() {
|
182
|
return $_SESSION['EMAIL'];
|
183
|
}
|
184
|
|
185
|
// Get the current users home folder
|
186
|
function get_home_folder() {
|
187
|
return $_SESSION['HOME_FOLDER'];
|
188
|
}
|
189
|
|
190
|
// Get the current users timezone
|
191
|
function get_timezone() {
|
192
|
if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
|
193
|
return $_SESSION['TIMEZONE'];
|
194
|
} else {
|
195
|
return '-72000';
|
196
|
}
|
197
|
}
|
198
|
|
199
|
// Validate supplied email address
|
200
|
function validate_email($email) {
|
201
|
if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $email)) {
|
202
|
return true;
|
203
|
} else {
|
204
|
return false;
|
205
|
}
|
206
|
}
|
207
|
|
208
|
// Print a success message which then automatically redirects the user to another page
|
209
|
function print_success($message, $redirect = 'index.php') {
|
210
|
global $TEXT;
|
211
|
$success_template = new Template(ADMIN_PATH.'/interface');
|
212
|
$success_template->set_file('page', 'success.html');
|
213
|
$success_template->set_block('page', 'main_block', 'main');
|
214
|
$success_template->set_var('MESSAGE', $message);
|
215
|
$success_template->set_var('REDIRECT', $redirect);
|
216
|
$success_template->set_var('NEXT', $TEXT['NEXT']);
|
217
|
$success_template->parse('main', 'main_block', false);
|
218
|
$success_template->pparse('output', 'page');
|
219
|
}
|
220
|
|
221
|
// Print an error message
|
222
|
function print_error($message, $link = 'index.php', $auto_footer = true) {
|
223
|
global $TEXT;
|
224
|
$success_template = new Template(ADMIN_PATH.'/interface');
|
225
|
$success_template->set_file('page', 'error.html');
|
226
|
$success_template->set_block('page', 'main_block', 'main');
|
227
|
$success_template->set_var('MESSAGE', $message);
|
228
|
$success_template->set_var('LINK', $link);
|
229
|
$success_template->set_var('BACK', $TEXT['BACK']);
|
230
|
$success_template->parse('main', 'main_block', false);
|
231
|
$success_template->pparse('output', 'page');
|
232
|
if($auto_footer == true) {
|
233
|
$this->print_footer();
|
234
|
}
|
235
|
exit();
|
236
|
}
|
237
|
|
238
|
// Validate send email
|
239
|
function mail($fromaddress, $toaddress, $subject, $message) {
|
240
|
$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
|
241
|
$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
|
242
|
$subject = preg_replace('/[\r\n]/', '', $subject);
|
243
|
$message = preg_replace('/[\r\n]/', '<br \>', $message);
|
244
|
|
245
|
/*
|
246
|
SOME PROVIDERS (LIKE GMX) DOES NOT DELIVER MAILS VIA DEFAULT PHP mail() FUNCTION AS
|
247
|
THIS FUNCTION DOES NOT PROVIDE SMTP AUTHENTIFICATION
|
248
|
NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE
|
249
|
|
250
|
NOTE:
|
251
|
To use SMTP for sending out mails, you have to specify the SMTP host of your domain
|
252
|
via the variable "WBMAILER_SMTP_HOST" in the "config.php" file
|
253
|
If variable is not defined, the WBMAILER class uses the PHP mail() function per default
|
254
|
|
255
|
the mail header is automatically created by PHPMailer and therefore commented out
|
256
|
UPDATE INTRODUCED BY DOC (C. SOMMER, 22. October 2006)
|
257
|
*/
|
258
|
|
259
|
/*
|
260
|
if ($fromaddress=='') {
|
261
|
$fromaddress = SERVER_EMAIL;
|
262
|
}
|
263
|
|
264
|
if(defined('DEFAULT_CHARSET')) {
|
265
|
$charset = DEFAULT_CHARSET;
|
266
|
} else {
|
267
|
$charset='utf-8';
|
268
|
}
|
269
|
|
270
|
$headers = "MIME-Version: 1.0\n";
|
271
|
$headers .= "Content-type: text/plain; charset=".$charset."\n";
|
272
|
$headers .= "X-Priority: 3\n";
|
273
|
$headers .= "X-MSMail-Priority: Normal\n";
|
274
|
$headers .= "X-Mailer: Website Baker\n";
|
275
|
$headers .= "From: ".$fromaddress."\n";
|
276
|
$headers .= "Return-Path: ".$fromaddress."\n";
|
277
|
$headers .= "Reply-To: ".$fromaddress."\n";
|
278
|
$headers .= "\n"; // extra empty line needed??
|
279
|
|
280
|
if (OPERATING_SYSTEM=='windows') {
|
281
|
//str_replace("\n","\r\n",$headers);
|
282
|
str_replace("\n","\r\n",$message);
|
283
|
}
|
284
|
|
285
|
if(mail($toaddress, $subject, $message, $headers)) {
|
286
|
return true;
|
287
|
} else {
|
288
|
return false;
|
289
|
}
|
290
|
*/
|
291
|
|
292
|
// create PHPMailer object and define default settings
|
293
|
$myMail = new wbmailer();
|
294
|
|
295
|
// set user defined from address
|
296
|
if ($fromaddress!='') {
|
297
|
$myMail->From = $fromaddress; // FROM:
|
298
|
$myMail->AddReplyTo($fromaddress); // REPLY TO:
|
299
|
}
|
300
|
|
301
|
// define recepient and information to send out
|
302
|
$myMail->AddAddress($toaddress); // TO:
|
303
|
$myMail->Subject = $subject; // SUBJECT
|
304
|
$myMail->Body = $message; // CONTENT (HTML)
|
305
|
$myMail->AltBody = strip_tags($message); // CONTENT (TEXT)
|
306
|
|
307
|
// check if there are any send mail errors, otherwise say successful
|
308
|
if (!$myMail->Send()) {
|
309
|
return false;
|
310
|
} else {
|
311
|
return true;
|
312
|
}
|
313
|
}
|
314
|
|
315
|
}
|
316
|
?>
|