/
class.wb.php
1308 lines (1208 loc) · 44.7 KB
/
class.wb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WBCE CMS
* Way Better Content Editing.
* Visit https://wbce.org to learn more and to join the community.
*
* @copyright Ryan Djurovich (2004-2009)
* @copyright WebsiteBaker Org. e.V. (2009-2015)
* @copyright WBCE Project (2015-)
* @license GNU GPL2 (or any later version)
*/
// Prevent this file from being accessed directly
defined('WB_PATH') or die("Access Denied");
class Wb extends SecureForm
{
// store a direct output
public $sDirectOutput = '';
public $page_sections = array();
public $password_chars = 'a-zA-Z0-9\_\-\!\#\*\+\@\$\&\:\.';
public $iPassMinLength = 6;
/**
* @brief General initialization function performed
* when frontend or backend is loaded.
*/
public function __construct($mode = SecureForm::FRONTEND)
{
parent::__construct($mode);
}
/**
* @brief Check if the Password matches the needed pattern and length
* and encode it correctly if true.
* This method will return an error message if false.
*
* @param string $sPassword
* @param string $sNewPasswordRetyped
* @return mixed may be array if error message
* or string with the correctly encoded password
* @global array $MESSAGE
*/
public function checkPasswordPattern($sPassword, $sNewPasswordRetyped = null)
{
global $MESSAGE;
$iMinPassLength = 6;
$bPasswordOk = false;
$aErrMsg = array();
if ($sPassword != '') {
$sPattern = '/[^' . $this->password_chars . ']/';
if (preg_match($sPattern, $sPassword)) {
$aErrMsg[] = $MESSAGE['PREFERENCES_INVALID_CHARS'] . '[1]';
} else {
$bPasswordOk = true;
}
if ($sNewPasswordRetyped != null) {
if ($sPassword != $sNewPasswordRetyped) {
// $bPasswordOk = false;
$aErrMsg[] = $MESSAGE['USERS_PASSWORD_MISMATCH'] . '[2]';
}
}
if (strlen($sPassword) < $iMinPassLength) {
// $bPasswordOk = false;
$aErrMsg[] = $MESSAGE['USERS_PASSWORD_TOO_SHORT'] . '[3]';
}
}
return (!empty($aErrMsg)) ? $aErrMsg : $this->doPasswordEncode($sPassword);
}
/**
* @param string $sPassword
*/
public function doPasswordEncode($sPassword)
{
if (function_exists('password_hash')) {
return password_hash($sPassword, PASSWORD_DEFAULT);
} else { // fallback to old behavior, hopefully never needed
md5($sPassword);
}
}
/**
* @brief Check if the Password is the correct one for a given user.
* This method will true if it matches, otherwise false false.
*
* @param int $iUserID
* @param string $sPassword
*/
public function doCheckPassword($iUserID, $sPassword)
{
global $database;
// Get the password hash from Database
$sDbPasswordHash = $database->get_one('SELECT `password` FROM `{TP}users` WHERE `user_id` = ' . $iUserID . ' AND `active` = 1');
if ($sDbPasswordHash === null) {
// db lookup failed (wrong user id supplied?)
return false;
}
if (strpos($sDbPasswordHash, '$') === false) {
// old md5 hash stored in db
if ($sDbPasswordHash === md5($sPassword)) {
// yes, it is the correct password, now update the db entry first
$sNewHash = $database->escapeString($this->doPasswordEncode($sPassword));
$database->query("UPDATE `{TP}users` SET `password` = '$sNewHash' WHERE `user_id` = " . $iUserID . ' AND `active` = 1');
// ignore any possible failure and continue with the authentication or whatever
return true;
} else {
// wrong password
return false;
}
// should never reach this (see below)
return false;
} else {
return password_verify($sPassword, $sDbPasswordHash);
}
// should never reach this but it is good practice to return false
// in case anything goes wrong in future modifications of the code above...
return false;
}
/**
* @brief returns a password input field and prepares the insert queue
* for the password strength meter
*
* @param string $sNameAttr
*/
public function passwordField($sNameAttr = '')
{
$sRetVal = '';
if ($sNameAttr != '') {
$sRetVal = '<input type="password" id="' . $sNameAttr . '" name="' . $sNameAttr . '" value="" class="wdt250" autocomplete="new-password" />';
I::insertCssFile(WB_URL . '/include/password-strength-meter/password.min.css', 'HEAD BTM-', 'PwStrenght');
I::insertJsFile(WB_URL . '/include/password-strength-meter/password.min.js', 'HEAD BTM-', 'PwStrenght');
// Get String Translations
$sLanguagesDir = WB_PATH . '/include/password-strength-meter/languages/';
$sLanguageFile = $sLanguagesDir . strtolower(LANGUAGE) . '.js';
if (file_exists($sLanguageFile)) {
$sLangFile = get_url_from_path($sLanguageFile);
} else {
$sLangFile = get_url_from_path($sLanguagesDir . '/en.js');
}
I::insertJsFile($sLangFile, 'HEAD BTM-', 'PwStrenghtLang');
$sToJs = <<<_JsCode
jQuery(document).ready(function($) {
$('#$sNameAttr').password({
minimumLength: $this->iPassMinLength,
enterPass: PwStrenghtLang.enterPass,
shortPass: PwStrenghtLang.shortPass,
badPass: PwStrenghtLang.badPass,
goodPass: PwStrenghtLang.goodPass,
strongPass: PwStrenghtLang.strongPass
});
});
_JsCode;
I::insertJsCode($sToJs, 'HEAD BTM-', 'PwStrenght');
}
return $sRetVal;
}
/**
* @brief For easy output of JSON strings XML or Ajax......
* If you want the whole page to be processed
* (for internal functionality or whatever)
* before output is done, just set the class variable manually
*
* @code
* $wb->sDirectOutput = "My cool string.";
* $admin->sDirectOutput = "My cool string.";
* @endcode
*
* DirectOutput is triggered once before normal output is done.
*
* @param $sContent The content to pipe out
* @return string echos out this string
*/
public function DirectOutput($sContent = false)
{
// Move to class
if (is_string($sContent)) {
$this->sDirectOutput .= $sContent;
}
// Return if Class var is still empty
if (empty($this->sDirectOutput)) {
return;
}
// kill all output buffering
while (ob_get_level()) {
ob_end_clean();
}
// directly output everyting and exit
echo $this->sDirectOutput;
exit;
}
/**
* Am I Group Member (of the following groups)?
* @brief Check if current user is member of at least one of given groups
* NOTE: SuperAdmin (user_id = 1) is always member of ALL groups
*
* @param unspec $groups_list An array or a comma seperated list of group-ids
* @return bool true: if current user is member of one of this groups, otherwise false
*/
public function ami_group_member($mGroups = '')
{
if ($this->get_group_id() == 1) {
return true;
}
return $this->is_group_match($mGroups, $this->get_groups_id());
}
/**
* @brief Get the current users main GROUP_ID.
* NOTE: a user may be member in differend user groups.
*
* @return int
*/
public function get_group_id()
{
return $this->get_session('GROUP_ID');
}
/**
* @brief Get SESSION data
*
* @param string $field
* @return string
*/
public function get_session($field)
{
return (isset($_SESSION[$field]) ? $_SESSION[$field] : null);
}
/**
* @brief Check if one or more group_ids are in both group lists
*
* @param unspec $mGroups_1 : an array or a coma seperated list of group-ids
* @param unspec $mGroups_2 : an array or a coma seperated list of group-ids
* @param array &$matches : an array-var whitch will return possible matches
* @return bool true there is a match, otherwise false
*/
public function is_group_match($mGroups_1 = '', $mGroups_2 = '', &$matches = null)
{
if ($mGroups_1 == '' || $mGroups_2 == '') {
return false;
}
if (!is_array($mGroups_1)) {
// it's either a single value or a CSV
$mGroups_1 = explode(',', $mGroups_1);
}
if (!is_array($mGroups_2)) {
// it's either a single value or a CSV
$mGroups_2 = explode(',', $mGroups_2);
}
$matches = array_intersect($mGroups_1, $mGroups_2);
return (sizeof($matches) != 0);
}
/**
* @brief Get the current users GROUPS_IDs.
* NOTE: a user may be member in differend user groups.
*
* @return array
*/
public function get_groups_id() : array
{
$session_groups = $this->get_session('GROUPS_ID');
$groups = (
(!empty($session_groups))
? explode(",", $session_groups)
: []
);
return $groups;
}
/**
* @brief Check whether we should show a page or not (for front-end)
*
* @param array $page
* @return bool
*/
public function show_page($page)
{
$retval = ($this->page_is_visible($page) && $this->page_is_active($page));
return $retval;
}
/**
* @brief Check whether a page is visible or not.
* This will check page-visibility and user- and group-rights.
*
* @param array $page
* @return bool false: If page-visibility is 'none' or 'deleted', or page-vis. is 'registered'
* or 'private' and user isn't allowed to see the page.
* true: If page-visibility is 'public' or 'hidden', or page-vis. is 'registered'
* or 'private' and user _is_ allowed to see the page.
*/
public function page_is_visible($page)
{
$show_it = false; // shall we show the page_link?
$page_id = $page['page_id'];
$visibility = $page['visibility'];
$viewing_groups = $page['viewing_groups'];
$viewing_users = $page['viewing_users'];
// First check if visibility is 'none', 'deleted'
if ($visibility == 'none') {
return (false);
} elseif ($visibility == 'deleted') {
return (false);
}
// Now check if visibility is 'hidden', 'private' or 'registered'
if ($visibility == 'hidden') {
// hidden: hide the menu-link, but show the page
$show_it = true;
} elseif ($visibility == 'private' || $visibility == 'registered') {
// Check if the user is logged in
if ($this->is_authenticated() == true) {
// Now check if the user has perms to view the page
$in_group = false;
foreach ($this->get_groups_id() as $cur_gid) {
if (in_array($cur_gid, explode(',', $viewing_groups))) {
$in_group = true;
}
}
if ($in_group || in_array($this->get_user_id(), explode(',', $viewing_users))) {
$show_it = true;
} else {
$show_it = false;
}
} else {
$show_it = false;
}
} elseif ($visibility == 'public') {
$show_it = true;
} else {
$show_it = false;
}
return ($show_it);
}
/**
* @brief Check if user is already authenticated (logged in)
* since vers. 1.4 it should be prefered to use
* the method isLoggedIn() instead.
*
* @return bool
*/
public function is_authenticated()
{
return $this->isLoggedIn();
}
/**
* @brief Check if the user is logged in
*
* @return bool
*/
public function isLoggedIn()
{
$iSessionUserID = $this->get_session('USER_ID');
return ($iSessionUserID != null && $iSessionUserID != "" && is_numeric($iSessionUserID));
}
/**
* @brief Get the current users USER_ID
*
* @return int
*/
public function get_user_id()
{
return $this->get_session('USER_ID');
}
/**
* @brief Check if there is at least one active section on this page.
*
* @param array $page
* @return bool
*/
public function page_is_active($page)
{
$has_active_sections = false;
$now = time();
$sql = 'SELECT `publ_start`, `publ_end` FROM `{TP}sections` WHERE `page_id`=' . (int)$page['page_id'];
$query_sections = $this->_oDb->query($sql);
if ($query_sections->numRows() != 0) {
while ($section = $query_sections->fetchRow()) {
if ($now < $section['publ_end'] && ($now > $section['publ_start'] || (int)$section['publ_start'] == 0) || $now > $section['publ_start'] && (int)$section['publ_end'] == 0) {
$has_active_sections = true;
break;
}
}
}
return ($has_active_sections);
}
/**
* @brief Check if the user is SuperAdmin(UserID = 1)
*
* @return bool
*/
public function isSuperAdmin()
{
return ($this->get_session('USER_ID') == 1);
}
/**
* @brief Check if the user is Admin (GroupID = 1)
*
* @return bool
*/
public function isAdmin()
{
if ($this->get_session('GROUP_ID') == 1) {
return true;
}
return (in_array(1, $this->get_groups_id()));
}
/**
* @brief The purpose of $this->strip_slashes() _was_ in further time to undo the effects of magic_quotes_gpc==ON
* So actually, id did not change anything to $input if PHP >=5.4 - so this is just here for backward compatibility
*
* @param string $input
* @return string
*/
public function strip_slashes($input)
{
return $input;
}
/**
* @brief a dummy function left over from gpc
* we keep it just in case modules rely on it even if it does nothing anymore
*
* @param string $input
* @return string
*/
public function strip_magic($input)
{
return $input;
}
/**
* @brief Escape backslashes for use with mySQL LIKE strings
*
* @param string $input
* @return string
*/
public function escape_backslashes($input)
{
return str_replace("\\", "\\\\", $input);
}
/**
* @brief Generate full page_link based on the
* `link` content from the `{TP}pages` table
*
* @param unspec $uLinkId
* @return string
*/
public function page_link($uLinkId = null)
{
$sLinkUrl = '';
if ($uLinkId == null && defined('PAGE_ID')) {
$uLinkId = (int)PAGE_ID;
}
if ($uLinkId == null && isset($_GET['page_id'])) {
$uLinkId = (int)$_GET['page_id'];
}
if (is_numeric($uLinkId)) {
$sSql = "SELECT `link` FROM `{TP}pages` WHERE `page_id` = %d";
$sLink = $GLOBALS['database']->get_one(sprintf($sSql, $uLinkId));
$sLinkUrl = WB_URL . PAGES_DIRECTORY . $sLink . PAGE_EXTENSION;
} else {
// Check for :// in the link (used in URL's) as well as mailto:
if (strstr($uLinkId, '://') == '' and substr($uLinkId, 0, 7) != 'mailto:') {
$sLinkUrl = WB_URL . PAGES_DIRECTORY . $uLinkId . PAGE_EXTENSION;
} else {
$sLinkUrl = $uLinkId;
}
}
return $sLinkUrl;
}
/**
* @brief Get POST data and escape it
*
* @param string $field
* @return string
*/
public function get_post_escaped($field)
{
$result = $this->get_post($field);
return (is_null($result)) ? null : $this->add_slashes($result);
}
/**
* @brief Get POST data
*
* @param string $field
* @return string
*/
public function get_post($field)
{
return (isset($_POST[$field]) ? $_POST[$field] : null);
}
/**
* @brief Modified addslashes function
*
* @param string $input
* @return string
*/
public function add_slashes($input)
{
if (!is_string($input)) {
return $input;
}
return addslashes($input);
}
/**
* @brief Get GET data
*
* @param string $field
* @return string
*/
public function get_get($field)
{
return (isset($_GET[$field]) ? $_GET[$field] : null);
}
/**
* @brief Get SERVER data
*
* @param string $field
* @return string
*/
public function get_server($field)
{
return (isset($_SERVER[$field]) ? $_SERVER[$field] : null);
}
/**
* @brief Get the current users GROUP_NAMEs as CSV string.
* NOTE: a user may be member in differend user groups.
*
* @return string
*/
public function get_group_name()
{
return implode(",", $this->get_session('GROUP_NAME'));
}
/**
* @brief Get the current users GROUP_NAMEs as array.
* NOTE: a user may be member in differend user groups.
*
* @return array
*/
public function get_groups_name()
{
return $this->get_session('GROUP_NAME');
}
/**
* @brief Get the current users USERNAME
*
* @return string
*/
public function get_username()
{
return $this->get_session('USERNAME');
}
/**
* @brief Get the current users DISPLAY_NAME
*
* @return string
*/
public function get_display_name()
{
return $this->get_session('DISPLAY_NAME');
}
/**
* @brief Get the current users EMAIL address
*
* @return string
*/
public function get_email()
{
return $this->get_session('EMAIL');
}
/**
* @brief Get the current users HOME_FOLDER
*
* @return string
*/
public function get_home_folder()
{
return $this->get_session('HOME_FOLDER');
}
/**
* @brief Validate the supplied email address
*
* @param string
* @return string
*/
public function validate_email($email)
{
if (function_exists('idn_to_ascii')) {
// use pear if available
$email = @idn_to_ascii($email);
} else {
require_once WB_PATH . '/include/idna_convert/idna_convert.class.php';
$IDN = new idna_convert();
$email = $IDN->encode($email);
unset($IDN);
}
// regex from NorHei 2011-01-11
$retval = preg_match("/^((([!#$%&'*+\\-\/\=?^_`{|}~\w])|([!#$%&'*+\\-\/\=?^_`{|}~\w][!#$%&'*+\\-\/\=?^_`{|}~\.\w]{0,}[!#$%&'*+\\-\/\=?^_`{|}~\w]))[@]\w+(([-.]|\-\-)\w+)*\.\w+(([-.]|\-\-)\w+)*)$/", $email);
return ($retval != false);
}
/**
* @brief set one or more bit in a integer value
*
* @param int $value Reference to the integer, containing the value
* @param int $bits2set The bitmask which should be added to the value
* @return void
*/
public function bit_set(&$value, $bits2set)
{
$value |= $bits2set;
}
/**
* @brief reset one or more bit from a integer value
*
* @param int $value Reference to the integer, containing the value
* @param int $bits2reset The bitmask which should be removed from value
* @return void
*/
public function bit_reset(&$value, $bits2reset)
{
$value &= ~$bits2reset;
}
/**
* @brief check if one or more bit in a integer value is set
*
* @param int $value Reference to the integer, containing the value
* @param int $bits2set The bitmask which should be added to value
* @return void
*/
public function bit_isset($value, $bits2test)
{
return (($value & $bits2test) == $bits2test);
}
/**
* @brief Print a success message which then automatically redirects
* the user to a specified page
*
* @param mixed $uMsg may be a single string or an array
* @param string $sRedirectUri URI to the redirect page
* @return string
*/
public function print_success($uMsg, $sRedirectUri = 'index.php', $bAutoFooter = false)
{
$this->messageBox($uMsg, 'success', $sRedirectUri, $bAutoFooter);
}
/**
* since vers. 1.4.0
* @brief Print a modal box
*
* @param mixed $uMsg may be a single string or an array
* @param string $sRedirectUri URI for the redirect
* @return string
*/
public function messageBox($uMsg, $sType = 'info', $sRedirectUri = 'index.php', $bAutoFooter = false, $bUseRedirect = true)
{
if (!is_array($uMsg)) {
$uMsg = array(
$uMsg
);
}
// get correct redirect time
$iRedirectTime = (defined('REDIRECT_TIMER')) ? REDIRECT_TIMER : 0;
$iRedirectTime = ($iRedirectTime > 10000) ? 10000 : $iRedirectTime;
$aToTwig = array(
'MESSAGE_TYPE' => $sType,
'MESSAGES' => $uMsg,
'REDIRECT_URL' => $sRedirectUri,
'REDIRECT_TIME' => $iRedirectTime,
'USE_REDIRECT' => $bUseRedirect
);
$this->getThemeFile('message_box.twig', $aToTwig);
if ($bAutoFooter == true) {
if (method_exists($this, "print_footer")) {
$this->print_footer();
}
exit();
}
}
public function getThemeFile($sTplName = '', $aToTwig = array())
{
$aTemplateLocs = array();
$aCheckDirs = array(
THEME_PATH . '/templates/',
WB_PATH . '/templates/theme_fallbacks/templates/'
);
foreach ($aCheckDirs as $dir) {
if (is_dir($dir)) {
$aTemplateLocs[] = $dir;
}
}
$oTwig = getTwig($aTemplateLocs);
$oTemplate = $oTwig->load($sTplName);
$oTemplate->display($aToTwig);
}
/**
* @brief Print an error message with a "back" link/button to a specified page
*
* @param mixed $uMsg may be a single string or an array
* @param string $sRedirectUri URI for the "back" link
* @return string
*/
public function print_error($uMsg, $sRedirectUri = 'index.php', $bAutoFooter = true)
{
$this->messageBox($uMsg, 'error', $sRedirectUri, $bAutoFooter);
}
/**
* @brief Validate and send a mail
*
* @param string $fromaddress // FROM:
* @param string $toaddress // TO:
* @param string $subject // SUBJECT
* @param string $message // The Message to be send
* @param string $fromname // From Name
* @return boolean
*/
public function mail($fromaddress, $toaddress, $subject, $message, $fromname = '')
{
// INTEGRATED OPEN SOURCE PHPMAILER CLASS FOR SMTP SUPPORT AND MORE.
// SOME SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION.
// NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE. (C. Sommer)
$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
$subject = preg_replace('/[\r\n]/', '', $subject);
// create PHPMailer object and define default settings
$myMail = new Mailer();
// set user defined FROM address
if ($fromaddress != '') {
if ($fromname != '') {
$myMail->FromName = $fromname;
}
$myMail->From = $fromaddress; // FROM:
$myMail->AddReplyTo($fromaddress); // REPLY TO:
}
// define recepient and information to send out
$myMail->AddAddress($toaddress); // TO:
$myMail->Subject = $subject; // SUBJECT
$myMail->Body = nl2br($message); // CONTENT (HTML)
$myMail->AltBody = strip_tags($message); // CONTENT (TEXT)
// check if there are any send mail errors and return accordingly
if (!$myMail->Send()) {
return false;
} else {
return true;
}
}
/**
* @brief Checks if there is an override Backend Theme template file
*
* @param string $sThemeFile set the template file name including the file extension
* @return string the relative theme path
*
*/
public function correct_theme_source($sThemeFile = 'start.htt')
{
$sSysThemeFile = WB_PATH . '/templates/theme_fallbacks/templates/' . $sThemeFile;
$sOverrideFile = THEME_PATH . '/templates/' . $sThemeFile;
if (file_exists($sOverrideFile)) {
return $sOverrideFile;
} elseif (file_exists($sSysThemeFile)) {
return $sSysThemeFile;
} else {
die('Following Backend Theme file is missing: ' . $sThemeFile);
}
}
/**
* @brief Check if a foldername doesn't have invalid characters
*
* @param string $str to check
* @return bool
*/
public function checkFolderName($str)
{
return !(preg_match('#\^|\\\|\/|\.|\?|\*|"|\'|\<|\>|\:|\|#i', $str) ? true : false);
}
/**
* @brief Check the given path to make sure current path
* is within given basedir normally document root
*
* @param string $sCurrentPath
* @param string $sBaseDir
* @return string $sCurrentPath or bool FALSE
*/
public function checkpath($sCurrentPath, $sBaseDir = WB_PATH)
{
// Clean the cuurent path
$sCurrentPath = rawurldecode($sCurrentPath);
$sCurrentPath = realpath($sCurrentPath);
$sBaseDir = realpath($sBaseDir);
// $sBaseDir needs to exist in the $sCurrentPath
$pos = stripos($sCurrentPath, $sBaseDir);
if ($pos === false) {
return false;
} elseif ($pos == 0) {
return $sCurrentPath;
} else {
return false;
}
}
/**
* @brief This method registers the files and writes them
* to the DOM using the Insert Class methods
*
* @param string $sModfileType css|js|jquery|js_vars
* @param string $sEndPosition frontend|backend
* @return void uses Insert Class methods
*/
public function register_modfiles($sModfileType = "css", $sEndPosition = "frontend")
{
$aToInsert = $this->collect_modfiles($sEndPosition);
$sModfileType = strtolower($sModfileType);
switch ($sModfileType) {
case 'css':
if (isset($aToInsert['css']) && is_array($aToInsert['css'])) {
foreach ($aToInsert['css'] as $sCssFile) {
I::insertCssFile($sCssFile, 'HEAD MODFILES');
}
}
break;
case 'js_sysvars':
case 'jquery':
if ($sModfileType != 'js_sysvars') {
$aJqueryFiles = array();
if ($sModfileType == 'jquery') {
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-min.js';
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-insert.js';
// $aJqueryFiles[] = WB_URL . '/include/jquery/jquery-include.js';
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-migrate-min.js';
// workout to insert ui.css and theme
$sFile = WB_URL . '/modules/jquery/jquery_theme.js';
$aJqueryFiles[] = file_exists(str_replace(WB_URL, WB_PATH, $sFile)) ? $sFile : WB_URL . '/include/jquery/jquery_theme.js';
// workout to insert plugins functions, set in templatedir
$sFile = TEMPLATE_DIR . '/jquery_frontend.js';
if (file_exists(str_replace(WB_URL, WB_PATH, $sFile))) {
$aJqueryFiles[] = $sFile;
}
}
foreach ($aJqueryFiles as $sJsFile) {
I::insertJsFile($sJsFile, 'HEAD MODFILES');
}
}
break;
case 'js':
// insert system vars to be ready for all JS code
if (defined("URL_VAR_COMPATIBILITY_MODE") && URL_VAR_COMPATIBILITY_MODE==true) {
$sJsSysvars = "\t\tvar URL = WB_URL = '" . WB_URL . "';";
} else {
$sJsSysvars = "\t\tvar WB_URL = '" . WB_URL . "';";
}
if (defined("LANGUAGE")) {
$sJsSysvars .= "\n\t\tvar LANGUAGE = '" . strtolower(LANGUAGE) . "';";
}
if (defined("PAGE_ID")) {
$sJsSysvars .= "\n\t\tvar PAGE_ID = '" . PAGE_ID . "';";
}
if (isset($_REQUEST['page_id']) && is_numeric($_REQUEST['page_id'])) {
$sJsSysvars .= "\n\t\tvar PAGE_ID = '" . (int)$_REQUEST['page_id'] . "';";
}
if (isset($_REQUEST['section_id']) && is_numeric($_REQUEST['section_id'])) {
$sJsSysvars .= "\n\t\tvar SECTION_ID = '" . (int)$_REQUEST['section_id'] . "';";
}
if (defined("TEMPLATE_DIR")) {
$sJsSysvars .= "\n\t\tvar TEMPLATE_DIR = '" . TEMPLATE_DIR . "';";
}
if (defined("THEME_URL") && !defined("WB_FRONTEND")) {
$sJsSysvars .= "\n\t\tvar THEME_URL = '" . THEME_URL . "';";
}
if (defined("ADMIN_URL") && !defined("WB_FRONTEND")) {
$sJsSysvars .= "\n\t\tvar ADMIN_URL = '" . ADMIN_URL . "';";
}
$sJsSysvars .= "\n\t\tvar SESSION_TIMEOUT = '" . $this->get_session_timeout() . "';";
$sJsSysvars .= "\n";
I::insertJsCode($sJsSysvars, "HEAD TOP+", 'js_sysvars');
// insert js files to head
if (isset($aToInsert['js_head']) && is_array($aToInsert['js_head'])) {
foreach ($aToInsert['js_head'] as $sJsFile) {
I::insertJsFile($sJsFile, 'HEAD MODFILES');
}
}
// insert js files before the closing </body> tag
if (isset($aToInsert['js_body']) && is_array($aToInsert['js_body'])) {
foreach ($aToInsert['js_body'] as $sJsFile) {
I::insertJsFile($sJsFile, 'BODY BTM-');
}
}
break;
default:
break;
}
}
/**
* @brief Query the database in order to determine which modfiles
* to use (from snippets, page-type modules, tools etc.)
* and create a assoc array of all the modfiles to be inserted.
*
* @param string $sEndPosition frontend|backend
* @return array modfiles collection as assoc array
*/
public function collect_modfiles($sEndPosition = 'frontend')
{
$aToInsert = array();
$sSql = ''; // start collecting the SQL Query
// get snippet modfiles if in FRONTEND
if (defined('WB_FRONTEND')) {
$sSql .= "SELECT `directory` as 'module_dir' FROM `{TP}addons` WHERE `function` LIKE '%snippet%'";
}
// check if we should use page-type module modfiles
$iPageTypePID = null;
if (defined('PAGE_ID')) {
$iPageTypePID = PAGE_ID;
}
if (!defined('PAGE_ID') && isset($_REQUEST['page_id']) && strposm($_SERVER['PHP_SELF'], array(
'pages/sections.php',
'pages/settings.php'
)) == false) {
$iPageTypePID = (int)$_REQUEST['page_id'];
}
if ($iPageTypePID != null && !defined('WB_FRONTEND')) {
// dev note: frontend modfiles for page type modules are being added
// with the get_section_content() function in the frontend.functions.php
if ($sSql != '') {
$sSql .= " UNION ALL ";
}
$sSql .= "SELECT `module` as 'module_dir' FROM `{TP}sections` WHERE `page_id` = " . $iPageTypePID;
}
// if it's a tool, get its modfiles
if (isset($_GET['tool'])) {
if ($sSql != '') {
$sSql .= " UNION ALL ";
}