Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. $(".post-like a").click(function(){
  4.  
  5. heart = $(this);
  6.  
  7. post_id = heart.data("post_id");
  8.  
  9. jQuery.ajax({
  10. type: "post",
  11. url: ajax_var.url,
  12. data: "action=post-like&nonce="+ajax_var.nonce+"&post_like=&post_id="+post_id,
  13. success: function(count){
  14. if(count != "already")
  15. {
  16. heart.addClass("voted");
  17. heart.siblings(".count").css({ opacity: 0 }).fadeTo("slow",1).text(count);
  18. }
  19. }
  20. });
  21.  
  22. return false;
  23. })
  24.  
  25. function post_like(){
  26. $nonce = $_POST['nonce'];
  27.  
  28. if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
  29. die ( 'Busted!');
  30.  
  31. if(isset($_POST['post_like']))
  32. {
  33. $ip = $_SERVER['REMOTE_ADDR'];
  34. $post_id = $_POST['post_id'];
  35.  
  36. $meta_IP = get_post_meta($post_id, "voted_IP");
  37.  
  38. $voted_IP = $meta_IP[0];
  39. if(!is_array($voted_IP))
  40. $voted_IP = array();
  41.  
  42. $meta_count = get_post_meta($post_id, "votes_count", true);
  43.  
  44. if(!hasAlreadyVoted($post_id))
  45. {
  46. $voted_IP[$ip] = time();
  47.  
  48. update_post_meta($post_id, "voted_IP", $voted_IP);
  49. update_post_meta($post_id, "votes_count", ++$meta_count);
  50.  
  51. echo $meta_count;
  52. }
  53. else
  54. echo "already";
  55. }
  56. exit;}function getPostLikeLink($post_id){
  57.  
  58. $vote_count = get_post_meta($post_id, "votes_count", true);
  59.  
  60. if (empty($vote_count)) {$vote_count = 0;}
  61.  
  62. $output = '<div class="vote"><p class="post-like">';
  63. if(hasAlreadyVoted($post_id))
  64. $output .= ' <span title="'.__('I like this article', $themename).'" class="qtip like alreadyvoted"></span>';
  65. else
  66. $output .= '<a href="#" data-post_id="'.$post_id.'">
  67. <span title="'.__('I like this article', $themename).'"class="qtip like ">Kool</span>
  68. </a>';
  69.  
  70. $output .= '<span class="count">'.$vote_count.'</span></p></div>';
  71.  
  72. return $output;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement