Beispiel #1
0
 /**
  * @param \ElggEntity $entity
  * @return int
  */
 public function getNumLikes(\ElggEntity $entity)
 {
     $guid = $entity->guid;
     if (!isset($this->num_likes[$guid])) {
         $this->num_likes[$guid] = likes_count($entity);
     }
     return $this->num_likes[$guid];
 }
Beispiel #2
0
/**
 * Web service to get users who liked an entity
 *
 * @param string $entity_guid guid of object 
 *
 * @return bool
 */
function likes_getusers($entity_guid)
{
    $entity = get_entity($entity_guid);
    if (likes_count($entity) > 0) {
        $list = elgg_get_annotations(array('guid' => $entity_guid, 'annotation_name' => 'likes', 'limit' => 99));
        foreach ($list as $singlelike) {
            $likes[$singlelike->id]['userid'] = $singlelike->owner_guid;
            $likes[$singlelike->id]['time_created'] = $singlelike->time_created;
            $likes[$singlelike->id]['access_id'] = $singlelike->access_id;
        }
    } else {
        $likes = elgg_echo('likes:userslikedthis', array(likes_count($entity)));
    }
    return $likes;
}
Beispiel #3
0
// check to see if the user has already liked this
if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'likes')) {
    if (!elgg_annotation_exists($guid, 'likes')) {
        $url = elgg_get_site_url() . "action/likes/add?guid={$guid}";
        $params = array('href' => $url, 'text' => elgg_view_icon('thumbs-up'), 'title' => elgg_echo('likes:likethis'), 'is_action' => true);
        $likes_button = elgg_view('output/url', $params);
    } else {
        $options = array('guid' => $guid, 'annotation_name' => 'likes', 'owner_guid' => elgg_get_logged_in_user_guid());
        $likes = elgg_get_annotations($options);
        $url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
        $params = array('href' => $url, 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'is_action' => true);
        $likes_button = elgg_view('output/url', $params);
    }
}
echo $likes_button;
$list = '';
$num_of_likes = likes_count($vars['entity']);
if ($num_of_likes) {
    // display the number of likes
    if ($num_of_likes == 1) {
        $likes_string = elgg_echo('likes:userlikedthis', array($num_of_likes));
    } else {
        $likes_string = elgg_echo('likes:userslikedthis', array($num_of_likes));
    }
    $params = array('text' => $likes_string, 'title' => elgg_echo('likes:see'), 'rel' => 'popup', 'href' => "#likes-{$guid}");
    $list = elgg_view('output/url', $params);
    $list .= "<div class='elgg-module elgg-module-popup elgg-likes-list hidden clearfix' id='likes-{$guid}'>";
    $list .= elgg_list_annotations(array('guid' => $guid, 'annotation_name' => 'likes', 'limit' => 99));
    $list .= "</div>";
    echo $list;
}
Beispiel #4
0
/**
 * Elgg delete like action
 *
 */
// Support deleting by id in case we're deleting another user's likes
$id = (int) get_input('id');
$like = NULL;
if ($id) {
    $like = elgg_get_annotation_from_id($id);
}
if (!$like) {
    $likes = elgg_get_annotations(array('guid' => (int) get_input('guid'), 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), 'annotation_name' => 'likes'));
    $like = $likes[0];
}
if ($like && $like->canEdit()) {
    $entity = $like->getEntity();
    $like->delete();
    system_message(elgg_echo("likes:deleted"));
    if ($entity && elgg_is_xhr()) {
        $num_of_likes = likes_count($entity);
        if ($num_of_likes == 1) {
            $likes_string = elgg_echo('likes:userlikedthis', array($num_of_likes));
        } else {
            $likes_string = elgg_echo('likes:userslikedthis', array($num_of_likes));
        }
        echo json_encode(['text' => $likes_string, 'selector' => "[data-likes-guid={$entity->guid}]", 'num_likes' => $num_of_likes]);
    }
    forward(REFERER);
}
register_error(elgg_echo("likes:notdeleted"));
forward(REFERER);
Beispiel #5
0
?>
>

    <div class="top-inner clearfix">
      <div class="post-categories"><img src="<?php 
echo get_template_directory_uri() . '/img/label.svg';
?>
" alt="Label icon"><?php 
the_category(' &bull; ');
?>
</div>
      <span class="likes"><img src="<?php 
echo get_template_directory_uri() . '/img/like-black.svg';
?>
" alt="Like icon"><?php 
likes_count();
?>
</span>
    </div>

    <div class="post-image">
      <a href="<?php 
the_permalink();
?>
" data-type="page-transition" title="<?php 
the_title();
?>
" rel="bookmark"><?php 
the_post_thumbnail('large');
?>
</a>
Beispiel #6
-1
function theme_ffd_questions_alt_menu_hook_handler($hook, $type, $return_value, $params)
{
    if (empty($params) || !is_array($params)) {
        return $return_value;
    }
    $entity = elgg_extract("entity", $params);
    if (empty($params) || !elgg_instanceof($entity, "object", "question")) {
        return $return_value;
    }
    // view counter
    if (elgg_is_active_plugin("entity_view_counter")) {
        $count = entity_view_counter_count_views($entity);
        $return_value[] = ElggMenuItem::factory(array("name" => "view_counter", "text" => elgg_view_icon("eye", "mrs") . elgg_echo("theme_ffd:entity_view_counter:questions:menu:views", array($count)), "href" => false, "priority" => 100));
    }
    // likes
    if (elgg_is_active_plugin("likes")) {
        $count = likes_count($entity);
        $return_value[] = ElggMenuItem::factory(array("name" => "likes", "text" => elgg_view_icon("thumbs-up", "mrs") . elgg_echo("theme_ffd:likes:questions:menu:views", array($count)), "href" => false, "priority" => 200));
    }
    // answers
    $answer_options = array("type" => "object", "subtype" => "answer", "container_guid" => $entity->getGUID(), "count" => true);
    $num_answers = elgg_get_entities($answer_options);
    $return_value[] = ElggMenuItem::factory(array("name" => "answers", "text" => elgg_view_icon("comment-o", "mrs") . elgg_echo("theme_ffd:answers:questions:menu:views", array($num_answers)), "href" => false, "priority" => 400));
    return $return_value;
}