This repository has been archived by the owner on Oct 11, 2020. It is now read-only.
/
class.kunena.php
1422 lines (1187 loc) · 51.3 KB
/
class.kunena.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
/**
* @version $Id$
* Kunena Component
* @package Kunena
*
* @Copyright (C) 2008 - 2009 Kunena Team All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.com
*
* Based on FireBoard Component
* @Copyright (C) 2006 - 2007 Best Of Joomla All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.bestofjoomla.com
*/
// Dont allow direct linking
defined( '_JEXEC' ) or die('Restricted access');
// Set charset
define('KUNENA_CHARSET', 'UTF-8');
// Joomla absolute path
define('KUNENA_JLIVEURL', JURI::root());
$app =& JFactory::getApplication();
// Joomla template dir
define('KUNENA_JTEMPLATEPATH', KUNENA_ROOT_PATH .DS. "templates".DS . $app->getTemplate());
define('KUNENA_JTEMPLATEURL', KUNENA_JLIVEURL. "templates/".$app->getTemplate());
global $kunena_my;
require_once (KUNENA_PATH_LIB .DS. "kunena.config.class.php");
$document =& JFactory::getDocument();
$fbConfig =& CKunenaConfig::getInstance();
$kunena_db = &JFactory::getDBO();
$kunena_my = &JFactory::getUser();
/**
*@desc Getting the correct Itemids, for components required
*/
$Itemid = JRequest::getInt('Itemid', 0, 'REQUEST');
//check if we have all the itemid sets. if so, then no need for DB call
if (!defined("KUNENA_COMPONENT_ITEMID")) {
$kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_kunena' AND published='1'");
$Itemid = $kunena_db->loadResult();
if ($Itemid < 1) {
$Itemid = 0;
}
define("KUNENA_COMPONENT_ITEMID", (int)$Itemid);
define("KUNENA_COMPONENT_ITEMID_SUFFIX", "&Itemid=" . KUNENA_COMPONENT_ITEMID);
//JomSocial
if ($fbConfig->pm_component == 'jomsocial' || $fbConfig->fb_profile == 'jomsocial' || $fbConfig->avatar_src == 'jomsocial')
{
// Only proceed if jomSocial is really installed
if ( file_exists( KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/core.php' ) )
{
$kunena_db->setQuery("SELECT id FROM #__menu WHERE link LIKE 'index.php?option=com_community%' AND published='1' ORDER BY id ASC LIMIT 1");
$JOMSOCIAL_Itemid = $kunena_db->loadResult();
check_dberror('Unable to load jomSocial item id');
define("KUNENA_JOMSOCIAL_ITEMID", (int)$JOMSOCIAL_Itemid);
define("KUNENA_JOMSOCIAL_ITEMID_SUFFIX", "&Itemid=" . KUNENA_JOMSOCIAL_ITEMID);
// Prevent JomSocial from loading their jquery library - we got one loaded already
if (!defined('C_ASSET_JQUERY')) define( 'C_ASSET_JQUERY', 1 );
include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/core.php');
include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/messaging.php');
// A bug in the JomSocial 1.6 pre-release is throwing a hard php error when this include is enabled
// for now I have moved it straight into post.php - the only place the userpoints classes
// are being used. We might want to change that back for future releases.
// include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/userpoints.php');
//PM popup requires JomSocial css to be loaded from selected template
$config =& CFactory::getConfig();
$document->addStyleSheet(KUNENA_JLIVEURL.'components/com_community/assets/window.css');
$document->addStyleSheet(KUNENA_JLIVEURL.'components/com_community/templates/'.$config->get('template').'/css/style.css');
}
else
{
// JomSocial not present reset config settings to avoid problems
$fbConfig->pm_component = $fbConfig->pm_component == 'jomsocial' ? 'none' : $fbConfig->pm_component;
$fbConfig->fb_profile = $fbConfig->fb_profile == 'jomsocial' ? 'kunena' : $fbConfig->fb_profile;
$fbConfig->avatar_src = $fbConfig->avatar_src == 'jomsocial' ? 'kunena' : $fbConfig->avatar_src;
// Do not save new config - thats a task for the backend
// This is just a catch all in case it is not present
}
}
//Community Builder 1.2 integration
if ($fbConfig->pm_component == 'cb' || $fbConfig->fb_profile == 'cb' || $fbConfig->avatar_src == 'cb')
{
// Get Community Builder compability
require_once (KUNENA_PATH_LIB .DS. "kunena.communitybuilder.php");
global $kunenaProfile;
$kunenaProfile =& CkunenaCBProfile::getInstance();
}
//Clexus PM
if ($fbConfig->pm_component == 'clexuspm' || $fbConfig->fb_profile == 'clexuspm') {
$kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_mypms' AND published='1'");
$CPM_Itemid = $kunena_db->loadResult();
check_dberror('Unable to load Clexus item id');
define("KUNENA_CPM_ITEMID", (int)$CPM_Itemid);
define("KUNENA_CPM_ITEMID_SUFFIX", "&Itemid=" . KUNENA_CPM_ITEMID);
}
// UddeIM
if ($fbConfig->pm_component == 'uddeim') {
$kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_uddeim' AND published='1'");
$UIM_itemid = $kunena_db->loadResult();
check_dberror('Unable to load uddeim item id');
define("KUNENA_UIM_ITEMID", (int)$UIM_itemid);
define("KUNENA_UIM_ITEMID_SUFFIX", "&Itemid=" . KUNENA_UIM_ITEMID);
}
// MISSUS
if ($fbConfig->pm_component == 'missus') {
$kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_missus' AND published='1'");
$MISSUS_itemid = $kunena_db->loadResult();
check_dberror('Unable to load missus item id');
define("KUNENA_MISSUS_ITEMID", (int)$MISSUS_itemid);
define("KUNENA_MISSUS_ITEMID_SUFFIX", "&Itemid=" . KUNENA_MISSUS_ITEMID);
}
// PROFILE LINK
if ($fbConfig->fb_profile == "jomsocial") {
$profilelink = 'index.php?option=com_community&view=profile&userid=';
define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_community&view=profile&Itemid=" . KUNENA_JOMSOCIAL_ITEMID . "&userid=");
}
else if ($fbConfig->fb_profile == "cb") {
$profilelink = 'index.php?option=com_comprofiler&task=userProfile&user=';
define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_comprofiler&task=userProfile" . KUNENA_CB_ITEMID_SUFFIX . "&user=");
}
else if ($fbConfig->fb_profile == "aup") { // integration AlphaUserPoints
$db =& JFactory::getDBO();
$query = "SELECT id FROM #__menu WHERE `link`='index.php?option=com_alphauserpoints&view=account' AND `type`='component' AND `published`='1'";
$db->setQuery( $query );
$AUP_itemid = $db->loadResult();
define("KUNENA_AUP_ITEMID", (int)$AUP_itemid);
define("KUNENA_AUP_ITEMID_SUFFIX", "&Itemid=" . KUNENA_AUP_ITEMID);
$profilelink = 'index.php?option=com_alphauserpoints&view=account&userid=';
define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_alphauserpoints&view=account&Itemid=" . KUNENA_AUP_ITEMID . "&userid=");
}
else if ($fbConfig->fb_profile == "clexuspm") {
$profilelink = 'index.php?option=com_mypms&task=showprofile&user=';
define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_mypms&task=showprofile&Itemid=" . KUNENA_CPM_ITEMID . "&user=");
}
else {
$profilelink = 'index.php?option=com_kunena&func=fbprofile&userid=';
define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_kunena&func=fbprofile&Itemid=" . KUNENA_COMPONENT_ITEMID . "&userid=");
}
}
/* _\|/_
(o o)
+----oOO-{_}-OOo--------------------------------+
| Now we have the components Itemids everywhere |
| Please use these constants where ever needed |
+----------------------------------------------*/
// Kunena live url
define('KUNENA_LIVEURL', KUNENA_JLIVEURL . 'index.php?option=com_kunena' . KUNENA_COMPONENT_ITEMID_SUFFIX);
define('KUNENA_CLEANLIVEURL', KUNENA_JLIVEURL . 'index.php?option=com_kunena&no_html=1' . KUNENA_COMPONENT_ITEMID_SUFFIX);
define('KUNENA_LIVEURLREL', 'index.php?option=com_kunena' . KUNENA_COMPONENT_ITEMID_SUFFIX);
// Kunena souces absolute path
define('KUNENA_DIRECTURL', KUNENA_JLIVEURL . 'components/com_kunena/');
// Kunena direct url
define('KUNENA_URLSOURCESPATH', KUNENA_DIRECTURL . 'lib/');
if (!defined("KUNENA_JCSSURL")) {
$kunena_db->setQuery("SELECT template FROM #__templates_menu WHERE client_id='0'");
$current_stylesheet = $kunena_db->loadResult();
define('KUNENA_JCSSURL', KUNENA_JLIVEURL . 'templates/' . $current_stylesheet . '/css/template_css.css');
}
// Kunena uploaded files directory
define('KUNENA_LIVEUPLOADEDPATH', KUNENA_JLIVEURL . 'images/fbfiles');
// now continue with other paths
$fb_user_template = JRequest::getString('fb_user_template', '', 'COOKIE');
$fb_user_img_template = JRequest::getString('fb_user_img_template', '', 'COOKIE');
// don't allow directory travelling
$fb_user_template = strtr($fb_user_template, '\\/', '');
$fb_user_img_template = strtr($fb_user_template, '\\/', '');
if (strlen($fb_user_template) > 0 && file_exists(KUNENA_PATH_TEMPLATE .DS. $fb_user_template))
{
$fb_cur_template = $fb_user_template;
}
else if (file_exists(KUNENA_PATH_TEMPLATE .DS. $fbConfig->template))
{
$fb_cur_template = $fbConfig->template;
}
else
{
$fb_cur_template = 'default_ex';
}
if (strlen($fb_user_img_template) > 0 && file_exists(KUNENA_PATH_TEMPLATE .DS. $fb_user_template .DS. 'images'))
{
$fb_cur_img_template = $fb_user_img_template;
}
else if (file_exists(KUNENA_PATH_TEMPLATE .DS. $fbConfig->templateimagepath .DS. 'images'))
{
$fb_cur_img_template = $fbConfig->templateimagepath;
}
else
{
$fb_cur_img_template = 'default_ex';
}
// only for preview module - maybe used later by users to change template
define('KUNENA_ABSTMPLTPATH', KUNENA_PATH_TEMPLATE .DS. $fb_cur_template);
define('KUNENA_ABSTMPLTMAINIMGPATH', KUNENA_PATH_TEMPLATE .DS. $fb_cur_img_template);
// IMAGES ABSOLUTE PATH
if (is_dir(KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. KUNENA_LANGUAGE) .DS) {
define('KUNENA_ABSIMAGESPATH', KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. KUNENA_LANGUAGE .DS);
}
else {
define('KUNENA_ABSIMAGESPATH', KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. 'english' .DS);
}
// absolute images path
define('KUNENA_ABSICONSPATH', KUNENA_ABSIMAGESPATH . 'icons/');
// absolute icons path
define('KUNENA_ABSEMOTIONSPATH', KUNENA_ABSIMAGESPATH . 'emoticons/');
// absolute emoticons path
define('KUNENA_ABSGRAPHPATH', KUNENA_ABSIMAGESPATH . 'graph/');
// absolute graph path
define('KUNENA_ABSRANKSPATH', KUNENA_ABSIMAGESPATH . 'ranks/');
// absolute ranks path
define('KUNENA_ABSCATIMAGESPATH', KUNENA_PATH_UPLOADED .DS. $fbConfig->catimagepath); // Kunena category images absolute path
define('KUNENA_TMPLTURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/");
define('KUNENA_TMPLTMAINIMGURL', KUNENA_DIRECTURL . "template/{$fb_cur_img_template}/");
// IMAGES URL PATH
define('KUNENA_TMPLTCSSURL', KUNENA_TMPLTURL . 'kunena.forum.css');
if (is_dir(KUNENA_ABSTMPLTMAINIMGPATH . '/images/' . KUNENA_LANGUAGE)) {
define('KUNENA_URLIMAGESPATH', KUNENA_TMPLTMAINIMGURL . 'images/' .KUNENA_LANGUAGE. '/');
}
else {
define('KUNENA_URLIMAGESPATH', KUNENA_TMPLTMAINIMGURL . 'images/english/');
}
// url images path
define('KUNENA_URLICONSPATH', KUNENA_URLIMAGESPATH . 'icons/');
// url icons path
define('KUNENA_URLEMOTIONSPATH', KUNENA_URLIMAGESPATH . 'emoticons/');
// url emoticons path
define('KUNENA_URLGRAPHPATH', KUNENA_URLIMAGESPATH . 'graph/');
// url graph path
define('KUNENA_URLRANKSPATH', KUNENA_URLIMAGESPATH . 'ranks/');
// url ranks path
define('KUNENA_URLCATIMAGES', KUNENA_LIVEUPLOADEDPATH ."/{$fbConfig->catimagepath}/"); // Kunena category images direct url
if (file_exists(KUNENA_ABSTMPLTPATH .DS. 'js' .DS. 'jquery-1.3.2.min.js'))
{
define('KUNENA_JQURL', KUNENA_DIRECTURL . 'template/' . $fb_cur_template . '/js/jquery-1.3.2.min.js');
}
else
{
define('KUNENA_JQURL', KUNENA_DIRECTURL . 'template/default/js/jquery-1.3.2.min.js');
}
if (file_exists(KUNENA_ABSTMPLTPATH .DS. 'js' .DS. 'kunenaforum.js'))
{
define('KUNENA_COREJSPATH', '/components/com_kunena/template/' . $fb_cur_template . '/js/kunenaforum.js');
define('KUNENA_COREJSURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/js/kunenaforum.js");
}
else
{
define('KUNENA_COREJSPATH', '/components/com_kunena/template/default/js/kunenaforum.js');
define('KUNENA_COREJSURL', KUNENA_DIRECTURL . 'template/default/js/kunenaforum.js');
}
function KUNENA_fmodReplace($x, $y) { //function provided for older PHP versions which do not have an fmod function yet
$i = floor($x / $y);
// r = x - i * y
return $x - $i * $y;
}
function KUNENA_check_image_type(&$type) {
switch ($type)
{
case 'jpeg':
case 'pjpeg':
case 'jpg':
case 'JPEG':
case 'PJPEG':
case 'JPG':
return '.jpg';
break;
case 'gif':
case 'GIF':
return '.gif';
break;
case 'png':
case 'PNG':
return '.png';
break;
}
return false;
}
function getFBGroupName($id) {
$kunena_db = &JFactory::getDBO();
$gr = '';
$kunena_db->setQuery("SELECT id, title FROM #__fb_groups AS g, #__fb_users as u WHERE u.group_id=g.id and u.userid='{$id}'");
$gr = $kunena_db->loadObject();
if ($gr == NULL) {
$gr = new stdClass();
$gr->id = 0;
$gr->title = _VIEW_VISITOR;
}
return $gr;
}
class CKunenaTools {
var $id = null;
/*
function fbGetCurrentTime () {
// tells current FB internal representing time
$fbConfig =& CKunenaConfig::getInstance();
return time() + ($fbConfig->board_ofset * 3600);
}
*/
function fbGetInternalTime ($time=null) {
// tells internal FB representing time from UTC $time
$fbConfig =& CKunenaConfig::getInstance();
// Prevent zeroes
if($time===0) {
return 0;
}
if($time===null) {
$time = time();
}
return $time + ($fbConfig->board_ofset * 3600);
}
function fbGetShowTime ($time=null, $space='FB') {
// converts internal (FB)|UTC representing time to display time
// could consider user properties (zones) for future
$kunena_db = &JFactory::getDBO();
$fbConfig =& CKunenaConfig::getInstance();
// Prevent zeroes
if($time===0) {
return 0;
}
if($time===null) {
$time = CKunenaTools::fbGetInternalTime();
$space = 'FB';
}
if($space=='UTC') {
return $time + ($fbConfig->board_ofset * 3600);
}
return $time;
}
function whoisID($id) {
$kunena_db = &JFactory::getDBO();
$id = intval($kunena_db->getEscaped($id));
$kunena_db->setQuery("SELECT username, id FROM #__users WHERE id='{$id}'");
return $kunena_db->loadResult();
}
function reCountUserPosts() {
$kunena_db = &JFactory::getDBO();
// Reset category counts as next query ignores users which have written no messages
$kunena_db->setQuery("UPDATE #__fb_users SET posts=0");
$kunena_db->query();
check_dberror("Unable to reset category post counts.");
// Update user post count (ignore unpublished categories and hidden messages)
$kunena_db->setQuery("INSERT INTO #__fb_users (userid, posts)"
." SELECT m.userid, COUNT(m.userid) "
." FROM #__fb_messages AS m"
." INNER JOIN #__fb_users AS u ON u.userid = m.userid"
." WHERE m.hold=0 and m.catid IN (SELECT id FROM #__fb_categories WHERE published=1)"
." GROUP BY m.userid"
." ON DUPLICATE KEY UPDATE posts=VALUES(posts)");
$kunena_db->query();
check_dberror("Unable to update user posts.");
}
function reCountBoardsRecursion(&$array, $current)
{
foreach ($array[$current]->children as $child)
{
if (!$array[$child]->published) continue;
if (!empty($array[$child]->children)) CKunenaTools::reCountBoardsRecursion($array, $child);
$array[$current]->numTopics += $array[$child]->numTopics;
$array[$current]->numPosts += $array[$child]->numPosts;
if (isset($array[$current]->id) && $array[$child]->id_last_msg > $array[$current]->id_last_msg)
{
$array[$current]->id_last_msg = $array[$child]->id_last_msg;
$array[$current]->time_last_msg = $array[$child]->time_last_msg;
}
}
}
function reCountBoards()
{
$kunena_db = &JFactory::getDBO();
include_once (KUNENA_PATH_LIB .DS. 'kunena.db.iterator.class.php');
// Reset category counts as next query ignores empty categories
$kunena_db->setQuery("UPDATE #__fb_categories SET numTopics=0, numPosts=0");
$kunena_db->query();
check_dberror("Unable to reset category post counts.");
// Update category post count
$kunena_db->setQuery("INSERT INTO #__fb_categories (id, numTopics, numPosts, id_last_msg, time_last_msg)"
." SELECT c.id, SUM( m.parent=0 ), SUM( m.parent>0 ), MAX( m.id ), MAX( m.time )"
." FROM #__fb_messages as m"
." INNER JOIN #__fb_categories AS c ON c.id=m.catid"
." WHERE m.catid>0 AND m.hold=0"
." GROUP BY catid "
." ON DUPLICATE KEY UPDATE numTopics=VALUES(numTopics), numPosts=VALUES(numPosts), id_last_msg=VALUES(id_last_msg), time_last_msg=VALUES(time_last_msg)");
$kunena_db->query();
check_dberror("Unable to update categories post count.");
// Load categories to be counted
$kunena_db->setQuery("SELECT id, parent, published, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories");
$cats = $kunena_db->loadObjectList('id');
check_dberror("Unable to load categories.");
foreach ($cats as $c)
{
if (isset($cats[$c->parent])) $cats[$c->parent]->children[] = $c->id;
else $cats[0]->children[] = $c->id;
}
CKunenaTools::reCountBoardsRecursion($cats, 0);
// now back to db
foreach ($cats as $c)
{
if (!isset($c->id)) continue;
$kunena_db->setQuery("UPDATE #__fb_categories SET"
." numTopics=" . intval($c->numTopics)
.", numPosts=" . intval($c->numPosts)
.", id_last_msg=" . intval($c->id_last_msg)
.", time_last_msg=" . intval($c->time_last_msg)
." WHERE id=" . intval($c->id));
$kunena_db->query();
check_dberror("Unable to update categories.");
}
}
function updateNameInfo()
{
$kunena_db = &JFactory::getDBO();
$fbConfig =& CKunenaConfig::getInstance();
$fb_queryName = $fbConfig->username ? "username" : "name";
$query = "UPDATE #__fb_messages AS m, #__users AS u
SET m.name = u.$fb_queryName
WHERE m.userid = u.id";
$kunena_db->setQuery($query);
$kunena_db->query();
check_dberror ("Unable to update user name information");
return $kunena_db->getAffectedRows();
}
function modifyCategoryStats($msg_id, $msg_parent, $msg_time, $msg_cat) {
$kunena_db = &JFactory::getDBO();
$kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories ORDER BY id ASC");
$cats = $kunena_db->loadObjectList();
check_dberror("Unable to load categories.");
foreach ($cats as $c) {
$ctg[$c->id] = $c;
}
while ($msg_cat) {
// traverse parental from orig msg_cat
if ($msg_parent == 0) {
$ctg[$msg_cat]->numTopics++;
}
else {
$ctg[$msg_cat]->numPosts++;
}
$ctg[$msg_cat]->id_last_msg = $msg_id;
$ctg[$msg_cat]->time_last_msg = $msg_time;
// store to db (only changed)
$kunena_db->setQuery(
"UPDATE `#__fb_categories`"
." SET `time_last_msg`='" . $ctg[$msg_cat]->time_last_msg . "'"
.",`id_last_msg`='" . $ctg[$msg_cat]->id_last_msg . "'"
.",`numTopics`='" . $ctg[$msg_cat]->numTopics . "'"
.",`numPosts`='" . $ctg[$msg_cat]->numPosts . "'"
." WHERE (`id`='" . $ctg[$msg_cat]->id . "') ");
$kunena_db->query();
echo $kunena_db->getErrorMsg();
// parent
$msg_cat = $ctg[$msg_cat]->parent;
}
return;
}
function decreaseCategoryStats($msg_id, $msg_cat) {
//topic : 1 , message = 0
$kunena_db = &JFactory::getDBO();
$kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories ORDER BY id ASC");
$cats = $kunena_db->loadObjectList();
check_dberror("Unable to load categories.");
foreach ($cats as $c) {
$ctg[$c->id] = $c;
}
$kunena_db->setQuery("SELECT id FROM #__fb_messages WHERE id='{$msg_id}' OR thread='{$msg_id}'");
$msg_ids = $kunena_db->loadResultArray();
check_dberror("Unable to load messages.");
$cntTopics = 0;
$cntPosts = 0;
if (count($msg_ids) > 0) {
foreach ($msg_ids as $msg) {
if ($msg == $msg_id) {
$cntTopics = 1;
}
else {
$cntPosts++;
}
}
}
while ($msg_cat) {
unset($lastMsgInCat);
$kunena_db->setQuery("SELECT id, time FROM #__fb_messages WHERE catid='{$msg_cat}' AND (thread!='{$msg_id}' AND id!='{$msg_id}') ORDER BY time DESC LIMIT 1;");
$lastMsgInCat = $kunena_db->loadObject();
check_dberror("Unable to load messages.");
$ctg[$msg_cat]->numTopics = (int) ($ctg[$msg_cat]->numTopics - $cntTopics);
$ctg[$msg_cat]->numPosts = (int) ($ctg[$msg_cat]->numPosts - $cntPosts);
$ctg[$msg_cat]->id_last_msg = $lastMsgInCat->id;
$ctg[$msg_cat]->time_last_msg = $lastMsgInCat->time;
$msg_cat = $ctg[$msg_cat]->parent;
}
// now back to db
foreach ($ctg as $cc) {
$kunena_db->setQuery("UPDATE `#__fb_categories` SET `time_last_msg`='" . $cc->time_last_msg . "',`id_last_msg`='" . $cc->id_last_msg . "',`numTopics`='" . $cc->numTopics . "',`numPosts`='" . $cc->numPosts . "' WHERE `id`='" . $cc->id . "' ");
$kunena_db->query();
check_dberror("Unable to update categories.");
}
return;
}
function showBulkActionCats($disabled = 1) {
$kunena_db = &JFactory::getDBO();
$options = array ();
$options[] = JHTML::_('select.option', '0', " ");
$lists['parent'] = KUNENA_GetAvailableForums(0, "", $options, $disabled);
echo $lists['parent'];
}
function fbDeletePosts($isMod, $return) {
$app =& JFactory::getApplication();
$backUrl = $app->getUserState ( "com_kunena.ActionBulk" );
$kunena_my = &JFactory::getUser();
$kunena_db = &JFactory::getDBO();
if (!CKunenaTools::isModOrAdmin() && !$isMod) {
$app->redirect($return, _POST_NOT_MODERATOR);
}
$items = fbGetArrayInts("fbDelete");
$dellattach = 1;
// start iterating here
foreach ($items as $id => $value) {
$kunena_db->setQuery("SELECT id, catid, parent, thread, subject, userid FROM #__fb_messages WHERE id='{$id}'");
if (!$kunena_db->query()) {
return -2;
}
$mes = $kunena_db->loadObject();
$thread = $mes->thread;
if ($mes->parent == 0) {
// this is the forum topic; if removed, all children must be removed as well.
$children = array ();
$userids = array ();
$kunena_db->setQuery("SELECT userid, id, catid FROM #__fb_messages WHERE thread='{$id}' OR id='{$id}'");
foreach ($kunena_db->loadObjectList() as $line) {
$children[] = $line->id;
if ($line->userid > 0) {
$userids[] = $line->userid;
}
}
$children = implode(',', $children);
}
else {
//this is not the forum topic, so delete it and promote the direct children one level up in the hierarchy
$kunena_db->setQuery('UPDATE #__fb_messages SET parent=\'' . $mes->parent . '\' WHERE parent=\'' . $id . '\'');
if (!$kunena_db->query()) {
return -1;
}
$children = $id;
$userids = $mes->userid > 0 ? $mes->userid : '';
}
//Delete the post (and it's children when it's the first post)
$kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $id . ' OR thread=' . $id);
if (!$kunena_db->query()) {
return -2;
}
// now update stats
CKunenaTools::decreaseCategoryStats($id, $mes->catid);
//Delete message text(s)
$kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid IN (' . $children . ')');
if (!$kunena_db->query()) {
return -3;
}
//Update user post stats
if (count($userids) > 0) {
$userids = implode(',', $userids);
$kunena_db->setQuery('UPDATE #__fb_users SET posts=posts-1 WHERE userid IN (' . $userids . ')');
if (!$kunena_db->query()) {
return -4;
}
}
//Delete (possible) ghost post
$kunena_db->setQuery("SELECT mesid FROM #__fb_messages_text WHERE message='catid={$mes->catid}&id={$id}'");
$int_ghost_id = $kunena_db->loadResult();
if ($int_ghost_id > 0) {
$kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $int_ghost_id);
$kunena_db->query();
$kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid=' . $int_ghost_id);
$kunena_db->query();
}
//Delete attachments
if ($dellattach) {
$kunena_db->setQuery("SELECT filelocation FROM #__fb_attachments WHERE mesid IN ({$children})");
$fileList = $kunena_db->loadObjectList();
check_dberror("Unable to load attachments.");
if (count($fileList) > 0) {
foreach ($fileList as $fl) {
unlink ($fl->filelocation);
}
$kunena_db->setQuery('DELETE FROM #__fb_attachments WHERE mesid IN (' . $children . ')');
$kunena_db->query();
}
}
} //end foreach
CKunenaTools::reCountBoards();
$app->redirect($return, _KUNENA_BULKMSG_DELETED);
}
function getEMailToList($catid, $thread, $subscriptions = false, $moderators = false, $admins = false, $excludeList = '0') {
$catid = intval ( $catid );
$thread = intval ( $thread );
if ( $catid == '0' || $thread == '0' )
return array();
// Make sure that category exists and fetch access info
$kunena_db = &JFactory::getDBO ();
$query = "SELECT pub_access, pub_recurse, admin_access, admin_recurse FROM #__fb_categories WHERE id={$catid}";
$kunena_db->setQuery ($query);
$access = $kunena_db->loadObject ();
check_dberror ( "Unable to load category access rights." );
if (!$access) return array();
$arogroups = '';
if ($subscriptions) {
// Get all allowed Joomla groups to make sure that subscription is valid
$kunena_acl = &JFactory::getACL ();
$public = array ();
$admin = array ();
if ($access->pub_access > 0) {
if ($access->pub_recurse) {
$public = $kunena_acl->get_group_children ( $access->pub_access, 'ARO', 'RECURSE' );
}
$public [] = $access->pub_access;
}
if ($access->admin_access > 0) {
if ($access->admin_recurse) {
$admin = $kunena_acl->get_group_children ( $access->admin_access, 'ARO', 'RECURSE' );
}
$admin [] = $access->admin_access;
}
$arogroups = implode ( ',', array_unique ( array_merge ( $public, $admin ) ) );
if ($arogroups)
$arogroups = "u.gid IN ({$arogroups})";
}
$querysel = "SELECT u.id, u.name, u.username, u.email,
MAX(0 + ( s.thread IS NOT NULL )) AS subscription,
MAX(0 + ( c.moderated=1 AND p.moderator=1 AND ( m.catid IS NULL OR m.catid={$catid}) )) AS moderator,
MAX(0 + ( u.gid IN (24, 25) )) AS admin
FROM #__users AS u
LEFT JOIN #__fb_users AS p ON u.id=p.userid
LEFT JOIN #__fb_moderation AS m ON u.id=m.userid
LEFT JOIN #__fb_categories AS c ON m.catid=c.id
LEFT JOIN #__fb_subscriptions AS s ON u.id=s.userid AND s.thread=$thread";
$where = array ();
if ($subscriptions)
$where [] = " ( s.thread IS NOT NULL" . ($arogroups ? " AND {$arogroups}" : '') . " ) ";
if ($moderators)
$where [] = " ( c.moderated=1 AND p.moderator=1 AND ( m.catid IS NULL OR m.catid={$catid} ) ) ";
if ($admins)
$where [] = " ( u.gid IN (24, 25) ) ";
$subsList = array ();
if (count ($where)) {
$where = " AND (" . implode ( ' OR ', $where ) . ")";
$query = $querysel . " WHERE u.block=0 AND u.id NOT IN ($excludeList) $where GROUP BY u.id";
$kunena_db->setQuery ( $query );
$subsList = $kunena_db->loadObjectList ();
check_dberror ( "Unable to load email list." );
}
return $subsList;
}
function isModOrAdmin($id = 0) {
$kunena_my = &JFactory::getUser();
// echo '<div>CALL isModOrAdmin</div>';
$userid = intval($id);
if ($userid) {
$user = new JUser($userid);
}
else {
$user = $kunena_my;
}
if (strtolower($user->usertype) == 'super administrator' || strtolower($user->usertype) == 'administrator') {
return true;
}
return false;
}
function fbMovePosts($catid, $isMod, $return) {
$app =& JFactory::getApplication();
$backUrl = $app->getUserState ( "com_kunena.ActionBulk" );
$kunena_db = &JFactory::getDBO();
$kunena_my = &JFactory::getUser();
// $isMod if user is moderator in the current category
if (!$isMod) {
// Test also if user is a moderator in some other category
$kunena_db->setQuery("SELECT userid FROM #__fb_moderation WHERE userid='{$kunena_my->id}'");
$isMod = $kunena_db->loadResult();
check_dberror("Unable to load moderation info.");
}
$isAdmin = CKunenaTools::isModOrAdmin();
//isMod will stay until better group management comes in
if (!$isAdmin && !$isMod) {
$app->redirect($return, _POST_NOT_MODERATOR);
}
$catid = (int)$catid;
if ($catid > 0) {
$items = fbGetArrayInts("fbDelete");
// start iterating here
foreach ($items as $id => $value) {
$id = (int)$id;
$kunena_db->setQuery("SELECT subject, catid, time AS timestamp FROM #__fb_messages WHERE id='{$id}'");
$oldRecord = $kunena_db->loadObjectList();
check_dberror("Unable to load message detail.");
$oldCatObj = new jbCategory($kunena_db, $oldRecord[0]->catid);
$newCatObj = new jbCategory($kunena_db, $catid);
if ($newCatObj && $newCatObj->parent>0 && fb_has_moderator_permission($kunena_db, $oldCatObj, $kunena_my->id, $isAdmin)) {
$newSubject = _MOVED_TOPIC . " " . $oldRecord[0]->subject;
$kunena_db->setQuery("SELECT MAX(time) AS timestamp FROM #__fb_messages WHERE thread='{$id}'");
$lastTimestamp = $kunena_db->loadResult();
check_dberror("Unable to load messages max(time).");
if ($lastTimestamp == "") {
$lastTimestamp = $oldRecord[0]->timestamp;
}
//perform the actual move
$kunena_db->setQuery("UPDATE #__fb_messages SET `catid`='$catid' WHERE `id`='$id' OR `thread`='$id'");
$kunena_db->query();
check_dberror("Unable to move thread.");
$err = _POST_SUCCESS_MOVE;
} else {
$err = _POST_NOT_MODERATOR;
}
} //end foreach
} else {
$err = _POST_NO_DEST_CATEGORY;
}
CKunenaTools::reCountBoards();
$app->redirect($return, $err);
}
function fbRemoveXSS($val, $reverse = 0) {
// now the only remaining whitespace attacks are \t, \n, and \r
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
$ra = array_merge($ra1, $ra2);
$ra2 = $ra;
array_walk($ra2, "fbReturnDashed");
if ($reverse) {
$val = str_ireplace($ra2, $ra, $val);
}
else {
//replace them all with a dummy variable, and later replace them in CODE
$val = str_ireplace($ra, $ra2, $val);
}
return $val;
}
function &prepareContent(&$content)
{
$fbConfig =& CKunenaConfig::getInstance();
// Joomla Mambot Support, Thanks hacksider
if ($fbConfig->jmambot)
{
$row = new stdClass();
$row->text =& $content;
$params = new JParameter( '' );
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onPrepareContent', array (&
$row, & $params, 0));
$content =& $row->text;
}
return $content;
}
function getAllowedForums($uid = 0, $gid = 0, &$kunena_acl) {
$kunena_db = &JFactory::getDBO();
function _has_rights(&$kunena_acl, $gid, $access, $recurse) {
if ($gid == $access) return 1;
if ($recurse) {
$childs = $kunena_acl->get_group_children($access, 'ARO', 'RECURSE');
return (is_array($childs) and in_array($gid, $childs));
}
return 0;
}
$catlist = '';
$query = "SELECT c.id, c.pub_access, c.pub_recurse, c.admin_access, c.admin_recurse, c.moderated"
. ",(m.userid IS NOT NULL) AS ismod FROM #__fb_categories c"
. " LEFT JOIN #__fb_moderation m ON c.id=m.catid AND m.userid='{$uid}' WHERE published='1'";
$kunena_db->setQuery($query);
$rows = $kunena_db->loadObjectList();
check_dberror("Unable to load category list.");
if ($rows) {
foreach($rows as $row) {
if (($gid == 24 || $gid == 25) or
($row->moderated and $row->ismod) or
($row->pub_access == 0) or
($row->pub_access == -1 and $uid > 0) or
($row->pub_access > 0 and _has_rights($kunena_acl, $gid, $row->pub_access, $row->pub_recurse)) or
($row->admin_access > 0 and _has_rights($kunena_acl, $gid, $row->admin_access, $row->admin_recurse))
) $catlist .= (($catlist == '')?'':',').$row->id;
}
}
return $catlist;
}
} // end of class
/**
* Moderator Table Class
*
* Provides access to the #__fb_moderator table
*/
class fbModeration
extends JTable {
/** @var int Unique id*/
var $catid = null;
/** @var int */
var $userid = null;
/** @var int */
var $future1 = null;
/** @var int */
var $future2 = null;
/**
* @param database A database connector object
*/
function __construct(&$kunena_db) {
parent::__construct('#__fb_moderation', 'catid', $kunena_db);
}
}
class fbForum
extends JTable {
/** @var int Unique id*/
var $id = null;
/** @var string */
var $parent = null;
/** @var string */
var $name = null;
var $cat_emoticon = null;
var $locked = null;
var $alert_admin = null;
var $moderated = null;
var $pub_access = null;
var $pub_recurse = null;
var $admin_access = null;
var $admin_recurse = null;
var $public = null;
var $ordering = null;
var $future2 = null;
var $published = null;
var $checked_out = null;
var $checked_out_time = null;
var $review = null;
var $allow_anonymous = null;
var $post_anonymous = null;
var $hits = null;
var $description = null;
var $class_sfx = null;
var $headerdesc = null;
/**
* @param database A database connector object
*/
function __construct( &$kunena_db )