Changeset 1731502
- Timestamp:
- 09/18/2017 09:35:00 AM (7 years ago)
- Location:
- comment-popularity/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
comment-popularity/trunk/README.txt
r1406301 r1731502 5 5 Requires at least: 3.9 6 6 Tested up to: 4.5 7 Stable tag: 1.4. 17 Stable tag: 1.4. 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 130 130 131 131 == Changelog == 132 133 134 135 136 137 132 138 133 139 = 1.4.1 = -
comment-popularity/trunk/comment-popularity.php
r1406301 r1731502 4 4 Plugin URI: https://github.com/humanmade/comment-popularity 5 5 Description: Allow visitors to vote on comments. 6 Version: 1.4. 16 Version: 1.4. 7 7 Author: Human Made Limited 8 8 Author URI: http://humanmade.co.uk -
comment-popularity/trunk/composer.lock
r1728064 r1731502 5 5 "This file is @generated automatically" 6 6 ], 7 "hash": "5cd2f03691af23d2d4aae70e8f409b0a",8 7 "content-hash": "95b7890e4ce1f78b4d9074cc281a4bb6", 9 8 "packages": [ 10 9 { 11 10 "name": "twig/twig", 12 "version": "v1. 24.0",11 "version": "v1.", 13 12 "source": { 14 13 "type": "git", 15 14 "url": "https://github.com/twigphp/Twig.git", 16 "reference": " 3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8"15 "reference": "" 17 16 }, 18 17 "dist": { 19 18 "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": "", 22 21 "shasum": "" 23 22 }, 24 23 "require": { 25 "php": ">=5. 2.7"24 "php": ">=5." 26 25 }, 27 26 "require-dev": { 27 28 28 "symfony/debug": "~2.7", 29 "symfony/phpunit-bridge": "~ 2.7"29 "symfony/phpunit-bridge": "~" 30 30 }, 31 31 "type": "library", 32 32 "extra": { 33 33 "branch-alias": { 34 "dev-master": "1. 24-dev"34 "dev-master": "1.4-dev" 35 35 } 36 36 }, … … 38 38 "psr-0": { 39 39 "Twig_": "lib/" 40 41 42 40 43 } 41 44 }, … … 67 70 "templating" 68 71 ], 69 "time": "201 6-01-25 21:22:18"72 "time": "201" 70 73 } 71 74 ], … … 73 76 { 74 77 "name": "squizlabs/php_codesniffer", 75 "version": " 2.6.0",78 "version": "", 76 79 "source": { 77 80 "type": "git", 78 81 "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", 79 "reference": " 1bcdf03b068a530ac1962ce671dead356eeba43b"82 "reference": "" 80 83 }, 81 84 "dist": { 82 85 "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": "", 85 88 "shasum": "" 86 89 }, … … 89 92 "ext-tokenizer": "*", 90 93 "ext-xmlwriter": "*", 91 "php": ">=5. 1.2"94 "php": ">=5." 92 95 }, 93 96 "require-dev": { … … 95 98 }, 96 99 "bin": [ 97 " scripts/phpcs",98 " scripts/phpcbf"100 "/phpcs", 101 "/phpcbf" 99 102 ], 100 103 "type": "library", 101 104 "extra": { 102 105 "branch-alias": { 103 "dev-master": " 2.x-dev"106 "dev-master": ".x-dev" 104 107 } 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 ]132 108 }, 133 109 "notification-url": "https://packagist.org/downloads/", … … 147 123 "standards" 148 124 ], 149 "time": "201 6-04-03 22:58:34"125 "time": "201" 150 126 } 151 127 ], -
comment-popularity/trunk/inc/class-comment-popularity.php
r1406301 r1731502 10 10 * Plugin version number. 11 11 */ 12 const HMN_CP_PLUGIN_VERSION = '1.4. 1';12 const HMN_CP_PLUGIN_VERSION = '1.4.'; 13 13 14 14 /** … … 163 163 164 164 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; 166 170 break; 167 171 … … 218 222 if ( ! empty( $role_obj ) ) { 219 223 220 if ( in_array( 'manage_user_karma_settings', $role_obj->capabilities ) ) {224 if ( in_array( 'manage_user_karma_settings', $role_obj->capabilities) ) { 221 225 $role_obj->remove_cap( 'manage_user_karma_settings' ); 222 226 } … … 239 243 $template_path = apply_filters( 'hmn_cp_template_path', plugin_dir_path( __FILE__ ) . '/templates' ); 240 244 241 $loader = new \Twig_Loader_Filesystem( $template_path );245 $loader = new \Twig_Loader_Filesystem( $template_path ); 242 246 $this->twig = new \Twig_Environment( $loader ); 243 247 … … 278 282 * Disallow object cloning 279 283 */ 280 private function __clone() {} 284 private function __clone() { 285 } 281 286 282 287 /** … … 290 295 291 296 $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 ); 293 302 294 303 $args = array( … … 432 441 public function insert_comment_callback( $comment_id, $comment ) { 433 442 434 if ( ! $comment->user_id ) 443 if ( ! $comment->user_id ) 435 444 return; 436 437 if ( ! $user = get_userdata( $comment->user_id ) ) 445 } 446 447 if ( ! $user = get_userdata( $comment->user_id ) ) { 438 448 return; 449 439 450 440 451 $is_expert = $this->get_comment_author_expert_status( $user->ID ); … … 470 481 471 482 // WP_Comment_Query arguments 472 $defaults = array 473 'status' 474 'type' 475 'order' 476 'orderby' 483 $defaults = array( 484 'status' => 'approve', 485 'type' => 'comment', 486 'order' => 'DESC', 487 'orderby' => 'comment_karma', 477 488 ); 478 489 … … 481 492 // The Comment Query 482 493 $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 ) 486 497 return wp_list_comments( $args, $comments ); 498 487 499 488 500 return $comments; … … 537 549 $user_karma = get_user_option( 'hmn_user_karma', $user_id ); 538 550 539 return ( '' !== $user_karma ) ? (int) $user_karma : 0;551 return ( '' !== $user_karma ) ? (int)$user_karma : 0; 540 552 } 541 553 … … 588 600 $labels = $this->get_vote_labels(); 589 601 590 $vote_is_valid = $this->get_visitor()->is_vote_valid( $comment_id, $labels[ $vote ] );591 592 602 $vote_value = $this->get_vote_value( $vote ); 593 603 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 ); 608 607 } 609 608 … … 624 623 625 624 // Get the comment author object. 626 $email = get_comment_author_email( $comment_id );625 $email = get_comment_author_email( $comment_id ); 627 626 $author = get_user_by( 'email', $email ); 628 627 … … 637 636 638 637 $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' => '', 643 681 ); 644 682 … … 658 696 659 697 // Traditional WordPress plugin locale filter 660 $locale = apply_filters( 'plugin_locale',get_locale(), 'comment-popularity' );661 $mofile 698 $locale get_locale(), 'comment-popularity' ); 699 $mofile = sprintf( '%1$s-%2$s.mo', 'comment-popularity', $locale ); 662 700 663 701 // Setup paths to current locale file -
comment-popularity/trunk/inc/class-visitor.php
r1728064 r1731502 284 284 285 285 $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 ] ); 289 288 290 289 if ( ! empty( $comments_voted_on ) ) { -
comment-popularity/trunk/inc/upgrade.php
r976435 r1731502 10 10 function hmn_cp_trigger_upgrades() { 11 11 12 // Get actual plugin version.13 $current_version = HMN_Comment_Popularity::HMN_CP_PLUGIN_VERSION;14 15 12 // Get latest version stored in DB option. 16 13 $hmn_cp_plugin_version = get_option( 'hmn_cp_plugin_version' ); 17 14 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; 24 18 } 25 19 26 // Determine if we need to run upgrade routine for versions earlier than 1.2.127 if ( version_compare( $hmn_cp_plugin_version, $current_version, '<' )) {28 hmn_cp_v121_upgrade();20 // 21 if ( ) { 22 ); 29 23 } 30 24 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 } 33 34 } 35 34 36 add_action( 'admin_init', 'hmn_cp_trigger_upgrades' ); 35 37 36 38 /** 37 39 * Copy unprefixed option value to new prefixed option. 40 41 38 42 */ 39 function hmn_cp_v121_upgrade( ) {43 function hmn_cp_v121_upgrade() { 40 44 41 $users = get_users();45 42 46 43 foreach( $users as $user ) {47 44 48 45 $hmn_comments_voted_on = get_user_option( 'comments_voted_on', $user->ID ); 49 if ( ! $old_option ) { 50 continue; 51 } 46 52 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 ); 51 54 delete_user_option( $user->ID, 'comments_voted_on', true ); 52 55
Note: See TracChangeset
for help on using the changeset viewer.