Plugin Directory

Changeset 1731502

Timestamp:
09/18/2017 09:35:00 AM (7 years ago)
Author:
pauldewouters
Message:

Preparing for 1.4.2 release

Location:
comment-popularity/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • comment-popularity/trunk/README.txt

    r1406301 r1731502  
    55Requires at least: 3.9
    66Tested up to: 4.5
    7 Stable tag: 1.4.1
     7Stable tag: 1.4.
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    130130
    131131== Changelog ==
     132
     133
     134
     135
     136
     137
    132138
    133139= 1.4.1 =
  • comment-popularity/trunk/comment-popularity.php

    r1406301 r1731502  
    44Plugin URI: https://github.com/humanmade/comment-popularity
    55Description: Allow visitors to vote on comments.
    6 Version: 1.4.1
     6Version: 1.4.
    77Author: Human Made Limited
    88Author URI: http://humanmade.co.uk
  • comment-popularity/trunk/composer.lock

    r1728064 r1731502  
    55        "This file is @generated automatically"
    66    ],
    7     "hash": "5cd2f03691af23d2d4aae70e8f409b0a",
    87    "content-hash": "95b7890e4ce1f78b4d9074cc281a4bb6",
    98    "packages": [
    109        {
    1110            "name": "twig/twig",
    12             "version": "v1.24.0",
     11            "version": "v1.",
    1312            "source": {
    1413                "type": "git",
    1514                "url": "https://github.com/twigphp/Twig.git",
    16                 "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8"
     15                "reference": ""
    1716            },
    1817            "dist": {
    1918                "type": "zip",
    20                 "url": "https://api.github.com/repos/twigphp/Twig/zipball/3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
    21                 "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
     19                "url": "https://api.github.com/repos/twigphp/Twig/zipball/",
     20                "reference": "",
    2221                "shasum": ""
    2322            },
    2423            "require": {
    25                 "php": ">=5.2.7"
     24                "php": ">=5."
    2625            },
    2726            "require-dev": {
     27
    2828                "symfony/debug": "~2.7",
    29                 "symfony/phpunit-bridge": "~2.7"
     29                "symfony/phpunit-bridge": "~"
    3030            },
    3131            "type": "library",
    3232            "extra": {
    3333                "branch-alias": {
    34                     "dev-master": "1.24-dev"
     34                    "dev-master": "1.4-dev"
    3535                }
    3636            },
     
    3838                "psr-0": {
    3939                    "Twig_": "lib/"
     40
     41
     42
    4043                }
    4144            },
     
    6770                "templating"
    6871            ],
    69             "time": "2016-01-25 21:22:18"
     72            "time": "201"
    7073        }
    7174    ],
     
    7376        {
    7477            "name": "squizlabs/php_codesniffer",
    75             "version": "2.6.0",
     78            "version": "",
    7679            "source": {
    7780                "type": "git",
    7881                "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
    79                 "reference": "1bcdf03b068a530ac1962ce671dead356eeba43b"
     82                "reference": ""
    8083            },
    8184            "dist": {
    8285                "type": "zip",
    83                 "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1bcdf03b068a530ac1962ce671dead356eeba43b",
    84                 "reference": "1bcdf03b068a530ac1962ce671dead356eeba43b",
     86                "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/",
     87                "reference": "",
    8588                "shasum": ""
    8689            },
     
    8992                "ext-tokenizer": "*",
    9093                "ext-xmlwriter": "*",
    91                 "php": ">=5.1.2"
     94                "php": ">=5."
    9295            },
    9396            "require-dev": {
     
    9598            },
    9699            "bin": [
    97                 "scripts/phpcs",
    98                 "scripts/phpcbf"
     100                "/phpcs",
     101                "/phpcbf"
    99102            ],
    100103            "type": "library",
    101104            "extra": {
    102105                "branch-alias": {
    103                     "dev-master": "2.x-dev"
     106                    "dev-master": ".x-dev"
    104107                }
    105             },
    106             "autoload": {
    107                 "classmap": [
    108                     "CodeSniffer.php",
    109                     "CodeSniffer/CLI.php",
    110                     "CodeSniffer/Exception.php",
    111                     "CodeSniffer/File.php",
    112                     "CodeSniffer/Fixer.php",
    113                     "CodeSniffer/Report.php",
    114                     "CodeSniffer/Reporting.php",
    115                     "CodeSniffer/Sniff.php",
    116                     "CodeSniffer/Tokens.php",
    117                     "CodeSniffer/Reports/",
    118                     "CodeSniffer/Tokenizers/",
    119                     "CodeSniffer/DocGenerators/",
    120                     "CodeSniffer/Standards/AbstractPatternSniff.php",
    121                     "CodeSniffer/Standards/AbstractScopeSniff.php",
    122                     "CodeSniffer/Standards/AbstractVariableSniff.php",
    123                     "CodeSniffer/Standards/IncorrectPatternException.php",
    124                     "CodeSniffer/Standards/Generic/Sniffs/",
    125                     "CodeSniffer/Standards/MySource/Sniffs/",
    126                     "CodeSniffer/Standards/PEAR/Sniffs/",
    127                     "CodeSniffer/Standards/PSR1/Sniffs/",
    128                     "CodeSniffer/Standards/PSR2/Sniffs/",
    129                     "CodeSniffer/Standards/Squiz/Sniffs/",
    130                     "CodeSniffer/Standards/Zend/Sniffs/"
    131                 ]
    132108            },
    133109            "notification-url": "https://packagist.org/downloads/",
     
    147123                "standards"
    148124            ],
    149             "time": "2016-04-03 22:58:34"
     125            "time": "201"
    150126        }
    151127    ],
  • comment-popularity/trunk/inc/class-comment-popularity.php

    r1406301 r1731502  
    1010     * Plugin version number.
    1111     */
    12     const HMN_CP_PLUGIN_VERSION = '1.4.1';
     12    const HMN_CP_PLUGIN_VERSION = '1.4.';
    1313
    1414    /**
     
    163163
    164164            case 'downvote':
    165                 $value = apply_filters( 'hmn_cp_downvote_value', -1 );
     165                $value = apply_filters( 'hmn_cp_downvote_value', - 1 );
     166                break;
     167
     168            case 'undo':
     169                $value = 0;
    166170                break;
    167171
     
    218222            if ( ! empty( $role_obj ) ) {
    219223
    220                 if ( in_array( 'manage_user_karma_settings', $role_obj->capabilities) ) {
     224                if ( in_array( 'manage_user_karma_settings', $role_obj->capabilities) ) {
    221225                    $role_obj->remove_cap( 'manage_user_karma_settings' );
    222226                }
     
    239243        $template_path = apply_filters( 'hmn_cp_template_path', plugin_dir_path( __FILE__ ) . '/templates' );
    240244
    241         $loader = new \Twig_Loader_Filesystem( $template_path );
     245        $loader = new \Twig_Loader_Filesystem( $template_path );
    242246        $this->twig = new \Twig_Environment( $loader );
    243247
     
    278282     * Disallow object cloning
    279283     */
    280     private function __clone() {}
     284    private function __clone() {
     285    }
    281286
    282287    /**
     
    290295
    291296        $js_file = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? '../assets/js/voting.js' : '../assets/js/voting.min.js';
    292         wp_register_script( 'comment-popularity', plugins_url( $js_file, __FILE__ ), array( 'jquery', 'underscore', 'growl' ), self::HMN_CP_PLUGIN_VERSION );
     297        wp_register_script( 'comment-popularity', plugins_url( $js_file, __FILE__ ), array(
     298            'jquery',
     299            'underscore',
     300            'growl'
     301        ), self::HMN_CP_PLUGIN_VERSION );
    293302
    294303        $args = array(
     
    432441    public function insert_comment_callback( $comment_id, $comment ) {
    433442
    434         if ( ! $comment->user_id )
     443        if ( ! $comment->user_id )
    435444            return;
    436 
    437         if ( ! $user = get_userdata( $comment->user_id ) )
     445        }
     446
     447        if ( ! $user = get_userdata( $comment->user_id ) ) {
    438448            return;
     449
    439450
    440451        $is_expert = $this->get_comment_author_expert_status( $user->ID );
     
    470481
    471482        // WP_Comment_Query arguments
    472         $defaults = array (
    473             'status'         => 'approve',
    474             'type'           => 'comment',
    475             'order'          => 'DESC',
    476             'orderby'        => 'comment_karma',
     483        $defaults = array(
     484            'status'  => 'approve',
     485            'type'    => 'comment',
     486            'order'   => 'DESC',
     487            'orderby' => 'comment_karma',
    477488        );
    478489
     
    481492        // The Comment Query
    482493        $comment_query = new \WP_Comment_Query;
    483         $comments = $comment_query->query( $get_comments_args );
    484 
    485         if ( $html )
     494        $comments = $comment_query->query( $get_comments_args );
     495
     496        if ( $html )
    486497            return wp_list_comments( $args, $comments );
     498
    487499
    488500        return $comments;
     
    537549        $user_karma = get_user_option( 'hmn_user_karma', $user_id );
    538550
    539         return ( '' !== $user_karma ) ? (int)$user_karma : 0;
     551        return ( '' !== $user_karma ) ? (int)$user_karma : 0;
    540552    }
    541553
     
    588600        $labels = $this->get_vote_labels();
    589601
    590         $vote_is_valid = $this->get_visitor()->is_vote_valid( $comment_id, $labels[ $vote ] );
    591 
    592602        $vote_value = $this->get_vote_value( $vote );
    593603
    594         if ( is_wp_error( $vote_is_valid ) ) {
    595 
    596             $error_code = $vote_is_valid->get_error_code();
    597             $error_msg = $vote_is_valid->get_error_message( $error_code );
    598 
    599             $return = array(
    600                 'error_code'    => $error_code,
    601                 'error_message' => $error_msg,
    602                 'comment_id'    => $comment_id,
    603                 'vote_type'     => '',
    604             );
    605 
    606             return $return;
    607 
     604        $result = $this->is_vote_valid( $comment_id, $labels, $vote );
     605        if (  is_array( $result ) ) {
     606            return $this->send_error( $result['error_code'], $result['error_msg'], $comment_id );
    608607        }
    609608
     
    624623
    625624        // Get the comment author object.
    626         $email = get_comment_author_email( $comment_id );
     625        $email = get_comment_author_email( $comment_id );
    627626        $author = get_user_by( 'email', $email );
    628627
     
    637636
    638637        $return = array(
    639             'success_message'    => __( 'Thanks for voting!', 'comment-popularity' ),
    640             'weight'     => $this->get_comment_weight( $comment_id ),
    641             'comment_id' => $comment_id,
    642             'vote_type'  => $labels[ $vote ],
     638            'success_message' => __( 'Thanks for voting!', 'comment-popularity' ),
     639            'weight'          => $this->get_comment_weight( $comment_id ),
     640            'comment_id'      => $comment_id,
     641            'vote_type'       => $labels[ $vote ],
     642        );
     643
     644        return $return;
     645    }
     646
     647    /**
     648     * @return array|bool
     649     */
     650    protected function is_vote_valid( $comment_id, $labels, $action ) {
     651        $user_can_vote = $this->get_visitor()->is_vote_valid( $comment_id, $labels[ $vote ] );
     652        if ( is_wp_error( $user_can_vote ) ) {
     653
     654            return [
     655                'error_code' => $error->get_error_code(),
     656                'error_msg'  => $error->get_error_message( $error_code ),
     657            ];
     658        }
     659
     660        // Prevent negative weight if not allowed.
     661        $comment = get_comment( $comment_id );
     662        if ( ( $action === 'downvote' && ! $this->is_negative_comment_weight_allowed() ) && 0 >= $comment->comment_karma ) {
     663            $error_code = 'downvote_zero_karma';
     664            $error_msg  = __( 'Unable to downvote a comment with no karma', 'comment-popularity' );
     665
     666            return [
     667                'error_code' => $error_code,
     668                'error_msg'  => $error_msg,
     669            ];
     670        }
     671
     672        return true;
     673    }
     674
     675    protected function send_error( $error_code, $error_msg, $comment_id ) {
     676        $return = array(
     677            'error_code'    => $error_code,
     678            'error_message' => $error_msg,
     679            'comment_id'    => $comment_id,
     680            'vote_type'     => '',
    643681        );
    644682
     
    658696
    659697        // Traditional WordPress plugin locale filter
    660         $locale        = apply_filters( 'plugin_locale', get_locale(), 'comment-popularity' );
    661         $mofile        = sprintf( '%1$s-%2$s.mo', 'comment-popularity', $locale );
     698        $locale get_locale(), 'comment-popularity' );
     699        $mofile = sprintf( '%1$s-%2$s.mo', 'comment-popularity', $locale );
    662700
    663701        // Setup paths to current locale file
  • comment-popularity/trunk/inc/class-visitor.php

    r1728064 r1731502  
    284284
    285285        $comments_voted_on = $this->retrieve_logged_votes();
    286         $logged_votes      = $this->retrieve_logged_votes();
    287 
    288         unset( $logged_votes[ 'comment_id_' . $comment_id ] );
     286
     287        unset( $comments_voted_on[ 'comment_id_' . $comment_id ] );
    289288
    290289        if ( ! empty( $comments_voted_on ) ) {
  • comment-popularity/trunk/inc/upgrade.php

    r976435 r1731502  
    1010function hmn_cp_trigger_upgrades() {
    1111
    12     // Get actual plugin version.
    13     $current_version = HMN_Comment_Popularity::HMN_CP_PLUGIN_VERSION;
    14 
    1512    // Get latest version stored in DB option.
    1613    $hmn_cp_plugin_version = get_option( 'hmn_cp_plugin_version' );
    1714
    18     // If the option doesn't exist, then we are upgrading from a version older than 1.2.1
    19     if ( ! $hmn_cp_plugin_version ) {
    20         $hmn_cp_plugin_version = '1.2.0';
    21 
    22         // Start tracking versions.
    23         add_option( 'hmn_cp_plugin_version', $hmn_cp_plugin_version );
     15    // No need to do anything if current version.
     16    if ( version_compare( $hmn_cp_plugin_version, HMN_Comment_Popularity::HMN_CP_PLUGIN_VERSION, '>=' ) ) {
     17        return;
    2418    }
    2519
    26     // Determine if we need to run upgrade routine for versions earlier than 1.2.1
    27     if ( version_compare( $hmn_cp_plugin_version, $current_version, '<' ) ) {
    28         hmn_cp_v121_upgrade();
     20    //
     21    if ( ) {
     22        );
    2923    }
    3024
    31     // Bump the version number in the DB.
    32     update_option( 'hmn_cp_plugin_version', HMN_Comment_Popularity::HMN_CP_PLUGIN_VERSION );
     25    // Do we have users with the old option key? Upgrade in batches of 100.
     26    $user_query = new WP_User_Query( array(
     27        'number'   => 100,
     28        'meta_key' => 'comments_voted_on',
     29    ) );
     30    $users = $user_query->get_results();
     31    if ( ! empty( $users ) ) {
     32        hmn_cp_v121_upgrade( $users );
     33    }
    3334}
     35
    3436add_action( 'admin_init', 'hmn_cp_trigger_upgrades' );
    3537
    3638/**
    3739 * Copy unprefixed option value to new prefixed option.
     40
     41
    3842 */
    39 function hmn_cp_v121_upgrade() {
     43function hmn_cp_v121_upgrade() {
    4044
    41     $users = get_users();
     45   
    4246
    43     foreach( $users as $user ) {
     47   
    4448
    45         $hmn_comments_voted_on = get_user_option( 'comments_voted_on', $user->ID );
     49        if ( ! $old_option ) {
     50            continue;
     51        }
    4652
    47         if ( ! $hmn_comments_voted_on )
    48             continue;
    49 
    50         update_user_option( $user->ID, 'hmn_comments_voted_on', $hmn_comments_voted_on );
     53        update_user_option( $user->ID, 'hmn_comments_voted_on', $old_option );
    5154        delete_user_option( $user->ID, 'comments_voted_on', true );
    5255
Note: See TracChangeset for help on using the changeset viewer.