Plugin Directory

Changeset 3290923


Ignore:
Timestamp:
05/10/2025 02:29:58 PM (8 months ago)
Author:
metodiew
Message:

Updating the plugin

Location:
quote-comments/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • quote-comments/trunk/quote-comments.php

    r2632905 r3290923  
    44Plugin URI: https://github.com/metodiew/Quote-Comments
    55Description: Creates a little quote icon in comment boxes which, when clicked, copies that comment to the comment box wrapped in blockquotes.
    6 Version: 2.2.1
     6Version: 3.0.0
     7Requires at least: 4.0
     8Requires PHP: 7.2
    79Author: Stanko Metodiev
    810Author URI: https://metodiew.com
     11License: GPLv2 or later
     12Text Domain: quote-comments
    913*/
    1014
    1115/**
    12  * @TODO
    13  *
    14  * This is the real TO DO list:
    15  * - fix all notifications, notes, issues and errors
    16  * - improve the code base
     16 * @TODO: apply some coding styling updates
    1717 */
    1818
    19  
    20  /**
    21   * That's the previous @TODO:
    22   *
    23     - phase out "get_comment_time" option
    24     - clean up remaining functions for reply
    25     - improve reply layout
    26     - recode JS
    27   */
    28 
    29 load_plugin_textdomain('quote-comments', NULL, dirname(plugin_basename(__FILE__)) . "/languages");
    30 
    31 // Add a define variable, we'll need it later :)
     19/**
     20 * Load plugin textdomain.
     21 */
     22function quote_comments_load_textdomain() {
     23    load_plugin_textdomain( 'quote-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     24}
     25add_action( 'init', 'quote_comments_load_textdomain' );
     26
     27/**
     28 * Define variable for the plugin version.
     29 */
    3230if ( ! defined( 'QUOTE_COMMENTS_VERSION' ) ) {
    33     define( 'QUOTE_COMMENTS_VERSION', '2.2.1' );
    34 }
    35 
    36 function quote_scripts () {
    37 
    38     if ( function_exists('plugin_url') )
    39         $plugin_url = plugin_url();
    40     else
    41         $plugin_url = get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__));
    42 
    43     wp_register_script('quote_comments_js', ($plugin_url . '/quote-comments.js'), false, '1.0');
    44     wp_enqueue_script('quote_comments_js');
    45 
    46 }
    47 if (!is_admin()) {
    48     add_action('init', 'quote_scripts');
    49 }
    50 
    51 
    52 
    53 
    54 
    55 
    56 function add_quote_button($output) {
    57 
     31    define( 'QUOTE_COMMENTS_VERSION', '3.0.0' );
     32}
     33
     34/**
     35 * Enqueue Plugin Assets
     36 */
     37function quote_comments_assets () {
     38    wp_enqueue_script( 'quote-comments',  plugins_url( 'quote-comments.js' , __FILE__ ), array(), QUOTE_COMMENTS_VERSION, array( 'strategy'  => 'defer', 'in_footer' => true ) );
     39
     40}
     41add_action( 'wp_enqueue_scripts', 'quote_comments_assets' );
     42
     43
     44function add_quote_button( $output ) {
    5845
    5946    global $user_ID;
    60     if (get_option('comment_registration') && !$user_ID) {
     47    if ( get_option( 'comment_registration' ) && ! $user_ID ) {
    6148       
    6249        return $output;
     
    7966            $button .= '</a>';
    8067        //}
    81        
     68
    8269        $button .= '&nbsp;&nbsp;';
    8370        $button .= '<span id="name'.get_comment_ID().'" style="display: none;">'.get_comment_author().'</span>';
     
    9481        $button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
    9582        $button .= 'return false;">';
    96         $button .= "" . get_option('quote_comments_title') . "";
     83        $button .= "" . esc_attr( get_option( 'quote_comments_title' ) ) . "";
    9784       
    9885       
     
    10592            $button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
    10693            $button .= 'return false;">';
    107             $button .= "" . get_option('quote_comments_replytitle') . "";
     94            $button .= "" . esc_attr( get_option( 'quote_comments_replytitle' ) ) . "";
    10895        }
    10996       
     
    151138        // quote link
    152139        $button = "";
    153         $button .= '</a>&nbsp;&nbsp;';
     140        // $button .= '</a>&nbsp;&nbsp;';
    154141        $button .= '<span id="name'.get_comment_ID().'" style="display: none;">'.get_comment_author().'</span>';
    155142        $button .= '<a class="comment_quote_link" ';
     
    165152        $button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
    166153        $button .= 'return false;">';
    167         $button .= "" . get_option('quote_comments_title') . "";
     154        $button .= "" . esc_attr( get_option('quote_comments_title') ) . "";
    168155       
    169156       
     
    176163            $button .= 'try { addComment.moveForm(\'div-comment-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\'); } catch(e) {}; ';
    177164            $button .= 'return false;">';
    178             $button .= "" . get_option('quote_comments_replytitle') . "";
     165            $button .= "" . esc_attr( get_option('quote_comments_replytitle') ) . "";
    179166        }
    180167       
     
    184171        }
    185172
    186 
    187 
    188173        if (comments_open() && have_comments() && get_comment_type() != "pingback" && get_comment_type() != "trackback") {
    189174            return($output . $button);
     
    210195} else {
    211196    if (!is_admin()) {
    212         //add_action('get_comment_text', 'add_quote_button');
    213197        add_filter('get_comment_text', 'add_quote_button');
    214198    }
     
    272256
    273257/**
    274  * Options Page
     258 * Options Page values
    275259 */
    276 
    277 
    278 // Options
    279 $qc_themename = "Quote Comments";
    280 $qc_shortname = "quote_comments";
    281 
    282 
    283 $qc_options = array (
    284 
    285     array(  "name" => __('Quote-link title?','quote-comments'),
    286         //"desc" => __('Title of comment link.','quote-comments'),
    287         "id" => $qc_shortname."_title",
    288         "std" => "(Quote)",
    289         "type" => "text"),
    290 
    291     array(  "name" => __('Show author in quote?','quote-comments'),
    292         "desc" => __('Show authors','quote-comments'),
    293         "id" => $qc_shortname."_author",
    294         "std" => true,
    295         "type" => "checkbox"),
    296 
    297     array(  "name" => __('Show reply link?','quote-comments'),
    298         "desc" => __('Show reply link','quote-comments'),
    299         "id" => $qc_shortname."_replylink",
    300         "std" => false,
    301         "type" => "checkbox"),
    302 
    303     array(  "name" => __('Reply-link title?','quote-comments'),
    304         //"desc" => __('Title of comment link.','quote-comments'),
    305         "id" => $qc_shortname."_replytitle",
    306         "std" => "(Reply)",
    307         "type" => "text"),
    308 
    309     array(  "name" => __('Insert Quote link using which hook?','quote-comments'),
    310         "desc" => __('Which plugin hook should be used to insert the quote link?','quote-comments'),
    311         "id" => $qc_shortname."_pluginhook",
    312         "std" => 'get_comment_text',
    313         "type" => "radio",
    314         "options" => array( 'get_comment_time' => "<code>get_comment_time</code> (places the link close to the authors name)",
    315                             'get_comment_text' => "<code>get_comment_text</code> (places the link after the comment body text -- most compatible)") ),
    316 
    317 
    318 );
     260function quote_comments_options_values() {
     261    $qc_options = array (
     262
     263        array(  "name" => __('Quote-link title?','quote-comments'),
     264            "desc" => __('Title of comment link.','quote-comments'),
     265            "id" => "quote_comments_title",
     266            "std" => "(Quote)",
     267            "type" => "text"),
     268
     269        array(  "name" => __('Show author in quote?','quote-comments'),
     270            "desc" => __('Show authors','quote-comments'),
     271            "id" => "quote_comments_author",
     272            "std" => true,
     273            "type" => "checkbox"),
     274
     275        array(  "name" => __('Show reply link?','quote-comments'),
     276            "desc" => __('Show reply link','quote-comments'),
     277            "id" => "quote_comments_replylink",
     278            "std" => false,
     279            "type" => "checkbox"),
     280
     281        array(  "name" => __('Reply-link title?','quote-comments'),
     282            //"desc" => __('Title of comment link.','quote-comments'),
     283            "id" => "quote_comments_replytitle",
     284            "std" => "(Reply)",
     285            "type" => "text"),
     286
     287        array(  "name" => __('Insert Quote link using which hook?','quote-comments'),
     288            "desc" => __('Which plugin hook should be used to insert the quote link?','quote-comments'),
     289            "id" => "quote_comments_pluginhook",
     290            "std" => 'get_comment_text',
     291            "type" => "radio",
     292            "options" => array( 'get_comment_time' => "<code>get_comment_time</code> (places the link close to the authors name)",
     293                                'get_comment_text' => "<code>get_comment_text</code> (places the link after the comment body text -- most compatible)") ),
     294    );
     295
     296    return $qc_options;
     297}
    319298
    320299
     
    324303function quotecomments_add_admin() {
    325304
    326     global $qc_themename, $qc_shortname, $qc_options, $blog_id;
     305    $qc_options = quote_comments_options_values();
    327306
    328307    if ( ! empty( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
     
    332311            // update options
    333312            foreach ($qc_options as $value) {
    334                 update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    335 
    336             foreach ($qc_options as $value) {
    337                 if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
     313                if( isset( $_REQUEST[ $value['id'] ] ) ) {
     314                    update_option( esc_attr( $value['id'] ), sanitize_text_field( $_REQUEST[ $value['id'] ] ) );
     315
     316                } else {
     317                    delete_option( esc_attr( $value['id'] ) );
     318                }
     319            }
    338320
    339321            header("Location: options-general.php?page=quote-comments.php&saved=true");
     
    344326
    345327    // add options page
    346     add_options_page($qc_themename, $qc_themename, 'manage_options', basename(__FILE__), 'quotecomments_admin');
     328    add_options_page( 'Quote Comments', 'Quote Comments', 'manage_options', basename(__FILE__), 'quotecomments_admin');
    347329    //add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
    348330
     
    351333function quotecomments_admin() {
    352334
    353     global $qc_themename, $qc_shortname, $qc_options;
     335    $qc_options = quote_comments_options_values();
    354336
    355337    if (! empty( $_REQUEST['saved'] ) ) {
    356         echo '<div id="message" class="updated fade"><p><strong>'.$qc_themename.' '.__('settings saved.','quote-comments').'</strong></p></div>';
     338        echo '<div id="message" class="updated fade"><p><strong> Quote Comments '.__('settings saved.','quote-comments').'</strong></p></div>';
    357339    }
    358340
     
    361343?>
    362344<div class="wrap">
    363 <h2><?php echo $qc_themename; _e(': General Options', 'quote-comments'); ?></h2>
     345<h2><?php _e('Quote Comments: General Options', 'quote-comments'); ?></h2>
    364346
    365347<form method="post" action="">
    366 
    367     <p class="submit">
    368         <input class="button-primary" name="save" type="submit" value="<?php _e('Save changes','quote-comments'); ?>" />   
    369         <input type="hidden" name="action" value="save" />
    370     </p>
    371 
    372 
    373348    <?php // Smart options ?>
    374349    <table class="form-table">
     
    379354        ?>
    380355        <tr valign="top">
    381             <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'quote-comments'); ?></label></th>
     356            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
    382357            <td>
    383                 <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" />
     358                <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']; } ?>" />
    384359                <?php
    385360                if ( ! empty( $value['desc'] ) ) {
    386                     _e($value['desc'],'quote-comments');
     361                    echo $value['desc'];
    387362                }
    388363                ?>
     
    396371        ?>
    397372        <tr valign="top">
    398             <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'quote-comments'); ?></label></th>
     373            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
    399374                <td>
    400375                    <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
     
    412387        ?>
    413388        <tr valign="top">
    414             <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'quote-comments'); ?></label></th>
     389            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
    415390            <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
    416391                if( get_option($value['id']) != "") {
    417                         echo __(stripslashes(get_option($value['id'])),'quote-comments');
     392                        echo stripslashes( esc_attr( get_option($value['id'] ) ) );
    418393                    }else{
    419                         echo __($value['std'],'quote-comments');
    420                 }?></textarea><br /><?php echo __($value['desc'],'quote-comments'); ?></td>
     394                        echo $value['std'];
     395                }?></textarea><br /><?php echo $value['desc']; ?></td>
    421396        </tr>
    422397        <?php
     
    426401        ?>
    427402        <tr valign="top">
    428             <th scope="row"><?php echo __($value['name'],'quote-comments'); ?></th>
     403            <th scope="row"><?php echo $value['name']; ?></th>
    429404            <td>
    430405                <?php foreach ($value['options'] as $key=>$option) {
    431                 $radio_setting = get_option($value['id']);
     406                $radio_setting = esc_attr( get_option($value['id'] ) );
    432407                if($radio_setting != ''){
    433408                    if ($key == get_option($value['id']) ) {
     
    453428        ?>
    454429        <tr valign="top">
    455             <th scope="row"><?php echo __($value['name'],'quote-comments'); ?></th>
     430            <th scope="row"><?php echo $value['name']; ?></th>
    456431            <td>
    457432                <?php
     
    463438                ?>
    464439                <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
    465                 <label for="<?php echo $value['id']; ?>"><?php echo __($value['desc'],'quote-comments'); ?></label>
     440                <label for="<?php echo $value['id']; ?>"><?php echo $value['desc']; ?></label>
    466441            </td>
    467442        </tr>
     
    492467
    493468add_action('admin_menu' , 'quotecomments_add_admin');
    494 
    495 
    496 
    497 ?>
  • quote-comments/trunk/readme.txt

    r2632905 r3290923  
    11=== Quote Comments ===
    2 Contributors: metodiew, Joen
     2Contributors: metodiew
    33Donate link: https://metodiew.com/
    44Tags: quote, comments, javascript, textile, wysiwyg
    5 Requires at least: 2.5.0
    6 Tested up to: 5.8.2
     5Requires at least: 5.0.0
     6Tested up to: 6.8.1
    77Stable tag: 2.2
    88Stable tag: trunk
     
    3030
    31311. The default look: a little (Quote) link next to the comment time.
    32 2. An alternate look, where the icon has been styled to look like a Quote icon. Click the tiny quote icon to quote.
    33 3. Quote Comments options page.
     322. Quote Comments options page.
    3433
    3534== Frequently Asked Questions ==
     
    7877== Changelog ==
    7978
     79= 3.0.0 =
     80* Release date - May 10, 2025
     81* Address the vulnerability report from https://patchstack.com/database/report-preview/d7891563-a582-42b3-95ef-8985948d7d74?pin=InwTOqOOYguvviZ6
     82* Add additional escaping
     83* Optimize the code base
     84
    8085= 2.2.1 =
    8186* Release date - November 20, 2021
Note: See TracChangeset for help on using the changeset viewer.