本文整理汇总了PHP中elgg_annotation_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_annotation_exists函数的具体用法?PHP elgg_annotation_exists怎么用?PHP elgg_annotation_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_annotation_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interactionsMenuSetup
/**
* Setups entity interactions menu
*
* @param string $hook "register"
* @param string $type "menu:interactions"
* @param array $menu Menu
* @param array $params Hook parameters
* @uses $params['entity'] An entity that we are interacting with
* @uses $params['active_tab'] Currently active tab, default to 'comments'
* @return array
*/
public static function interactionsMenuSetup($hook, $type, $menu, $params)
{
$entity = elgg_extract('entity', $params, false);
/* @var ElggEntity $entity */
if (!elgg_instanceof($entity)) {
return $menu;
}
$active_tab = elgg_extract('active_tab', $params);
// Commenting
$comments_count = $entity->countComments();
$can_comment = $entity->canComment();
if ($can_comment) {
$menu[] = ElggMenuItem::factory(array('name' => 'comments', 'text' => $entity instanceof Comment ? elgg_echo('interactions:reply:create') : elgg_echo('interactions:comment:create'), 'href' => "stream/comments/{$entity->guid}", 'priority' => 200, 'data-trait' => 'comments', 'item_class' => 'interactions-action'));
}
if ($can_comment || $comments_count) {
$menu[] = ElggMenuItem::factory(array('name' => 'comments:badge', 'text' => elgg_view('framework/interactions/elements/badge', array('entity' => $entity, 'icon' => 'comments', 'type' => 'comments', 'count' => $comments_count)), 'href' => "stream/comments/{$entity->guid}", 'selected' => $active_tab == 'comments', 'priority' => 100, 'data-trait' => 'comments', 'item_class' => 'interactions-tab'));
}
if (elgg_is_active_plugin('likes')) {
// Liking and unliking
$likes_count = $entity->countAnnotations('likes');
$can_like = $entity->canAnnotate(0, 'likes');
$does_like = elgg_annotation_exists($entity->guid, 'likes');
if ($can_like) {
$before_text = elgg_echo('interactions:likes:before');
$after_text = elgg_echo('interactions:likes:after');
$menu[] = ElggMenuItem::factory(array('name' => 'likes', 'text' => $does_like ? $after_text : $before_text, 'href' => "action/stream/like?guid={$entity->guid}", 'is_action' => true, 'priority' => 400, 'link_class' => 'interactions-state-toggler', 'item_class' => 'interactions-action', 'data-guid' => $entity->guid, 'data-trait' => 'likes', 'data-state' => $does_like ? 'after' : 'before'));
}
if ($can_like || $likes_count) {
$menu[] = ElggMenuItem::factory(array('name' => 'likes:badge', 'text' => elgg_view('framework/interactions/elements/badge', array('entity' => $entity, 'icon' => 'likes', 'type' => 'likes', 'count' => $likes_count)), 'href' => "stream/likes/{$entity->guid}", 'selected' => $active_tab == 'likes', 'data-trait' => 'likes', 'priority' => 300, 'item_class' => 'interactions-tab'));
}
}
return $menu;
}
示例2: currentUserLikesEntity
/**
* @param int $entity_guid
* @return bool
*/
public function currentUserLikesEntity($entity_guid)
{
if (!isset($this->current_user_likes[$entity_guid])) {
$this->current_user_likes[$entity_guid] = elgg_annotation_exists($entity_guid, 'likes');
}
return $this->current_user_likes[$entity_guid];
}
示例3: likes_river_menu_setup
/**
* Add a like button to river actions
*/
function likes_river_menu_setup($hook, $type, $return, $params)
{
if (elgg_is_logged_in()) {
$item = $params['item'];
// only like group creation #3958
if ($item->type == "group" && $item->view != "river/group/create") {
return $return;
}
// don't like users #4116
if ($item->type == "user") {
return $return;
}
$object = $item->getObjectEntity();
if (!elgg_in_context('widgets') && $item->annotation_id == 0) {
if ($object->canAnnotate(0, 'likes')) {
$hasLiked = elgg_annotation_exists($object->guid, 'likes');
// Always register both. That makes it super easy to toggle with javascript
$return[] = ElggMenuItem::factory(array('name' => 'like', '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;
}
示例4: like_post_API
function like_post_API($entity_guid)
{
$params = array('types' => 'object', 'subtypes' => 'thewire', 'guid' => $entity_guid);
$latest_wire = elgg_get_entities($params);
if (elgg_annotation_exists($entity_guid, 'likes')) {
//delete like
if ($entity_guid) {
$like = elgg_get_annotation_from_id($entity_guid);
}
if (!$like) {
$likes = elgg_get_annotations(array('guid' => $entity_guid, 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), 'annotation_name' => 'likes'));
$like = $likes[0];
}
if ($latest_wire) {
if ($like && $like->canEdit()) {
$like->delete();
//echo elgg_echo("likes:deleted");
return '3';
//return 'delete';
} else {
//echo elgg_echo("likes:notdeleted");
//return 'notdelete';
return '4';
}
} else {
return '6';
}
} else {
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
//echo elgg_echo("likes:notfound");
//return'not found';
return '5';
}
if ($latest_wire) {
$user = elgg_get_logged_in_user_entity();
$annotation_id = create_annotation($entity->guid, 'likes', "likes", "", $user->guid, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation_id) {
//echo elgg_echo("likes:failure");
//return 'like failure';
return '2';
}
// notify if poster wasn't owner
return '1';
//echo elgg_echo("likes:likes");
//return 'like';
} else {
return '6';
}
}
}
示例5: customactivity_river_menu_handler
function customactivity_river_menu_handler($hook, $type, $items, $params)
{
$item = $params['item'];
$object = $item->getObjectEntity();
if (!elgg_in_context('widgets') && !$item->annotation_id && $object instanceof ElggEntity) {
if (elgg_is_active_plugin('likes') && $object->canAnnotate(0, 'likes')) {
if (!elgg_annotation_exists($object->getGUID(), 'likes')) {
// user has not liked this yet
$options = array('name' => 'like', 'href' => "action/likes/add?guid={$object->guid}", 'text' => elgg_view_icon('thumbs-up'), 'title' => elgg_echo('likes:likethis'), 'is_action' => true, 'priority' => 100);
} else {
// user has liked this
$options = array('name' => 'like', 'href' => "action/likes/delete?guid={$object->guid}", 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'is_action' => true, 'priority' => 100);
}
$items[] = ElggMenuItem::factory($options);
}
}
return $items;
}
示例6: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
$entity_guid = (int) $params->guid;
//check to see if the user has already liked the item
if (elgg_annotation_exists($entity_guid, 'likes')) {
throw new GraphException(elgg_echo("likes:alreadyliked"), HttpResponse::HTTP_NOT_MODIFIED);
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
throw new GraphException(elgg_echo("likes:notfound"), HttpResponse::HTTP_NOT_FOUND);
}
// limit likes through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate(0, 'likes')) {
// plugins should register the error message to explain why liking isn't allowed
throw new GraphException(elgg_echo("likes:notallowed"), HttpResponse::HTTP_FORBIDDEN);
}
$user = elgg_get_logged_in_user_entity();
$annotation_id = create_annotation($entity->guid, 'likes', "likes", "", $user->guid, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation_id) {
throw new GraphException(elgg_echo("likes:failure"));
}
// notify if poster wasn't owner
if ($entity->owner_guid != $user->guid) {
$owner = $entity->getOwnerEntity();
$annotation = elgg_get_annotation_from_id($annotation_id);
$title_str = $entity->getDisplayName();
if (!$title_str) {
$title_str = elgg_get_excerpt($entity->description);
}
$site = elgg_get_site_entity();
$subject = elgg_echo('likes:notifications:subject', array($user->name, $title_str), $owner->language);
$body = elgg_echo('likes:notifications:body', array($owner->name, $user->name, $title_str, $site->name, $entity->getURL(), $user->getURL()), $owner->language);
notify_user($entity->owner_guid, $user->guid, $subject, $body, array('action' => 'create', 'object' => $annotation));
}
return array('nodes' => array(elgg_get_annotation_from_id($annotation_id)));
}
示例7: likes_add
/**
* Web service to like an entity
*
* @param string $entity_guid guid of object to like
*
* @return bool
*/
function likes_add($entity_guid)
{
if (elgg_annotation_exists($entity_guid, 'likes')) {
return elgg_echo("likes:alreadyliked");
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
return elgg_echo("likes:notfound");
}
// limit likes through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate(0, 'likes')) {
return elgg_echo("likes:notallowed");
}
$user = elgg_get_logged_in_user_entity();
$annotation = create_annotation($entity->guid, 'likes', "likes", "", $user->guid, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation) {
return elgg_echo("likes:failure");
}
elgg_create_river_item('annotation/annotatelike', 'likes', $user->guid, $entity->guid, "", 0, $annotation);
return elgg_echo("likes:likes");
}
示例8: likes_river_menu_setup
/**
* Add a like button to river actions
*/
function likes_river_menu_setup($hook, $type, $return, $params)
{
if (elgg_is_logged_in()) {
$item = $params['item'];
$object = $item->getObjectEntity();
if (!elgg_in_context('widgets') && $item->annotation_id == 0) {
if ($object->canAnnotate(0, 'likes')) {
if (!elgg_annotation_exists($object->getGUID(), 'likes')) {
// user has not liked this yet
$url = "action/likes/add?guid={$object->getGUID()}";
$options = array('name' => 'like', 'href' => $url, 'text' => elgg_view('likes/display', array('entity' => $object)), 'is_action' => true, 'priority' => 100);
} else {
// user has liked this
$likes = elgg_get_annotations(array('guid' => $object->getGUID(), 'annotation_name' => 'likes', 'annotation_owner_guid' => elgg_get_logged_in_user_guid()));
$url = elgg_get_site_url() . "action/likes/delete?annotation_id={$likes[0]->id}";
$options = array('name' => 'like', 'href' => $url, 'text' => elgg_view('likes/display', array('entity' => $object)), 'is_action' => true, 'priority' => 100);
}
$return[] = ElggMenuItem::factory($options);
}
}
}
return $return;
}
示例9: getStats
/**
* Returns entity statistics
* @return array
*/
public function getStats()
{
$stats = array('replies' => array('count' => $this->countReplies()), 'likes' => array('count' => $this->countAnnotations('likes'), 'state' => elgg_annotation_exists($entity->guid, 'likes') ? 'after' : 'before'));
return elgg_trigger_plugin_hook('get_stats', 'interactions', array('entity' => $entity), $stats);
}
示例10: get_entity
$tidypics_batch = get_entity($like_entry->entity_guid);
// Get images related to this batch
$images = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $tidypics_batch->getGUID(), 'inverse_relationship' => true, 'type' => 'object', 'subtype' => 'image', 'limit' => false));
// move the like to the album if more than a single image was uploaded in this batch
if (count($images) > 1) {
$album = get_entity($tidypics_batch->container_guid);
// in case the same user who liked the Tidypics batch entry on the activity already
// liked the album delete the annotation to prevent double likes
if (elgg_annotation_exists($album->guid, 'likes', $like_entry->owner_guid)) {
elgg_delete_annotation_by_id($like_entry->id);
} else {
// fix annotation
$query = "\n\t\t\t\t\tUPDATE {$db_prefix}annotations\n\t\t\t\t\tSET entity_guid = {$album->guid},\n\t\t\t\t\t\taccess_id = {$album->access_id}\n\t\t\t\t\tWHERE id = {$like_entry->id}\n\t\t\t";
update_data($query);
}
// move the like to the image if only a single image was uploaded in the batch
} else {
// in case the same user who liked the Tidypics batch entry on the activity already
// liked the image delete the annotation to prevent double likes
if (elgg_annotation_exists($images[0]->guid, 'likes', $like_entry->owner_guid)) {
elgg_delete_annotation_by_id($like_entry->id);
} else {
// fix annotation
$query = "\n\t\t\t\t\tUPDATE {$db_prefix}annotations\n\t\t\t\t\tSET entity_guid = {$images[0]->guid},\n\t\t\t\t\t\taccess_id = {$images[0]->access_id}\n\t\t\t\t\tWHERE id = {$like_entry->id}\n\t\t\t";
update_data($query);
}
}
}
// End of Update Part 4/4
elgg_set_ignore_access($ia);
access_show_hidden_entities($access_status);
示例11: facebook_theme_river_menu_handler
function facebook_theme_river_menu_handler($hook, $type, $items, $params)
{
$item = $params['item'];
$object = $item->getObjectEntity();
if (!elgg_in_context('widgets') && !$item->annotation_id && $object instanceof ElggEntity) {
if (elgg_is_active_plugin('likes') && $object->canAnnotate(0, 'likes')) {
if (!elgg_annotation_exists($object->getGUID(), 'likes')) {
// user has not liked this yet
$options = array('name' => 'like', 'href' => "action/likes/add?guid={$object->guid}", 'text' => elgg_echo('likes:likethis'), 'is_action' => true, 'priority' => 100);
} else {
// user has liked this
$options = array('name' => 'like', 'href' => "action/likes/delete?guid={$object->guid}", 'text' => elgg_echo('likes:remove'), 'is_action' => true, 'priority' => 100);
}
$items[] = ElggMenuItem::factory($options);
}
if ($object->canAnnotate(0, 'generic_comment')) {
$items[] = ElggMenuItem::factory(array('name' => 'comment', 'href' => "#comments-add-{$object->guid}", 'text' => elgg_echo('comment'), 'title' => elgg_echo('comment:this'), 'rel' => "toggle", 'priority' => 50));
}
if ($object instanceof ElggUser && !$object->isFriend()) {
$items[] = ElggMenuItem::factory(array('name' => 'addfriend', 'href' => "/action/friends/add?friend={$object->guid}", 'text' => elgg_echo('friend:user:add', array($object->name)), 'is_action' => TRUE));
}
if (elgg_instanceof($object, 'object', 'groupforumtopic')) {
$items[] = ElggMenuItem::factory(array('name' => 'reply', 'href' => "#groups-reply-{$object->guid}", 'title' => elgg_echo('reply:this'), 'text' => elgg_echo('reply')));
}
}
return $items;
}
示例12: array
<?php
/**
* Elgg favourites button
*
* @uses $vars['entity']
*/
if (!isset($vars['entity'])) {
return true;
}
$guid = $vars['entity']->getGUID();
// check to see if the user has already marked this as favourite
if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'favourite')) {
if (!elgg_annotation_exists($guid, 'favourite')) {
$url = elgg_get_site_url() . "action/favourites/add?guid={$guid}";
$params = array('href' => $url, 'text' => elgg_view_icon('star-empty'), 'title' => elgg_echo('favourites:markthis'), 'is_action' => true, 'is_trusted' => true);
$favourites_button = elgg_view('output/url', $params);
} else {
$url = elgg_get_site_url() . "action/favourites/delete?guid={$guid}";
$params = array('href' => $url, 'text' => elgg_view_icon('star-alt'), 'title' => elgg_echo('favourites:remove'), 'is_action' => true, 'is_trusted' => true);
$favourites_button = elgg_view('output/url', $params);
}
}
echo $favourites_button;
示例13: pleio_api_like_entity
function pleio_api_like_entity($guid)
{
$user = elgg_get_logged_in_user_entity();
$user_id = $user !== false ? $user->guid : 0;
$guid = (int) $guid;
//check to see if the user has already liked the item
if (elgg_annotation_exists($guid, 'likes')) {
return new ErrorResult(elgg_echo("likes:alreadyliked"));
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($guid);
if (!$entity) {
return new ErrorResult(elgg_echo("likes:notfound"));
}
// limit likes through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate($user_id, 'likes')) {
return new ErrorResult(elgg_echo("likes:failure"));
}
$annotation = create_annotation($entity->guid, 'likes', "likes", "", $user_id, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation) {
return new ErrorResult(elgg_echo("likes:failure"));
}
// notify if poster wasn't owner
if ($entity->owner_guid != $user->guid) {
likes_notify_user($entity->getOwnerEntity(), $user, $entity);
}
return new SuccessResult(elgg_echo("likes:likes"));
}
示例14: testElggAnnotationExists
public function testElggAnnotationExists()
{
$e = new ElggObject();
$e->save();
$guid = $e->getGUID();
$this->assertFalse(elgg_annotation_exists($guid, 'test_annotation'));
$e->annotate('test_annotation', rand(0, 10000));
$this->assertTrue(elgg_annotation_exists($guid, 'test_annotation'));
// this metastring should always exist but an annotation of this name should not
$this->assertFalse(elgg_annotation_exists($guid, 'email'));
$options = array('guid' => $guid, 'limit' => 0);
$this->assertTrue(elgg_disable_annotations($options));
$this->assertTrue(elgg_annotation_exists($guid, 'test_annotation'));
$this->assertTrue($e->delete());
$this->assertFalse(elgg_annotation_exists($guid, 'test_annotation'));
}
示例15: likes_notification_action
function likes_notification_action($hook, $entity_type, $returnvalue, $params)
{
if (!elgg_annotation_exists($entity_guid, 'likes')) {
$entity_guid = get_input('guid');
$entity = get_entity($entity_guid);
$to_guid = $entity->owner_guid;
$from_entity = elgg_get_logged_in_user_entity();
$from_guid = $from_entity->guid;
if ($to_guid != $from_guid) {
$url_user = elgg_view('output/url', array('href' => $from_entity->getURL(), 'text' => $from_entity->name, 'class' => 'elgg-river-subject'));
$description = elgg_echo('live_notifications:like', array($url_user, $entity->getUrl()));
if ($entity->getSubtype() == 'thewire') {
$description .= '<br/><i>' . elgg_get_excerpt($entity->description, 60) . '</i>';
} else {
$description .= '<a href="' . $entity->getUrl() . '" title="">' . $entity->title . '</a>';
}
add_new_notification($to_guid, $from_guid, 'like', $entity_guid, $description);
}
}
return true;
}