function bplike_activity_update_button() { $liked_count = 0; if (is_user_logged_in() && bp_get_activity_type() !== 'activity_liked') { if (bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)) { $users_who_like = array_keys(bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)); $liked_count = count($users_who_like); } if (!bp_like_is_liked(bp_get_activity_id(), 'activity_update', get_current_user_id())) { ?> <a href="#" class="button bp-primary-action like" id="like-activity-<?php echo bp_get_activity_id(); ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "> <?php echo bp_like_get_text('like'); if ($liked_count) { echo ' <span>' . $liked_count . '</span>'; } ?> </a> <?php } else { ?> <a href="#" class="button bp-primary-action unlike" id="unlike-activity-<?php echo bp_get_activity_id(); ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "> <?php echo bp_like_get_text('unlike'); if ($liked_count) { echo '<span>' . $liked_count . '</span>'; } ?> </a> <?php } // Checking if there are users who like item. if (isset($users_who_like)) { view_who_likes(bp_get_activity_id(), 'activity_update'); } } }
function bplike_blog_post_button($content) { $liked_count = 0; if (is_user_logged_in()) { if (get_post_meta(get_the_ID(), 'liked_count', true)) { $users_who_like = array_keys(get_post_meta(get_the_ID(), 'liked_count', true)); $liked_count = count($users_who_like); // print_r($users_who_like); } ob_start(); if (!bp_like_is_liked(get_the_ID(), 'blog_post', get_current_user_id())) { ?> <a href="#" class="blogpost like" id="like-blogpost-<?php echo get_the_ID(); ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "> <?php echo bp_like_get_text('like'); if ($liked_count) { echo ' <span>' . $liked_count . '</span>'; } ?> </a> <?php } else { ?> <a href="#" class="blogpost unlike" id="unlike-blogpost-<?php echo get_the_ID(); ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "> <?php echo bp_like_get_text('unlike'); if ($liked_count) { echo '<span>' . $liked_count . '</span>'; } ?> </a> <?php } if (isset($users_who_like)) { view_who_likes('blog_post'); // may need to add params here } $content .= ob_get_clean(); } return $content; }
function bplike_blog_button() { global $post; if (!$id && is_single()) { $id = $post->ID; } if (is_user_logged_in() && get_post_meta($id, 'liked_count', true)) { $liked_count = count(get_post_meta($id, 'liked_count', true)); } if (!bp_like_is_liked($id, 'blogpost')) { ?> <div class="like-box"><a href="#" class="like_blogpost" id="like-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } else { ?> <div class="like-box"><a href="#" class="unlike_blogpost" id="unlike-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } }
function bplike_activity_comment_button() { $liked_count = 0; if (is_user_logged_in()) { if (bp_activity_get_meta(bp_get_activity_comment_id(), 'liked_count', true)) { $users_who_like = array_keys(bp_activity_get_meta(bp_get_activity_comment_id(), 'liked_count', true)); $liked_count = count($users_who_like); } if (!bp_like_is_liked(bp_get_activity_comment_id(), 'activity_comment', get_current_user_id())) { ?> <a href="#" class="acomment-reply bp-primary-action like" id="like-activity-<?php echo bp_get_activity_comment_id(); ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' <span><small>' . $liked_count . '</small></span>'; } ?> </a> <?php } else { ?> <a href="#" class="acomment-reply bp-primary-action unlike" id="unlike-activity-<?php echo bp_get_activity_comment_id(); ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' <span><small>' . $liked_count . '</small></span>'; } ?> </a> <?php } } }
/** * bp_like_get_likes() * * Outputs a list of users who have liked a given item. * */ function bp_like_get_likes($item_id = '', $type = '', $user_id = '') { global $bp; if (!$type || !$item_id) { return false; } if (!$user_id) { $user_id = $bp->loggedin_user->id; } if ($type == 'activity') { /* Grab some core data we will need later on, specific to activities */ $users_who_like = array_keys(bp_activity_get_meta($item_id, 'liked_count')); $liked_count = count(bp_activity_get_meta($item_id, 'liked_count')); $output = ''; /* Intercept any messages if nobody likes it, just incase the button was clicked when it shouldn't be */ if ($liked_count == 0) { $output .= bp_like_get_text('get_likes_no_likes'); } elseif (bp_like_get_settings('likers_visibility') == 'show_all') { /* Settings say we should show their name. */ if (bp_like_get_settings('name_or_avatar') == 'name') { /* Current user likes it too, remove them from the liked count and output appropriate message */ if (bp_like_is_liked($item_id, 'activity', $user_id)) { // remove current user from liked count. $liked_count = $liked_count - 1; if ($liked_count == 1) { //only current user and 1 other person likes this. $output .= bp_like_get_text('get_likes_you_and_singular'); $other = $users_who_like[count($users_who_like)]; $output .= 'You and ' . bp_core_get_userlink($other) . ' liked this.'; } elseif ($liked_count == 0) { //current user is the only person to like this. $output .= bp_like_get_text('get_likes_only_liker'); } else { $output .= bp_like_get_text('get_likes_you_and_plural'); } } else { if ($liked_count == 1) { $output .= bp_like_get_text('get_likes_count_people_singular'); } else { $output .= bp_like_get_text('get_likes_count_people_plural'); } } /* Now output the name of each person who has liked it (except the current user obviously) */ foreach ($users_who_like as $id) { if ($id != $user_id) { $output .= ' · <a href="' . bp_core_get_user_domain($id) . '" title="' . bp_core_get_user_displayname($id) . '">' . bp_core_get_user_displayname($id) . '</a>'; } } } elseif (bp_like_get_settings('name_or_avatar') == 'avatar') { /* Output the avatar of each person who has liked it. */ foreach ($users_who_like as $id) { $output .= '<a href="' . bp_core_get_user_domain($id) . '" title="' . bp_core_get_user_displayname($id) . '">' . bp_core_fetch_avatar(array('item_id' => $id, 'object' => 'user', 'type' => 'thumb', 'width' => 30, 'height' => 30)) . '</a> '; } } } elseif (bp_like_get_settings('likers_visibility') == 'friends_names_others_numbers' && bp_is_active('friends')) { /* Grab some information about their friends. */ $users_friends = friends_get_friend_user_ids($user_id); if (!empty($users_friends)) { $friends_who_like = array_intersect($users_who_like, $users_friends); } /* Current user likes it, so reduce the liked count by 1, to get the number of other people who like it. */ if (bp_like_is_liked($item_id, 'activity', $user_id)) { $liked_count = $liked_count - 1; } /* Settings say we should show their names. */ if (bp_like_get_settings('name_or_avatar') == 'name') { /* Current user likes it too, tell them. */ if (bp_like_is_liked($item_id, 'activity', $user_id)) { $output .= 'You '; } /* Output the name of each friend who has liked it. */ foreach ($users_who_like as $id) { if (in_array($id, $friends_who_like)) { //$output .= ' · <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a> '; $output .= bp_core_get_userlink($id); $liked_count = $liked_count - 1; } } /* If non-friends like it, say so. */ if ($liked_count == 1) { $output .= bp_like_get_text('get_likes_and_people_singular'); } elseif ($liked_count > 1) { $output .= bp_like_get_text('get_likes_and_people_plural'); } else { $output .= bp_like_get_text('get_likes_like_this'); } } elseif (bp_like_get_settings('name_or_avatar') == 'avatar') { /* Output the avatar of each friend who has liked it, as well as the current users' if they have. */ if (!empty($friends_who_like)) { foreach ($users_who_like as $id) { if ($id == $user_id || in_array($id, $friends_who_like)) { $user_info = get_userdata($id); $output .= '<a href="' . bp_core_get_user_domain($id) . '" title="' . bp_core_get_user_displayname($id) . '">' . get_avatar($user_info->user_email, 30) . '</a> '; } } } } elseif (bp_like_get_settings('likers_visibility') == 'friends_names_others_numbers' && !bp_is_active('friends') || bp_like_get_settings('likers_visibility') == 'just_numbers') { /* Current user likes it too, remove them from the liked count and output appropriate message */ if (bp_like_is_liked($item_id, 'activity', $user_id)) { $liked_count = $liked_count - 1; if ($liked_count == 1) { $output .= bp_like_get_text('get_likes_you_and_singular'); } elseif ($liked_count == 0) { $output .= bp_like_get_text('get_likes_only_liker'); } else { $output .= bp_like_get_text('get_likes_you_and_plural'); } } else { if ($liked_count == 1) { $output .= bp_like_get_text('get_likes_count_people_singular'); } else { $output .= bp_like_get_text('get_likes_count_people_plural'); } } } } } /* Filter out the placeholder. */ $output = str_replace('%count%', $liked_count, $output); echo $output; }
/** * bp_like_button() * * Outputs the 'Like/Unlike' and 'View likes/Hide likes' buttons. * */ function bp_like_button($id = '', $type = '') { $users_who_like = 0; $liked_count = 0; /* Set the type if not already set, and check whether we are outputting the button on a blogpost or not. */ if (!$type && !is_single()) { $type = 'activity'; } elseif (!$type && is_single()) { $type = 'blogpost'; } if ($type == 'activity') { $activity = bp_activity_get_specific(array('activity_ids' => bp_get_activity_id())); $activity_type = $activity['activities'][0]->type; if (is_user_logged_in() && $activity_type !== 'activity_liked') { if (bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)) { $users_who_like = array_keys(bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)); $liked_count = count($users_who_like); } if (!bp_like_is_liked(bp_get_activity_id(), 'activity')) { ?> <a href="#" class="like" id="like-activity-<?php bp_activity_id(); ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } else { ?> <a href="#" class="unlike" id="unlike-activity-<?php bp_activity_id(); ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } if ($users_who_like) { ?> <a href="#" class="view-likes" id="view-likes-<?php bp_activity_id(); ?> "><?php echo bp_like_get_text('view_likes'); ?> </a> <p class="users-who-like" id="users-who-like-<?php bp_activity_id(); ?> "></p> <?php } } } elseif ($type == 'blogpost') { global $post; if (!$id && is_single()) { $id = $post->ID; } if (is_user_logged_in() && get_post_meta($id, 'liked_count', true)) { $liked_count = count(get_post_meta($id, 'liked_count', true)); } if (!bp_like_is_liked($id, 'blogpost')) { ?> <div class="like-box"><a href="#" class="like_blogpost" id="like-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } else { ?> <div class="like-box"><a href="#" class="unlike_blogpost" id="unlike-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } } }
/** * Hook to insert the report user on BP blog post and activity * * @global type $l10n * @global type $post * @param type $id * @param type $type */ function wangguard_bp_report_button($id = '', $type = '') { if (!is_user_logged_in()) { return; } if (!$type && !is_single()) { $type = 'activity'; } elseif (!$type && is_single()) { $type = 'blogpost'; } if (function_exists("is_textdomain_loaded")) { if (!is_textdomain_loaded("wangguard")) { load_textdomain("wangguard", PLUGINDIR . "/wangguard/languages/wangguard-" . WPLANG . ".mo"); } } else { global $l10n; if (!isset($l10n['wangguard'])) { load_textdomain("wangguard", PLUGINDIR . " /wangguard/languages/wangguard-" . WPLANG . ".mo"); } } if ($type == 'activity') { $activity = bp_activity_get_specific(array('activity_ids' => bp_get_activity_id())); if (!empty($activity['activities'][0])) { $user_id = $activity['activities'][0]->user_id; $user_object = new WP_User($user_id); if (empty($user_object->ID)) { return; } if (!wangguard_is_admin($user_object)) { if (true || !bp_like_is_liked(bp_get_activity_id(), 'activity')) { ?> <a href="javascript:void(0)" class="button wangguard-user-report" rel="<?php echo $user_object->ID; ?> " title="<?php echo __('Report user', 'wangguard'); ?> "><?php echo __('Report user', 'wangguard'); ?> </a> <?php } } } } elseif ($type == 'blogpost') { global $post; if (empty($post->post_author)) { return; } $user_id = $post->post_author; $user_object = new WP_User($user_id); if (empty($user_object->ID)) { return; } if (!wangguard_is_admin($user_object)) { if (true || !bp_like_is_liked($id, 'blogpost')) { ?> <div class="activity-list"><div class="activity-meta"><a href="javascript:void(0)" class="button wangguard-user-report" rel="<?php echo $user_object->ID; ?> " title="<?php echo __('Report user', 'wangguard'); ?> "><?php echo __('Report user', 'wangguard'); ?> </a></div></div> <?php } } } }
function bplike_activity_button() { // Debugging. // echo bp_get_activity_type(); $liked_count = 0; $bp_like_comment_id = bp_get_activity_comment_id(); if (empty($bp_like_comment_id)) { $bp_like_id = bp_get_activity_id(); $bp_like_view = 'button view-likes'; if (bp_like_is_liked($bp_like_id, 'activity')) { $bp_like_css = 'button unlike'; } else { $bp_like_css = 'button like'; } } else { $bp_like_id = bp_get_activity_comment_id(); $bp_like_view = 'acomment-reply bp-primary-action view-likes'; if (bp_like_is_liked($bp_like_id, 'activity')) { $bp_like_css = 'acomment-reply bp-primary-action unlike'; } else { $bp_like_css = 'acomment-reply bp-primary-action like'; } } // Debugging. //print_r( bp_activity_get_meta( $bp_like_id , 'liked_count' , true )); $activity = bp_activity_get_specific(array('activity_ids' => $bp_like_id)); $activity_type = $activity['activities'][0]->type; // Debugging. //print_r($activity); if ($activity_type === null) { $activity_type = 'activity_update'; } if (is_user_logged_in() && $activity_type !== 'activity_liked') { if (bp_activity_get_meta($bp_like_id, 'liked_count', true)) { $users_who_like = array_keys(bp_activity_get_meta($bp_like_id, 'liked_count', true)); $liked_count = count($users_who_like); } if (!bp_like_is_liked($bp_like_id, 'activity')) { ?> <a href="#" class="<?php echo $bp_like_css; ?> " id="like-activity-<?php echo $bp_like_id; ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } else { ?> <a href="#" class="<?php echo $bp_like_css; ?> " id="unlike-activity-<?php echo $bp_like_id; ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } // Checking if there are users who like item. if (isset($users_who_like)) { view_who_likes(); } } }