forked from foliovision/thoughtful-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fv-thoughtful-comments.php
1569 lines (1300 loc) · 63.9 KB
/
fv-thoughtful-comments.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
/*
Plugin Name: FV Thoughtful Comments
Plugin URI: http://foliovision.com/
Description: Manage incomming comments more effectively by using frontend comment moderation system provided by this plugin.
Version: 0.3.2
Author: Foliovision
Author URI: http://foliovision.com/seo-tools/wordpress/plugins/thoughtful-comments/
The users cappable of moderate_comments are getting all of these features and are not blocked
*/
/* Copyright 2009 - 2015 Foliovision (email : [email protected])
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @package foliovision-tc
* @author Foliovision <[email protected]>
* version 0.3.1
*/
include( 'fp-api.php' );
if( class_exists('fv_tc_Plugin') ) :
class fv_tc extends fv_tc_Plugin {
/**
* Plugin directory URI
* @var string
*/
var $url;
/**
* Plugin version
* @var string
*/
var $strVersion = '0.3.1';
/**
* Decide if scripts will be loaded on current page
* True if array( $fv_tc, 'frontend' ) filter was aplied on current page
* @bool
*/
var $loadScripts = false;
/**
* Comment author name obtained from cookie - if it has unapproved comments being shown
* @string
*/
var $cache_comment_author;
/**
* Current comments count
* @int
*/
var $cache_comment_count;
/**
* Comment cache data
* @array
*/
var $cache_data;
/**
* Comment cache filename
* @string
*/
var $cache_filename;
/**
* Class contructor. Sets all basic variables.
*/
function __construct(){
$this->url = trailingslashit( site_url() ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
$this->readme_URL = 'http://plugins.trac.wordpress.org/browser/thoughtful-comments/trunk/readme.txt?format=txt';
add_action( 'in_plugin_update_message-thoughtful-comments/fv-thoughtful-comments.php', array( &$this, 'plugin_update_message' ) );
add_action( 'admin_init', array( $this, 'option_defaults' ) );
}
function option_defaults() {
$options = get_option('thoughtful_comments');
if( !$options ){
update_option( 'thoughtful_comments', array( 'shorten_urls' => true, 'reply_link' => true, 'comment_autoapprove_count' => 1 ) );
}
else{
//make autoapprove count 1 by default
if( !isset($options['comment_autoapprove_count']) || (intval($options['comment_autoapprove_count']) < 1) ){
$options['comment_autoapprove_count'] = 1;
update_option( 'thoughtful_comments', $options );
}
}
}
function admin_css(){
if( !isset($_GET['page']) || $_GET['page'] != 'manage_fv_thoughtful_comments' ) {
return;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo plugins_url('css/admin.css',__FILE__); ?>" />
<?php
}
function ap_action_init()
{
// Localization
load_plugin_textdomain('fv_tc', false, dirname(plugin_basename(__FILE__)) . "/languages");
}
function admin_init() {
/*
Simple text field which is sanitized to fit into YYYY-MM-DD and only >= editors are able to edit it for themselves
*/
x_add_metadata_field( 'fv_tc_moderated', 'user', array(
'field_type' => 'text',
'label' => 'Moderation queue',
'display_column' => true,
'display_column_callback' => 'fv_tc_x_add_metadata_field'
)
);
}
function admin_menu(){
add_options_page( 'FV Thoughtful Comments', 'FV Thoughtful Comments', 'manage_options', 'manage_fv_thoughtful_comments', array($this, 'options_panel') );
}
/**
* Adds the plugin functions into Comment Moderation in backend. Hooked on comment_row_actions.
*
* @param array $actions Array containing all the actions associated with each of the comments
*
* @global object Current comment object
* @global object Post object associated with the current comment
*
* @todo Delete thread options should be displayed only fif the comment has some children, but that may be too much for the SQL server
*
* @return array Comment actions array with our new items in it.
*/
function admin($actions) {
global $comment, $post;/*, $_comment_pending_count;*/
if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
$this->loadScripts = true;
/* If the IP isn't on the blacklist yet, display delete and ban ip link */
$banned = stripos(trim(get_option('blacklist_keys')),$comment->comment_author_IP);
$child = $this->comment_has_child($comment->comment_ID, $comment->comment_post_ID);
if($banned===FALSE)
$actions['delete_ban'] = $this->get_t_delete_ban($comment);
else
$actions['delete_ban'] = '<a href="#">' . __('Already banned!', 'fv_tc') . '</a>';
if($child>0) {
$actions['delete_thread'] = $this->get_t_delete_thread($comment);
if($banned===FALSE)
$actions['delete_thread_ban'] = $this->get_t_delete_thread_ban($comment);
/*else
$actions['delete_banned'] = '<a href="#">Already banned!</a>';*/
}
// blacklist email address
/*if(stripos(trim(get_option('blacklist_keys')),$comment->comment_author_email)!==FALSE)
$actions['blacklist_email'] = "Email Already Blacklisted";
else
$actions['blacklist_email'] = "<a href='$blacklist_email' target='_blank' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Blacklist Email' ) . "'>" . __( 'Blacklist Email' ) . '</a>';*/
}
return $actions;
}
function cache_purge() {
if( !isset($_POST['action']) || !isset($_POST['option_page']) || $_POST['action'] != 'update' || $_POST['option_page'] != 'discussion' ) {
return;
}
global $blog_id;
if( !file_exists(WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/') ) {
return;
}
$files = @glob(WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/*'); //
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
}
function cache_start( $args ) {
$options = get_option('thoughtful_comments');
if( empty($options['comment_cache']) ) {
return $args;
}
require_once( dirname(__FILE__).'/walkers.php' );
global $wp_query, $post, $blog_id, $wptouch_pro;
$this->cache_comment_count = get_comments_number();
$this->cache_comment_author = false;
foreach ($_COOKIE as $n => $v) {
if (substr($n, 0, 20) == 'comment_author_email') {
$this->cache_comment_author = $v;
}
}
$bCommenterUnapproved = false;
if( $this->cache_comment_author && $wp_query->comments ) {
foreach( $wp_query->comments as $objComment ) {
if( $objComment->comment_author_email == $this->cache_comment_author && $objComment->comment_approved == 0 ) {
$bCommenterUnapproved = true;
}
}
}
if( !$bCommenterUnapproved ) {
$this->cache_comment_author = false;
} else {
echo "<!--fv comments cache - unapproved comments for $this->cache_comment_author - not serving cached data -->\n";
}
$sMobile = ( !empty($wptouch_pro->is_mobile_device) && $wptouch_pro->is_mobile_device ) ? '-wptouch' : '';
$this->cache_data = false;
$this->cache_filename = $post->ID.'-'.$post->post_name.$sMobile.'-cpage'.$wp_query->query_vars['cpage'].'.tmp';
if( !file_exists(WP_CONTENT_DIR.'/cache/') ) {
mkdir(WP_CONTENT_DIR.'/cache/');
}
if( !file_exists(WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/') ) {
mkdir(WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/');
}
$this->cache_filename = WP_CONTENT_DIR . '/cache/thoughtful-comments-'.$blog_id.'/'.$this->cache_filename; // check if exists!
if( file_exists( $this->cache_filename ) ) {
$this->cache_data = unserialize( file_get_contents( $this->cache_filename ) );
}
if ( !is_array($this->cache_data) ) {
$this->cache_data = array();
}
$aCache = $this->cache_data;
if( !is_user_logged_in() && !$this->cache_comment_author && isset($aCache['html']) && ($aCache['date'] + 7200) > date( 'U' ) && isset($aCache['comments']) && $aCache['comments'] == $this->cache_comment_count && !isset( $_COOKIE['fv-debug'] ) ) {
echo "<!--fv comments cache from $this->cache_filename @ ".$aCache['date']."-->\n";
echo $aCache['html'];
// skip the rest of the output!
$args['walker'] = new FV_TC_Walker_Comment_blank;
} else {
$args['walker'] = new FV_TC_Walker_Comment_capture;
}
return $args;
}
/**
* Filter for manage_users_columns to add new column into user management table
*
* @param array $columns Array of all the columns
*
* @return array Array with added columns
*/
function column($columns) {
$columns['fv_tc_moderated'] = "Moderation queue";
return $columns;
}
/**
* Filter for manage_users_custom_column inserting the info about comment moderation into the right column
*
* @return string Column content
*/
function column_content($content) {
/* $args[0] = column content (empty), $args[1] = column name, $args[2] = user ID */
$args = func_get_args();
/* Check the custom column name */
if($args[1] == 'fv_tc_moderated') {
/* output Allow user to comment without moderation/Moderate future comments by this user by using user ID in $args[2] */
return $this->get_t_moderated($args[2],false);
}
return $content;
}
/**
* Remove the esc_html filter for admins so that the comment highlight is visible
*
* @param string $contnet Comment author name
*
* @return string Comment author name
*/
function comment_author_no_esc_html( $content ) {
if( current_user_can('manage_options') ) {
remove_filter( 'comment_author', 'esc_html' );
}
return $content;
}
/**
* Check if comment has any child
*
* @param int $id Comment ID
*
* @global object Wordpress db object
*
* @return number of child comments
*/
function comment_has_child($id, $postid) {
global $wp_query;
/// addition 2010/06/02 - check if you have comments filled in
if ($wp_query->comments != NULL ) {
foreach( $wp_query->comments AS $comment ) {
if( $comment->comment_parent == $id ) {
return true;
}
}
}
return false;
// forget about the database!
/*global $wpdb;
return $wpdb->get_var("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_id = '{$postid}' AND comment_parent = '{$id}' LIMIT 1");
*/
}
/**
* Replace url of reply link only with #
* functionality is done only by JavaScript
*/
function comment_reply_links ($strLink = null) {
$options = get_option('thoughtful_comments');
$strReplyKeyWord = 'comment-';
if( isset( $options['tc_replyKW'] ) && !empty( $options[ 'tc_replyKW' ] ) ) {
$strReplyKeyWord = $options['tc_replyKW'];
}
$strLink = preg_replace(
'~href="([^"]*)"~' ,
'href="$1' . urlencode( '#' . $strReplyKeyWord . get_comment_ID() ) . '"',
$strLink
);
if ($options['reply_link']) {
$noscript = '<noscript>' . __('Reply link does not work in your browser because JavaScript is disabled.', 'fv_tc') . '<br /></noscript>';
$link_script = preg_replace( '~href.*onclick~' , 'href="#" onclick' , $strLink );
return $noscript . $link_script;
}
return $strLink;
}
/**
* Clear the URI for use in onclick events.
*
* @param string The original URI
*
* @return string Cleaned up URI
*/
function esc_url($url) {
if(function_exists('esc_url'))
return esc_url($url);
/* Legacy WP support */
else
return clean_url($url);
}
/**
* Filter for comment_text. Displays frontend moderation options if user can edit posts.
*
* @param string $content Comment text.
*
* @global int Current user ID
* @global object Current comment object
*
* @return string Comment text with added features.
*/
function frontend ($content) {
if( is_admin() ) {
return $content;
}
global $user_ID, $comment, $post;
if( !isset($this->can_edit) ) { // for performance reasons only check once!
if( current_user_can('edit_posts') && current_user_can( 'edit_comment', $comment->comment_ID ) ) {
$this->can_edit = true;
} else {
$this->can_edit = false;
}
}
if( $this->can_edit ) {
$this->loadScripts = true;
//$child = $this->comment_has_child($comment->comment_ID, $comment->comment_post_ID);
/* Container */
$out = '<p class="tc-frontend">';
/* Approve comment */
if($comment->comment_approved == '0') {
$out .= '<span id="comment-'.$comment->comment_ID.'-approve">'.$this->get_t_approve($comment).' </span>';
}
/* Delete comment */
$out .= $this->get_t_delete($comment).' ';
/* Delete thread */
//if($child>0) {
$out .= $this->get_t_delete_thread($comment).' ';
//}
/* If IP isn't banned */
if(stripos(trim(get_option('blacklist_keys')),$comment->comment_author_IP)===FALSE) {
/* Delete and ban */
$out .= $this->get_t_delete_ban($comment);//.' | ';
/* Delete thread and ban */
//if($child>0)
$out .= ' | '.$this->get_t_delete_thread_ban($comment);
} else {
$out .= 'IP '.$comment->comment_author_IP.' ';
$out .= __('already banned!', 'fv_tc' );
}
/* Moderation status */
$user_info = ( isset($comment->user_id) && $comment->user_id > 0 ) ? get_userdata($comment->user_id) : false;
if( $user_info && $user_info->user_level < 3) {
$out .= '<br />'.$this->get_t_moderated($comment->user_id);
} else if( $user_info && $user_info->user_level >= 3 ) {
$out .= '<br /><abbr title="' . __('Comments from this user level are automatically approved', 'fv_tc') . '">' . __('Power user', 'fv_tc') . '</a>';
}
$out .= '</p>';
$out .= '<span id="fv-tc-comment-'.$comment->comment_ID.'"></span>';
return $content . $out;
}
return $content;
}
function get_js_translations() {
$aStrings = Array(
'comment_delete' => __('Do you really want to trash this comment?', 'fv_tc'),
'delete_error' => __('Error deleting comment', 'fv_tc'),
'comment_delete_ban_ip' => __('Do you really want to trash this comment and ban the IP?', 'fv_tc'),
'comment_delete_replies' => __('Do you really want to trash this comment and all the replies?', 'fv_tc'),
'comment_delete_replies_ban_ip' => __('Do you really want to trash this comment with all the replies and ban the IP?', 'fv_tc'),
'moderate_future' => __('Moderate future comments by this user','fv_tc'),
'unmoderate' => __('Unmoderated','fv_tc'),
'without_moderation' => __('Allow user to comment without moderation','fv_tc'),
'moderate' => __('Moderated','fv_tc'),
'mod_error' => __('Error','fv_tc'),
'wait' => __('Wait...', 'fv_tc'),
);
return $aStrings;
}
/**
* Generate the anchor for approve function
*
* @param object $comment Comment object
*
* @return string HTML of the anchor
*/
function get_t_approve($comment) {
return '<a href="#" onclick="fv_tc_approve('.$comment->comment_ID.'); return false">' . __('Approve', 'fv_tc') . '</a>';
//return '<a href="#" onclick="fv_tc_approve('.$comment->comment_ID.',\''.$this->esc_url( wp_nonce_url($this->url.'/ajax.php','fv-tc-approve_' . $comment->comment_ID)).'\', \''. __('Wait...', 'fv_tc').'\'); return false">' . __('Approve', 'fv_tc') . '</a>';
}
/**
* Generate the anchor for delete function
*
* @param object $comment Comment object
*
* @return string HTML of the anchor
*/
function get_t_delete($comment) {
return '<a href="#" class="fv-tc-del" onclick="fv_tc_delete('.$comment->comment_ID.'); return false">' . __('Trash', 'fv_tc') . '</a>';
}
/**
* Generate the anchor for delete and ban IP function
*
* @param object $comment Comment object
*
* @return string HTML of the anchor
*/
function get_t_delete_ban($comment) {
return '<a href="#" class="fv-tc-ban" onclick="fv_tc_delete_ban('.$comment->comment_ID.',\''.$comment->comment_author_IP.'\'); return false">' . __('Trash & Ban IP', 'fv_tc') . '</a>';
}
/**
* Generate the anchor for delete thread function
*
* @param object $comment Comment object
*
* @return string HTML of the anchor
*/
function get_t_delete_thread($comment) {
return '<a href="#" class="fv-tc-delthread" onclick="fv_tc_delete_thread('.$comment->comment_ID.'); return false">' . __('Trash Thread', 'fv_tc') . '</a>';
}
/**
* Generate the anchor for delete thread and ban IP function
*
* @param object $comment Comment object
*
* @return string HTML of the anchor
*/
function get_t_delete_thread_ban($comment) {
return '<a href="#" class="fc-tc-banthread" onclick="fv_tc_delete_thread_ban('.$comment->comment_ID.',\''.$comment->comment_author_IP.'\'); return false">' . __('Trash Thread & Ban IP','fv_tc') . '</a>';
}
/**
* Generate the anchor for auto approving function
*
* @param object $comment Comment object
* @param bool $frontend Alters the anchor text if the function is used in backend.
*
* @return string HTML of the anchor
*/
function get_t_moderated($user_ID, $frontend = true) {
if($frontend)
$frontend2 = 'true';
else
$frontend2 = 'false';
$out = '<a href="#" class="commenter-'.$user_ID.'-moderated" onclick="fv_tc_moderated('.$user_ID.', '. $frontend2 .'); return false">';
if(!get_user_meta($user_ID,'fv_tc_moderated'))
if($frontend)
$out .= __('Allow user to comment without moderation','fv_tc') . '</a>';
else
$out .= __('Moderated', 'fv_tc') . '</a>';
else
if($frontend)
$out .= __('Moderate future comments by this user', 'fv_tc') . '</a>';
else
$out .= __('Unmoderated', 'fv_tc') . '</a>';
return $out;
}
/**
* Filter for pre_comment_approved. Skip moderation queue if the user is allowed to comment without moderation
*
* @params string $approved Current moderation queue status
*
* @global int Comment author user ID
*
* @return string New comment status
*/
function moderate($approved) {
global $user_ID;
///////////////////////////
/*global $wp_filter;
var_dump($wp_filter['pre_comment_approved']);
echo '<h3>before: </h3>';
var_dump($approved);
echo '<h3>fv_tc actions: </h3>';
if(get_user_meta($user_ID,'fv_tc_moderated')) {
echo '<p>putting into approved</p>';
}
else {
echo '<p>putting into unapproved</p>';
}
die('end');*/
/////////////////////////
if(get_user_meta($user_ID,'fv_tc_moderated'))
return true;
return $approved;
}
function fv_tc_admin_description(){
_e('Thoughtful Comments supercharges comment moderation by moving it into the front end (i.e. in context). It also allows banning by IP, email address or domain.', 'fv_tc');
}
function fv_tc_admin_comment_tweaks(){
$options = get_option('thoughtful_comments');
?>
<table class="optiontable form-table">
<tr valign="top">
<th scope="row"><?php _e('Automatic link shortening', 'fv_tc'); ?>:
<br/>
<select type="select" id="shorten_urls" name="shorten_urls">
<option value="0" <?php if($options['shorten_urls'] === true) echo "selected"; ?> >link to domain.com</option>
<option value="50" <?php if($options['shorten_urls'] === 50) echo "selected"; ?> >Shorten to 50 characters</option>
<option value="100" <?php if($options['shorten_urls'] === false) echo "selected"; ?> >Shorten to 100 characters</option>
</select>
</th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;"><fieldset><legend class="screen-reader-text"><span><?php _e('Link shortening', 'fv_tc'); ?></span></legend>
<td><label for="shorten_urls"><span><?php _e('Shortens the plain URL link text in comments to "link to: domain.com" or strip URL after N characters and add … at the end. Hides long ugly URLs', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Reply link', 'fv_tc'); ?> </th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;"><fieldset><legend class="screen-reader-text"><span><?php _e('Reply link', 'fv_tc'); ?></span></legend>
<input id="reply_link" type="checkbox" name="reply_link" value="1" <?php if( $options['reply_link'] ) echo 'checked="checked"'; ?> /></td>
<td><label for="reply_link"><span><?php _e('Disable HTML replies. <br /><small>(Lightens your server load. Reply function still works, but through JavaScript.)</small>', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<?php if( get_option('comment_whitelist') ): ?>
<tr valign="top">
<th scope="row"><?php _e('Comments before auto-approval', 'fv_tc'); ?> </th>
<td colspan="2"><fieldset><legend class="screen-reader-text"><span><?php _e('Comments before auto-approval', 'fv_tc'); ?></span></legend>
<input id="comment_autoapprove_count" type="text" name="comment_autoapprove_count" value="<?php echo ( isset($options['comment_autoapprove_count']) ) ? $options['comment_autoapprove_count'] : 1; ?>" />
<label for="reply_link"><span><?php _e('Number of approved comments before auto-approval', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<?php endif; ?>
<tr valign="top">
<th scope="row"><?php _e('Allow nicename change', 'fv_tc'); ?> </th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;"><fieldset><legend class="screen-reader-text"><span><?php _e('Allow nicename editing', 'fv_tc'); ?></span></legend>
<input id="user_nicename_edit" type="checkbox" name="user_nicename_edit" value="1"
<?php if( isset($options['user_nicename_edit']) && $options['user_nicename_edit'] ) echo 'checked="checked"'; ?> /></td>
<td><label for="user_nicename_edit"><span><?php _e('Allow site administrators to change user nicename (author URL) on the "Edit user" screen.', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<?php
$bCommentReg = get_option( 'comment_registration' );
if( isset( $bCommentReg ) && 1 == $bCommentReg ) { ?>
<tr valign="top">
<th scope="row"><?php _e('Reply link Keyword', 'fv_tc'); ?> </th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;"><fieldset><legend class="screen-reader-text"><span><?php _e('Reply link', 'fv_tc'); ?></span></legend>
<input id="tc_replyKW" type="text" name="tc_replyKW" size="10" value="<?php if( isset( $options['tc_replyKW'] ) ) echo $options['tc_replyKW']; else echo 'comment-'; ?>" /></td>
<td><label for="tc_replyKW"><span><?php _e('<strong>Advanced!</strong> Only change this if your "Log in to Reply" link doesn\'t bring the commenter back to the comment they wanted to comment on after logging in.', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<?php } ?>
<tr valign="top">
<th scope="row"><?php _e('Comment cache (advanced)', 'fv_tc'); ?> </th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;"><fieldset><legend class="screen-reader-text"><span><?php _e('Comment cache (advanced)', 'fv_tc'); ?></span></legend>
<input id="comment_cache" type="checkbox" name="comment_cache" value="1"
<?php if( isset($options['comment_cache']) && $options['comment_cache'] ) echo 'checked="checked"'; ?> /></td>
<td><label for="comment_cache"><span><?php _e('Caches the comments section of your posts into HTML files. If your posts have hundreds of comments and you don\'t want to use comment paging, this feature speeds up the PHP processing time considerably. Useful even if you use a WP cache plugin, as users see cached comments if they don\'t have an unapproved comment in the list.', 'fv_tc'); ?></span></label><br />
</td>
</tr>
<?php if( isset($options['comment_cache']) && $options['comment_cache'] ) : ?>
<tr valign="top">
<th scope="row"></th>
<td style="margin-bottom: 0; width: 11px; padding-right: 2px;">
</td>
<td>
<?php global $blog_id; ?>
<p><?php _e('Current cache directory: ', 'fv_tc'); echo WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/'; ?></p>
<p><?php _e('Cache files: ', 'fv_tc'); echo count( @glob(WP_CONTENT_DIR.'/cache/thoughtful-comments-'.$blog_id.'/*') ); ?></p>
<p>Hint: save Settings -> Discussion to purge the cache</p>
</td>
</tr>
<?php endif; ?>
</table>
<p>
<input type="submit" name="fv_feedburner_replacement_submit" class="button-primary" value="<?php _e('Save Changes', 'fv_tc') ?>" />
</p>
<?php
}
function fv_tc_admin_comment_instructions(){
?>
<table class="optiontable form-table">
<tr valign="top">
<th scope="row"></th>
<td><p><?php _e('After install with comments held up for moderation, you will notice several things on your site frontend:', 'fv_tc'); ?><br />
<?php _e('- comments held up for moderation appear with highlighted commenters name,', 'fv_tc'); ?><br />
<?php _e('- comments count in single posts or archives is highlighted if there are comments held up for moderation,', 'fv_tc'); ?><br />
<?php _e('- all comments have additional buttons for moderation.', 'fv_tc'); ?></p></td>
</tr>
<tr valign="top">
<th scope="row">Comment Moderation</th>
<td><img src="<?php echo $this->url; ?>/screenshot-1.png" alt="FV Thoughtful Comments frontend" style="max-width: 100%; height: auto;"></td>
</tr>
<tr valign="top">
<th scope="row">User Moderation</th>
<td>
<img src="<?php echo $this->url; ?>/screenshot-3.png" alt="FV Thoughtful Comments frontend" style="max-width: 100%; height: auto;"></td>
</tr>
</table>
<?php
}
function fv_tc_admin_enqueue_scripts(){
if( !isset($_GET['page']) || $_GET['page'] != 'manage_fv_thoughtful_comments' ) {
return;
}
wp_enqueue_script('postbox');
}
function options_panel() {
add_meta_box( 'fv_tc_description', 'Description', array( $this, 'fv_tc_admin_description' ), 'fv_tc_settings', 'normal' );
add_meta_box( 'fv_tc_comment_tweaks', 'Comment Tweaks', array( $this,'fv_tc_admin_comment_tweaks' ), 'fv_tc_settings', 'normal' );
add_meta_box( 'fv_tc_comment_instructions', 'Instructions', array( $this,'fv_tc_admin_comment_instructions' ), 'fv_tc_settings', 'normal' );
if (!empty($_POST)) :
check_admin_referer('thoughtful_comments');
$shorten_urls = false;
switch( $_POST['shorten_urls'] ){
case '0':
$shorten_urls = true;
break;
case '50':
$shorten_urls = 50;
break;
case '100':
$shorten_urls = false;
break;
}
$options = array(
'shorten_urls' => $shorten_urls,
'reply_link' => ( isset($_POST['reply_link']) && $_POST['reply_link'] ) ? true : false,
'comment_autoapprove_count' => ( isset($_POST['comment_autoapprove_count']) && intval($_POST['comment_autoapprove_count']) > 0 ) ? intval($_POST['comment_autoapprove_count']) : 1,
'tc_replyKW' => isset( $_POST['tc_replyKW'] ) ? $_POST['tc_replyKW'] : 'comment-',
'user_nicename_edit' => ( isset($_POST['user_nicename_edit']) && $_POST['user_nicename_edit'] ) ? true : false,
'comment_cache' => ( isset($_POST['comment_cache']) && $_POST['comment_cache'] ) ? true : false,
);
if( update_option( 'thoughtful_comments', $options ) ) :
?>
<div id="message" class="updated fade">
<p>
<strong>
<?php _e('Settings saved', 'fv_tc'); ?>
</strong>
</p>
</div>
<?php
endif; // update_option
endif; // $_POST
?>
<div class="wrap">
<div style="position: absolute; right: 20px; margin-top: 5px">
<a href="http://foliovision.com/seo-tools/wordpress/plugins/thoughtful-comments" target="_blank" title="Documentation"><img alt="visit foliovision" src="http://foliovision.com/shared/fv-logo.png" /></a>
</div>
<div>
<div id="icon-options-general" class="icon32"><br /></div>
<h2>FV Thoughtful Comments</h2>
</div>
<form method="post" action="">
<?php wp_nonce_field('thoughtful_comments') ?>
<div id="poststuff" class="ui-sortable">
<?php
do_meta_boxes('fv_tc_settings', 'normal', false );
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
</div>
</form>
</div>
<style>
#refresh-result{
margin-top: 20px;
}
#refresh-resultt td{
padding: 5px;
border: solid 1px #ccc;
}
</style>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
// close postboxes that should be closed
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
// postboxes setup
postboxes.add_postbox_toggles('fv_tc_settings');
});
//]]>
</script>
<?php
}
/**
* Action for wp_print_scripts - enqueues plugin js which is dependend on jquery. Improved in 0.2.3 ////
*
* @global int Current user ID
*/
function scripts() {
if( $this->loadScripts ) {
wp_enqueue_script('fv_tc',$this->url. '/js/fv_tc.js',array('jquery'), $this->strVersion, true);
wp_localize_script('fv_tc', 'fv_tc_translations', $this->get_js_translations());
wp_localize_script('fv_tc', 'fv_tc_ajaxurl', admin_url('admin-ajax.php'));
}
}
/**
* Filter for comments_number. Shows number of unapproved comments for every article in the frontend if the user can edit the post. In WP, all the unapproved comments are shown both to contributors and authors in wp-admin, but we don't do that in frontend.
*
* @global int Current user ID
* @global object Current post object
*
* @param string $content Text containing the number of comments.
*
* @return string Number of comments with inserted number of unapproved comments.
*/
function show_unapproved_count($content) {
global $user_ID;
global $post;
if($user_ID && current_user_can('edit_post', $post->ID)) {
if(function_exists('get_comments'))
$comments = get_comments( array('post_id' => $post->ID, 'order' => 'ASC', 'status' => 'hold') );
/* Legacy WP support */
else {
global $wpdb;
$comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = {$post->ID} AND comment_approved = '0' ORDER BY comment_date ASC");
}
$count = count($comments);
if($count!= 0) {
//return '<span class="tc_highlight"><abbr title="This post has '.$count.' unapproved comments">'.str_ireplace(' comm','/'.$count.'</abbr></span> comm',$content).'';
$content = preg_replace( '~(\d+)~', '<span class="tc_highlight"><abbr title="' . sprintf( _n( 'This post has one unapproved comment.', 'This post has %d unapproved comments.', $count, 'fv_tc' ), $count ) . '">$1</abbr></span>', $content );
return $content;
}
}
return $content;
}
/**
* Styling for the plugin
*/
function styles() {
global $post;
// this is executed in the header, so we can't do the check for every post on index/archive pages, so we better load styles if there are any unapproved comments to show. it's loaded even for contributors which don't need it.
if(!is_admin() && current_user_can('edit_posts')) {
echo '<link rel="stylesheet" href="'.$this->url.'/css/frontend.css?ver='.$this->strVersion.'" type="text/css" media="screen" />';
}
}
/**
* Thesis is not using comment_text filter. It uses thesis_hook_after_comment action, so this outputs our links
*
* @param string $new_status Empty string.
*/
function thesis_frontend_show($content) {
echo $this->frontend($content);
}
/**
* Call hooks for when a comment status transition occurs.
*
* @param string $new_status New comment status.
* @param string $old_status Previous comment status.
* @param object $comment Comment data.
*/
function transition_comment_status( $new_status, $old_status, $comment ) {
global $wpdb;
if( $old_status == 'trash' && $new_status != 'spam' ) { // restoring comment
$children = get_comment_meta( $comment->comment_ID, 'children', true );
if( $children && is_array( $children ) ) {
$children = implode( ',', $children );
$wpdb->query( "UPDATE $wpdb->comments SET comment_parent = '{$comment->comment_ID}' WHERE comment_ID IN ({$children}) " );
}
delete_comment_meta( $comment->comment_ID, 'children' );
}
if( $new_status == 'trash' ) { // trashing comment
if( function_exists( 'update_comment_meta' ) ) { // store children in meta
$children = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = '{$comment->comment_ID}' " );
if( $children ) {
update_comment_meta( $comment->comment_ID, 'children', $children );
}
} // assign new parents
$wpdb->query( "UPDATE $wpdb->comments SET comment_parent = '{$comment->comment_parent}' WHERE comment_parent = '{$comment->comment_ID}' " );
/*var_dump( $old_status );
echo ' -> ';
var_dump( $new_status ); // approved
die();*/
}
}
/**
* Shows unapproved comments bellow posts if user can moderate_comments. Hooked to comments_array. In WP, all the unapproved comments are shown both to contributors and authors in wp-admin, but we don't do that in frontend.
*
* @param array $comments Original array of the post comments, that means only the approved comments.
* @global int Current user ID.
* @global object Current post object.
*
* @return array Array of both approved and unapproved comments.
*/
function unapproved($comments) {
global $user_ID;
global $post;
/*if( count($comments) > 200 ) {
remove_filter( 'comment_text', 'wptexturize' );
remove_filter( 'comment_text', 'convert_smilies', 20 );
remove_filter( 'comment_text', 'wpautop', 30 );
add_filter( 'comment_text', array( $this, 'wpautop_lite' ), 30 );
}*/
/* Check user permissions */
if($user_ID && current_user_can('edit_post', $post->ID)) {
/* Use the standard WP function to get the comments */
if(function_exists('get_comments'))
$comments = get_comments( array('post_id' => $post->ID, 'order' => 'ASC') );
/* Use DB query for older WP versions */
else {
global $wpdb;
$comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = {$post->ID} AND comment_approved != 'spam' ORDER BY comment_date ASC");
}
/* Target array where both approved and unapproved comments are added */
$new_comments = array();
foreach($comments AS $comment) {
/* Don't display the spam comments */
if($comment->comment_approved == 'spam')
continue;
/* Highlight the comment author in case the comment isn't approved yet */
if($comment->comment_approved == '0') {
/* Alternative - highlight the comment content */
//$comment->comment_content = '<div id="comment-'.$comment->comment_ID.'-unapproved" style="background: #ffff99;">'.$comment->comment_content.'</div>';
$comment->comment_author = '<span id="comment-'.$comment->comment_ID.'-unapproved" class="tc_highlight">'.$comment->comment_author.'</span>';
}
$new_comments[] = $comment;
}
return $new_comments;
}
return $comments;
}
/* Experimental stuff */
/* mess with the WP blacklist mechanism */
function blacklist($author) {
$args = func_get_args();
echo '<p>'.$args[0].', '.$args[1].', '.$args[2].', '.$args[3].', '.$args[4].', '.$args[5].'</p>';
//die('blacklist dies');
}
function comment_moderation_headers( $message_headers ) {
$options = get_option('thoughtful_comments');
if( isset( $options['enhance_notify'] ) && $options['enhance_notify'] == false ) return $message_headers;
$message_headers .= "\r\n"."Content-Type: text/html"; // this should add up
return $message_headers;
}
function comment_moderation_text( $notify_message ) {
$options = get_option('thoughtful_comments');
if( isset( $options['enhance_notify'] ) && $options['enhance_notify'] == false ) return $notify_message;