Making WordPress.org

Ticket #1755: 1755.1.patch

File 1755.1.patch, 2.7 KB (added by keesiemeijer, 8 years ago)

Add Reddit-style voting.

  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-voting.php

     
    298298                $comment_link = get_comment_link( $comment_id );
    299299                $nonce        = wp_create_nonce( 'user-note-vote-' . $comment_id );
    300300                $disabled_str = __( 'Voting for this note is disabled', 'wporg' );
     301                $cancel_str   = __( 'Click to cancel your vote', 'wporg' );
    301302                $log_in_str   = __( 'You must log in to vote on the helpfulness of this note', 'wporg' );
    302303                $log_in_url   = add_query_arg( 'redirect_to', urlencode( $comment_link ), 'https://login.wordpress.org' );
    303304
     
    310311                // Up vote link
    311312                $user_upvoted = self::has_user_upvoted_comment( $comment_id );
    312313                if ( $can_vote ) {
     314                        $cancel = $user_upvoted ? '. ' . $cancel_str . '.' : '';
    313315                        $title = $user_upvoted ?
    314                                 __( 'You have voted to indicate this note was helpful', 'wporg' ) :
     316                                __( 'You have voted to indicate this note was helpful', 'wporg' ) . $cancel :
    315317                                __( 'Vote up if this note was helpful', 'wporg' );
    316                         $tag = $user_upvoted ? 'span' : 'a';
     318                        $tag = 'a';
    317319                } else {
    318320                        $title = ! $logged_in ? $log_in_str : $disabled_str;
    319321                        $tag = $logged_in ? 'span' : 'a';
     
    350352                // Down vote link
    351353                $user_downvoted = ( $user_upvoted ? false : self::has_user_downvoted_comment( $comment_id ) );
    352354                if ( $can_vote ) {
     355                        $cancel = $user_downvoted ? '. ' . $cancel_str . '.' : '';
    353356                        $title = $user_downvoted ?
    354                                 __( 'You have voted to indicate this note was not helpful', 'wporg' ) :
     357                                __( 'You have voted to indicate this note was not helpful', 'wporg' ) . $cancel :
    355358                                __( 'Vote down if this note was not helpful', 'wporg' );
    356                         $tag = $user_downvoted ? 'span' : 'a';
     359                        $tag = 'a';
    357360                } else {
    358361                        $title = ! $logged_in ? $log_in_str : $disabled_str;
    359362                        $tag = $logged_in ? 'span' : 'a';
     
    485488                // Get list of people who cast the same vote.
    486489                $add_to_list = get_comment_meta( $comment_id, $add_to, true );
    487490
    488                 // Don't do anything if user is recasting the same vote as before.
     491                // Remove user from list if recasting the same vote as before.
    489492                if ( in_array( $user_id, (array) $add_to_list ) ) {
    490                         return false;
     493                        unset( $add_to_list[ array_search( $user_id, $add_to_list ) ] );
     494                        update_comment_meta( $comment_id, $add_to, $add_to_list );
     495                        return true;
    491496                }
    492497
    493498                // If the user had previously cast the opposite vote, undo that older vote.