Example #1
3
/**
 * Get The Post like number
 *
 * @author       	Alimir
 * @param           Integer $postID	 
 * @since           1.7 
 * @return          String
 */
function wp_ulike_get_post_likes($postID)
{
    $val = get_post_meta($postID, '_liked', true);
    return wp_ulike_format_number($val);
}
Example #2
1
 /**
  * Most Liked Topics Function
  *
  * @author       	Alimir
  * @since           2.3
  * @updated         2.4
  * @return			String
  */
 public function most_liked_topics(array $settings)
 {
     global $wpdb;
     $request = "SELECT posts.ID, posts.post_title, posts.post_content, meta.meta_value\n                    FROM\n                    " . $wpdb->prefix . "posts AS posts,\n                    " . $wpdb->prefix . "postmeta AS meta,\n                    " . $wpdb->prefix . "ulike_forums AS likes\n                    WHERE\n                    posts.ID = meta.post_ID\n                    AND meta.post_ID = likes.topic_id\n                    AND posts.post_status = 'publish'\n                    AND meta.meta_key = '_topicliked'\n                    " . $this->period($settings['period']) . "\n                    GROUP BY posts.ID\n                    ORDER BY CAST( meta.meta_value AS SIGNED ) DESC LIMIT " . $settings['numberOf'] . "\n                    ";
     $posts = $wpdb->get_results($request);
     foreach ($posts as $post) {
         $post_title = empty($post->post_title) ? $post->post_content : stripslashes($post->post_title);
         $permalink = get_permalink($post->ID);
         $post_count = $post->meta_value;
         echo $settings['before_item'];
         echo '<a href="' . $permalink . '" title="' . $post_title . '" rel="nofollow">' . wp_trim_words($post_title, $num_words = $settings['trim'], $more = null) . '</a>';
         echo $settings['show_count'] == '1' ? ' <span class="wp_counter_span">' . wp_ulike_format_number($post_count) . '</span>' : '';
         echo $settings['after_item'];
     }
 }
Example #3
0
 /**
  * Logged by IP/UserName method
  *
  * @author       	Alimir
  * @param           Array $data
  * @since           2.0
  * @updated         2.3		 
  * @return			String
  */
 public function loggedby_other_ways(array $data)
 {
     $liked = wp_ulike_format_number($data["get_like"]);
     $tmp1 = $this->get_template($data["id"], $data["method"], $liked, 1, 0);
     $tmp2 = $this->get_template($data["id"], $data["method"], $liked, 1, 1);
     $loggin_method = wp_ulike_get_setting($data['setting'], 'logging_method');
     $button_type = wp_ulike_get_setting('wp_ulike_general', 'button_type');
     $second_condition = true;
     //check for by_username login method
     if ($loggin_method == 'by_cookie_ip') {
         $condition = $this->wpdb->get_var("SELECT COUNT(*) FROM " . $this->wpdb->prefix . $data['table'] . " WHERE " . $data['column'] . " = '" . $data['id'] . "' AND ip = '" . $data['user_ip'] . "'");
         $second_column = 'ip';
         $second_val = $data['user_ip'];
     } else {
         if ($loggin_method == 'by_username') {
             $condition = $this->wpdb->get_var("SELECT COUNT(*) FROM " . $this->wpdb->prefix . $data['table'] . " WHERE " . $data['column'] . " = '" . $data['id'] . "' AND user_id = '" . $data['user_id'] . "'");
             $user_info = get_userdata($data['user_id']);
             // check for user data
             if (!$user_info) {
                 $second_condition = false;
             }
             // if user not exist, condition will be false
             $second_column = 'user_id';
             $second_val = $data['user_id'];
             if (!is_user_logged_in()) {
                 $tmp1 = $this->get_template($data["id"], $data["method"], $liked, 1, 2);
             }
         }
     }
     if ($data["type"] == 'post') {
         if ($condition == 0 && !isset($_COOKIE[$data["cookie"] . $data["id"]])) {
             if ($button_type == 'image') {
                 $counter = $tmp1['like_img'];
             } else {
                 $counter = $tmp1['like_text'];
             }
         } else {
             if ($condition != 0 && isset($_COOKIE[$data["cookie"] . $data["id"]]) && $second_condition) {
                 if ($this->get_user_status($data['table'], $data['column'], $second_column, $data['id'], $second_val) == "like") {
                     if ($button_type == 'image') {
                         $counter = $tmp2['unlike_img'];
                     } else {
                         $counter = $tmp2['unlike_text'];
                     }
                 } else {
                     if ($button_type == 'image') {
                         $counter = $tmp1['like_img'];
                     } else {
                         $counter = $tmp1['like_text'];
                     }
                 }
             } else {
                 if ($button_type == 'image') {
                     $counter = $tmp1['permission_img'];
                 } else {
                     $counter = $tmp1['permission_text'];
                 }
             }
         }
     } else {
         if ($data["type"] == 'process') {
             if ($condition == 0 && !isset($_COOKIE[$data["cookie"] . $data["id"]])) {
                 $newLike = $data["get_like"] + 1;
                 $this->update_meta_data($data["id"], $data["key"], $newLike);
                 $this->wpdb->query("INSERT INTO " . $this->wpdb->prefix . $data['table'] . " VALUES ('', '" . $data['id'] . "', NOW(), '" . $data['user_ip'] . "', '" . $data['user_id'] . "', 'like')");
                 if (is_user_logged_in()) {
                     wp_ulike_bp_activity_add($data['user_id'], $data['id'], $data['key']);
                 }
                 setcookie($data["cookie"] . $data["id"], time(), time() + 3600 * 24 * 365, '/');
                 do_action('wp_ulike_mycred_like', $data['id'], $data['key']);
                 $counter = wp_ulike_format_number($newLike);
             } else {
                 if ($condition != 0 && isset($_COOKIE[$data["cookie"] . $data["id"]]) && $second_condition) {
                     if ($this->get_user_status($data['table'], $data['column'], $second_column, $data['id'], $second_val) == "like") {
                         $newLike = $data["get_like"] - 1;
                         $this->update_meta_data($data["id"], $data["key"], $newLike);
                         $this->wpdb->query("\n\t\t\t\t\t\t\tUPDATE " . $this->wpdb->prefix . $data['table'] . "\n\t\t\t\t\t\t\tSET status = 'unlike'\n\t\t\t\t\t\t\tWHERE " . $data['column'] . " = '" . $data['id'] . "' AND {$second_column} = '{$second_val}'\n\t\t\t\t\t\t");
                         do_action('wp_ulike_mycred_unlike', $data['id'], $data['key']);
                         $counter = wp_ulike_format_number($newLike);
                     } else {
                         $newLike = $data["get_like"] + 1;
                         $this->update_meta_data($data["id"], $data["key"], $newLike);
                         $this->wpdb->query("\n\t\t\t\t\t\t\tUPDATE " . $this->wpdb->prefix . $data['table'] . "\n\t\t\t\t\t\t\tSET status = 'like'\n\t\t\t\t\t\t\tWHERE " . $data['column'] . " = '" . $data['id'] . "' AND {$second_column} = '{$second_val}'\n\t\t\t\t\t\t");
                         do_action('wp_ulike_mycred_like', $data['id'], $data['key']);
                         $counter = wp_ulike_format_number($newLike);
                     }
                 } else {
                     $counter = wp_ulike_format_number($data["get_like"]);
                 }
             }
         }
     }
     //end post process
     return $counter;
 }
Example #4
0
 /**
  * Most Liked Comments Function
  *
  * @author       	Alimir
  * @since           1.9
  * @updated         2.3	 
  * @return			String
  */
 public function most_liked_comments($numberOf, $before, $after, $show_count, $show_thumb, $trim, $sizeOf)
 {
     global $wpdb;
     $request = "SELECT * FROM " . $wpdb->prefix . "comments, " . $wpdb->prefix . "commentmeta";
     $request .= " WHERE " . $wpdb->prefix . "comments.comment_ID = " . $wpdb->prefix . "commentmeta.comment_id";
     $request .= " AND comment_approved='1' AND meta_key='_commentliked'";
     $request .= " ORDER BY " . $wpdb->prefix . "commentmeta.meta_value+0 DESC LIMIT {$numberOf}";
     $comments = $wpdb->get_results($request);
     foreach ($comments as $comment) {
         $comment_author = stripslashes($comment->comment_author);
         $post_permalink = get_permalink($comment->comment_post_ID);
         $post_title = get_the_title($comment->comment_post_ID);
         $comment_permalink = get_permalink($comment->comment_ID);
         $comment_likes_count = $comment->meta_value;
         echo $before;
         echo $show_thumb == '1' ? get_avatar($comment->comment_author_email, $sizeOf) : '';
         echo '<span class="comment-author-link">' . $comment_author . '</span> ' . __('on', 'alimir');
         echo ' <a href="' . $post_permalink . '#comment-' . $comment->comment_ID . '" title="' . $post_title . '" rel="nofollow">' . wp_trim_words($post_title, $num_words = $trim, $more = null) . '</a>';
         echo $show_count == '1' ? ' <span class="wp_counter_span">' . wp_ulike_format_number($comment_likes_count) . '</span>' : '';
         echo $after;
     }
 }