-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquote-comments.php
More file actions
executable file
·468 lines (342 loc) · 13.7 KB
/
quote-comments.php
File metadata and controls
executable file
·468 lines (342 loc) · 13.7 KB
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
<?php
/*
Plugin Name: Quote Comments
Plugin URI: https://github.com/metodiew/Quote-Comments
Description: Creates a little quote icon in comment boxes which, when clicked, copies that comment to the comment box wrapped in blockquotes.
Version: 3.0.0
Requires at least: 4.0
Requires PHP: 7.2
Author: Stanko Metodiev
Author URI: https://metodiew.com
License: GPLv2 or later
Text Domain: quote-comments
*/
/**
* @TODO: apply some coding styling updates
*/
/**
* Load plugin textdomain.
*/
function quote_comments_load_textdomain() {
load_plugin_textdomain( 'quote-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'quote_comments_load_textdomain' );
/**
* Define variable for the plugin version.
*/
if ( ! defined( 'QUOTE_COMMENTS_VERSION' ) ) {
define( 'QUOTE_COMMENTS_VERSION', '3.0.0' );
}
/**
* Enqueue Plugin Assets
*/
function quote_comments_assets () {
wp_enqueue_script( 'quote-comments', plugins_url( 'quote-comments.js' , __FILE__ ), array(), QUOTE_COMMENTS_VERSION, array( 'strategy' => 'defer', 'in_footer' => true ) );
}
add_action( 'wp_enqueue_scripts', 'quote_comments_assets' );
function add_quote_button( $output ) {
global $user_ID;
if ( get_option( 'comment_registration' ) && ! $user_ID ) {
return $output;
} else if (!is_feed() && comments_open()) {
$commentID = get_comment_id();
if (function_exists('mcecomment_init')) {
$mce = ", true";
} else {
$mce = ", false";
}
// quote link
$button = "";
// fixme close if using "get_comment_time"
//if (get_option('quote_comments_pluginhook') == "get_comment_time") {
$button .= '</a>';
//}
$button .= ' ';
$button .= '<span id="name'.get_comment_ID().'" style="display: none;">'.get_comment_author().'</span>';
$button .= '<a class="comment_quote_link" ';
$button .= 'href="javascript:void(null)" ';
$button .= 'title="' . __('Click here or select text to quote comment', 'quote-comments'). '" ';
if( get_option('quote_comments_author') == true ) {
$button .= 'onmousedown="quote(\'' . get_comment_ID() .'\', document.getElementById(\'name'.get_comment_ID().'\').innerHTML, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
} else {
$button .= 'onmousedown="quote(\'' . get_comment_ID() .'\', null, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
}
$button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
$button .= 'return false;">';
$button .= "" . esc_attr( get_option( 'quote_comments_title' ) ) . "";
// reply link
if (get_option('quote_comments_replylink') == true) {
$button .= '</a> ';
$button .= '<a class="comment_reply_link" href="javascript:void(null)" ';
$button .= 'title="' . __('Click here to respond to author', 'quote-comments'). '" ';
$button .= 'onmousedown="inlinereply(\'' . get_comment_ID() .'\', document.getElementById(\'name'.get_comment_ID().'\').innerHTML, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
$button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
$button .= 'return false;">';
$button .= "" . esc_attr( get_option( 'quote_comments_replytitle' ) ) . "";
}
// close anchor link if body text (if using get comment time, this </a> is already here due to a bug)
if (get_option('quote_comments_pluginhook') == "get_comment_text") {
$button .= "</a>";
}
// output
if (comments_open() && have_comments() && get_comment_type() != "pingback" && get_comment_type() != "trackback") {
//echo ($output . $button);
return ($output . $button);
}
} else {
//echo ($output . $button);
return ($output . $button);
}
}
// this function to be phased out with "get_comment_time"
function add_quote_button_filter($output) {
global $user_ID;
if (get_option('comment_registration') && !$user_ID) {
return $output;
} else if (!is_feed() && comments_open()) {
$commentID = get_comment_id();
if (function_exists('mcecomment_init')) {
$mce = ", true";
} else {
$mce = ", false";
}
// quote link
$button = "";
// $button .= '</a> ';
$button .= '<span id="name'.get_comment_ID().'" style="display: none;">'.get_comment_author().'</span>';
$button .= '<a class="comment_quote_link" ';
$button .= 'href="javascript:void(null)" ';
$button .= 'title="' . __('Click here or select text to quote comment', 'quote-comments'). '" ';
if( get_option('quote_comments_author') == true ) {
$button .= 'onmousedown="quote(\'' . get_comment_ID() .'\', document.getElementById(\'name'.get_comment_ID().'\').innerHTML, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
} else {
$button .= 'onmousedown="quote(\'' . get_comment_ID() .'\', null, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
}
$button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
$button .= 'return false;">';
$button .= "" . esc_attr( get_option('quote_comments_title') ) . "";
// reply link
if (get_option('quote_comments_replylink') == true) {
$button .= '</a> ';
$button .= '<a class="comment_reply_link" href="javascript:void(null)" ';
$button .= 'title="' . __('Click here to respond to author', 'quote-comments'). '" ';
$button .= 'onmousedown="inlinereply(\'' . get_comment_ID() .'\', document.getElementById(\'name'.get_comment_ID().'\').innerHTML, \'comment\',\'div-comment-'. get_comment_ID() .'\''. $mce .');';
$button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
$button .= 'return false;">';
$button .= "" . esc_attr( get_option('quote_comments_replytitle') ) . "";
}
// close anchor link if body text
if (get_option('quote_comments_pluginhook') == "get_comment_text") {
$button .= "</a>";
}
if (comments_open() && have_comments() && get_comment_type() != "pingback" && get_comment_type() != "trackback") {
return($output . $button);
}
} else {
return($output . $button);
}
}
if (get_option('quote_comments_pluginhook') == 'get_comment_time') {
if (!is_admin()) {
add_filter('get_comment_time', 'add_quote_button_filter');
}
} else {
if (!is_admin()) {
add_filter('get_comment_text', 'add_quote_button');
}
}
function add_quote_tags($output) {
global $user_ID;
if (get_option('comment_registration') && !$user_ID) {
return $output;
} else if (!is_feed() && comments_open()) {
return "\n<div id='q-".get_comment_ID()."'>\n\n\n" . $output . "\n\n\n</div>\n";
} else {
return $output;
}
/*
global $user_ID;
if (get_option('comment_registration') && !$user_ID) {
echo $output;
} else if (!is_feed() && comments_open()) {
echo "\n<div id='q-".get_comment_ID()."'>\n\n\n" . $output . "\n\n\n</div>\n";
} else {
echo $output;
}
*/
}
if (!is_admin()) {
//add_filter('get_comment_text', 'add_quote_tags');
add_filter('get_comment_text', 'add_quote_tags', 1);
}
/**
* Options Page values
*/
function quote_comments_options_values() {
$qc_options = array (
array( "name" => __('Quote-link title?','quote-comments'),
"desc" => __('Title of comment link.','quote-comments'),
"id" => "quote_comments_title",
"std" => "(Quote)",
"type" => "text"),
array( "name" => __('Show author in quote?','quote-comments'),
"desc" => __('Show authors','quote-comments'),
"id" => "quote_comments_author",
"std" => true,
"type" => "checkbox"),
array( "name" => __('Show reply link?','quote-comments'),
"desc" => __('Show reply link','quote-comments'),
"id" => "quote_comments_replylink",
"std" => false,
"type" => "checkbox"),
array( "name" => __('Reply-link title?','quote-comments'),
//"desc" => __('Title of comment link.','quote-comments'),
"id" => "quote_comments_replytitle",
"std" => "(Reply)",
"type" => "text"),
array( "name" => __('Insert Quote link using which hook?','quote-comments'),
"desc" => __('Which plugin hook should be used to insert the quote link?','quote-comments'),
"id" => "quote_comments_pluginhook",
"std" => 'get_comment_text',
"type" => "radio",
"options" => array( 'get_comment_time' => "<code>get_comment_time</code> (places the link close to the authors name)",
'get_comment_text' => "<code>get_comment_text</code> (places the link after the comment body text -- most compatible)") ),
);
return $qc_options;
}
function quotecomments_add_admin() {
$qc_options = quote_comments_options_values();
if ( ! empty( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
if ( ! empty( $_REQUEST['action'] ) && 'save' == $_REQUEST['action'] ) {
// update options
foreach ($qc_options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) {
update_option( esc_attr( $value['id'] ), sanitize_text_field( $_REQUEST[ $value['id'] ] ) );
} else {
delete_option( esc_attr( $value['id'] ) );
}
}
header("Location: options-general.php?page=quote-comments.php&saved=true");
die;
}
}
// add options page
add_options_page( 'Quote Comments', 'Quote Comments', 'manage_options', basename(__FILE__), 'quotecomments_admin');
//add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
}
function quotecomments_admin() {
$qc_options = quote_comments_options_values();
if (! empty( $_REQUEST['saved'] ) ) {
echo '<div id="message" class="updated fade"><p><strong> Quote Comments '.__('settings saved.','quote-comments').'</strong></p></div>';
}
// Show options
?>
<div class="wrap">
<h2><?php _e('Quote Comments: General Options', 'quote-comments'); ?></h2>
<form method="post" action="">
<?php // Smart options ?>
<table class="form-table">
<?php foreach ($qc_options as $value) {
switch ( $value['type'] ) {
case 'text':
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
<td>
<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo esc_attr( get_option( $value['id'] ) ); } else { echo $value['std']; } ?>" />
<?php
if ( ! empty( $value['desc'] ) ) {
echo $value['desc'];
}
?>
</td>
</tr>
<?php
break;
case 'select':
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
<td>
<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?>
<option<?php if ( get_option( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
<?php } ?>
</select>
</td>
</tr>
<?php
break;
case 'textarea':
$ta_options = $value['options'];
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
<td><textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="<?php echo $ta_options['cols']; ?>" rows="<?php echo $ta_options['rows']; ?>"><?php
if( get_option($value['id']) != "") {
echo stripslashes( esc_attr( get_option($value['id'] ) ) );
}else{
echo $value['std'];
}?></textarea><br /><?php echo $value['desc']; ?></td>
</tr>
<?php
break;
case 'radio':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<?php foreach ($value['options'] as $key=>$option) {
$radio_setting = esc_attr( get_option($value['id'] ) );
if($radio_setting != ''){
if ($key == get_option($value['id']) ) {
$checked = "checked=\"checked\"";
} else {
$checked = "";
}
}else{
if($key == $value['std']){
$checked = "checked=\"checked\"";
}else{
$checked = "";
}
}?>
<input type="radio" name="<?php echo $value['id']; ?>" id="<?php echo $value['id'] . $key; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><label for="<?php echo $value['id'] . $key; ?>"><?php echo $option; ?></label><br />
<?php } ?>
</td>
</tr>
<?php
break;
case 'checkbox':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<?php
if(get_option($value['id'])){
$checked = "checked=\"checked\"";
}else{
$checked = "";
}
?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
<label for="<?php echo $value['id']; ?>"><?php echo $value['desc']; ?></label>
</td>
</tr>
<?php
break;
default:
break;
}
}
?>
</table>
<p class="submit">
<input class="button-primary" name="save" type="submit" value="<?php _e('Save changes','quote-comments'); ?>" />
<input type="hidden" name="action" value="save" />
</p>
</form>
</div><?php //.wrap ?>
<?php
}
add_action('admin_menu' , 'quotecomments_add_admin');