-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.inc
2890 lines (2444 loc) · 106 KB
/
functions.inc
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
/* vim: set expandtab sw=4 ts=4 sts=4: */
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog Forums Plugin 2.9.0 |
// +---------------------------------------------------------------------------+
// | functions.inc |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2011 by the following authors: |
// | Geeklog Community Members geeklog-forum AT googlegroups DOT com |
// | |
// | Copyright (C) 2000,2001 by the following authors: |
// | Tony Bibbs tony AT tonybibbs DOT com |
// | |
// | Forum Plugin Authors |
// | Mr.GxBlock www.gxblock.com |
// | Matthew DeWyer matt AT mycws DOT com www.cweb.ws |
// | Blaine Lang geeklog AT langfamily DOT ca www.langfamily.ca |
// +---------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// +---------------------------------------------------------------------------+
if (strpos(strtolower($_SERVER['PHP_SELF']), 'functions.inc') !== false) {
die('This file can not be used on its own.');
}
// Need to declare this for global scope issues during install and upgrades
global $_DB_table_prefix, $LANG_configselects;
// used for Likes and Topic controls
define("FORUM_PLUGIN_NAME", 'forum');
// Forum topic type for Likes
define("LIKES_TYPE_FORUM_POST", 'post');
// Forum types for Geeklog Topic assignments
define("TOPIC_TYPE_FORUM_TOPIC", 'topic');
define("TOPIC_TYPE_FORUM_FORUM", 'forum');
define("TOPIC_TYPE_FORUM_CATEGORY", 'category');
/**
* Include language file
*/
$plugin_path = $_CONF['path'] . 'plugins/forum/';
$langfile = $plugin_path . 'language/' . $_CONF['language'] . '.php';
if (file_exists($langfile)) {
require_once $langfile;
} else {
require_once $plugin_path . 'language/english.php';
}
/**
* This language string is inherited from Geeklog Core, which makes
* it static, so we define it here instead of in the language files.
*/
global $LANG32, $_TABLES;
$PLG_forum_MESSAGE3002 = $LANG32[9]; // This plugin requires a newer version of Geeklog
/**
* Add to $_TABLES array the tables forum plugin uses
*/
$_TABLES['forum_userprefs'] = $_DB_table_prefix . 'forum_userprefs';
$_TABLES['forum_topic'] = $_DB_table_prefix . 'forum_topic';
$_TABLES['forum_categories'] = $_DB_table_prefix . 'forum_categories';
$_TABLES['forum_forums'] = $_DB_table_prefix . 'forum_forums';
$_TABLES['forum_watch'] = $_DB_table_prefix . 'forum_watch';
$_TABLES['forum_moderators'] = $_DB_table_prefix . 'forum_moderators';
$_TABLES['forum_banned_ip'] = $_DB_table_prefix . 'forum_banned_ip';
$_TABLES['forum_log'] = $_DB_table_prefix . 'forum_log';
$_TABLES['forum_userinfo'] = $_DB_table_prefix . 'forum_userinfo';
/**
* DEPRECATED references to tables.
* Do not use these, as they will be soon removed.
*
* TODO: remove these references in version 2.10.0
$_TABLES['gf_userprefs'] = $_DB_table_prefix . 'forum_userprefs';
$_TABLES['gf_topic'] = $_DB_table_prefix . 'forum_topic';
$_TABLES['gf_categories'] = $_DB_table_prefix . 'forum_categories';
$_TABLES['gf_forums'] = $_DB_table_prefix . 'forum_forums';
$_TABLES['gf_watch'] = $_DB_table_prefix . 'forum_watch';
$_TABLES['gf_moderators'] = $_DB_table_prefix . 'forum_moderators';
$_TABLES['gf_banned_ip'] = $_DB_table_prefix . 'forum_banned_ip';
$_TABLES['gf_log'] = $_DB_table_prefix . 'forum_log';
$_TABLES['gf_userinfo'] = $_DB_table_prefix . 'forum_userinfo';
*/
/**
* Load the plugin configuration
*/
global $CONF_FORUM;
$CONF_FORUM = [];
require_once $_CONF['path_system'] . 'classes/config.class.php';
$plg_config = config::get_instance();
$temp = $plg_config->get_config('forum');
if (is_array($temp)) {
$CONF_FORUM = array_merge($CONF_FORUM, $temp);
$CONF_FORUM['recaptcha'] = (isset($CONF_FORUM['recaptcha'])) ? (int) $CONF_FORUM['recaptcha'] : 0;
}
// *******************
// Hack to enable Site Notifications for new forum posts under Configuration -> Geeklog -> Miscellaneous -> Miscellaneous -> Notifications
// This really should be some sort of plugin api that could handle the notification in the Configuration if it has been added but the plugin is disabled or uninstalled
// Currently if plugin disabled and notification option exists then instead of saying 'New Forum Posts' it will default to first item in list
// Plus this is only in English
$LANG_configselects['Core'][25] = array_merge($LANG_configselects['Core'][25], array('New Forum Posts' => 'forum'));
// *******************
/**
* Include forum config file
*/
require_once $_CONF['path'] . 'plugins/forum/config.php';
$CONF_FORUM['debug'] = false;
$CONF_FORUM['layout_url'] = $_CONF['site_url'] . '/forum';
$CONF_FORUM['imgset'] = CTL_plugin_dirLocation('forum', 'image_set', true);
$CONF_FORUM['imgset_path'] = CTL_plugin_dirLocation('forum', 'image_set', false);
$CONF_FORUM['path_include'] = $_CONF['path'] . 'plugins/forum/include/';
$CONF_FORUM['charset'] = COM_getCharset();
$CONF_FORUM['add_forum_menu_check'] = 0; // Reset Check to false. If needed it is set to true in gf_format.php where then used by plugin_getBlocks_forum
// User Preference Config Parms. Check if user has set their preference or use defaults
if (!empty($_USER['uid']) AND ($_USER['uid'] > 1) AND DB_getItem($_TABLES['forum_userprefs'],"uid","uid='{$_USER['uid']}'") == $_USER['uid']) {
$sql = DB_query("Select * FROM {$_TABLES['forum_userprefs']} WHERE uid = '{$_USER['uid']}'");
$userprefs = DB_fetchArray($sql);
$CONF_FORUM['show_topics_perpage'] = $userprefs['topicsperpage'];
$CONF_FORUM['show_posts_perpage'] = $userprefs['postsperpage'];
$CONF_FORUM['popular_limit'] = $userprefs['popularlimit'];
$CONF_FORUM['show_members_perpage'] = $userprefs['membersperpage'];
$CONF_FORUM['show_search_perpage'] = $userprefs['searchlines'];
$CONF_FORUM['show_topicreview'] = $userprefs['showiframe'];
$CONF_FORUM['show_anonymous_posts'] = $userprefs['viewanonposts'];
$CONF_FORUM['notify_once'] = $userprefs['notify_once'];
}
// Now make sure config options are setup okay and meet requirements else set to defaults (not min values)
// If make changes here make sure reflected in checks on userprefs.php page as these below can be affected by user prefs
$CONF_FORUM['show_topics_perpage'] = (isset($CONF_FORUM['show_topics_perpage']) && $CONF_FORUM['show_topics_perpage'] > 9) ? $CONF_FORUM['show_topics_perpage'] : 10; // This default is also stored in DB
$CONF_FORUM['show_posts_perpage'] = (isset($CONF_FORUM['show_posts_perpage']) && $CONF_FORUM['show_posts_perpage'] > 2) ? $CONF_FORUM['show_posts_perpage'] : 10; // This default is also stored in DB
$CONF_FORUM['popular_limit'] = isset($CONF_FORUM['popular_limit']) ? $CONF_FORUM['popular_limit'] : 0; // This default is in config file
$CONF_FORUM['show_members_perpage'] = (isset($CONF_FORUM['show_members_perpage']) && $CONF_FORUM['show_members_perpage'] > 9) ? $CONF_FORUM['show_members_perpage'] : 20; // This default is in config file
$CONF_FORUM['show_search_perpage'] = (isset($CONF_FORUM['show_search_perpage']) && $CONF_FORUM['show_search_perpage'] > 9) ? $CONF_FORUM['show_search_perpage'] : 20; // This default is also stored in DB
// These below do not have user specific preference and are site wide
$CONF_FORUM['show_messages_perpage'] = (isset($CONF_FORUM['show_messages_perpage']) && $CONF_FORUM['show_messages_perpage'] > 9) ? $CONF_FORUM['show_messages_perpage'] : 20; // This default is also stored in DB
$CONF_FORUM['show_newposts_perpage'] = (isset($CONF_FORUM['show_newposts_perpage']) && $CONF_FORUM['show_newposts_perpage'] > 9) ? $CONF_FORUM['show_newposts_perpage'] : 20; // This default is in config file
$CONF_FORUM['show_popular_perpage'] = (isset($CONF_FORUM['show_popular_perpage']) && $CONF_FORUM['show_popular_perpage'] > 9) ? $CONF_FORUM['show_popular_perpage'] : 20; // This default is in config file
$CONF_FORUM['installed_version'] = floatval(DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = 'forum'"));
/**
* Initialize the handling of smilies
*/
require_once $CONF_FORUM['path_include'] . 'ForumSmilies.class.php';
$_SMILIES = new ForumSmilies();
/**
* Initialize Forum CSS variable to track if css file needs to be loaded
*/
global $FORUM_CSS;
$FORUM_CSS = false;
/**
* Returns the items for this plugin that should appear on the main menu
*/
function plugin_getmenuitems_forum()
{
global $CONF_FORUM,$_CONF,$LANG_GF00;
//if ($CONF_FORUM['registration_required'] == 0 || SEC_hasRights('forum.user')) {
if ($CONF_FORUM['registration_required'] == 0 || ($CONF_FORUM['registration_required'] && SEC_hasRights('forum.user'))) {
$menuitems["{$LANG_GF00['pluginlabel']}"] = "{$_CONF['site_url']}/forum/index.php";
return $menuitems;
}
}
function plugin_autotags_forum($op,$content='',$autotag='') {
global $_CONF, $LANG_GF00, $LANG_GF01, $FORUM_CSS;
if ($op == 'tagname') {
return 'forum';
} elseif ($op == 'description') {
return array('forum' => $LANG_GF00['autotag_desc_forum']);
} elseif ($op == 'parse') {
$FORUM_CSS = true;
$id = COM_applyFilter($autotag['parm1']);
if (!empty($id)) {
$linktext = $LANG_GF01['HERE'];
if (!empty($autotag['parm2'])) $linktext = $autotag['parm2'];
$url = forum_buildForumPostURL($id);
$filelink = COM_createLink($linktext, $url);
$content = str_replace($autotag['tagstr'], $filelink, $content);
}
return $content;
}
}
/**
* This will put an option for forum admin in the command and control block on moderation.php
*
*/
function plugin_cclabel_forum()
{
global $_CONF;
if (SEC_hasRights('forum.edit')) {
return array('Forum',$_CONF['site_admin_url'] . "/plugins/forum/index.php",$_CONF['site_url'] . '/forum/images/forum.png');
}
}
/**
* returns the administrative option for this plugin
*
*/
function plugin_getadminoption_forum()
{
global $_TABLES, $_CONF, $LANG_GF00;
if (SEC_hasRights('forum.edit')) {
$numtopics = DB_getItem($_TABLES['forum_topic'],"COUNT(*)");
return array($LANG_GF00['pluginlabel'], $_CONF['site_admin_url'] . '/plugins/forum/index.php', $numtopics);
}
}
/**
* Returns the user menuitem option for this plugin
* Only one menu item can be returned.
*/
function plugin_getuseroption_forum()
{
global $CONF_FORUM, $_CONF, $LANG_GF00;
// if ($CONF_FORUM['registration_required'] == 0 || SEC_hasRights('forum.user')) {
if ($CONF_FORUM['registration_required'] == 0 || ($CONF_FORUM['registration_required'] && SEC_hasRights('forum.user'))) {
return array($LANG_GF00['useradminmenu'], $_CONF['site_url'] . '/forum/userprefs.php', 0);
}
}
function plugin_user_create_forum ($uid)
{
global $_TABLES;
DB_query ("INSERT INTO {$_TABLES['forum_userinfo']} (uid) VALUES ('{$uid}')");
}
/**
* Called if admin deletes a user - Removes any moderator and Watch Records for user
*/
function plugin_user_delete_forum ($uid)
{
global $_TABLES;
DB_query("DELETE FROM {$_TABLES['forum_moderators']} WHERE mod_uid ='$uid'");
DB_query("DELETE FROM {$_TABLES['forum_watch']} WHERE uid ='$uid'");
DB_query("DELETE FROM {$_TABLES['forum_userinfo']} WHERE uid ='$uid'");
DB_query("DELETE FROM {$_TABLES['forum_userprefs']} WHERE uid ='$uid'");
DB_query("DELETE FROM {$_TABLES['forum_log']} WHERE uid ='$uid'");
DB_query("UPDATE {$_TABLES['forum_topic']} SET uid = 1 WHERE uid = '$uid'");
}
function plugin_profileextrassave_forum($uid = '')
{
global $_CONF,$_USER, $HTTP_POST_VARS, $_TABLES, $CONF_FORUM;
require_once $CONF_FORUM['path_include'] . 'gf_format.php';
if (empty($uid)) {
$uid = $_USER['uid'];
}
// Make sure post variables are set. Remember edit can happen by User for User Settings and edit/new by Admin on User Admin form
// Forum plugin fields display both on the Admin User form and the user settings form (so no reason to check which form we are on)
if ($uid > 1) {
$aim = isset($_POST['forum_aim']) ? gf_preparefordb($_POST['forum_aim'],'html') : '';
$icq = isset($_POST['forum_icq']) ? gf_preparefordb($_POST['forum_icq'],'html') : '';
$yim = isset($_POST['forum_yim']) ? gf_preparefordb($_POST['forum_yim'],'html') : '';
$msnm = isset($_POST['forum_msnm']) ? gf_preparefordb($_POST['forum_msnm'],'html') : '';
$interests = isset($_POST['forum_interests']) ? gf_preparefordb($_POST['forum_interests'],'html') : '';
$occupation = isset($_POST['forum_occupation']) ? gf_preparefordb($_POST['forum_occupation'],'html') : '';
DB_save ($_TABLES['forum_userinfo'], "uid,aim,yim,icq,msnm,interests,occupation",
"'$uid','$aim','$yim','$icq','$msnm','$interests','$occupation'");
}
}
function plugin_profilevariablesedit_forum($uid, &$template)
{
global $_TABLES, $LANG_GF04, $CONF_FORUM;
$nrows = 0;
// Remember edit can happen by User for User Settings and edit/new by Admin on User Admin form
// Forum plugin fields display both on the Admin User form and the user settings form
if ($uid > 1) {
$result = DB_query ("SELECT uid,aim,icq,yim,msnm,interests,occupation FROM {$_TABLES['forum_userinfo']} WHERE uid = $uid");
$nrows = DB_numRows($result);
$A = DB_fetchArray($result);
}
if (($uid == 1) || ($nrows == 0)) {
$A['aim'] = '';
$A['icq'] = '';
$A['yim'] = '';
$A['msnm'] = '';
$A['interests'] = '';
$A['occupation'] = '';
}
if ($CONF_FORUM['profile']['aim']) {
$template->set_var ('lang_field', $LANG_GF04['label_aim']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['aim']);
$template->set_var('fieldname', 'forum_aim');
$template->set_var('fieldmaxlength', '128');
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['icq']) {
$template->set_var ('lang_field', $LANG_GF04['label_icq']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['icq']);
$template->set_var('fieldname', 'forum_icq');
$template->set_var('fieldmaxlength', '128');
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['yim']) {
$template->set_var ('lang_field', $LANG_GF04['label_yim']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['yim']);
$template->set_var('fieldname', 'forum_yim');
$template->set_var('fieldmaxlength', '128');
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['msnm']) {
$template->set_var ('lang_field', $LANG_GF04['label_msnm']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['msnm']);
$template->set_var('fieldname', 'forum_msnm');
$template->set_var('fieldmaxlength', '128');
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['interests']) {
$template->set_var ('lang_field', $LANG_GF04['label_interests']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['interests']);
$template->set_var('fieldname', 'forum_interests');
$template->set_var('fieldmaxlength', '255');
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['occupation']) {
$template->set_var ('lang_field', $LANG_GF04['label_occupation']);
$template->set_var ('lang_field_text', '');
$template->set_var('field', $A['occupation']);
$template->set_var('fieldname', 'forum_occupation');
$template->set_var('fieldmaxlength', '255');
$template->parse('display_fields', 'display_field', true);
}
}
function plugin_profilevariablesdisplay_forum ($uid, &$template)
{
global $_TABLES, $_CONF, $LANG_GF02, $LANG_GF04, $CONF_FORUM;
$postlimit = "10"; // How many posts you want displayed
$username = DB_getItem ($_TABLES['users'], 'username', "uid = $uid");
$title = sprintf($LANG_GF02['msg158'], $postlimit, $username);
$template->set_var ('start_block_last10', COM_startBlock($title, '', 'blockheader-child.thtml'));
$template->set_var('end_block_last10', COM_endBlock('blockfooter-child.thtml'));
$query = DB_query ("SELECT id,date,forum,subject FROM {$_TABLES['forum_topic']} WHERE uid = {$uid} ORDER BY date DESC LIMIT 100");
$numposts = 0;
while (list($postid,$date,$forum_id,$subject) = DB_fetchArray($query)) {
$grp_id = DB_getItem($_TABLES['forum_forums'],'grp_id',"forum_id='$forum_id'");
$groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'");
if (SEC_inGroup($groupname) OR $grp_id == 2) {
$numposts++;
$postdate = COM_getUserDateTimeFormat ($date);
$template->set_var ('row_number', $numposts . '.');
$articleUrl = forum_buildForumPostURL($postid);
$template->set_var('item_title',
COM_createLink(
stripslashes($subject),
$articleUrl,
array('class'=>'b'))
);
$template->set_var ('item_date', $postdate[0]);
if ($numposts == 1) {
$template->parse('last10_rows', 'last10_row');
} else {
$template->parse('last10_rows', 'last10_row', true);
}
if ($numposts >= $postlimit) {
break;
}
}
}
if ($numposts == 0) {
$template->set_var('last10_rows', $LANG_GF02['msg155']);
}
$template->parse('last10_blocks', 'last10_block', true);
// Cannot take just this as may include posts the user viewing does not have access too see new solution below
//$count = DB_count ($_TABLES['forum_topic'], 'uid', $uid);
// Taken in part from COM_getPermSQL
// Cannot use COM_getPermSQL as it includes other security table columns like owner_id which the forum does not use
// Grab current user group access as they can only know of forum posts they have access to about the user they are viewing
$UserGroups = SEC_getUserGroups();
$sql = "SELECT COUNT(uid) count_uid FROM {$_TABLES['forum_topic']} ft, {$_TABLES['forum_forums']} ff, {$_TABLES['groups']} g
WHERE ft.forum = ff.forum_id AND ff.grp_id = g.grp_id
AND ft.uid = {$uid} ";
$sql .= "AND (g.grp_id = 2 OR (ff.grp_id IN (" . implode(',', $UserGroups) . ")))";
$result = DB_query($sql);
$A = DB_fetchArray($result);
$count = $A['count_uid'];
$template->set_var ('lang_number_field', $LANG_GF02['msg156']);
$template->set_var ('number_field', COM_numberFormat($count));
$template->parse('field_statistics', 'field_statistic', true);
/* Display Instant Messaging Handles */
$result = DB_query ("SELECT uid,aim,icq,yim,msnm,interests,occupation FROM {$_TABLES['forum_userinfo']} WHERE uid = $uid");
$nrows = DB_numRows($result);
$A = DB_fetchArray($result);
if ($nrows == 0) {
$A['aim'] = '';
$A['icq'] = '';
$A['yim'] = '';
$A['msnm'] = '';
$A['interests'] = '';
$A['occupation'] = '';
}
if ($CONF_FORUM['profile']['aim']) {
$template->set_var ('lang_field', $LANG_GF04['label_aim']);
$template->set_var('field', $A['aim']);
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['icq']) {
$template->set_var ('lang_field', $LANG_GF04['label_icq']);
$template->set_var('field', $A['icq']);
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['yim']) {
$template->set_var ('lang_field', $LANG_GF04['label_yim']);
$template->set_var('field', $A['yim']);
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['msnm']) {
$template->set_var ('lang_field', $LANG_GF04['label_msnm']);
$template->set_var('field', $A['msnm']);
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['interests']) {
$template->set_var ('lang_field', $LANG_GF04['label_interests']);
$template->set_var('field', $A['interests']);
$template->parse('display_fields', 'display_field', true);
}
if ($CONF_FORUM['profile']['occupation']) {
$template->set_var ('lang_field', $LANG_GF04['label_occupation']);
$template->set_var('field', $A['occupation']);
$template->parse('display_fields', 'display_field', true);
}
}
function plugin_statssummary_forum() {
global $_CONF, $_TABLES, $LANG_GF00;
// This shows in the summary box
$total_items = DB_count($_TABLES['forum_topic']); // Total number of Forum Posts
$summary_label = $LANG_GF00['statslabel'];
$retval[] = $summary_label;
$retval[] = $total_items;
return $retval;
}
/**
* shows the statistics for the plugin when stats.php is called.
* If $showsitestats is 1 then we are to only print the overall stats in the 'site statistics box'
* otherwise we show the detailed stats for the photo album
*
* @showsitestate int Flag to let us know which stats to get
*/
function plugin_showstats_forum($showsitestats)
{
global $_CONF, $_TABLES, $LANG_GF00,$LANG_GF01, $CONF_FORUM;
// Use themes stats template files
if (COM_versionCompare(VERSION, '2.2.0', '>=')) {
$stat_templates = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'stats'));
} else { // For Geeklog 2.1.3 support
$stat_templates = COM_newTemplate($_CONF['path_layout'] . '/stats');
}
$stat_templates->set_file(array('itemstats'=>'itemstatistics.thtml',
'statrow'=>'singlestat.thtml'));
$retval = '';
$header_arr = array(
array('text' => $LANG_GF01['TOPICSUBJECT'], 'field' => 'topicsubject'),
array('text' => $LANG_GF01['VIEWS'], 'field' => 'views'),
);
$data_arr = array();
$text_arr = array('has_menu' => false,
'title' => $LANG_GF00['statsheading1'],
);
$result = DB_query("SELECT forum,subject,views,id FROM {$_TABLES['forum_topic']} WHERE pid='0' ORDER BY views DESC");
$nrows = DB_numRows($result);
if ($nrows > 0) {
$displaycount = 0;
while (list ($forum,$subject, $views,$id) = DB_fetchARRAY($result)) {
$forum_id = DB_getItem($_TABLES['forum_topic'],'forum',"id='$id'");
$grp_id = DB_getItem($_TABLES['forum_forums'],'grp_id',"forum_id='$forum_id'");
$groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'");
if (SEC_inGroup($groupname) OR $grp_id == 2) {
$url = forum_buildForumPostURL($id);
$S['topicsubject'] = '<a href="' . $url . '">' . $subject . '</a>';
$S['views'] = COM_numberFormat($views);
$data_arr[$displaycount] = $S;
$displaycount++;
if ($displaycount > 10) {
break;
}
}
}
$retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
} else {
$retval .= $LANG_GF00['statsheading3'];
}
$header_arr = array(
array('text' => $LANG_GF01['TOPICSUBJECT'], 'field' => 'topicsubject'),
array('text' => $LANG_GF01['REPLIES'], 'field' => 'replies'),
);
$data_arr = array();
$text_arr = array('has_menu' => false,
'title' => $LANG_GF00['statsheading2'],
);
$result = DB_query("SELECT forum,subject,replies,id FROM {$_TABLES['forum_topic']} WHERE pid='0' ORDER BY replies DESC");
$nrows = DB_numRows($result);
if ($nrows > 0) {
$stat_templates->set_var('item_label',$LANG_GF01['TOPICSUBJECT']);
$stat_templates->set_var('stat_name',$LANG_GF01['REPLIES']);
$displaycount=0;
while (list ($forum,$subject, $replies,$id) = DB_fetchARRAY($result)) {
$forum_id = DB_getItem($_TABLES['forum_topic'],'forum',"id='$id'");
$grp_id = DB_getItem($_TABLES['forum_forums'],'grp_id',"forum_id='$forum_id'");
$groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'");
if (SEC_inGroup($groupname) OR $grp_id == 2) {
$url = forum_buildForumPostURL($id);
$S['topicsubject'] = '<a href="' . $url . '">' . $subject . '</a>';
$S['replies'] = COM_numberFormat($replies);
$data_arr[$displaycount] = $S;
$displaycount++;
if ($displaycount > 10) {
break;
}
}
}
$retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
} else {
$retval .= $LANG_GF00['statsheading3'];
}
return $retval;
}
/**
* Geeklog is asking us to provide any new items that show up in the type drop-down
* on search.php. Let's let users search the Filelistings in the Filemgmt Plugin
*
*/
function plugin_searchtypes_forum()
{
global $LANG_GF00;
$tmp['forum'] = $LANG_GF00['searchlabel'];
return $tmp;
}
/**
* this searches for files matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @param string $query Keywords user is looking for
* @param date $datestart Start date to get results for
* @param date $dateend End date to get results for
* @param string $topic The topic they were searching in
* @param string $type Type of items they are searching, or 'all' (deprecated)
* @param int $author Get all results by this author
* @param string $keyType search key type: 'all', 'phrase', 'any'
* @param int $page page number of current search (deprecated)
* @param int $perpage number of results per page (deprecated)
* @return object search result object
*
*/
function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
global $LANG_GF01, $_TABLES, $_GROUPS;
// Make sure the query is SQL safe
$query = trim(addslashes($query));
if (COM_versionCompare(VERSION, '2.2.1sr1', '>=')) {
$sql = "SELECT ft.id, ft.date, ft.subject AS title, ft.comment AS description, ft.views AS hits, ft.uid, "
. "'' AS url " // empty URL means will be defined later based on id
. "FROM {$_TABLES['forum_topic']} ft, {$_TABLES['forum_forums']} ff "
. "WHERE ft.forum = ff.forum_id AND (ff.grp_id IN ('" . implode( "','", $_GROUPS ) . "')) AND ft.date <> 1 ";
} else {
// https://github.com/Geeklog-Plugins/forum/issues/87
// As of Forum v2.9.4 forum topic URL now required to use parent topic and page number. In search sql URL can now be changed before display (as of Geeklog v2.2.1sr1)
$sql = "SELECT ft.id, ft.date, ft.subject AS title, ft.comment AS description, ft.views AS hits, ft.uid, "
. "CONCAT('/forum/viewtopic.php?showtopic=', ft.id) AS url "
. "FROM {$_TABLES['forum_topic']} ft, {$_TABLES['forum_forums']} ff "
. "WHERE ft.forum = ff.forum_id AND (ff.grp_id IN ('" . implode( "','", $_GROUPS ) . "')) AND ft.date <> 1 ";
}
if (!empty($datestart) || !empty($dateend)) {
// Do some date checking and fill in missing dates
$delim = '-';
if (empty($datestart) || (strtotime($datestart) == false)) {
$datestart = "0000-00-00";
} else {
$datestart = date('Y-m-d', strtotime($datestart));
}
if (empty($dateend) || (strtotime($dateend) == false)) {
$dateend = date('Y-m-d');
} else {
$dateend = date('Y-m-d', strtotime($dateend));
}
$DS = explode($delim, $datestart);
$DE = explode($delim, $dateend);
$startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
$enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
//return " $type (UNIX_TIMESTAMP($column) BETWEEN '$startdate' AND '$enddate') ";
$sql .= "AND (date BETWEEN '$startdate' AND '$enddate') ";
}
if (!empty($author)) {
$sql .= "AND (uid = '$author') ";
}
$search = new SearchCriteria('forum', $LANG_GF01['FORUM']);
$columns = array('title' => 'subject', 'comment');
list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
$search->setSQL($sql);
$search->setFTSQL($ftsql);
$search->setRank(3);
$search->setAppendQuery(true);
return $search;
}
// Format content to be displayed in the search results
function plugin_searchformat_forum($id, $contentType, $content)
{
// Remove any BBCode from forum post
if ($contentType == 'description') {
return forum_stripBBCode($content);
} elseif ($contentType == 'url') {
// For URL content contain query info
return html_entity_decode(forum_buildForumPostURL($id)); // For some reason urldecode was not converting the & in the query string so used html_entity_decode
}
}
/* RSS FEED Related API functions */
function plugin_getfeednames_forum ()
{
global $_TABLES;
$feeds = array ();
$result = DB_query ("SELECT forum_id,forum_name FROM {$_TABLES['forum_forums']} ORDER BY forum_order");
$num = DB_numRows ($result);
if ($num > 0) {
$feeds[] = array ('id' => '0', 'name' => 'all forums');
}
for ($i = 0; $i < $num; $i++) {
$A = DB_fetchArray ($result);
$feeds[] = array ('id' => $A['forum_id'], 'name' => $A['forum_name']);
}
return $feeds;
}
function forum_buildFeedsSql ($forumID, $limits)
{
global $CONF_FORUM;
if ($CONF_FORUM['installed_version'] < 2.6) {
return '';
}
$groups = array ();
$usergroups = SEC_getUserGroups(1);
foreach ($usergroups as $group) {
$groups[] = $group;
}
$grouplist = implode(',',$groups);
if ($forumID > 0) {
$where = " WHERE forum=$forumID AND no_newposts=0 AND forum.grp_id IN ($grouplist) ";
} else {
$where = " WHERE no_newposts=0 AND forum.grp_id IN ($grouplist) ";
}
$limitsql = '';
if (!empty ($limits)) {
if (substr ($limits, -1) == 'h') { // last xx hours
$limitsql = '';
$hours = substr ($limits, 0, -1);
if (!empty ($where)) {
$where .= ' AND ';
}
$where .= "date >= DATE_SUB(NOW(),INTERVAL $hours HOUR) ORDER BY date DESC";
} else {
$limitsql = ' ORDER BY date DESC LIMIT ' . $limits;
}
}
else
{
$limitsql = ' ORDER BY date DESC LIMIT 10';
}
$sql = $where . $limitsql;
return $sql;
}
function plugin_getfeedcontent_forum ($feed, &$link, &$update)
{
global $_CONF, $_TABLES, $CONF_FORUM, $LANG_GF01;
$content = array();
$lids = array();
$ids = array();
if ($CONF_FORUM['installed_version'] < 2.6) {
return $content;
}
$allow_smilies = $CONF_FORUM['allow_smilies'];
$CONF_FORUM['allow_smilies']=0;
require_once $CONF_FORUM['path_include'] . 'gf_format.php';
if ( !function_exists('str_ireplace'))
{
require_once 'PHP/Compat.php';
PHP_Compat::loadFunction( 'str_ireplace' );
}
require_once $CONF_FORUM['path_include'] . 'bbcode/stringparser_bbcode.class.php';
$result = DB_query ("SELECT topic,limits,content_length FROM {$_TABLES['syndication']} WHERE fid = $feed");
$F = DB_fetchArray ($result);
$sql = "SELECT topic.id,topic.forum,topic.subject,topic.uid,topic.name,topic.comment,topic.date,topic.postmode,forum.forum_name,forum.grp_id ";
$sql .= "FROM {$_TABLES['forum_topic']} topic LEFT JOIN {$_TABLES['forum_forums']} forum ON topic.forum=forum.forum_id ";
$sql .= forum_buildFeedsSql ($F['topic'], $F['limits']);
$result = DB_query ($sql);
while ($A = DB_fetchArray($result)) {
$preface = '';
if ($F['content_length'] == 0) {
$comment = '';
} elseif ($F['content_length'] > 1) {
if ($A['postmode'] == 'html' || $A['postmode'] == 'HTML') {
$comment = COM_truncateHTML($A['comment'], $F['content_length'], '...');
} else {
$comment = COM_truncate($A['comment'], $F['content_length'], '...');
}
} else {
$comment = $A['comment'];
$preface = $LANG_GF01['BY'] . ' ';
if ( $A['uid'] > 1 ) {
$preface .= '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['uid'] . '">' . $A['name'] . '</a>';
} else {
$preface .= $A['name'];
}
$preface .= '<br' . XHTML . '><br' . XHTML . '>';
}
// Handle Pre ver 2.5 quoting and New Line Formatting - consider adding this to a migrate function
if ($CONF_FORUM['pre2.5_mode']) {
if ( stristr($comment,'[code') == false ) {
$comment = str_replace('<pre>','[code]',$comment);
$comment = str_replace('</pre>','[/code]',$comment);
}
$comment = str_replace(array("<br" . XHTML . ">\r\n","<br" . XHTML . ">\n\r","<br" . XHTML . ">\r","<br" . XHTML . ">\n"), '<br' . XHTML . '>', $comment );
$comment = preg_replace("/\[QUOTE\sBY=\s(.+?)\]/i","[QUOTE] Quote by $1:",$comment);
/* Reformat code blocks - version 2.3.3 and prior */
$comment = str_replace( '<pre class="forumCode">', '[code]', $comment );
$comment = preg_replace("/\[QUOTE\sBY=(.+?)\]/i","[QUOTE] Quote by $1:",$comment);
}
$comment = gf_formatTextBlock($comment,$A['postmode'],'preview');
$comment = str_replace('{','{',$comment);
$comment = str_replace('}','}',$comment);
// we don't have a stylesheet in the news feed, so replace our div with the style...
$comment = str_replace('<div class="quotemain">','<div style="border: 1px dotted #000;border-left: 4px solid #8394B2;color:#465584; padding: 4px; margin: 5px auto 8px auto;">',$comment);
$desc = $preface . $comment;
$link = forum_buildForumPostURL($A['id']);
$content[] = array ('title' => $A['forum_name'] . ' :: ' . $A['subject'],
'summary' => $desc,
'text' => $desc,
'link' => $link,
'uid' => $A['uid'],
'date' => $A['date'],
'format' => $A['postmode'],
);
$ids[] = $A['id'];
}
if ($F['topic'] == 0) {
$link = "{$_CONF['site_url']}/forum/index.php";
} else {
$link = "{$_CONF['site_url']}/forum/index.php.php?forum={$F['topic']}";
}
if (count($ids) > 0 ) {
$update = implode (',', $ids);
}
$CONF_FORUM['allow_smilies'] = $allow_smilies;
return $content;
}
function plugin_feedupdatecheck_forum ($feed, $topic, $update_data, $limit)
{
global $_TABLES;
$sql = "SELECT id,forum.grp_id FROM {$_TABLES['forum_topic']} topic LEFT JOIN {$_TABLES['forum_forums']} forum ON topic.forum=forum.forum_id " . forum_buildFeedsSql ($topic, $limit);
$result = DB_query ($sql);
$num = DB_numRows ($result);
$ids = array ();
for ($i = 0; $i < $num; $i++) {
$A = DB_fetchArray ($result);
$ids[] = $A['id'];
}
$current = implode (',', $ids);
//COM_errorLog ("Update check for downloads: comparing new list ($current) with old list ($update_data)", 1);
return ( $current != $update_data ) ? false : true;
}
/* End of RSS Feed Related Functions */
/**
* Called by the plugin Editor to display the current plugin code version
* This may be different then the version installed and registered currently.
* If newer then you may want to run the update
*/
function plugin_chkVersion_forum() {
global $_CONF;
static $pi_version = NULL;
if ($pi_version === NULL) {
require_once $_CONF['path'] . 'plugins/forum/autoinstall.php';
$inst_parms = plugin_autoinstall_forum('forum');
$pi_version = $inst_parms['info']['pi_version'];
}
return $pi_version;
}
/**
* Called by the plugin Editor to run the SQL Update for a plugin update
*/
function plugin_upgrade_forum() {
global $_CONF, $_TABLES, $CONF_FORUM;
$installed_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = 'forum'");
$code_version = plugin_chkVersion_forum();
if ($installed_version == $code_version) return true; // nothing to do
require_once $_CONF['path'] . 'plugins/forum/autoinstall.php';
if (!plugin_compatible_with_this_version_forum('forum')) return 3002;
// Retrieve other plugin info like min geeklog version and homepage
$inst_parms = plugin_autoinstall_forum('forum');
$current_version = $installed_version;
// Include the upgrade functions
require_once $_CONF['path'] . 'plugins/forum/upgrade.inc';
$done = false;
while (!$done) {
switch ($current_version) {
case "2.3" :
case "2.3.2" :
if (upgrade_232() != 0) break 2;
$current_version = "2.5RC1";
break;
case "2.5RC1" :
if (upgrade_25() != 0) break 2;
$current_version = "2.6";
break;
case "2.6" :
case "2.7" :
case "2.7.1" :
case "2.7.2" :
case "2.7.2.JPr5" :
case "2.7.2.JPr6" :
case "2.7.3" :
case "2.7.3.JPr1" :
case "2.7.4" :
case "2.7.4.JPr1" :
case "2.7.5.JPr1" :
if (upgrade_274() != 0) break 2;
$current_version = "2.8.0";
break;
case "2.8.0" :
if (upgrade_280() != 0) break 2;
$current_version = "2.9.0";
break;
case "2.9.0" :
if (upgrade_290() != 0) break 2;
$current_version = "2.9.1";
break;
case "2.9.1" :
$current_version = "2.9.2";
break;
case "2.9.2" :
if (upgrade_293() != 0) break 2;
$current_version = "2.9.3";
break;
case "2.9.3" :
if (upgrade_294() != 0) break 2;
$current_version = "2.9.4";
break;
case "2.9.4" :