1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category frontend
|
5
|
* @package framework
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9
|
* @link http://www.websitebaker2.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.x
|
12
|
* @requirements PHP 5.2.2 and higher
|
13
|
* @version $Id: class.wb.php 1457 2011-06-25 17:18:50Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.wb.php $
|
15
|
* @lastmodified $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Must include code to stop this file being access directly
|
20
|
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
|
21
|
// Include PHPLIB template class
|
22
|
require_once(WB_PATH."/include/phplib/template.inc");
|
23
|
|
24
|
require_once(WB_PATH.'/framework/class.database.php');
|
25
|
|
26
|
// Include new wbmailer class (subclass of PHPmailer)
|
27
|
require_once(WB_PATH."/framework/class.wbmailer.php");
|
28
|
|
29
|
require_once(WB_PATH."/framework/SecureForm.php");
|
30
|
|
31
|
class wb extends SecureForm
|
32
|
{
|
33
|
|
34
|
public $password_chars = 'a-zA-Z0-9\_\-\!\#\*\+\@\$\&\:'; // General initialization function
|
35
|
// performed when frontend or backend is loaded.
|
36
|
|
37
|
public function __construct($mode = SecureForm::FRONTEND) {
|
38
|
parent::__construct($mode);
|
39
|
}
|
40
|
|
41
|
/* ****************
|
42
|
* check if one or more group_ids are in both group_lists
|
43
|
*
|
44
|
* @access public
|
45
|
* @param mixed $groups_list1: an array or a coma seperated list of group-ids
|
46
|
* @param mixed $groups_list2: an array or a coma seperated list of group-ids
|
47
|
* @param array &$matches: an array-var whitch will return possible matches
|
48
|
* @return bool: true there is a match, otherwise false
|
49
|
*/
|
50
|
function is_group_match( $groups_list1 = '', $groups_list2 = '', &$matches = null )
|
51
|
{
|
52
|
if( $groups_list1 == '' ) { return false; }
|
53
|
if( $groups_list2 == '' ) { return false; }
|
54
|
if( !is_array($groups_list1) )
|
55
|
{
|
56
|
$groups_list1 = explode(',', $groups_list1);
|
57
|
}
|
58
|
if( !is_array($groups_list2) )
|
59
|
{
|
60
|
$groups_list2 = explode(',', $groups_list2);
|
61
|
}
|
62
|
$matches = array_intersect( $groups_list1, $groups_list2);
|
63
|
return ( sizeof($matches) != 0 );
|
64
|
}
|
65
|
/* ****************
|
66
|
* check if current user is member of at least one of given groups
|
67
|
* ADMIN (uid=1) always is treated like a member of any groups
|
68
|
*
|
69
|
* @access public
|
70
|
* @param mixed $groups_list: an array or a coma seperated list of group-ids
|
71
|
* @return bool: true if current user is member of one of this groups, otherwise false
|
72
|
*/
|
73
|
function ami_group_member( $groups_list = '' )
|
74
|
{
|
75
|
if( $this->get_user_id() == 1 ) { return true; }
|
76
|
return $this->is_group_match( $groups_list, $this->get_groups_id() );
|
77
|
}
|
78
|
|
79
|
// Check whether a page is visible or not.
|
80
|
// This will check page-visibility and user- and group-rights.
|
81
|
/* page_is_visible() returns
|
82
|
false: if page-visibility is 'none' or 'deleted', or page-vis. is 'registered' or 'private' and user isn't allowed to see the page.
|
83
|
true: if page-visibility is 'public' or 'hidden', or page-vis. is 'registered' or 'private' and user _is_ allowed to see the page.
|
84
|
*/
|
85
|
function page_is_visible($page)
|
86
|
{
|
87
|
$show_it = false; // shall we show the page?
|
88
|
$page_id = $page['page_id'];
|
89
|
$visibility = $page['visibility'];
|
90
|
$viewing_groups = $page['viewing_groups'];
|
91
|
$viewing_users = $page['viewing_users'];
|
92
|
|
93
|
// First check if visibility is 'none', 'deleted'
|
94
|
if($visibility == 'none')
|
95
|
{
|
96
|
return(false);
|
97
|
} elseif($visibility == 'deleted')
|
98
|
{
|
99
|
return(false);
|
100
|
}
|
101
|
|
102
|
// Now check if visibility is 'hidden', 'private' or 'registered'
|
103
|
if($visibility == 'hidden') { // hidden: hide the menu-link, but show the page
|
104
|
$show_it = true;
|
105
|
} elseif($visibility == 'private' || $visibility == 'registered')
|
106
|
{
|
107
|
// Check if the user is logged in
|
108
|
if($this->is_authenticated() == true)
|
109
|
{
|
110
|
// Now check if the user has perms to view the page
|
111
|
$in_group = false;
|
112
|
foreach($this->get_groups_id() as $cur_gid)
|
113
|
{
|
114
|
if(in_array($cur_gid, explode(',', $viewing_groups)))
|
115
|
{
|
116
|
$in_group = true;
|
117
|
}
|
118
|
}
|
119
|
if($in_group || in_array($this->get_user_id(), explode(',', $viewing_users))) {
|
120
|
$show_it = true;
|
121
|
} else {
|
122
|
$show_it = false;
|
123
|
}
|
124
|
} else {
|
125
|
$show_it = false;
|
126
|
}
|
127
|
} elseif($visibility == 'public') {
|
128
|
$show_it = true;
|
129
|
} else {
|
130
|
$show_it = false;
|
131
|
}
|
132
|
return($show_it);
|
133
|
}
|
134
|
// Check if there is at least one active section on this page
|
135
|
function page_is_active($page)
|
136
|
{
|
137
|
global $database;
|
138
|
$has_active_sections = false;
|
139
|
$page_id = $page['page_id'];
|
140
|
$now = time();
|
141
|
$query_sections = $database->query("SELECT publ_start,publ_end FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
142
|
if($query_sections->numRows() != 0)
|
143
|
{
|
144
|
while($section = $query_sections->fetchRow())
|
145
|
{
|
146
|
if($now<$section['publ_end'] && ($now>$section['publ_start'] || $section['publ_start']==0) || $now>$section['publ_start'] && $section['publ_end']==0)
|
147
|
{
|
148
|
$has_active_sections = true;
|
149
|
break;
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
return($has_active_sections);
|
154
|
}
|
155
|
|
156
|
// Check whether we should show a page or not (for front-end)
|
157
|
function show_page($page)
|
158
|
{
|
159
|
if($this->page_is_visible($page) && $this->page_is_active($page))
|
160
|
{
|
161
|
return true;
|
162
|
} else {
|
163
|
return false;
|
164
|
}
|
165
|
}
|
166
|
|
167
|
// Check if the user is already authenticated or not
|
168
|
function is_authenticated() {
|
169
|
if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID']))
|
170
|
{
|
171
|
return true;
|
172
|
} else {
|
173
|
return false;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
// Modified addslashes function which takes into account magic_quotes
|
178
|
function add_slashes($input) {
|
179
|
if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
180
|
return $input;
|
181
|
}
|
182
|
$output = addslashes($input);
|
183
|
return $output;
|
184
|
}
|
185
|
|
186
|
// Ditto for stripslashes
|
187
|
// Attn: this is _not_ the counterpart to $this->add_slashes() !
|
188
|
// Use stripslashes() to undo a preliminarily done $this->add_slashes()
|
189
|
// The purpose of $this->strip_slashes() is to undo the effects of magic_quotes_gpc==On
|
190
|
function strip_slashes($input) {
|
191
|
if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
|
192
|
return $input;
|
193
|
}
|
194
|
$output = stripslashes($input);
|
195
|
return $output;
|
196
|
}
|
197
|
|
198
|
// Escape backslashes for use with mySQL LIKE strings
|
199
|
function escape_backslashes($input) {
|
200
|
return str_replace("\\","\\\\",$input);
|
201
|
}
|
202
|
|
203
|
function page_link($link){
|
204
|
// Check for :// in the link (used in URL's) as well as mailto:
|
205
|
if(strstr($link, '://') == '' AND substr($link, 0, 7) != 'mailto:') {
|
206
|
return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
207
|
} else {
|
208
|
return $link;
|
209
|
}
|
210
|
}
|
211
|
|
212
|
// Get POST data
|
213
|
function get_post($field) {
|
214
|
if(isset($_POST[$field])) {
|
215
|
return $_POST[$field];
|
216
|
} else {
|
217
|
return null;
|
218
|
}
|
219
|
}
|
220
|
|
221
|
// Get POST data and escape it
|
222
|
function get_post_escaped($field) {
|
223
|
$result = $this->get_post($field);
|
224
|
return (is_null($result)) ? null : $this->add_slashes($result);
|
225
|
}
|
226
|
|
227
|
// Get GET data
|
228
|
function get_get($field) {
|
229
|
if(isset($_GET[$field])) {
|
230
|
return $_GET[$field];
|
231
|
} else {
|
232
|
return null;
|
233
|
}
|
234
|
}
|
235
|
|
236
|
// Get SESSION data
|
237
|
function get_session($field) {
|
238
|
if(isset($_SESSION[$field])) {
|
239
|
return $_SESSION[$field];
|
240
|
} else {
|
241
|
return null;
|
242
|
}
|
243
|
}
|
244
|
|
245
|
// Get SERVER data
|
246
|
function get_server($field) {
|
247
|
if(isset($_SERVER[$field])) {
|
248
|
return $_SERVER[$field];
|
249
|
} else {
|
250
|
return null;
|
251
|
}
|
252
|
}
|
253
|
|
254
|
// Get the current users id
|
255
|
function get_user_id() {
|
256
|
return $_SESSION['USER_ID'];
|
257
|
}
|
258
|
|
259
|
// Get the current users group id
|
260
|
function get_group_id() {
|
261
|
return $_SESSION['GROUP_ID'];
|
262
|
}
|
263
|
|
264
|
// Get the current users group ids
|
265
|
function get_groups_id() {
|
266
|
return explode(",", $_SESSION['GROUPS_ID']);
|
267
|
}
|
268
|
|
269
|
// Get the current users group name
|
270
|
function get_group_name() {
|
271
|
return implode(",", $_SESSION['GROUP_NAME']);
|
272
|
}
|
273
|
|
274
|
// Get the current users group name
|
275
|
function get_groups_name() {
|
276
|
return $_SESSION['GROUP_NAME'];
|
277
|
}
|
278
|
|
279
|
// Get the current users username
|
280
|
function get_username() {
|
281
|
return $_SESSION['USERNAME'];
|
282
|
}
|
283
|
|
284
|
// Get the current users display name
|
285
|
function get_display_name() {
|
286
|
return ($_SESSION['DISPLAY_NAME']);
|
287
|
}
|
288
|
|
289
|
// Get the current users email address
|
290
|
function get_email() {
|
291
|
return $_SESSION['EMAIL'];
|
292
|
}
|
293
|
|
294
|
// Get the current users home folder
|
295
|
function get_home_folder() {
|
296
|
return $_SESSION['HOME_FOLDER'];
|
297
|
}
|
298
|
|
299
|
// Get the current users timezone
|
300
|
function get_timezone() {
|
301
|
if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
|
302
|
return $_SESSION['TIMEZONE'];
|
303
|
} else {
|
304
|
return '-72000';
|
305
|
}
|
306
|
}
|
307
|
|
308
|
// Validate supplied email address
|
309
|
function validate_email($email) {
|
310
|
if(function_exists('idn_to_ascii')){ /* use pear if available */
|
311
|
$email = idn_to_ascii($email);
|
312
|
}else {
|
313
|
require_once(WB_PATH.'/include/idna_convert/idna_convert.class.php');
|
314
|
$IDN = new idna_convert();
|
315
|
$email = $IDN->encode($email);
|
316
|
unset($IDN);
|
317
|
}
|
318
|
// regex from NorHei 2011-01-11
|
319
|
$retval = preg_match("/^((([!#$%&'*+\\-\/\=?^_`{|}~\w])|([!#$%&'*+\\-\/\=?^_`{|}~\w][!#$%&'*+\\-\/\=?^_`{|}~\.\w]{0,}[!#$%&'*+\\-\/\=?^_`{|}~\w]))[@]\w+(([-.]|\-\-)\w+)*\.\w+(([-.]|\-\-)\w+)*)$/", $email);
|
320
|
return ($retval != false);
|
321
|
}
|
322
|
|
323
|
/* ****************
|
324
|
* set one or more bit in a integer value
|
325
|
*
|
326
|
* @access public
|
327
|
* @param int $value: reference to the integer, containing the value
|
328
|
* @param int $bits2set: the bitmask witch shall be added to value
|
329
|
* @return void
|
330
|
*/
|
331
|
function bit_set( &$value, $bits2set )
|
332
|
{
|
333
|
$value |= $bits2set;
|
334
|
}
|
335
|
|
336
|
/* ****************
|
337
|
* reset one or more bit from a integer value
|
338
|
*
|
339
|
* @access public
|
340
|
* @param int $value: reference to the integer, containing the value
|
341
|
* @param int $bits2reset: the bitmask witch shall be removed from value
|
342
|
* @return void
|
343
|
*/
|
344
|
function bit_reset( &$value, $bits2reset)
|
345
|
{
|
346
|
$value &= ~$bits2reset;
|
347
|
}
|
348
|
|
349
|
/* ****************
|
350
|
* check if one or more bit in a integer value are set
|
351
|
*
|
352
|
* @access public
|
353
|
* @param int $value: reference to the integer, containing the value
|
354
|
* @param int $bits2set: the bitmask witch shall be added to value
|
355
|
* @return void
|
356
|
*/
|
357
|
function bit_isset( $value, $bits2test )
|
358
|
{
|
359
|
return (($value & $bits2test) == $bits2test);
|
360
|
}
|
361
|
|
362
|
/*
|
363
|
// Validate supplied email address
|
364
|
function validate_email($email) {
|
365
|
if(function_exists('idn_to_ascii')){ // use pear if available
|
366
|
$email = idn_to_ascii($email);
|
367
|
}else {
|
368
|
require_once(WB_PATH.'/include/idna_convert/idna_convert.class.php');
|
369
|
$IDN = new idna_convert();
|
370
|
$email = $IDN->encode($email);
|
371
|
unset($IDN);
|
372
|
}
|
373
|
return !(filter_var($email, FILTER_VALIDATE_EMAIL) == false);
|
374
|
}
|
375
|
*/
|
376
|
// Print a success message which then automatically redirects the user to another page
|
377
|
function print_success( $message, $redirect = 'index.php' ) {
|
378
|
global $TEXT;
|
379
|
if(is_array($message)) {
|
380
|
$message = implode ('<br />',$message);
|
381
|
}
|
382
|
// fetch redirect timer for sucess messages from settings table
|
383
|
$redirect_timer = ((defined( 'REDIRECT_TIMER' )) && (REDIRECT_TIMER <= 10000)) ? REDIRECT_TIMER : 0;
|
384
|
// add template variables
|
385
|
$tpl = new Template( THEME_PATH.'/templates' );
|
386
|
$tpl->set_file( 'page', 'success.htt' );
|
387
|
$tpl->set_block( 'page', 'main_block', 'main' );
|
388
|
$tpl->set_block( 'main_block', 'show_redirect_block', 'show_redirect' );
|
389
|
$tpl->set_var( 'MESSAGE', $message );
|
390
|
$tpl->set_var( 'REDIRECT', $redirect );
|
391
|
$tpl->set_var( 'REDIRECT_TIMER', $redirect_timer );
|
392
|
$tpl->set_var( 'NEXT', $TEXT['NEXT'] );
|
393
|
$tpl->set_var( 'BACK', $TEXT['BACK'] );
|
394
|
if ($redirect_timer == -1) {
|
395
|
$tpl->set_block( 'show_redirect', '' );
|
396
|
}
|
397
|
else {
|
398
|
$tpl->parse( 'show_redirect', 'show_redirect_block', true );
|
399
|
}
|
400
|
$tpl->parse( 'main', 'main_block', false );
|
401
|
$tpl->pparse( 'output', 'page' );
|
402
|
exit();
|
403
|
}
|
404
|
|
405
|
// Print an error message
|
406
|
function print_error($message, $link = 'index.php', $auto_footer = true) {
|
407
|
global $TEXT;
|
408
|
if(is_array($message)) {
|
409
|
$message = implode ('<br />',$message);
|
410
|
}
|
411
|
$success_template = new Template(THEME_PATH.'/templates');
|
412
|
$success_template->set_file('page', 'error.htt');
|
413
|
$success_template->set_block('page', 'main_block', 'main');
|
414
|
$success_template->set_var('MESSAGE', $message);
|
415
|
$success_template->set_var('LINK', $link);
|
416
|
$success_template->set_var('BACK', $TEXT['BACK']);
|
417
|
$success_template->parse('main', 'main_block', false);
|
418
|
$success_template->pparse('output', 'page');
|
419
|
if ( $auto_footer == true ) {
|
420
|
if ( method_exists($this, "print_footer") ) {
|
421
|
$this->print_footer();
|
422
|
}
|
423
|
}
|
424
|
exit();
|
425
|
}
|
426
|
|
427
|
// Validate send email
|
428
|
function mail($fromaddress, $toaddress, $subject, $message, $fromname='') {
|
429
|
/*
|
430
|
INTEGRATED OPEN SOURCE PHPMAILER CLASS FOR SMTP SUPPORT AND MORE
|
431
|
SOME SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION
|
432
|
NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE (C. Sommer)
|
433
|
|
434
|
NOTE:
|
435
|
To use SMTP for sending out mails, you have to specify the SMTP host of your domain
|
436
|
via the Settings panel in the backend of Website Baker
|
437
|
*/
|
438
|
|
439
|
$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
|
440
|
$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
|
441
|
$subject = preg_replace('/[\r\n]/', '', $subject);
|
442
|
$message_alt = $message;
|
443
|
$message = preg_replace('/[\r\n]/', '<br \>', $message);
|
444
|
|
445
|
// create PHPMailer object and define default settings
|
446
|
$myMail = new wbmailer();
|
447
|
|
448
|
// set user defined from address
|
449
|
if ($fromaddress!='') {
|
450
|
if($fromname!='') $myMail->FromName = $fromname; // FROM-NAME
|
451
|
$myMail->From = $fromaddress; // FROM:
|
452
|
$myMail->AddReplyTo($fromaddress); // REPLY TO:
|
453
|
}
|
454
|
|
455
|
// define recepient and information to send out
|
456
|
$myMail->AddAddress($toaddress); // TO:
|
457
|
$myMail->Subject = $subject; // SUBJECT
|
458
|
$myMail->Body = $message; // CONTENT (HTML)
|
459
|
$myMail->AltBody = strip_tags($message_alt); // CONTENT (TEXT)
|
460
|
|
461
|
// check if there are any send mail errors, otherwise say successful
|
462
|
if (!$myMail->Send()) {
|
463
|
return false;
|
464
|
} else {
|
465
|
return true;
|
466
|
}
|
467
|
}
|
468
|
|
469
|
}
|