コード例 #1
0
 /**
  * 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
0
ファイル: DataService.php プロジェクト: ibou77/elgg
 /**
  * @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
0
ファイル: start.php プロジェクト: tjcaverly/Elgg
/**
 * 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
0
ファイル: wire.php プロジェクト: shimarahimpur/wireAPI
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
0
ファイル: start.php プロジェクト: duanhv/mdg-social
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
0
 /**
  * {@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
0
ファイル: likes.php プロジェクト: manlui/elgg_with_rest_api
/**
 * 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
0
ファイル: start.php プロジェクト: rasul/Elgg
/**
 * 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
0
 /**
  * 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
0
ファイル: 2013121301.php プロジェクト: pingwangcs/51zhaohu
    $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
0
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
0
ファイル: button.php プロジェクト: epsylon/Hydra-dev
<?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
0
ファイル: methods.php プロジェクト: appstaat/pleio_api
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
0
ファイル: annotations.php プロジェクト: elainenaomi/labxp2014
 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
0
ファイル: start.php プロジェクト: socialweb/PiGo
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;
}
コード例 #16
0
ファイル: replies.php プロジェクト: socialweb/PiGo
$topic = elgg_extract('entity', $vars, FALSE);
$date_time = $topic->date_time;
$start_time = $topic->start_time;
$end_time = $topic->end_time;
$new_date_time = str_replace('-', ',', $date_time);
$new_start_time = str_replace(':', ',', $start_time);
$exp_date = $date_time;
//date_default_timezone_set('America/Chicago'); // CDT
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);
if ($show_add_form) {
    $mygrud = $vars['entity']->getGUID();
    $typean = 'group_topic_post';
    $owner_guid = elgg_get_logged_in_user_entity()->guid;
    if (elgg_annotation_exists($mygrud, $typean, $owner_guid) == 0) {
        echo '</br></br></br>';
        if ($today <= $expiration_date) {
            echo '</br></br><center style="font-size: 32px; font-weight: bold;">La tarea se cierra en:</center></br><table id="table" border="0">
	<tr>
        <td align="center" colspan="6"><div class="numbers" id="count2" style="padding: 10px; "></div></td>
	</tr>
	<tr id="spacer1">
        <td align="center" ><div class="title" ></div></td>
        <td align="center" ><div class="numbers" id="dday"></div></td>
        <td align="center" ><div class="numbers" id="dhour"></div></td>
        <td align="center" ><div class="numbers" id="dmin"></div></td>
        <td align="center" ><div class="numbers" id="dsec"></div></td>
        <td align="center" ><div class="title" ></div></td>
	</tr>
	<tr id="spacer2">
コード例 #17
0
ファイル: button.php プロジェクト: amcfarlane1251/ongarde
<?php

/**
 * Elgg likes button
 *
 * @uses $vars['entity']
 */
if (!isset($vars['entity'])) {
    return true;
}
$guid = $vars['entity']->getGUID();
// 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, 'is_trusted' => true);
        $likes_button = elgg_view('output/url', $params);
    } else {
        $like = elgg_get_annotations(array('guid' => $guid, 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), 'annotation_name' => 'likes'));
        $like = $like[0];
        $url = elgg_get_site_url() . "action/likes/delete?id={$like->id}";
        $params = array('href' => $url, 'text' => elgg_view_icon('thumbs-up-alt'), 'title' => elgg_echo('likes:remove'), 'is_action' => true, 'is_trusted' => true);
        $likes_button = elgg_view('output/url', $params);
    }
}
echo $likes_button;
コード例 #18
0
ファイル: add.php プロジェクト: epsylon/Hydra-dev
<?php

/**
 * Add as favourite action
 *
 */
$entity_guid = (int) get_input('guid');
//check to see if the user has already marked the item as favourite
if (elgg_annotation_exists($entity_guid, 'favourite')) {
    system_message(elgg_echo("favourites:alreadyfavourite"));
    forward(REFERER);
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
    register_error(elgg_echo("favourites:notfound"));
    forward(REFERER);
}
// limit markings as favourite through a plugin hook (to prevent liking your own content for example)
if (!$entity->canAnnotate(0, 'favourite')) {
    // plugins should register the error message to explain why marking as favourite isn't allowed
    forward(REFERER);
}
$user = elgg_get_logged_in_user_entity();
$annotation = create_annotation($entity->guid, 'favourite', "", "", $user->guid, $entity->access_id);
// tell user annotation didn't work if that is the case
if (!$annotation) {
    register_error(elgg_echo("favourites:failure"));
    forward(REFERER);
}
// notify if poster wasn't owner
コード例 #19
0
ファイル: delete.php プロジェクト: epsylon/Hydra-dev
<?php

/**
 * Tasks remove comment action
 *
 * @package ElggTasks
 */
group_gatekeeper();
elgg_load_library('elgg:tasks');
if (elgg_annotation_exists($annotation->guid)) {
    elgg_delete_annotation_by_id($annotation_id->id);
}
// Forward to the page the action occurred on
forward(REFERER);
コード例 #20
0
ファイル: button.php プロジェクト: amcfarlane1251/ongarde
<?php

/**
 * Elgg share button
 *
 * @uses $vars['entity']
 */
if (!isset($vars['entity'])) {
    return true;
}
$guid = $vars['entity']->getGUID();
// check to see if the user has already shared this
if (elgg_is_logged_in() && $vars['entity']->canAnnotate(0, 'share')) {
    if (!elgg_annotation_exists($guid, 'share')) {
        $url = elgg_get_site_url() . "action/share/share?guid={$guid}";
        $params = array('href' => $url, 'text' => elgg_view_icon('share'), 'title' => elgg_echo('share:this'), 'is_action' => true, 'is_trusted' => true);
        $share_button = elgg_view('output/url', $params);
    } else {
        $url = elgg_get_site_url() . "action/share/delete?guid={$guid}";
        //$ulr="#";
        $params = array('href' => $url, 'text' => elgg_view_icon('share-alt'), 'title' => elgg_echo('share:remove'), 'is_action' => true, 'is_trusted' => true);
        $share_button = elgg_view('output/url', $params);
    }
}
echo $share_button;
コード例 #21
0
ファイル: hooks.php プロジェクト: pleio/theme_ffd
function theme_ffd_questions_body_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;
    }
    // content subscriptions
    if (elgg_is_logged_in() && elgg_is_active_plugin("content_subscriptions")) {
        if (!content_subscriptions_check_subscription($entity->guid)) {
            $url = "action/content_subscriptions/subscribe?entity_guid=" . $entity->getGUID();
            $text = elgg_view_icon('clip', 'mrs') . elgg_echo('theme_ffd:questions:menu:subscribe');
        } else {
            $url = "action/content_subscriptions/subscribe?entity_guid=" . $entity->getGUID();
            $text = elgg_view_icon('clip', 'mrs') . elgg_echo('theme_ffd:questions:menu:unsubscribe');
        }
        $return_value[] = ElggMenuItem::factory(array("name" => "content_subscription", "text" => $text, "href" => $url, 'is_action' => true, "priority" => 90));
    }
    // likes
    if (elgg_is_logged_in() && elgg_is_active_plugin("likes") && $entity->canAnnotate(0, 'likes')) {
        // likes button
        if (!elgg_annotation_exists($entity->getGUID(), 'likes')) {
            $url = "action/likes/add?guid=" . $entity->getGUID();
            $text = elgg_view_icon('thumbs-up', 'mrs') . elgg_echo('theme_ffd:likes:questions:menu');
        } else {
            $url = "action/likes/delete?guid=" . $entity->getGUID();
            $text = elgg_view_icon('thumbs-up-alt', 'mrs') . elgg_echo('theme_ffd:likes:questions:menu:unlike');
        }
        $return_value[] = ElggMenuItem::factory(array('name' => 'like', 'text' => $text, 'href' => $url, 'is_action' => true, 'priority' => 100));
    }
    // answers
    $return_value[] = ElggMenuItem::factory(array("name" => "answer", "text" => elgg_view_icon("comment-o", "mrs") . elgg_echo("theme_ffd:answers:questions:menu"), "href" => "questions/view/" . $entity->getGUID() . "#questions-answer-add", "priority" => 400));
    return $return_value;
}
コード例 #22
0
ファイル: add.php プロジェクト: duanhv/mdg-social
<?php

/**
 * Elgg add like action
 *
 */
$entity_guid = (int) get_input('guid');
//check to see if the user has already liked the item
if (elgg_annotation_exists($entity_guid, 'likes')) {
    returnAjaxResult(false, elgg_echo("likes:alreadyliked"), $entity);
    exit;
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
    returnAjaxResult(false, elgg_echo("likes:notfound"), $entity);
    exit;
}
// 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
    returnAjaxResult(false);
    exit;
}
$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) {
    returnAjaxResult(false, elgg_echo("likes:failure"), $entity);
    exit;
}
コード例 #23
0
ファイル: share.php プロジェクト: amcfarlane1251/ongarde
<?php

/**
 * Elgg add share action
 *
 */
$entity_guid = (int) get_input('guid');
//check to see if the user has already shared the item
if (elgg_annotation_exists($entity_guid, 'share')) {
    system_message(elgg_echo("share:alreadyshared"));
    forward(REFERER);
}
// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
    register_error(elgg_echo("share:notfound"));
    forward(REFERER);
}
// limit likes through a plugin hook (to prevent sharing your own content for example)
if (!$entity->canAnnotate(0, 'share')) {
    // plugins should register the error message to explain why liking isn't allowed
    forward(REFERER);
}
/*
int 	$entity_guid Entity Guid
string 	$name Name of annotation
string 	$value Value of annotation
string 	$value_type Type of value (default is auto detection)
int 	$owner_guid Owner of annotation (default is logged in user)
int 	$access_id Access level of annotation
*/
コード例 #24
0
ファイル: request_ownership.php プロジェクト: lorea/Hydra-dev
<?php

$user_guid = elgg_get_logged_in_user_guid();
$project_guid = get_input('project_guid');
$description = get_input('description');
$project = get_entity($project_guid);
if (!$project instanceof PluginProject) {
    register_error(elgg_echo('plugins:error:not_found'));
    forward(REFERER);
}
if (empty($description)) {
    register_error(elgg_echo('plugins:error:invalid_ownership_request'));
    forward(REFERER);
}
$exists = elgg_annotation_exists($project_guid, 'ownership_request', $user_guid);
if ($exists) {
    register_error(elgg_echo('plugins:error:ownership_request_exists'));
    forward(REFERER);
}
$success = $project->annotate('ownership_request', $description, ACCESS_PUBLIC, $user_guid, 'text');
if (!$success) {
    register_error(elgg_echo('plugins:error:ownership_request_failed'));
    forward(REFERER);
}
// Get all admins and select two of them randomly
$admins = elgg_get_admins();
shuffle($admins);
$admins = array_slice($admins, 0, 2);
// Notify the admins about the new request
foreach ($admins as $admin) {
    $url = elgg_get_site_url() . "plugins/{$project->guid}/ownership_requests";
コード例 #25
0
 /**
  * Get interaction statistics
  *
  * @param ElggEntity $entity Entity
  * @return array
  */
 public static function getStats($entity)
 {
     if (!$entity instanceof ElggEntity) {
         return array();
     }
     $stats = array('comments' => array('count' => $entity->countComments()), 'likes' => array('count' => $entity->countAnnotations('likes'), 'state' => elgg_annotation_exists($entity->guid, 'likes') ? 'after' : 'before'));
     return elgg_trigger_plugin_hook('get_stats', 'interactions', array('entity' => $entity), $stats);
 }