1 |
449
|
Ruebenwurz
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2007, 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 SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION
|
247 |
|
|
NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE
|
248 |
|
|
|
249 |
|
|
NOTE:
|
250 |
|
|
To use SMTP for sending out mails, you have to specify the SMTP host of your domain
|
251 |
|
|
via the variable "WBMAILER_SMTP_HOST" in the "config.php" file
|
252 |
|
|
If variable is not defined, the WBMAILER class uses the PHP mail() function per default
|
253 |
|
|
|
254 |
|
|
the mail header is automatically created by PHPMailer and therefore commented out
|
255 |
|
|
UPDATE INTRODUCED BY DOC (C. SOMMER, 22. October 2006)
|
256 |
|
|
*/
|
257 |
|
|
|
258 |
|
|
/*
|
259 |
|
|
if ($fromaddress=='') {
|
260 |
|
|
$fromaddress = SERVER_EMAIL;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
if(defined('DEFAULT_CHARSET')) {
|
264 |
|
|
$charset = DEFAULT_CHARSET;
|
265 |
|
|
} else {
|
266 |
|
|
$charset='utf-8';
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
$headers = "MIME-Version: 1.0\n";
|
270 |
|
|
$headers .= "Content-type: text/plain; charset=".$charset."\n";
|
271 |
|
|
$headers .= "X-Priority: 3\n";
|
272 |
|
|
$headers .= "X-MSMail-Priority: Normal\n";
|
273 |
|
|
$headers .= "X-Mailer: Website Baker\n";
|
274 |
|
|
$headers .= "From: ".$fromaddress."\n";
|
275 |
|
|
$headers .= "Return-Path: ".$fromaddress."\n";
|
276 |
|
|
$headers .= "Reply-To: ".$fromaddress."\n";
|
277 |
|
|
$headers .= "\n"; // extra empty line needed??
|
278 |
|
|
|
279 |
|
|
if (OPERATING_SYSTEM=='windows') {
|
280 |
|
|
//str_replace("\n","\r\n",$headers);
|
281 |
|
|
str_replace("\n","\r\n",$message);
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
if(mail($toaddress, $subject, $message, $headers)) {
|
285 |
|
|
return true;
|
286 |
|
|
} else {
|
287 |
|
|
return false;
|
288 |
|
|
}
|
289 |
|
|
*/
|
290 |
|
|
|
291 |
|
|
// create PHPMailer object and define default settings
|
292 |
|
|
$myMail = new wbmailer();
|
293 |
|
|
|
294 |
|
|
// set user defined from address
|
295 |
|
|
if ($fromaddress!='') {
|
296 |
|
|
$myMail->From = $fromaddress; // FROM:
|
297 |
|
|
$myMail->AddReplyTo($fromaddress); // REPLY TO:
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
// define recepient and information to send out
|
301 |
|
|
$myMail->AddAddress($toaddress); // TO:
|
302 |
|
|
$myMail->Subject = $subject; // SUBJECT
|
303 |
|
|
$myMail->Body = $message; // CONTENT (HTML)
|
304 |
|
|
$myMail->AltBody = strip_tags($message); // CONTENT (TEXT)
|
305 |
|
|
|
306 |
|
|
// check if there are any send mail errors, otherwise say successful
|
307 |
|
|
if (!$myMail->Send()) {
|
308 |
|
|
return false;
|
309 |
|
|
} else {
|
310 |
|
|
return true;
|
311 |
|
|
}
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
}
|
315 |
242
|
stefan
|
?>
|