Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $(".post-like a").click(function(){
- heart = $(this);
- post_id = heart.data("post_id");
- jQuery.ajax({
- type: "post",
- url: ajax_var.url,
- data: "action=post-like&nonce="+ajax_var.nonce+"&post_like=&post_id="+post_id,
- success: function(count){
- if(count != "already")
- {
- heart.addClass("voted");
- heart.siblings(".count").css({ opacity: 0 }).fadeTo("slow",1).text(count);
- }
- }
- });
- return false;
- })
- function post_like(){
- $nonce = $_POST['nonce'];
- if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
- die ( 'Busted!');
- if(isset($_POST['post_like']))
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- $post_id = $_POST['post_id'];
- $meta_IP = get_post_meta($post_id, "voted_IP");
- $voted_IP = $meta_IP[0];
- if(!is_array($voted_IP))
- $voted_IP = array();
- $meta_count = get_post_meta($post_id, "votes_count", true);
- if(!hasAlreadyVoted($post_id))
- {
- $voted_IP[$ip] = time();
- update_post_meta($post_id, "voted_IP", $voted_IP);
- update_post_meta($post_id, "votes_count", ++$meta_count);
- echo $meta_count;
- }
- else
- echo "already";
- }
- exit;}function getPostLikeLink($post_id){
- $vote_count = get_post_meta($post_id, "votes_count", true);
- if (empty($vote_count)) {$vote_count = 0;}
- $output = '<div class="vote"><p class="post-like">';
- if(hasAlreadyVoted($post_id))
- $output .= ' <span title="'.__('I like this article', $themename).'" class="qtip like alreadyvoted"></span>';
- else
- $output .= '<a href="#" data-post_id="'.$post_id.'">
- <span title="'.__('I like this article', $themename).'"class="qtip like ">Kool</span>
- </a>';
- $output .= '<span class="count">'.$vote_count.'</span></p></div>';
- return $output;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement