/
class-bwp-recent-comments.php
1398 lines (1245 loc) · 59 KB
/
class-bwp-recent-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
/**
* Copyright (c) 2013 Khang Minh <betterwp.net>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* The template function to get a recent comment list
*
* If you don't provide any parameter, the list will be generated using options in the database (let's call this a global list).
* The $instance parameter allows you to build a "unique" comment list that is different from other comment lists
* Example use would be you create a comment list for post type A, and create another one for post type B
* while you still have a global list to display everything in one place.
* Support for different categories in my opinion is not necessary, it might be added in the future, if it has enough requests ;-)
*
* @param array $args hold all parameters
* @param bool $echo determine whether to echo or return the output
* @param bool $need_refresh determine whether to refresh the output or not
*/
function bwp_get_recent_comments($args = array(), $echo = true, $need_refresh = false)
{
global $bwp_rc;
if (!is_array($args)) return;
$defaults = $bwp_rc->get_default_parameters();
$args = wp_parse_args($args, $defaults);
extract($args);
return $bwp_rc->get_recent_comments($echo, $need_refresh, $instance, $post_type, $post_id, $comment_type, $separate, $limit, $tb_limit, $order, $custom_args = array('grouped' => $grouped, 'ajax' => $ajax, 'prev_str' => $prev_str, 'next_str' => $next_str), $paged, $paged_limit, $paged_template);
}
/**
* Derivative function for lazy people
*/
function bwp_get_recent_trackbacks()
{
return bwp_get_recent_comments(array('comment_type' => 'tb'));
}
/**
* Display a pagination for a static page
*
* @since 1.1.0
*/
function bwp_rc_get_pagination($limit, $prev_str = '', $next_str = '')
{
global $bwp_rc_left;
if (empty($limit)) return;
if (is_singular())
{
$paged = (int) get_query_var('bwprc_paged');
$paged = (empty($paged) || 0 > $paged) ? 1 : $paged;
$link = get_permalink();
// Previous comment link
$prev = ($paged > 1) ? sprintf('<a href="%s" title="' . __('Previous Comment Page', 'bwp-rc') . '">' . $prev_str . '</a> ', add_query_arg('bwprc_paged', $paged - 1, $link)) : '';
// Next comment link
$next = ($bwp_rc_left > $limit) ? sprintf('<a href="%s" title="' . __('Next Comment Page', 'bwp-rc') . '">' . $next_str . '</a>', add_query_arg('bwprc_paged', ($paged == 0) ? 2 : $paged + 1, $link)) : '';
// Output pagination
return apply_filters('bwp_rc_before_pagination', '') . "\n" . $prev . $next;
}
}
/**
* Display a paginated comment list
*
* @since 1.1.0
*/
function bwp_rc_paged_list($args = array(), $limit = 5, $prev_str = '««', $next_str = '»»', $echo = true)
{
$limit = (int) $limit; // number of comments per page
$paged = get_query_var('bwprc_paged'); // get the current page
$paged = (empty($paged) || 0 > $paged) ? 1 : $paged;
$args['paged'] = $paged;
$args['paged_limit'] = $limit;
$args['paged_template'] = true;
$args['prev_str'] = $prev_str;
$args['next_str'] = $next_str;
if ($echo)
bwp_get_recent_comments($args, true, true);
else
return bwp_get_recent_comments($args, false, true);
}
if (!class_exists('BWP_FRAMEWORK'))
require_once(dirname(__FILE__) . '/class-bwp-framework.php');
class BWP_RC extends BWP_FRAMEWORK {
/**
* Hold all instances of lists
*/
var $instances;
/**
* Default parameters for comments
*/
var $default_parameters;
/**
* Constructor
*/
function __construct($version = '1.2.2')
{
// Plugin's title
$this->plugin_title = 'BetterWP Recent Comments';
// Plugin's version
$this->set_version($version);
// Basic version checking
if (!$this->check_required_versions())
return;
// The default options
$options = array(
'input_comments' => 5,
'input_tbs' => 0,
'input_group_comments' => 0,
'select_output_method' => 'only_comments',
'select_order' => 'desc',
'enable_gravatars' => 'yes', // cb1
'input_gravatar_width' => 40,
'enable_smilies' => 'yes', // cb2
'input_title_trim' => 0,
'input_trim' => 25,
'select_long_method' => 'long_overflow',
'input_chunk' => 15,
'input_date' => 'M d, g:i A',
'input_ignore_ids' => '',
'disable_own_tb' => '', // cb4
'enable_css' => 'yes', // cb5
'enable_credit' => '', // cb6
'enable_ajax_nav' => '',
'input_no_found' => __('No recent %s found.', 'bwp-rc'),
'input_trimmed' => __('This %s has been trimmed to empty.', 'bwp-rc'),
'template_comment' => '<li class="recent-comment"><span class="recent-comment-avatar">%avatar%</span><span class="recent-comment-single"><span class="recent-comment-author">%author%</span><span class="recent-comment-text"> { %excerpt% } – </span> <a href="%link%" title="%post_title_attr%"><strong>%time%</strong></a></span></li>',
'template_paged_comment'=> '<li class="recent-comment"><span class="recent-comment-avatar">%avatar%</span><span class="recent-comment-single"><span class="recent-comment-author">%author%</span><span class="recent-comment-text"> { %excerpt% } – </span> <a href="%link%" title="%post_title_attr%"><strong>%time%</strong></a></span></li>',
'template_owner' => '',
'template_tbpb' => '<li class="recent-comment recent-comment-tb"><span class="recent-comment-single"><span class="recent-comment-author"><a href="%author_url%"><strong>%author%</strong></a></span><span class="recent-comment-text"> { %excerpt% } </span></span></li>',
'template_group_header' => '<li><strong><a href="%post_link%" title="%post_title_attr%">%post_title%</a> (<a href="#" title="' . __('This post has a total of %comment_count% comment(s)', 'bwp-rc') . '">%comment_count%</a>)</strong><ul>',
'template_group_footer' => '</ul></li>',
'template_ajax_older' => '<a title="' . __('View older comments', 'bwp-rc') . '" href="#" class="bwp-rc-older-nav">' . __('Older »', 'bwp-rc') . '</a>',
'template_ajax_newer' => '<a title="' . __('View newer comments', 'bwp-rc') . '" href="#" class="bwp-rc-newer-nav">' . __('« Newer', 'bwp-rc') . '</a>'
);
$this->build_properties('BWP_RC', 'bwp-rc', $options, 'BetterWP Recent Comments', dirname(dirname(__FILE__)) . '/bwp-recent-comments.php', 'http://betterwp.net/wordpress-plugins/bwp-recent-comments/', false);
$this->add_option_key('BWP_RC_OPTION_GENERAL', 'bwp_rc_general', __('General Options', 'bwp-rc'));
$this->add_option_key('BWP_RC_OPTION_TEMPLATE', 'bwp_rc_template', __('Template Options', 'bwp-rc'));
$this->add_extra_option_key('BWP_RC_INSTANCES', 'bwp_rc_instances', __('Instances', 'bwp-rc'));
// Define other constants
define('BWP_RC_COPYRIGHT', __('Generated by <a href="%s" title="Recent Comment Plugin">BWP Recent Comments</a>.', 'bwp-rc'));
define('BWP_RC_LIST', 'bwp_rc_list');
$this->default_parameters = array(
'instance' => BWP_RC_LIST, // the instance name for a separate comment list you would like to use.
'post_type' => '', // get comments for a specific post type only
'post_id' => '', // get comments from a specific post/page/custom post type, can be either the ID or postname
'comment_type' => '', // get only a specific comment type, 'comment': comment, 'tb': pingback or trackback, 'all': all types of comment
'limit' => 0, // determine how many comments to return, 0 to use option in db
'tb_limit' => 0, // determine how many trackbacks to return, 0 to use option in db, only used when separate is true
'order' => '', // determine how to sort the result, empty to use option in db
'separate' => false, // should we separate between comments and pingbacks/trackbacks
'paged' => NULL, // display paged comments
'paged_limit' => 5, // number of comments per page
'paged_template' => false,
'grouped' => 0, // set this to the number of comments per post, 0 to disable. The total number of comments will not exceed the 'limit' argument
'ajax' => false, // whether or not add ajax navigation
'prev_str' => '«',
'next_str' => '»'
);
// initialize instances
$db_instances = get_option('bwp_rc_instances');
if (!$db_instances || !is_array($db_instances))
$this->reset_instances();
else
$this->instances = $db_instances;
$this->init();
}
function insert_query_vars($vars)
{
array_push($vars, 'bwprc_paged');
return $vars;
}
function add_hooks()
{
// Actions and Filters
add_action('comment_post', array($this, 'comment_before_add'), 10, 2);
// Clear cache when necessary
add_action('edit_comment', array($this, 'clear_recent_comment_cache'));
add_action('delete_comment', array($this, 'clear_recent_comment_cache'));
add_action('delete_post', array($this, 'clear_recent_comment_cache'));
add_action('switch_theme', array($this, 'clear_recent_comment_cache'));
add_action('wp_set_comment_status', array($this, 'clear_recent_comment_cache'));
add_action('bwp_rc_access_options', array($this, 'clear_recent_comment_cache'));
add_action('bwp_rc_form_loaded', array($this, 'clear_recent_comment_cache'));
// Pagination query var - @since 1.1.0
add_filter('query_vars', array($this, 'insert_query_vars'));
// Shortcode for paged comment list - @since 1.2.0
add_shortcode('bwp-rc', array($this, 'parse_rc_shortcode'));
// Handle AJAX navigation request - @since 1.2.0
if ($this->is_ajax_nav_enabled() && isset($_GET['bwp_doing_ajax']))
{
if (!defined('DOING_AJAX'))
define('DOING_AJAX', true);
define('BWP_RC_DOING_AJAX', true);
add_action('init', array($this, 'handle_ajax_request'));
}
// Add the widget, only if WordPress's version is 2.9 or higher
if (version_compare(get_bloginfo('version'), '2.9', '>='))
{
require_once(dirname(__FILE__) . '/class-bwp-rc-widget.php');
add_action('widgets_init', 'bwp_recent_comment_register_widget');
}
}
private function is_ajax_nav_enabled()
{
if ('yes' == $this->options['enable_ajax_nav'])
return true;
foreach ($this->instances as $instance)
if (!empty($instance['ajax']))
return true;
return false;
}
function front_print_js()
{
if (!defined('BWP_AJAX_URL'))
{
?>
<script type="text/javascript">
var bwp_ajax_url = '<?php echo get_option('home'); ?>/';
</script>
<?php
define('BWP_AJAX_URL', true);
}
}
function enqueue_media()
{
if (!is_admin())
{
$css_file = ('yes' == $this->options['enable_gravatars']) ? 'bwp-recent-comments.css' : 'bwp-recent-comments-noava.css';
if ('yes' == $this->options['enable_css'])
wp_enqueue_style('bwp-rc', BWP_RC_CSS . '/' . $css_file, array(), $this->plugin_ver);
if ($this->is_ajax_nav_enabled())
{
wp_enqueue_script('bwp-rc', BWP_RC_JS . '/bwp-rc-ajax.js', array('jquery'), $this->plugin_ver);
add_action('wp_head', array($this, 'front_print_js'));
}
}
else
wp_enqueue_style('bwp-rc', BWP_RC_CSS . '/bwp-rc-widget.css');
}
function uninstall()
{
$db_instances = get_option(BWP_RC_INSTANCES);
if ($db_instances && is_array($db_instances))
{
foreach ($db_instances as $key => $instance)
delete_option($key);
delete_option(BWP_RC_INSTANCES);
}
}
/**
* Build the Menus
*/
function build_menus()
{
// Give BWP RC its own menus - create plugin's own menu if allowed
if (!empty(self::$_menu_under_settings))
{
add_options_page(__('BWP Recent Comments General Options', 'bwp-rc'), __('RC General Options', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_OPTION_GENERAL, array($this, 'build_option_pages'));
add_options_page(__('BWP Recent Comments Template Options', 'bwp-rc'), __('RC Template Options', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_OPTION_TEMPLATE, array($this, 'build_option_pages'));
add_options_page(__('BWP Recent Comments Instance List', 'bwp-rc'), __('RC Instances', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_INSTANCES, array($this, 'build_option_pages'));
}
else
{
add_menu_page(__('Better WordPress Recent Comments', 'bwp-rc'), 'BWP RC', BWP_RC_CAPABILITY, BWP_RC_OPTION_GENERAL, array($this, 'build_option_pages'), BWP_RC_IMAGES . '/icon_menu.png');
// Sub menus
add_submenu_page(BWP_RC_OPTION_GENERAL, __('BWP Recent Comments General Options', 'bwp-rc'), __('General Options', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_OPTION_GENERAL, array($this, 'build_option_pages'));
add_submenu_page(BWP_RC_OPTION_GENERAL, __('BWP Recent Comments Template Options', 'bwp-rc'), __('Template Options', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_OPTION_TEMPLATE, array($this, 'build_option_pages'));
add_submenu_page(BWP_RC_OPTION_GENERAL, __('BWP Recent Comments Instance List', 'bwp-rc'), __('Instances', 'bwp-rc'), BWP_RC_CAPABILITY, BWP_RC_INSTANCES, array($this, 'build_option_pages'));
}
}
/**
* Build the option pages
*
* Utilizes BWP Option Page Builder (@see BWP_OPTION_PAGE)
*/
function build_option_pages()
{
if (!current_user_can(BWP_RC_CAPABILITY))
wp_die(__('You do not have sufficient permissions to access this page.'));
// Init the class
$page = $_GET['page'];
$bwp_option_page = new BWP_OPTION_PAGE($page, array(), 'bwp-rc');
$options = array();
if (!empty($page))
{
if ($page == BWP_RC_OPTION_GENERAL)
{
$bwp_option_page->set_current_tab(1);
// Option Structures - Form
$form = array(
'items' => array('input', 'input', 'select', 'input', 'select', 'checkbox', 'heading', 'checkbox', 'checkbox', 'input', 'input', 'select', 'input', 'input', 'heading', 'input', 'input', 'input', 'checkbox', 'checkbox', 'checkbox'),
'item_labels' => array
(
__('Show at most', 'bwp-rc'),
__('Show at most', 'bwp-rc'),
__('Choose an output method', 'bwp-rc'),
__('Group at most', 'bwp-rc'),
__('Show', 'bwp-rc'),
__('Enable AJAX navigation?', 'bwp-rc'),
__('Formatting Options', 'bwp-rc'),
__('Enable gravatars?', 'bwp-rc'),
__('Convert smilies?', 'bwp-rc'),
__('Trim post titles to', 'bwp-rc'),
__('Trim comments to', 'bwp-rc'),
__('With long words, this plugin should', 'bwp-rc'),
__('Split into chunks of', 'bwp-rc'),
__('Choose a date format', 'bwp-rc'),
__('Miscellaneous', 'bwp-rc'),
__('Show this message', 'bwp-rc'),
__('Show this message', 'bwp-rc'),
__('Hide comments by specific ids', 'bwp-rc'),
__('Disable trackbacks/pingbacks from this website?', 'bwp-rc'),
__('Use CSS provided by this plugin?', 'bwp-rc'),
__('Give the author credits?', 'bwp-rc')
),
'heading' => array(
'h1' => __('<em>This section allows you to customize how recent comments would appear on your website. Currently, options in this section are global which mean they will affect all recent comment list instances you create.</em>', 'bwp-rc'),
'h2' => __('<em>Other options that fit nowhere.</em>', 'bwp-rc'),
),
'item_names' => array('input_comments', 'input_tbs', 'select_output_method', 'input_group_comments', 'select_order', 'cb7', 'h1', 'cb1', 'cb2', 'input_title_trim', 'input_trim', 'select_long_method', 'input_chunk', 'input_date', 'h2', 'input_no_found', 'input_trimmed', 'input_ignore_ids', 'cb4', 'cb5', 'cb6'),
'checkbox' => array
(
'cb1' => array(__('and each gravatar will be', 'bwp-rc') => 'enable_gravatars'),
'cb2' => array(__('Smilies such as <code>:-)</code> and <code>:-P</code> will be converted to icons.', 'bwp-rc') => 'enable_smilies'),
//'cb3' => array(__('Comments posted by you will be ignored.', 'bwp-rc') => 'disable_own_com'),
'cb4' => array(sprintf(__('All trackbacks/pingbacks originating from <code>%s</code> will be ignored.', 'bwp-rc'), get_option('home')) => 'disable_own_tb'),
'cb5' => array(__('If you disable this, be sure to add needed styles to your own stylesheets.', 'bwp-rc') => 'enable_css'),
'cb6' => array(__('A link to this plugin\'s official page will be added to the end of the of output of the first recent comment instance (i.e. only once). Thank you!', 'bwp-rc') => 'enable_credit'),
'cb7' => array(__('Navigation links will be added to the end of your comment list so that visitors can browse through them conveniently. You can also edit the templates for those links in the Template tab.', 'bwp-rc') => 'enable_ajax_nav')
),
'select' => array
(
'select_output_method' => array(
__('Do not show trackbacks/pingbacks', 'bwp-rc') => 'only_comments',
__('Show all comment types together', 'bwp-rc') => 'all_comments',
__('Show all comment types, but separately', 'bwp-rc') => 'all_sep_comments',
),
'select_order' => array(
__('Newer comments first', 'bwp-rc') => 'desc',
__('Older comments first', 'bwp-rc') => 'asc'
),
'select_long_method' => array(
__('Let the style handle the overflow', 'bwp-rc') => 'long_overflow',
__('Split the words into smaller chunks', 'bwp-rc') => 'long_break'
)
),
'input' => array
(
'input_comments' => array('size' => 5, 'label' => __('recent comments.', 'bwp-rc')),
'input_tbs' => array('size' => 5, 'label' => __('recent trackbacks/pingbacks (used when choose "separate" as output method.)', 'bwp-rc')),
'input_group_comments' => array('size' => 5, 'label' => __('comments for each post (0 to disable)', 'bwp-rc')),
'input_date' => array('size' => 10, 'label' => __('To choose an appropriate format, please consult <a href="http://codex.wordpress.org/Formatting_Date_and_Time" target="_blank">WordPress Codex</a>.', 'bwp-rc')),
'input_gravatar_width' => array('size' => 5, 'label' => __('pxs wide.', 'bwp-rc')),
'input_title_trim' => array('size' => 5, 'label' => __('words. If you specify <code>0</code>, no trim will occur.', 'bwp-rc')),
'input_trim' => array('size' => 5, 'label' => __('words. If you specify <code>0</code>, no trim will occur (not recommended).', 'bwp-rc')),
'input_chunk' => array('size' => 5, 'label' => __('characters. If you choose to split the long words, it will be split into chunks with such characters maximum.', 'bwp-rc')),
'input_no_found' => array('size' => 40, 'label' => __('when no comment/pingbacks found.', 'bwp-rc')),
'input_trimmed' => array('size' => 40, 'label' => __('when the comment excerpt is trimmed to empty.', 'bwp-rc')),
'input_ignore_ids' => array('size' => 20, 'label' => __('Separate user ids by commas, e.g. 1,2,3. Leave blank if not used.', 'bwp-rc'))
),
'container' => array
(
'cb7' => __('<em><strong>Note:</strong> If you use the template function <code>bwp_get_recent_comments()</code> or widgets to show the comment list, you can override the options here. Please note that you can not override options for the global list.</em>', 'bwp-rc'),
'input_chunk' => __('<em><strong>Note:</strong> Long words (without spaces) posted by visitors, such as <code>YEAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH</code>, might break your layout. If you use the default css provided by this plugin, it should handle such behaviour already (by adding <code>overflow: hidden</code> to the <code>recent-comment-text</code> class.) Splitting long words might result in unexpected results so it\'s best to just stick to css. If you want, you can use both methods, of course!</em>', 'bwp-rc')
),
'inline_fields' => array(
'cb1' => array('input_gravatar_width' => 'input')
)
);
// Get the default options
$options = $bwp_option_page->get_options(array('input_comments', 'input_tbs', 'select_output_method', 'input_group_comments', 'select_order', 'enable_gravatars', 'input_gravatar_width', 'enable_smilies', 'input_title_trim', 'input_trim', 'select_long_method', 'input_chunk', 'input_date', 'enable_css', 'enable_credit', 'input_ignore_ids', 'disable_own_tb', 'input_no_found', 'input_trimmed', 'enable_selective', 'enable_ajax_nav'), $this->options);
// Get option from the database
$options = $bwp_option_page->get_db_options($page, $options);
$option_formats = array('input_comments' => 'int', 'input_tbs' => 'int', 'input_group_comments' => 'int', 'input_gravatar_width' => 'int', 'input_title_trim' => 'int', 'input_trim' => 'int', 'input_chunk' => 'int', 'input_no_found' => 'html', 'input_trimmed' => 'html');
}
else if ($page == BWP_RC_OPTION_TEMPLATE)
{
$bwp_option_page->set_current_tab(2);
add_filter('bwp_ad_showable', function() { return false;});
// Option Structures - Form
$form = array(
'items' => array('heading', 'textarea', 'textarea', 'textarea', 'textarea', 'heading', 'textarea', 'textarea', 'heading', 'textarea', 'textarea'),
'item_labels' => array
(
__('Templates for your recent comment list', 'bwp-rc'),
__('Template for comments', 'bwp-rc'),
__('Template for trackbacks/pingbacks', 'bwp-rc'),
__('Template for comments by you', 'bwp-rc'),
sprintf(__('Template for paginated comments on a separate page — <a href="%s#comments_on_page" target="_blank">more info</a>', 'bwp-rc'), $this->plugin_url),
__('Templates for grouped comments', 'bwp-rc'),
__('Header template for a comment group, should start with <code><li></code> and end with <code><ul></code>', 'bwp-rc'),
__('Footer template for a comment group, should start with <code></ul></code> and end with <code></li></code>', 'bwp-rc'),
__('Templates for AJAX navigation', 'bwp-rc'),
__('<em>View older comments</em> template', 'bwp-rc'),
__('<em>View newer comments</em> template ', 'bwp-rc')
),
'item_names' => array('h1', 'template_comment', 'template_tbpb', 'template_owner', 'template_paged_comment', 'h2', 'template_group_header', 'template_group_footer', 'h3', 'template_ajax_older', 'template_ajax_newer'),
'heading' => array(
'h1' => __('<em>This section allows you to define your own template. Use tags listed below to add appropriate contents. Please note that after you press reset, you still have to press submit changes for the changes to be saved.</em>', 'bwp-rc'),
'h2' => __('<em>Edit the header and footer templates for a comment group. All tags listed above can be used.</em>', 'bwp-rc'),
'h3' => __('<em>Edit the Older and Newer buttons for AJAX navigation. Make sure the CSS classes, i.e. <strong>bwp-rc-older-nav</strong> and <strong>bwp-rc-newer-nav</strong> are left untouched. If you would like to add more classes to style, add them like this: <code>class="bwp-rc-older-nav my-class1 my-class2"</code>.</em>', 'bwp-rc')
),
'textarea' => array
(
'template_comment' => array('cols' => 70, 'rows' => 5),
'template_paged_comment' => array('cols' => 70, 'rows' => 5),
'template_owner' => array('cols' => 70, 'rows' => 5),
'template_tbpb' => array('cols' => 70, 'rows' => 5),
'template_group_header' => array('cols' => 70, 'rows' => 5),
'template_group_footer' => array('cols' => 70, 'rows' => 5),
'template_ajax_older' => array('cols' => 70, 'rows' => 2),
'template_ajax_newer' => array('cols' => 70, 'rows' => 2),
),
'inline' => array
(
'template_comment' => '<br /><br /><input type="submit" class="button" name="reset_comment" value="' . __('Reset', 'bwp-rc') . '" />',
'template_paged_comment' => '<br /><br /><input type="submit" class="button" name="reset_paged" value="' . __('Reset', 'bwp-rc') . '" />',
'template_owner' => '<br /><br /><em>' . __('Leave this blank if you do not wish to use.', 'bwp-rc') . '</em>',
'template_tbpb' => '<br /><br /><input type="submit" class="button" name="reset_tbpb" value="' . __('Reset', 'bwp-rc') . '" />',
'template_group_header' => '<br /><br /><input type="submit" class="button" name="reset_group_header" value="' . __('Reset', 'bwp-rc') . '" />',
'template_group_footer' => '<br /><br /><input type="submit" class="button" name="reset_group_footer" value="' . __('Reset', 'bwp-rc') . '" />',
'template_ajax_older' => '<br /><br /><input type="submit" class="button" name="reset_ajax_older" value="' . __('Reset', 'bwp-rc') . '" />',
'template_ajax_newer' => '<br /><br /><input type="submit" class="button" name="reset_ajax_newer" value="' . __('Reset', 'bwp-rc') . '" />'
),
'container' => array(
'h1' => '
<code>%excerpt%</code> - <em>' . __('Trimmed down comment', 'bwp-rc') . '</em><br />
<code>%link%</code> - <em>' . __('The comment\'s permalink', 'bwp-rc') . '</em><br />
<code>%author%</code> - <em>' . __('The name of the visitor', 'bwp-rc') . '</em><br />
<code>%author_url%</code> - <em>' . __('Link to the author\'s website or trackback/pingback\'s source', 'bwp-rc') . '</em><br />
<code>%author_archive%</code> - <em>' . __('Link to the author\'s post archive, if none found, author\'s name will be used', 'bwp-rc') . '</em><br />
<code>%time%</code> - <em>' . __('The timestamp of the comment', 'bwp-rc') . '</em><br />
<code>%avatar%</code> - <em>' . __('Avatar of the visitor (in HTML)', 'bwp-rc') . '</em><br />
<code>%post_title%</code> - <em>' . __('Title of the post', 'bwp-rc') . '</em><br />
<code>%post_title_attr%</code> - <em>' .__('Title of the post that has been properly escaped for title attribute', 'bwp-rc') . '</em><br />
<code>%post_link%</code> - <em>' . __('The post\'s permalink', 'bwp-rc') . '</em><br />
<code>%comment_count%</code> - <em>' . __('The post\'s comment count', 'bwp-rc') . '</em><br />
<code>%home%</code> - <em>' . __('The URL to your homepage', 'bwp-rc') . '</em><br />
<code>%comment_number%</code> - <em>' . __('A comment\'s ordinal number (#1, #2, #3, etc.)', 'bwp-rc') . '</em>')
);
// Get the default options
$options = $bwp_option_page->get_options(array('template_comment', 'template_paged_comment', 'template_tbpb', 'template_owner', 'template_group_header', 'template_group_footer', 'template_ajax_older', 'template_ajax_newer'), $this->options);
// Get option from the database
$options = $bwp_option_page->get_db_options($page, $options);
$option_formats = array('template_comment' => 'html', 'template_paged_comment' => 'html', 'template_tbpb' => 'html', 'template_owner' => 'html', 'template_group_header' => 'html', 'template_group_footer' => 'html', 'template_ajax_older' => 'html', 'template_ajax_newer' => 'html');
// Reset button
if (isset($_POST['reset_comment']))
$options['template_comment'] = $this->options_default['template_comment'];
if (isset($_POST['reset_tbpb']))
$options['template_tbpb'] = $this->options_default['template_tbpb'];
if (isset($_POST['reset_paged']))
$options['template_paged_comment'] = $this->options_default['template_paged_comment'];
if (isset($_POST['reset_group_header']))
$options['template_group_header'] = $this->options_default['template_group_header'];
if (isset($_POST['reset_group_footer']))
$options['template_group_footer'] = $this->options_default['template_group_footer'];
if (isset($_POST['reset_ajax_older']))
$options['template_ajax_older'] = $this->options_default['template_ajax_older'];
if (isset($_POST['reset_ajax_newer']))
$options['template_ajax_newer'] = $this->options_default['template_ajax_newer'];
}
else if ($page == BWP_RC_INSTANCES)
{
$bwp_option_page->set_current_tab(3);
// Option Structures - Form
$form = array(
'items' => array('heading', 'select', 'heading'),
'item_labels' => array
(
__('List of all instances you have created', 'bwp-rc'),
__('Choose an instance to delete', 'bwp-rc'),
__('Reset all instances', 'bwp-rc')
),
'item_names' => array('h1', 'sel1', 'h2'),
'heading' => array(
'h1' => __('Here you can see all instances you have created and currently you can delete any instance you don\'t use anymore.', 'bwp-rc'),
'h2' => __('If for some reasons you can not delelete an instance above (mostly because of malformed instances produced by previous versions\' bugs), you will have to reset all your instances here. Don\'t worry, though, all instances should be re-created automatically after you refresh public pages with comment instances on them.', 'bwp-rc')
),
'select' => array
(
'sel1' => array(__('----------', 'bwp-rc') => '')
),
'container' => array
(
'sel1' => '<input type="submit" class="button" name="delete_instance" value="' . __('Delete selected instance', 'bwp-rc') . '" />',
'h2' => '<input type="submit" class="button" name="reset_instances" value="' . __('Reset all instances now!', 'bwp-rc') . '" />'
)
);
if (isset($_POST['delete_instance']) && !empty($_POST['sel1']) && isset($this->instances[$_POST['sel1']]))
{
check_admin_referer($page);
delete_option($_POST['sel1']);
unset($this->instances[$_POST['sel1']]);
update_option(BWP_RC_INSTANCES, $this->instances);
}
else if (isset($_POST['reset_instances']))
$this->reset_instances();
$options = NULL;
// @since 1.0.1
if (!is_array($this->instances))
$this->reset_instances();
foreach ($this->instances as $instance_name => $instance)
{
if ($instance_name != BWP_RC_LIST)
$form['select']['sel1'][$this->str_replace_first('bwp_rc_instance_', '', $instance_name)] = $instance_name;
}
$option_formats = array();
add_filter('bwp_option_submit_button', create_function('', 'return "";'));
}
}
// Get option from user input
if (isset($_POST['submit_' . $bwp_option_page->get_form_name()]) && isset($options) && is_array($options))
{
check_admin_referer($page);
foreach ($options as $key => &$option)
{
if (isset($_POST[$key]))
$bwp_option_page->format_field($key, $option_formats);
if (!isset($_POST[$key]))
$option = '';
else if (isset($option_formats[$key]) && 0 == $_POST[$key] && 'int' == $option_formats[$key])
$option = 0;
else if (isset($option_formats[$key]) && empty($_POST[$key]) && 'int' == $option_formats[$key])
$option = $this->options_default[$key];
else if (!empty($_POST[$key]))
$option = trim(stripslashes($_POST[$key]));
else
$option = '';
}
update_option($page, $options);
// Update options successfully
$this->add_notice(__('All options have been saved.', 'bwp-rc'));
// Do this for this plugin only
$this->options = array_merge($this->options, $options);
}
// Assign the form and option array
$bwp_option_page->init($form, $options, $this->form_tabs);
// Build the option page
echo $bwp_option_page->generate_html_form();
// update the comment list automatically
do_action('bwp_rc_form_loaded');
}
/**
* Make the instance name db safe
*
* @since 1.0.1
*/
function format_instance_name($name = '')
{
$name = trim(strtolower($name));
return preg_replace('/[^a-z0-9-_\s]/ui', '', $name);
}
/**
* Reset all instances to its safe point
*
* @since 1.0.1
*/
function reset_instances()
{
$this->instances = array(BWP_RC_LIST => array());
update_option(BWP_RC_INSTANCES, $this->instances);
}
function str_replace_first($search, $replace, $subject)
{
$pos = strpos($subject, $search);
if ($pos !== false)
$subject = substr_replace($subject, $replace, $pos, strlen($search));
return $subject;
}
function get_instances()
{
return $this->instances;
}
function get_default_parameters()
{
return $this->default_parameters;
}
function is_credit_enable()
{
return $this->options['enable_credit'];
}
/**
* Trim a text to a certain number of words, adding a dotdotdot if necessary, and add break to long words.
*
* @param string $text The text to trim
* @param int $length The length you want to trim to
* @param boolean $chunk Split long words to chunks of this length
* @param boolean $autop Automatically add paragraph
*/
function trim_comment_excerpt($text = '', $length = 50, $chunk = 0, $autop = false)
{
if (empty($text))
return '';
// ensure that no comment has double spaces
$text = trim($text);
$text = preg_replace('/\s+/iu', ' ', $text);
$actual_length = count(explode(' ', $text));
$dotdotdot = ($actual_length > $length) ? apply_filters('bwp_rc_dotdotdot', '...') : '';
$words = explode(' ', $text, $length + 1);
if (count($words) > $length)
array_pop($words);
if (!empty($chunk))
{
$text = '';
foreach ($words as $word)
{
$tmp = preg_split("//u", $word, -1, PREG_SPLIT_NO_EMPTY);
if (0 < sizeof($tmp))
{
$wl = sizeof($tmp);
if ($chunk < $wl)
{
$text_chunked = array_chunk($tmp, $chunk);
foreach ($text_chunked as $chunked)
{
$text .= implode('', $chunked) . ' ';
}
}
else
$text .= $word . ' ';
}
}
//$text = preg_replace('#(\S{' . $chunk . ',})#eiu', "chunk_split('$1', $chunk, ' ')", $text);
}
else
$text = implode(' ', $words);
$text .= $dotdotdot;
if ($autop == true) $text = wpautop($text);
return trim($text);
}
/**
* Generate a group header for a group comments
*/
function generate_a_group($comment, $type = 'header')
{
if (!empty($type) && 'header' == $type)
$comment_template = $this->options['template_group_header'] . "\n";
if (!empty($type) && 'footer' == $type)
$comment_template = $this->options['template_group_footer'] . "\n";
// Magic happens here
$comment_string = $comment_template;
foreach ($comment as $key => $value)
$comment_string = str_replace('%' . $key . '%', $value, $comment_string);
return $comment_string;
}
/**
* Generate a single comment
*/
function generate_a_comment($comment, $type = '')
{
if (!empty($type) && 'paged' == $type)
$comment_template = $this->options['template_paged_comment'] . "\n";
else if (!empty($this->options['template_owner']) && 1 == $comment['user_id'])
$comment_template = $this->options['template_owner'] . "\n";
else if (empty($comment['type']))
$comment_template = $this->options['template_comment'] . "\n";
else
$comment_template = $this->options['template_tbpb'] . "\n";
// Magic happens here
$comment_string = $comment_template;
foreach ($comment as $key => $value)
$comment_string = str_replace('%' . $key . '%', $value, $comment_string);
return $comment_string;
}
function is_comment_showable($comment_type, $commentdata)
{
switch ($comment_type)
{
case 'comment':
if ($commentdata['comment_type'] == '')
return true;
break;
case 'tb':
if ($commentdata['comment_type'] == 'trackback' || $commentdata['comment_type'] == 'pingback')
return true;
break;
case 'all':
case '':
return true;
break;
}
return false;
}
/**
* Format comment contents
*/
function format_comment($commentdata)
{
$comment = array();
$comment['comment_number'] = isset($commentdata['comment_number']) ? $commentdata['comment_number'] : '';
$comment['pid'] = $commentdata['comment_post_ID'];
$comment['home'] = get_option('home');
$comment['user_id'] = $commentdata['user_id'];
$date_format = (!empty($this->options['input_date'])) ? $this->options['input_date'] : $this->options_default['input_date'];
$comment['time'] = date_i18n($date_format, strtotime($commentdata['comment_date']));
$comment['time'] = apply_filters('bwp_rc_date_format', $comment['time'], $commentdata['comment_date']);
// for dynamic comment_type loading
$comment['comment_type'] = $commentdata['comment_type'];
$comment['type'] = $commentdata['comment_type'];
// Format post_title, also trim it if necessary - @since 1.1.0
$trimmed_to = (!empty($this->options['input_title_trim'])) ? $this->options['input_title_trim'] : 0;
$comment['post_title'] = __($commentdata['post_title']);
if (!empty($trimmed_to)) $comment['post_title'] = $this->trim_comment_excerpt($comment['post_title'], $trimmed_to);
$comment_on = ($commentdata['comment_type'] == '') ? __('Comment on', 'bwp-rc') : __(' to', 'bwp-rc');
$comment['post_title_attr'] = sprintf('%s %s', ucfirst($commentdata['comment_type'] . $comment_on), esc_attr(__($comment['post_title'])));
// Author
$comment['author'] = esc_html($commentdata['comment_author']);
$comment['author_url'] = esc_url($commentdata['comment_author_url']);
$comment['author_archive'] = (!empty($comment['user_id'])) ?
sprintf('<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
get_author_posts_url($comment['user_id']),
esc_attr(sprintf( __('Posts by %s'), $comment['author'])),
$comment['author']
) : $comment['author'];
// Avatar
$avatar_width = (!empty($this->options['input_gravatar_width'])) ? $this->options['input_gravatar_width'] : $this->options_default['input_gravatar_width'];
$comment['avatar'] = ($this->options['enable_gravatars'] == 'yes') ? get_avatar($commentdata['comment_author_email'], $avatar_width, apply_filters('bwp_rc_default_avatar', NULL), __('User Avatar', 'bwp-rc')) : '';
// Links to post or comment page - @since 1.1.0
$comment['post_link'] = get_permalink($commentdata['comment_post_ID']);
$comment['link'] = get_comment_link($commentdata['comment_ID'], array('type' => 'comment'));
// Format the comment excerpt, let's start by stripping html, shortcodes
$comment['excerpt'] = strip_tags(strip_shortcodes($commentdata['comment_content']));
$chunk = ($this->options['select_long_method'] == 'long_break' && !empty($this->options['input_chunk'])) ? $this->options['input_chunk'] : 0;
$trimmed_to = (!empty($this->options['input_trim'])) ? $this->options['input_trim'] : 4000;
$comment['excerpt'] = $this->trim_comment_excerpt($comment['excerpt'], $trimmed_to, $chunk);
$comment['excerpt'] = ($this->options['enable_smilies'] == 'yes') ? convert_smilies($comment['excerpt']) : $comment['excerpt'];
// If exerpt is empty after these, add something to it
$comment_type = (!empty($comment['type'])) ? $comment['type'] : __('comment');
$comment['excerpt'] = (empty($comment['excerpt'])) ? sprintf($this->options['input_trimmed'], $comment_type) : $comment['excerpt'];
$comment['excerpt'] = stripslashes($comment['excerpt']);
// Misc things
$comment['comment_count'] = (int) $commentdata['comment_count'];
return $comment;
}
/**
* Sort the comment asc or desc
*/
private static function sort_comments($data, $order, $paged = false)
{
$comments = array();
$last_item = ($paged) ? array_pop($data) : false;
// ascending order
if ($order == 'asc')
{
foreach ($data as $comment)
$comments[] = array_pop($data);
if ($last_item)
$comments[] = $last_item;
}
else
$comments = $data;
return $comments;
}
private static function sort_grouped_comments(array $grouped_comments)
{
$return = array();
$done = array();
foreach ($grouped_comments as $comment)
{
$ppid = $comment['comment_post_ID'];
// If this comment_post_ID has been processed, don't to process it again
if (in_array($ppid, $done))
continue;
// Put the first comment in
$return[] = $comment;
foreach ($grouped_comments as $_comment)
{
if ($comment['comment_ID'] == $_comment['comment_ID'])
continue;
if ($ppid == $_comment['comment_post_ID'])
$return[] = $_comment;
}
$done[] = $ppid;
}
return $return;
}
private static function build_grouped_post_keys(array $grouped_posts)
{
$return = array();
foreach ($grouped_posts as $post)
$return[$post['ID']] = $post;
return $return;
}
private function build_ajax_nav($instance, $paged, $paged_limit, $paged_template = false)
{
global $bwp_rc_left;
$newer = (isset($paged) && 1 < $paged) ? $this->options['template_ajax_newer'] : '';
$older = ($bwp_rc_left > $paged_limit) ? $this->options['template_ajax_older'] : '';
// Info for next page
$instance = (empty($instance)) ? BWP_RC_LIST : $instance;
$response = '<li class="bwp-rc-ajax-nav">' . "\n";
$response .= "\t" . '<input type="hidden" name="bwp_rc_instance" value="' . $instance . '" />' . "\n";
$response .= "\t" . '<input type="hidden" name="bwp_rc_paged" value="' . $paged . '" />' . "\n";
$response .= "\t" . '<input type="hidden" name="bwp_rc_paged_limit" value="' . $paged_limit . '" />' . "\n";
$response .= ($paged_template) ? "\t" . '<input type="hidden" name="bwp_rc_paged_template" value="1" />' . "\n" : '';
return $response . $newer . ' ' . $older . '</li>' . "\n";
}
function parse_rc_shortcode($atts)
{
if (!is_singular())
return '';
extract(shortcode_atts(array(
'instance' => '',
'ajax' => '',
'limit' => 5,
'prev' => '««',
'next' => '»»'
), $atts));
$ajax = ('yes' == $ajax) ? true : false;
$output = '<ul class="bwp-rc-ulist">' . "\n";
$output .= bwp_rc_paged_list(array('instance' => $instance, 'ajax' => $ajax), $limit, $prev, $next, false) . "\n";
$output .= '</ul>' . "\n";
return $output;
}
function handle_ajax_request()
{
$actions = array('older', 'newer');
// What to do
if (empty($_GET['bwp_rc_action']) || !in_array($_GET['bwp_rc_action'], $actions))
die(-1);
$action = $_GET['bwp_rc_action'];
// Instance name
if (!empty($_GET['bwp_rc_instance']))
$instance = $this->format_instance_name($_GET['bwp_rc_instance']);
else
$instance = '';
// Current page
if (!empty($_GET['bwp_rc_paged']))
$paged = (int) preg_replace('/[^0-9]+/i', '', $_GET['bwp_rc_paged']);
// Limit
if (!empty($_GET['bwp_rc_paged_limit']))
$paged_limit = (int) preg_replace('/[^0-9]+/i', '', $_GET['bwp_rc_paged_limit']);
// Paged template
if (!empty($_GET['bwp_rc_paged_template']))
$paged_template = true;
else
$paged_template = false;
// Invalidated requests
if (empty($paged) || empty($paged_limit))
die(-1);
// Paged
if ('newer' == $action)
$paged = ($paged <= 1) ? 1 : $paged - 1;
else
$paged = $paged + 1;
// Response with comments
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
@header('X-Content-Type-Options: nosniff');
bwp_get_recent_comments(array('instance' => $instance, 'paged' => $paged, 'paged_limit' => $paged_limit, 'paged_template' => $paged_template), true, true);
die();
}
/**
* Generate the recent comment list
*/
function get_recent_comments($echo = true, $need_refresh = false, $instance = BWP_RC_LIST, $post_type = '', $post_id = NULL, $comment_type = '', $separate = false, $limit = 0, $tb_limit = 0, $order = '', $args = array(), $paged = NULL, $paged_limit = 5, $paged_template = false)
{
// $bwp_rc_left - determine how many recent comments left - @since 1.1.0
global $wpdb, $bwp_rc_left;
$bwp_rc_left = 0;
$credit = ($this->is_credit_enable() && !defined('BWP_RC_CREDIT_ADDED')) ? "\n" . '<li class="recent-comment recent-comment-credit">' . sprintf(BWP_RC_COPYRIGHT, BWP_RC_PLUGIN_URL) . '</li>' . "\n" : '';
// make sure we add credit only once
if (!defined('BWP_RC_CREDIT_ADDED'))
define('BWP_RC_CREDIT_ADDED', true);
// Comment type alias
$comment_alias = array(
'comment' => __('comment'),
'' => __('comment'),
'tb' => __('trackback'),
'all' => __('comment')
);
if (!isset($comment_alias[$comment_type])) $comment_type = '';
// Custom arguments - @since 1.2.0
$grouped = (!empty($args['grouped'])) ? $args['grouped'] : 0;
$ajax = (!empty($args['ajax'])) ? true : false;
$parameters = array('post_type' => $post_type, 'post_id' => $post_id, 'comment_type' => $comment_type, 'separate' => $separate, 'limit' => $limit, 'tb_limit' => $tb_limit, 'order' => $order, 'grouped' => $grouped, 'ajax' => $ajax);
// Determine whether this is a global list or a unique list
$instance = $this->format_instance_name($instance);
$the_instance = $instance;
if (empty($instance))
$instance = BWP_RC_LIST;
else if (BWP_RC_LIST != $instance)
$instance = 'bwp_rc_instance_' . str_replace(' ', '_', $instance);
// If the instance is not defined or missing a new parameter, add it
if (!isset($this->instances[$instance]) || !array_key_exists('post_id', $this->instances[$instance]) || !array_key_exists('grouped', $this->instances[$instance]) || !array_key_exists('ajax', $this->instances[$instance]))
{
$this->instances[$instance] = $parameters;
update_option(BWP_RC_INSTANCES, $this->instances);
}
if (!empty($this->instances[$instance]))
$saved_parameters = $this->instances[$instance];
else
$saved_parameters = $parameters;
// No need to refresh the comment list?