Plugin Directory

Changeset 1007332


Ignore:
Timestamp:
10/14/2014 02:47:12 PM (11 years ago)
Author:
tjsantilo
Message:

Updated the plugin with the files Clay sent me to implement the voter id feature - public.js, public.css, class-social-polling.php, and class-sp_comments.php.

Location:
because/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • because/trunk/README.txt

    r1000853 r1007332  
    77Tested up to: 4.0
    88<<<<<<< .mine
    9 Stable tag: 1.3.7
     9Stable tag: 1.3.8
    1010=======
    11 Stable tag: 1.3.7
     11Stable tag: 1.3.8
    1212>>>>>>> .r969865
    1313License: GPLv2 or later
  • because/trunk/public/assets/css/public.css

    r1000853 r1007332  
    2727   
    2828}
    29 .answer_divs:focus .answer_image,
    30 .answer_divs:HOVER .answer_image{
    31 border:5px solid #1e8cbe;
    32 
    33    
    34    
     29#answer_1_wrapper.answer_divs:focus .answer_image,
     30#answer_1_wrapper.answer_divs:HOVER .answer_image{
     31    border:5px solid #1e8cbe;
     32}
     33
     34#answer_2_wrapper.answer_divs:focus .answer_image,
     35#answer_2_wrapper.answer_divs:HOVER .answer_image{
     36    border:5px solid #1ebe50;
    3537}
    3638
     
    426428padding: 1em;
    427429}
     430
     431.comment_voted_a{
     432    color: #1e8cbe;
     433}
     434
     435.comment_voted_b{
     436    color: #1ebe50;
     437}
    428438/*
    429439//----------------------------
  • because/trunk/public/assets/js/public.js

    r999351 r1007332  
    5151                show_results($post_id);
    5252
    53                
    54         if(data === "You already voted"){
    55 $('#social_polling_see_results_wrapper').html('You Already Voted');
    56 }
    57 else{
    58 $('#social_polling_see_results_wrapper').html('');
    59 }
    60 
    61        
    62 
    63                
     53                if(data === "already_voted"){
     54                    $('#social_polling_see_results_wrapper').html('You Already Voted');
     55                }
     56                else{
     57                    $('#social_polling_see_results_wrapper').html('');
     58                    $('.sp_comment-list').html(data);
     59                }
    6460
    6561                //console.log(data+ajaxurl);
    66 
    67    
    6862
    6963            }//success
  • because/trunk/public/class-social-polling.php

    r999334 r1007332  
    306306         if($already_voted):
    307307         //You already voted
    308          return 'already_voted';
     308            $response['vote_status'] = 'already_voted';
     309            return $response;
    309310         else:
    310311            //Do the vote   
     
    313314       
    314315        if($do_vote):
    315          return 'voted';
     316            $response['vote_status'] = 'voted';
     317            //modify comments to display
     318            $this->add_id_to_comments($data);
     319            $response['new_comments'] = $this->update_comments($data);
    316320        else:
    317321         return false;
     
    319323     }//social_polling_vote
    320324     
    321      
     325     private function add_id_to_comments($data){
     326        global $wpdb;
     327
     328        $table = $wpdb->prefix . "postmeta";
     329        $query = "SELECT meta_key FROM $table WHERE post_id='" . $data['poll_id'] . "' AND meta_value='" . $data['vote_value']. "'";
     330        $ans_choice = $wpdb->get_row($query);
     331
     332        if ($ans_choice->meta_key == "social_polling_answer_one_field" || $ans_choice->meta_key == "_social_polling_answer_one_field"){
     333            $choice = "one";
     334        }
     335        else if ($ans_choice->meta_key == "social_polling_answer_two_field" || $ans_choice->meta_key == "_social_polling_answer_two_field"){
     336            $choice = "two";
     337        }
     338
     339        $table = $wpdb->prefix . "comments";
     340        $comments = $wpdb->get_results("SELECT comment_ID from $table where comment_post_ID='" . $data['poll_id'] . "' AND (comment_author_IP = '".$data['voter_ip']."'  ||    (user_id = '".$data['voter_id']."'  &&   user_id != '0' ))" );   
     341
     342        foreach($comments as $row){
     343            add_comment_meta($row->comment_ID,'vote_choice',$choice);
     344        }
     345               
     346        return;
     347     }
     348
     349     private function update_comments($data){
     350               
     351               
     352                $post_id = $data['poll_id'];
     353               
     354                $comment_args['post_id'] = $post_id;
     355
     356                $comments = get_comments( $comment_args );
     357
     358                ob_start();
     359
     360                wp_list_comments(array(
     361
     362                            'callback' => 'mytheme_comment',
     363
     364                            'walker' => new zipGun_walker_comment()
     365
     366                            //'per_page' => 10, //Allow comment pagination
     367
     368                            //'reverse_top_level' => $sortby == 'oldest' ? false : true //Show the latest comments at the top of the list
     369
     370                ), $comments);
     371
     372                $updated_comments = ob_get_contents();
     373
     374                ob_end_clean;
     375
     376     }
    322377     
    323378      public function get_poll_results($post_id){
     
    482537            endif;
    483538           
    484             switch($vote): 
     539            switch($vote[vote_status]):     
    485540            case('voted'):
    486                 echo 'You were voting on Post '.get_post_meta($post_id,'social_polling_question_field',true );
    487                 echo 'You voted '.$vote_value;
     541                // echo 'You were voting on Post '.get_post_meta($post_id,'social_polling_question_field',true );
     542                //  echo 'You voted '.$vote_value;
     543                echo $vote['new_comments'];
    488544            break;
    489545           
    490546            case('already_voted'):
    491                 echo 'You already voted';
     547                echo "already_voted";
    492548            break;         
    493549           
  • because/trunk/public/includes/class-sp_comments.php

    r966514 r1007332  
    8181            add_action('wp_ajax_sp_Comments_Ajax',  array( $this,'sp_Comments_Ajax'));
    8282
    83                        
     83            add_action('comment_post', array( $this,'check_user_vote'));
    8484
    8585           
     
    153153    }//Contruct
    154154
    155    
     155    // function to check if user has voted in the Polling
     156
     157    public function check_user_vote($comment_id){
     158        global $wpdb;
     159       
     160        if ( is_user_logged_in() ):
     161            $user_id = $this->get_voter('');   
     162        else:
     163            $user_id = md5($this->get_voter('ip_address'));
     164        endif;
     165
     166        $table = $wpdb->prefix . "social_polling";
     167        $post_id = get_the_ID();
     168
     169        // check to see if the user has voted on the current poll
     170        $query = "SELECT vote_value FROM $table WHERE poll_id='" . $post_id . "' AND (voter_ip = '".$user_id."'  ||    (voter_id = '".$user_id."'  &&   voter_id != '0' ))";
     171        $vote_val = $wpdb->get_row($query);
     172
     173        if ($vote_val){
     174            // if the user has voted then check to see which question in the poll the answer is
     175
     176            $table = $wpdb->prefix . "postmeta";
     177            $query = "SELECT meta_key FROM $table WHERE post_id='" . $post_id . "' AND meta_value='" . $vote_val->vote_value . "'";
     178            $ans_choice = $wpdb->get_row($query);
     179                   
     180
     181            // add vote identifier to the comment
     182            if ($ans_choice->meta_key == "social_polling_answer_one_field" || $ans_choice->meta_key == "_social_polling_answer_one_field"){
     183                add_comment_meta($comment_id,'vote_choice','one');
     184            }
     185            elseif ($ans_choice->meta_key == "social_polling_answer_two_field" || $ans_choice->meta_key == "social_polling_answer_two_field"){
     186                add_comment_meta($comment_id,'vote_choice','two'); 
     187            }
     188        }
     189    }
    156190
    157191   
     
    15101544}//CLASS spComments
    15111545
    1512 
    1513 
    1514 
    1515 
    1516 
     1546add_filter('comment_text', 'comment_vote_choice');
     1547
     1548function comment_vote_choice( $comment_text){
     1549
     1550        $comment_ID = get_comment_ID();
     1551   
     1552        echo "<p";
     1553       
     1554        $test = get_comment_meta($comment_ID,"vote_choice",true);
     1555
     1556        if ($test == "one"){
     1557            echo " class='comment_voted_a'";
     1558        }
     1559        elseif ($test == "two") {
     1560            echo " class='comment_voted_b'";
     1561        }
     1562       
     1563        echo ">$comment_text</p>";
     1564}
    15171565
    15181566function mytheme_comment($comment, $args, $depth) {
  • because/trunk/social-polling.php

    r1000853 r1007332  
    3434
    3535<<<<<<< .mine
    36  * Version:           1.3.7
     36 * Version:           1.3.8
    3737=======
    38  * Version:           1.3.7
     38 * Version:           1.3.8
    3939>>>>>>> .r969865
    4040
Note: See TracChangeset for help on using the changeset viewer.