-
Notifications
You must be signed in to change notification settings - Fork 19
/
lib-comment.php
3477 lines (3023 loc) · 143 KB
/
lib-comment.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
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.2 |
// +---------------------------------------------------------------------------+
// | lib-comment.php |
// | |
// | Geeklog comment library. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2017 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Mark Limburg - mlimburg AT users DOT sourceforge DOT net |
// | Jason Whittenburg - jwhitten AT securitygeeks DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// | Vincent Furia - vinny01 AT users DOT sourceforge DOT net |
// | Jared Wenerd - wenerd87 AT gmail DOT com |
// +---------------------------------------------------------------------------+
// | |
// | 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. |
// | |
// +---------------------------------------------------------------------------+
global $_CONF;
if (stripos($_SERVER['PHP_SELF'], basename(__FILE__)) !== false) {
die('This file can not be used on its own!');
}
// set to true to enable debug output in error.log
$_COMMENT_DEBUG = COM_isEnableDeveloperModeLog('comment');
if ($_CONF['allow_user_photo']) {
// only needed for the USER_getPhoto function
require_once $_CONF['path_system'] . 'lib-user.php';
}
define('COMMENT_ON_SAME_PAGE', ($_CONF['comment_on_same_page'] && !CMT_isCommentPage()));
global $CMT_formVariablePrefix; // Need to do this as lib-comment is not always required where we think
$CMT_formVariablePrefix = COMMENT_ON_SAME_PAGE ? 'cmt_' : ''; // this prefix is used in functions as a global variable in this library only
define('CMT_CID', $CMT_formVariablePrefix . 'cid');
define('CMT_SID', $CMT_formVariablePrefix . 'sid');
define('CMT_PID', $CMT_formVariablePrefix . 'pid');
define('CMT_TYPE', $CMT_formVariablePrefix . 'type');
define('CMT_USERNAME', $CMT_formVariablePrefix . 'username');
define('CMT_MODE', $CMT_formVariablePrefix . 'mode');
// Possible Comment Codes for Plugin Items
define('COMMENT_CODE_DISABLED', -1); // Comments will not display and no one can add, edit, etc...
define('COMMENT_CODE_ENABLED', 0); // Comments displayed and can be added, edited, etc... if user has access
define('COMMENT_CODE_CLOSED', 1); // Comments displayed but can not be added or edited by any user except admins
/**
* This function displays the comment control bar
* Prints the control that allows the user to interact with Geeklog Comments
*
* @param string $sid ID of item in question
* @param string $title Title of item
* @param string $type Type of item (i.e. article, photo, etc)
* @param string $order Order that comments are displayed in
* @param string $mode Mode (nested, flat, etc.)
* @param int $commentCode Comment code: -1=no comments, 0=allowed, 1=closed
* @return string HTML Formated comment bar
* @see CMT_userComments
*/
function CMT_commentBar($sid, $title, $type, $order, $mode, $commentCode = 0)
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG03, $CMT_formVariablePrefix;
$is_comment_page = CMT_isCommentPage();
$nrows = DB_count($_TABLES['comments'], array('sid', 'type'),
array($sid, $type));
$commentBar = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'comment'));
$commentBar->set_file(array('commentbar' => 'commentbar.thtml'));
$commentBar->set_block('commentbar', 'postcomment_jumplink');
$commentBar->set_block('commentbar', 'postcomment_button');
$commentBar->set_var('lang_comments', $LANG01[3]);
$commentBar->set_var('lang_refresh', $LANG01[39]);
$commentBar->set_var('lang_reply', $LANG01[60]);
$commentBar->set_var('lang_disclaimer', $LANG01[26]);
// hide stuff from anonymous users if they can't post
$hideFromAnon = false;
if (COM_isAnonUser() && (($_CONF['loginrequired'] == 1) || ($_CONF['commentsloginrequired'] == 1))) {
$hideFromAnon = true;
}
// check item for read permissions and comments enabled for it
$function = 'plugin_commentenabled_' . $type;
$commentEnabled = true;
if (function_exists($function)) {
// CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
if (PLG_commentEnabled($type, $sid) != COMMENT_CODE_ENABLED) {
$commentEnabled = false;
}
} else {
COM_deprecatedLog('plugin_getiteminfo_' . $type, '2.2.1', '3.0.0', 'plugin_commentenabled_' . $type . " is now required to check if comments are enabled for a plugin item.");
// This way will be depreciated as of Geeklog v3.0.0
// check item for read permissions at least
if (empty(PLG_getItemInfo($type, $sid, 'url'))) {
$commentEnabled = false;
}
}
// Misc Comment Messages
if ($commentCode == COMMENT_CODE_CLOSED) {
$commentBar->set_var('lang_comments_closed', $LANG03['comments_closed_msg']);
}
if ($commentCode == COMMENT_CODE_ENABLED && $hideFromAnon) {
if (COMMENT_ON_SAME_PAGE) {
// lang_comment_post_login_required is posted on the editor itself
} else {
$commentBar->set_var(
'lang_comment_post_login_required',
sprintf($LANG03[6], $_CONF['site_url'] . '/users.php')
);
}
}
if ($commentCode == COMMENT_CODE_CLOSED && !$commentEnabled) {
$commentBar->set_var('postcomment_action', '');
} else {
if (COMMENT_ON_SAME_PAGE) {
$commentBar->parse('postcomment_action', 'postcomment_jumplink');
} else {
$commentBar->parse('postcomment_action', 'postcomment_button');
}
}
$commentBar->set_var('num_comments', COM_numberFormat($nrows));
$commentBar->set_var('comment_type', $type);
$commentBar->set_var('sid', $sid);
$cmt_title = stripslashes($title);
$commentBar->set_var('story_title', $cmt_title);
// Article's are pre-escaped.
if ($type != 'article') {
$cmt_title = htmlspecialchars($cmt_title);
}
$commentBar->set_var('comment_title', $cmt_title);
// Link to plugin defined link or lacking that a generic link
$pluginItemUrl = CMT_getCommentUrlId($type, $sid);
$commentBar->set_var('article_url', $pluginItemUrl);
if ($is_comment_page) {
$link = COM_createLink($cmt_title, $pluginItemUrl,
array('class' => 'non-ul b'));
$commentBar->set_var('story_link', $link);
$commentBar->set_var('start_storylink_anchortag',
'<a href="' . $pluginItemUrl . '" class="non-ul">');
$commentBar->set_var('end_storylink_anchortag', '</a>');
} else {
$commentBar->set_var('story_link', $pluginItemUrl);
}
if (!COM_isAnonUser()) {
$username = $_USER['username'];
$fullname = $_USER['fullname'];
} else {
$result = DB_query("SELECT username,fullname FROM {$_TABLES['users']} WHERE uid = 1");
$N = DB_fetchArray($result);
$username = $N['username'];
$fullname = $N['fullname'];
}
if (empty($fullname)) {
$fullname = $username;
}
$commentBar->set_var('user_name', $username);
$commentBar->set_var('user_fullname', $fullname);
if (!COM_isAnonUser()) {
$author = COM_getDisplayName($_USER['uid'], $username, $fullname);
$commentBar->set_var('user_nullname', $author);
$commentBar->set_var('author', $author);
$commentBar->set_var('login_logout_url',
$_CONF['site_url'] . '/users.php?mode=logout');
$commentBar->set_var('lang_login_logout', $LANG01[35]);
} else {
$commentBar->set_var('user_nullname', '');
$commentBar->set_var('login_logout_url',
$_CONF['site_url'] . '/users.php?mode=new');
$commentBar->set_var('lang_login_logout', $LANG01[61]);
}
$comment_url = $_CONF['site_url'] . '/comment.php';
if ($is_comment_page) {
$commentBar->set_var('parent_url', $comment_url . '#comments');
$commentBar->set_var('editor_url', $comment_url . '#commenteditform');
$hidden = '';
$commentMode = Geeklog\Input::fRequest(CMT_MODE, '');
$cid = (int) Geeklog\Input::fRequest(CMT_CID, 0);
$pid = (int) Geeklog\Input::fRequest(CMT_PID, 0);
if (in_array($commentMode, array('view', $LANG03[28], $LANG03[34], $LANG03[14], 'edit'))) {
$hidden .= '<input type="hidden" name="' . CMT_CID . '" value="' . $cid . '"' . XHTML . '>';
$hidden .= '<input type="hidden" name="' . CMT_PID . '" value="' . $cid . '"' . XHTML . '>';
} elseif ($commentMode === 'display' || empty($commentMode)) {
$hidden .= '<input type="hidden" name="' . CMT_PID . '" value="' . $pid . '"' . XHTML . '>';
}
$hidden .= '<input type="hidden" name="mode" value="' . $commentMode . '"' . XHTML . '>';
$commentBar->set_var('hidden_field', $hidden);
$commentBar->set_var('hidden_field_reply', '');
$commentBar->set_var('nprefix', '');
} else { // article and plugin
$commentBar->set_var('parent_url', $pluginItemUrl . '#comments');
if (COMMENT_ON_SAME_PAGE) {
$commentBar->set_var('editor_url', $pluginItemUrl . '#commenteditform');
$commentBar->set_var('nprefix', $CMT_formVariablePrefix);
} else {
$commentBar->set_var('editor_url', $comment_url . '#commenteditform');
$commentBar->set_var('nprefix', '');
}
$hidden = '<input type="hidden" name="' . $type . '" value="' . $sid . '"' . XHTML . '>';
$commentBar->set_var('hidden_field', $hidden);
$commentBar->set_var('hidden_field_reply', $hidden);
}
// Order
$selector = COM_optionList($_TABLES['sortcodes'], 'code,name', $order);
$selector = COM_createControl('type-select', array(
'name' => 'order',
'select_items' => $selector
));
$commentBar->set_var('order_selector', $selector);
// Mode
$selector = COM_optionList($_TABLES['commentmodes'], 'mode,name', $mode);
$selector = COM_createControl('type-select', array(
'name' => $is_comment_page ? 'format' : 'mode',
'select_items' => $selector
));
$commentBar->set_var('mode_selector', $selector);
return $commentBar->finish($commentBar->parse('output', 'commentbar'));
}
/**
* This function prints &$comments (db results set of comments) in comment format
* -For previews, &$comments is assumed to be an associative array containing
* data for a single comment.
*
* @param array &$comments Database result set of comments to be printed
* @param string $mode 'flat', 'threaded', etc
* @param string $type Type of item (article, polls, etc.)
* @param string $order How to order the comments 'ASC' or 'DESC'
* @param boolean $delete_option if current user can delete comments
* @param boolean $preview Preview display (for edit) or not
* @param int $commentCode Comment code: -1=no comments, 0=allowed, 1=closed
* @param int $commentPage page number of comments to display
* @return string HTML Formatted Comment
*/
function CMT_getComment(&$comments, $mode, $type, $order, $delete_option = false, $preview = false, $commentCode = 0,
$commentPage = 1)
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG03, $LANG_ADMIN, $MESSAGE, $_IMAGE_TYPE;
$indent = 0; // begin with 0 indent
$retval = ''; // initialize return value
$template = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'comment'));
$template->set_file(array(
'comment' => 'comment.thtml',
'thread' => 'thread.thtml',
));
// Blocks
$template->set_block('comment', 'comment_signature');
$template->set_block('comment', 'comment_edit');
// generic template variables
$template->set_var('lang_authoredby', $LANG01[42]);
$template->set_var('lang_on', $LANG01[36]);
$template->set_var('lang_permlink', $LANG01[120]);
$template->set_var('order', $order);
if ($commentCode == COMMENT_CODE_ENABLED) {
$template->set_var('lang_replytothis', $LANG01[43]);
$template->set_var('lang_reply', $LANG01[25]);
} else {
$template->set_var('lang_replytothis', '');
$template->set_var('lang_reply', '');
}
// Make sure we have a default value for comment indentation
if (!isset($_CONF['comment_indent'])) {
$_CONF['comment_indent'] = 25;
}
if ($preview) {
// Means array is post variables
// These should all have been filtered already
$A = $comments;
if (empty($A['nice_date'])) {
$A['nice_date'] = time();
}
if (!isset($A['cid'])) {
$A['cid'] = 0;
}
if (!isset($A['photo'])) {
if (isset($_USER['photo'])) {
$A['photo'] = $_USER['photo'];
} else {
$A['photo'] = '';
}
}
if (!isset($A['email'])) {
if (isset($_USER['email'])) {
$A['email'] = $_USER['email'];
} else {
$A['email'] = '';
}
}
$mode = 'flat';
} else {
$A = DB_fetchArray($comments);
}
if (empty($A)) {
return '';
}
$commentMode = Geeklog\Input::fRequest(CMT_MODE, '');
// Do not create a new token if the following, as these items are handled later and need to compare the old token (this is currently checked in 2 spots in lib-comment)
// $submit can equal 'Submit Changes' || 'Save Changes to Queue' || 'Delete'
$submit = (($commentMode == $LANG03[29]) || ($commentMode == $LANG03[35]) || ($commentMode == $LANG_ADMIN['delete']));
$token = '';
if ($delete_option && !$preview && !$submit) {
$token = SEC_createToken();
}
// check for comment edit
$row = 1;
do {
// determines indentation for current comment
if ($mode === 'threaded' || $mode === 'nested') {
$indent = ($A['indent'] - $A['pindent']) * $_CONF['comment_indent'];
// set the maximum indentation level to 16
if ($indent > 400) {
$indent = 400;
}
}
// comment variables
$template->set_var('indent', $indent);
$template->set_var('author_name', GLText::stripTags($A['username']));
$template->set_var('author_id', $A['uid']);
$template->set_var('cid', $A['cid']);
$template->set_var('cssid', $row % 2);
if ($_CONF['likes_enabled'] != 0 && $_CONF['likes_comments'] != 0) {
$likes_control = LIKES_control('comment', '', $A['cid'], $_CONF['likes_comments']) . ' | ';
$template->set_var('likes_control', $likes_control);
} else {
$template->set_var('likes_control', '');
}
if ($A['uid'] > 1) {
$fullname = '';
if (!empty($A['fullname'])) {
$fullname = $A['fullname'];
}
$fullname = COM_getDisplayName($A['uid'], $A['username'],
$fullname);
$template->set_var('author', $fullname);
$altText = $fullname;
$photo = '';
if ($_CONF['allow_user_photo']) {
if (isset($A['photo']) && empty($A['photo'])) {
$A['photo'] = '(none)';
}
$photo = USER_getPhoto($A['uid'], $A['photo'], $A['email'], PLG_getThemeItem('comment-width-user-avatar', 'comment'), PLG_getThemeItem('comment-css-user-avatar', 'comment'));
}
$profile_link = $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['uid'];
if (!empty($photo)) {
$template->set_var('author_photo', $photo);
$camera_icon = '<img src="' . $_CONF['layout_url']
. '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""'
. XHTML . '>';
$template->set_var('camera_icon',
COM_createLink($camera_icon, $profile_link));
} else {
$template->set_var('author_photo', '');
$template->set_var('camera_icon', '');
}
$template->set_var('start_author_anchortag', '<a href="' . $profile_link . '">');
$template->set_var('end_author_anchortag', '</a>');
// $template->set_var('author_link', COM_createLink($fullname, $profile_link));
$template->set_var('author_link', COM_getProfileLink($A['uid'], $A['username'], $fullname));
} else {
// comment is from anonymous user
if (isset($A['name'])) {
$A['username'] = GLText::stripTags($A['name']);
}
$A['username'] = GLText::remove4byteUtf8Chars($A['username']); // Need to do this if doing a comment preview when adding/editing a comment
$anon_username = sprintf($LANG03['anon_user_name'], $A['username']);
$template->set_var('author', $anon_username);
$template->set_var('author_link', $anon_username);
if ($_CONF['allow_user_photo']) {
$photo = USER_getPhoto($A['uid'], '', '', PLG_getThemeItem('comment-width-user-avatar', 'comment'), PLG_getThemeItem('comment-css-user-avatar', 'comment'), $A['username']);
$template->set_var('author_photo', $photo);
} else {
$template->set_var('author_photo', '');
}
$template->set_var('camera_icon', '');
$template->set_var('start_author_anchortag', '');
$template->set_var('end_author_anchortag', '');
}
// hide reply link from anonymous users if they can't post replies
$hideFromAnon = false;
if (COM_isAnonUser() && (($_CONF['loginrequired'] == 1) || ($_CONF['commentsloginrequired'] == 1))) {
$hideFromAnon = true;
}
// this will hide HTML that should not be viewed in preview mode
if ($preview || $hideFromAnon) {
$template->set_var('hide_if_preview', 'style="display:none"');
} else {
$template->set_var('hide_if_preview', '');
}
// for threaded mode, add a link to comment parent
if ($mode === 'threaded' && $A['pid'] != 0 && $indent == 0) {
$pid = DB_getItem($_TABLES['comments'], 'pid',
"cid = '{$A['pid']}'");
if ($pid != 0) {
$pLink = $_CONF['site_url'] . '/comment.php?mode=display'
. '&sid=' . $A['sid'] . '&type=' . $type
. '&order=' . $order . '&pid=' . $pid
. '&format=threaded';
} else {
$pLink = $_CONF['site_url'] . '/comment.php?mode=view'
. '&sid=' . $A['sid'] . '&type=' . $type
. '&order=' . $order . '&cid=' . $A['pid']
. '&format=threaded';
}
$parent_link = COM_createLink($LANG01[44], $pLink) . ' | ';
$template->set_var('parent_link', $parent_link);
} else {
$template->set_var('parent_link', '');
}
list($date, ) = COM_getUserDateTimeFormat($A['nice_date'], 'date');
$template->set_var('date', $date);
$template->set_var('sid', $A['sid']);
$template->set_var('type', $A['type']);
// COMMENT edit rights
$edit_option = false;
if (isset($A['uid']) && isset($_USER['uid'])
&& !COM_isAnonUser()
&& ($_USER['uid'] == $A['uid']) && ($_CONF['comment_edit'] == 1)
&& ((time() - $A['nice_date']) < $_CONF['comment_edittime'])
&& (DB_getItem($_TABLES['comments'], 'COUNT(*)',
"pid = {$A['cid']}") == 0)
) {
$edit_option = true;
if (empty($token) && !$preview && !$submit) {
$token = SEC_createToken();
}
} elseif (SEC_hasRights('comment.moderate')) {
$edit_option = true;
}
if (COMMENT_ON_SAME_PAGE) {
$pluginUrl = CMT_getCommentUrlId($type, $A['sid']);
}
// edit link
$edit = '';
if ($edit_option) {
if (COMMENT_ON_SAME_PAGE) {
$editLink = $pluginUrl . '&' . CMT_MODE . '=edit&' . CMT_CID . '=' . $A['cid']
. '&mode=' . $mode
. '&order=' . $order
. '&cpage=' . $commentPage
. '#commenteditform';
} else {
$editLink = $_CONF['site_url'] . '/comment.php?mode=edit&cid=' . $A['cid'];
}
$edit = COM_createLink($LANG01[4], $editLink) . ' | ';
}
// unsubscribe link
$unsubscribe = '';
if (($_CONF['allow_reply_notifications'] == 1) && !COM_isAnonUser()
&& isset($A['uid']) && isset($_USER['uid'])
&& ($_USER['uid'] == $A['uid'])
) {
$hash = DB_getItem($_TABLES['commentnotifications'], 'deletehash',
"cid = {$A['cid']} AND uid = {$_USER['uid']}");
if (!empty($hash)) {
if (COMMENT_ON_SAME_PAGE) {
$unsubLink = $pluginUrl . '&' . CMT_MODE . "=unsubscribe&" . '&key=' . $hash;
} else {
$unsubLink = $_CONF['site_url']
. '/comment.php?mode=unsubscribe&key=' . $hash;
}
$unsubAttr = array('title' => $LANG03[43]);
$unsubscribe = COM_createLink($LANG03[42], $unsubLink, $unsubAttr) . ' | ';
}
}
// if deletion is allowed, displays delete link
if ($delete_option) {
$delOption = '';
// always place edit option first, if available
if (!empty($edit)) {
$delOption .= $edit;
}
// actual delete option
if (COMMENT_ON_SAME_PAGE) {
$delLink = $pluginUrl . '&' . CMT_MODE . '=delete&' . CMT_CID . '=' . $A['cid']
. '&' . CSRF_TOKEN . '=' . $token;
} else {
$delLink = $_CONF['site_url'] . '/comment.php?mode=delete&cid=' . $A['cid']
. '&' . CSRF_TOKEN . '=' . $token;
}
$delAttr = array('onclick' => "return confirm('{$MESSAGE[76]}');");
$delOption .= COM_createLink($LANG01[28], $delLink, $delAttr) . ' | ';
if (!empty($A['ipaddress'])) {
if (empty($_CONF['ip_lookup'])) {
$delOption .= $A['ipaddress'] . ' | ';
} else {
$ipLookUp = str_replace('*', $A['ipaddress'], $_CONF['ip_lookup']);
$delOption .= COM_createLink($A['ipaddress'], $ipLookUp) . ' | ';
}
}
if (!empty($unsubscribe)) {
$delOption .= $unsubscribe;
}
$template->set_var('delete_option', $delOption);
} elseif ($edit_option) {
$template->set_var('delete_option', $edit . $unsubscribe);
} elseif (!COM_isAnonUser()) {
$reportThis = '';
if ($A['uid'] != $_USER['uid']) {
$reportThisLink = $_CONF['site_url'] . '/comment.php?mode=report&cid=' . $A['cid'];
$report_attr = array('title' => $LANG01[110]);
$reportThis = COM_createLink($LANG01[109], $reportThisLink,
$report_attr) . ' | ';
}
$template->set_var('delete_option', $reportThis . $unsubscribe);
} else {
$template->set_var('delete_option', '');
}
// Comments really should a postmode that is saved with the comment (ie store either 'html' or 'plaintext') but they don't so lets figure out if comment is html by searching for html tags
if (preg_match('/<.*>/', $A['comment']) == 0) {
$A['comment'] = COM_nl2br($A['comment']);
}
// highlight search terms if specified
if (!empty($_REQUEST['query'])) {
$A['comment'] = COM_highlightQuery($A['comment'], Geeklog\Input::request('query'));
}
$A['comment'] = str_replace('$', '$', $A['comment']);
$A['comment'] = str_replace('{', '{', $A['comment']);
$A['comment'] = str_replace('}', '}', $A['comment']);
// Replace any plugin autolink tags
$A['comment'] = PLG_replaceTags($A['comment'], '', false, 'comment', $A['cid']);
// create a reply to link
$function = 'plugin_commentenabled_' . $type;
$commentEnabled = true;
if (function_exists($function)) {
// CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
if (PLG_commentEnabled($type, $A['sid']) != COMMENT_CODE_ENABLED) {
$commentEnabled = false;
}
} else {
COM_deprecatedLog('plugin_getiteminfo_' . $type, '2.2.1', '3.0.0', 'plugin_commentenabled_' . $type . " is now required to check if comments are enabled for a plugin item.");
// This way will be depreciated as of Geeklog v3.0.0
// check item for read permissions at least
if (empty(PLG_getItemInfo($type, $A['sid'], 'url'))) {
$commentEnabled = false;
}
}
$reply_link = '';
if ($commentCode == COMMENT_CODE_ENABLED || ($commentCode == COMMENT_CODE_CLOSED && $commentEnabled)) {
if (COMMENT_ON_SAME_PAGE) {
$reply_link = $pluginUrl
. '&' . CMT_PID . '=' . $A['cid']
. '&' . CMT_TYPE . '=' . $A['type']
. '&mode=' . $mode
. '&order=' . $order
. '&cpage=' . $commentPage
. '#commenteditform';
} else {
$reply_link = $_CONF['site_url'] . '/comment.php?sid=' . $A['sid']
. '&pid=' . $A['cid'] . '&type=' . $A['type'];
if ($_CONF['show_comments_at_replying'] == true) {
$reply_link .= '#commenteditform';
}
}
$reply_option = COM_createLink($LANG01[43], $reply_link, array('rel' => 'nofollow')) . ' | ';
$template->set_var('reply_option', $reply_option);
} else {
$template->set_var('reply_option', '');
}
$template->set_var('reply_link', $reply_link);
// Check for User Signature and add first
// Get signature of comment owner
if ($A['uid'] > 1) {
$sig = DB_getItem($_TABLES['users'], 'sig', "uid = {$A['uid']}");
if (!empty($sig)) {
$template->set_var('user_signature', COM_nl2br($sig));
$template->parse('comment_signature', 'comment_signature');
}
} else {
$template->set_var('user_signature', '');
$template->set_var('comment_signature', '');
}
// check for comment edit
$commentEdit = DB_query("SELECT cid,uid,UNIX_TIMESTAMP(time) AS time FROM {$_TABLES['commentedits']} WHERE cid = {$A['cid']}");
$B = DB_fetchArray($commentEdit);
if ($B) { //comment edit present
// get correct editor name
if ($A['uid'] == $B['uid']) {
$editName = $A['username'];
} else {
$editName = DB_getItem($_TABLES['users'], 'username', "uid={$B['uid']}");
}
// add edit info to text
list($date, ) = COM_getUserDateTimeFormat($B['time'], 'date');
$edit_info = $LANG03[30] . ' ' . $date . ' ' . $LANG03[31] . ' ' . $editName;
$template->set_var('user_edit_info', $edit_info);
$template->parse('comment_edit', 'comment_edit');
} else{
$template->unset_var('comment_edit');
}
// format title for display, must happen after reply_link is created
$A['title'] = htmlspecialchars($A['title']);
$A['title'] = str_replace('$', '$', $A['title']);
$template->set_var('title', $A['title']);
$template->set_var('comments', $A['comment']);
// parse the templates
if (($mode === 'threaded') && $indent > 0) {
$template->set_var('pid', $A['pid']);
$retval .= $template->parse('output', 'thread');
} else {
$template->set_var('pid', $A['cid']);
$retval .= $template->parse('output', 'comment');
}
$row++;
} while (!$preview && ($A = DB_fetchArray($comments)));
return $retval;
}
/**
* This function displays the comments in a high level format.
* Begins displaying user comments for an item
*
* @param string $sid ID for item to show comments for
* @param string $title Title of item
* @param string $type Type of item (article, polls, etc.)
* @param string $order How to order the comments 'ASC' or 'DESC'
* @param string $mode comment mode (nested, flat, etc.)
* @param int $pid id of parent comment
* @param int $page page number of comments to display
* @param boolean $cid true if $pid should be interpreted as a cid instead
* @param boolean $delete_option if current user can delete comments
* @param int $commentCode Comment code: -1=no comments, 0=allowed, 1=closed
* @return string HTML Formatted Comments
* @see CMT_commentBar
*/
function CMT_userComments($sid, $title, $type = 'article', $order = '', $mode = '', $pid = 0, $page = 1, $cid = false, $delete_option = false, $commentCode = 0)
{
global $_CONF, $_TABLES, $_USER, $LANG01;
$retval = '';
if (!COM_isAnonUser()) {
$result = DB_query("SELECT commentorder,commentmode,commentlimit FROM {$_TABLES['usercomment']} WHERE uid = '{$_USER['uid']}'");
$U = DB_fetchArray($result);
if (empty($order)) {
$order = $U['commentorder'];
}
if (empty($mode)) {
$mode = $U['commentmode'];
}
$limit = $U['commentlimit'];
}
if ($order != 'ASC' && $order != 'DESC') {
$order = $_CONF['comment_order'];
}
if (empty($mode)) {
$mode = $_CONF['comment_mode'];
}
if (empty($limit)) {
$limit = $_CONF['comment_limit'];
}
// Retrieve base url in case needed for 404 error
$pluginLink = CMT_getCommentUrlId($type, $sid);
if ($page == '') {
// Assume first page if none given
$page = 1;
} elseif (!is_numeric($page) || $page < 1) {
COM_handle404($pluginLink);
}
$start = $limit * ($page - 1);
// trap if start page num is so large that ends up turning into an exponent which makes the sql statement fail
if (!is_int($start)) {
COM_handle404($pluginLink);
}
$template = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'comment'));
$template->set_file(array('commentarea' => 'startcomment.thtml'));
$template->set_var('commentbar',
CMT_commentBar($sid, $title, $type, $order, $mode, $commentCode));
$template->set_var('sid', $sid);
$template->set_var('comment_type', $type);
$template->set_var('area_id', 'commentarea');
if ($mode === 'nested' || $mode === 'threaded' || $mode === 'flat') {
// build query
switch ($mode) {
case 'flat':
if ($cid) {
$count = 1;
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.cid = $pid AND type='{$type}'";
} else {
$count = DB_count($_TABLES['comments'],
array('sid', 'type'), array($sid, $type));
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.sid = '$sid' AND type='{$type}' "
. "ORDER BY date $order LIMIT $start, $limit";
}
break;
case 'nested':
case 'threaded':
default:
if ($order === 'DESC') {
$cOrder = 'c.rht DESC';
} else {
$cOrder = 'c.lft ASC';
}
// We can simplify the query, and hence increase performance
// when pid = 0 (when fetching all the comments for a given sid)
if ($cid) { // pid refers to commentid rather than parentid
// count the total number of applicable comments
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}'";
$result = DB_query($q2);
list($count) = DB_fetchArray($result);
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
} else { // pid refers to parentid rather than commentid
if ($pid == 0) { // the simple, fast case
// count the total number of applicable comments
$count = DB_count($_TABLES['comments'],
array('sid', 'type'), array($sid, $type));
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, 0 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND c.uid = u.uid AND type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
} else {
// count the total number of applicable comments
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}'";
$result = DB_query($q2);
list($count) = DB_fetchArray($result);
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent + 1 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
}
}
break;
}
$theComments = '';
$result = DB_query($q);
if (DB_numRows($result) == 0) {
if ($page > 1) {
// Requested invalid page
COM_handle404($pluginLink);
}
}
$theComments .= CMT_getComment($result, $mode, $type, $order, $delete_option, false, $commentCode, $page);
// Pagination
$tot_pages = ceil($count / $limit);
$is_comment_page = CMT_isCommentPage();
if ($is_comment_page) {
$pLink[0] = "comment.php?sid=$sid&type=$type"; // need type here as on comment.php and need to figure out where sid is from
$pLink[0] .= "&order=$order&format=$mode";
} else {
$pLink[0] = $pluginLink;
$pLink[0] .= "&order=$order&mode=$mode";
}
$pLink[1] = "#comments";
$page_str = "cpage=";
$template->set_var('pagenav',
COM_printPageNavigation($pLink, $page, $tot_pages, $page_str, false));
$template->set_var('comments', $theComments);
if (COMMENT_ON_SAME_PAGE) {
// check item for read permissions and comments enabled for it
$function = 'plugin_commentenabled_' . $type;
$commentEnabled = true;
if (function_exists($function)) {
// CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
if (PLG_commentEnabled($type, $sid) != COMMENT_CODE_ENABLED) {
$commentEnabled = false;
}
} else {
COM_deprecatedLog('plugin_getiteminfo_' . $type, '2.2.1', '3.0.0', 'plugin_commentenabled_' . $type . " is now required to check if comments are enabled for a plugin item.");
// This way will be depreciated as of Geeklog v3.0.0
// check item for read permissions at least
if (empty(PLG_getItemInfo($type, $sid, 'url'))) {
$commentEnabled = false;
}
}
if ($commentCode == COMMENT_CODE_ENABLED || ($commentCode == COMMENT_CODE_CLOSED && $commentEnabled)) {
$cMode = COM_applyFilter(COM_getArgument(CMT_MODE));
$html = CMT_handleComment($cMode, $type, $title, $sid, $mode);
$template->set_var('commenteditor', $html);
}
}
$retval = $template->finish($template->parse('output', 'commentarea'));
}
return $retval;
}
/**
* Displays the comment form
*
* @param string $title Title of comment
* @param string $comment Text of comment
* @param string $sid ID of object comment belongs to
* @param int $pid ID of parent comment
* @param string $type Type of object comment is posted to
* @param string $mode Mode, e.g. 'preview'
* @param string $postMode Indicates if comment is plain text or HTML
* @param string $format 'threaded', 'nested', or 'flat'
* @param string $order 'ASC' or 'DESC' or blank
* @param int $page Page number of comments to display
* @return string HTML for comment form
*/
function CMT_commentForm($title, $comment, $sid, $pid = 0, $type, $mode, $postMode, $format = '', $order = '', $page = 0)
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG03, $LANG12, $LANG_ADMIN
, $LANG_ACCESS, $MESSAGE, $_SCRIPTS, $CMT_formVariablePrefix;
$retval = '';
// never trust $uid ...
if (empty($_USER['uid'])) {
$uid = 1;
} else {
$uid = (int) $_USER['uid'];
}
$isAnon = ($uid <= 1);
if (empty($format)) {
if (isset($_REQUEST['format'])) {
$format = Geeklog\Input::fRequest('format');
}
if (!in_array($format, array('threaded', 'nested', 'flat', 'nocomment'))) {
if (COM_isAnonUser()) {
$format = $_CONF['comment_mode'];
} else {
$format = DB_getItem($_TABLES['usercomment'], 'commentmode', "uid = {$uid}");
}
}
}
if (empty($order)) {
if (isset($_REQUEST['order'])) {
$order = Geeklog\Input::fRequest('order');
}
}
if (empty($page)) {
if (isset($_REQUEST['cpage'])) {
$page = (int) Geeklog\Input::fRequest('cpage', 0);
if (empty($page)) {
$page = 1;
}
}
}
$commentUid = $uid;
$table = '';
$edit_comment = false;
$edit_comment_submission = false; // flag if in edit submission (not regular edit of comment)
if ($mode === 'edit' || $mode === $LANG03[28]) {
$table = $_TABLES['comments'];
$edit_comment = true;
} elseif ($mode === 'editsubmission' || $mode == $LANG03[34]) {
$table = $_TABLES['commentsubmissions'];
$edit_comment_submission = true;
}
if (!empty($table)) {
$cid = (int) Geeklog\Input::fRequest(CMT_CID, 0);
if ($cid <= 0) {
COM_handle404($_CONF['site_url'] . '/index.php');
}
$commentUid = DB_getItem($table, 'uid', "cid = '$cid'");
}
if (COM_isAnonUser() &&
(($_CONF['loginrequired'] == 1) || ($_CONF['commentsloginrequired'] == 1))
) {
if (COMMENT_ON_SAME_PAGE) {
$commentlogin = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'comment'));
$commentlogin->set_file(array('comment' => 'commentlogin.thtml'));
$commentlogin->set_var('start_block_postacomment', COM_startBlock($LANG03[1]));
$commentlogin->set_var(
'lang_comment_post_login_required',
sprintf($LANG03[6], $_CONF['site_url'] . '/users.php')
);
$commentlogin->set_var('end_block', COM_endBlock());
$retval .= $commentlogin->finish($commentlogin->parse('output', 'comment'));
} else {
$retval .= SEC_loginRequiredForm();
}
return $retval;
} else {
COM_clearSpeedlimit($_CONF['commentspeedlimit'], 'comment');
$last = 0;
if ($mode !== 'edit' && $mode !== 'editsubmission'
&& $mode != $LANG03[28] && $mode != $LANG03[34]
) {
// not edit mode or preview changes
$last = COM_checkSpeedlimit('comment');