<?php /** * Count of who has liked something * * @uses $vars['entity'] */ $num_of_likes = \Elgg\Likes\DataService::instance()->getNumLikes($vars['entity']); $guid = $vars['entity']->guid; // 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)); } $class = 'elgg-lightbox elgg-non-link'; if (!$num_of_likes) { $class .= ' hidden'; } $params = array('text' => $likes_string, 'title' => elgg_echo('likes:see'), 'class' => $class, 'href' => '#', 'data-likes-guid' => $vars['entity']->guid, 'data-colorbox-opts' => json_encode(['maxHeight' => '85%', 'href' => elgg_normalize_url("ajax/view/likes/popup?guid={$guid}")])); echo elgg_view('output/url', $params);
/** * Add a like button to river actions */ function likes_river_menu_setup($hook, $type, $return, $params) { if (!elgg_is_logged_in() || elgg_in_context('widgets')) { return; } $item = $params['item']; /* @var ElggRiverItem $item */ // only like group creation #3958 if ($item->type == "group" && $item->view != "river/group/create") { return; } if ($item->annotation_id != 0) { return; } $object = $item->getObjectEntity(); if (!$object || !$object->canAnnotate(0, 'likes')) { return; } $hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($object->guid); // Always register both. That makes it super easy to toggle with javascript $return[] = ElggMenuItem::factory(array('name' => 'likes', 'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"), 'text' => elgg_view_icon('thumbs-up'), 'title' => elgg_echo('likes:likethis'), 'item_class' => $hasLiked ? 'hidden' : '', 'priority' => 100)); $return[] = ElggMenuItem::factory(array('name' => 'unlike', 'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"), 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'item_class' => $hasLiked ? '' : 'hidden', 'priority' => 100)); // likes count $count = elgg_view('likes/count', array('entity' => $object)); if ($count) { $return[] = ElggMenuItem::factory(array('name' => 'likes_count', 'text' => $count, 'href' => false, 'priority' => 101)); } return $return; }
function wet4_elgg_river_menu_setup($hook, $type, $return, $params) { // $entity = $params['entity']; if (elgg_is_logged_in()) { $item = $params['item']; /* @var \ElggRiverItem $item */ $object = $item->getObjectEntity(); // add comment link but annotations cannot be commented on if (!$object || !$object->canAnnotate(0, 'likes')) { return; } $entContext = $object->getType(); if ($entContext == 'object') { $entContext = proper_subtypes($object->getSubtype()); //$entity->getSubtype(); } else { if ($entContext == 'group') { $entContext = elgg_echo('group'); } } if ($entContext != 'user') { $hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($object->guid); // Always register both. That makes it super easy to toggle with javascript $return[] = ElggMenuItem::factory(array('name' => 'likes', 'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"), 'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">Like This</span>', 'title' => elgg_echo('likes:likethis') . ' ' . $entContext, 'item_class' => $hasLiked ? 'hidden' : '', 'priority' => 100)); $return[] = ElggMenuItem::factory(array('name' => 'unlike', 'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"), 'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">Like This</span>', 'title' => elgg_echo('likes:remove') . ' ' . $entContext, 'item_class' => $hasLiked ? '' : 'hidden', 'priority' => 100)); // likes count $count = elgg_view('likes/count', array('entity' => $object)); if ($count) { $return[] = ElggMenuItem::factory(array('name' => 'likes_count', 'text' => $count, 'href' => false, 'priority' => 101)); } } $blocked_subtypes = array('comment', 'discussion_reply'); if (in_array($object->getSubtype(), $blocked_subtypes) || elgg_instanceof($object, 'user')) { //do not let comments or discussion replies to be reshared on the wire } else { $return[] = ElggMenuItem::factory(array('name' => 'thewire_tools_reshare', 'text' => '<i class="fa fa-share-alt fa-lg icon-unsel"><span class="wb-inv">Share this on the Wire</span></i>', 'title' => elgg_echo('thewire_tools:reshare'), 'href' => 'ajax/view/thewire_tools/reshare?reshare_guid=' . $object->getGUID(), 'link_class' => 'elgg-lightbox', 'item_class' => '', 'is_trusted' => true, 'priority' => 500)); } if (elgg_is_admin_logged_in()) { $options = array('name' => 'delete', 'href' => elgg_add_action_tokens_to_url("action/river/delete?id={$item->id}"), 'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">Delete This</span></i>', 'title' => elgg_echo('river:delete'), 'confirm' => elgg_echo('deleteconfirm'), 'priority' => 200); $return[] = \ElggMenuItem::factory($options); } } return $return; }
<?php /** * Elgg likes river preloader (extends page/components/list) * * @uses $vars['items'] Array of ElggEntity or ElggAnnotation objects * @uses $vars['list_class'] Additional CSS class for the <ul> element */ $user = elgg_get_logged_in_user_entity(); if ($user && !elgg_in_context('widgets') && ($vars['list_class'] === 'elgg-list-river' || $vars['list_class'] === 'elgg-list-entity') && count($vars['items']) > 2) { $preloader = new \Elgg\Likes\Preloader(\Elgg\Likes\DataService::instance()); $preloader->preloadForList($vars['items']); }
function wet4_elgg_river_menu_setup($hook, $type, $return, $params) { if (elgg_is_logged_in()) { $item = $params['item']; /* @var \ElggRiverItem $item */ $object = $item->getObjectEntity(); // add comment link but annotations cannot be commented on if ($item->annotation_id == 0) { if ($object->canComment()) { /* $options = array( 'name' => 'comment', 'href' => "#comments-add-$object->guid", 'text' => '<i class="fa fa-comment-o fa-lg icon-unsel"><span class="wb-inv">Comment on this</span></i>', 'title' => elgg_echo('comment:this'), //'rel' => 'toggle', 'data-toggle' => 'collapse', 'aria-expanded' => 'false', 'priority' => 50, ); $return[] = \ElggMenuItem::factory($options); */ } else { /* $options = array( 'name' => 'reply', 'href' => "#comments-add-$object->guid", 'text' => '<i class="fa fa-comment-o fa-lg icon-unsel"><span class="wb-inv">Comment on this</span></i>', 'title' => 'Reply to this', //'rel' => 'toggle', 'data-toggle' => 'collapse', 'aria-expanded' => 'false', 'priority' => 50, ); $return[] = \ElggMenuItem::factory($options); */ } } $object = $item->getObjectEntity(); if (!$object || !$object->canAnnotate(0, 'likes')) { return; } $hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($object->guid); // Always register both. That makes it super easy to toggle with javascript $return[] = ElggMenuItem::factory(array('name' => 'likes', 'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"), 'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">Like This</span>', 'title' => elgg_echo('likes:likethis'), 'item_class' => $hasLiked ? 'hidden' : '', 'priority' => 100)); $return[] = ElggMenuItem::factory(array('name' => 'unlike', 'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"), 'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">Like This</span>', 'title' => elgg_echo('likes:remove'), 'item_class' => $hasLiked ? '' : 'hidden', 'priority' => 100)); // likes count $count = elgg_view('likes/count', array('entity' => $object)); if ($count) { $return[] = ElggMenuItem::factory(array('name' => 'likes_count', 'text' => $count, 'href' => false, 'priority' => 101)); } if (elgg_is_admin_logged_in()) { $options = array('name' => 'delete', 'href' => elgg_add_action_tokens_to_url("action/river/delete?id={$item->id}"), 'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">Delete This</span></i>', 'title' => elgg_echo('river:delete'), 'confirm' => elgg_echo('deleteconfirm'), 'priority' => 200); $return[] = \ElggMenuItem::factory($options); } } return $return; }