Beispiel #1
0
 /**
  * Unserializes the event object stored in the database
  *
  * @param string $serialized Serialized string
  * @return string
  */
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     if (isset($data->action)) {
         $this->action = $data->action;
     }
     if (isset($data->object_id) && isset($data->object_type)) {
         switch ($data->object_type) {
             case 'object':
             case 'user':
             case 'group':
             case 'site':
                 $this->object = get_entity($data->object_id);
                 break;
             case 'annotation':
                 $this->object = elgg_get_annotation_from_id($data->object_id);
                 break;
             case 'metadata':
                 $this->object = elgg_get_metadata_from_id($data->object_id);
                 break;
             case 'relationship':
                 $this->object = get_relationship($data->object_id);
         }
     }
     if (isset($data->actor_guid)) {
         $this->actor = get_entity($data->actor_guid);
     }
 }
 /**
  * Creates random annotations on $entity
  *
  * @param \ElggEntity $entity
  * @param int        $max
  */
 protected function createRandomAnnotations($entity, $max = 1)
 {
     $annotations = array();
     for ($i = 0; $i < $max; $i++) {
         $name = 'test_annotation_name_' . rand();
         $value = rand();
         $id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
         $annotations[] = elgg_get_annotation_from_id($id);
     }
     return $annotations;
 }
Beispiel #3
0
 public function testCanEdit()
 {
     $user = new \ElggUser();
     $user->save();
     $id = $this->entity->annotate('test', 'foo', ACCESS_LOGGED_IN, elgg_get_logged_in_user_guid());
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertFalse($a->canEdit($user->guid));
     $id = $this->entity->annotate('test', 'foo2', ACCESS_LOGGED_IN, $user->guid);
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertTrue($a->canEdit($user->guid));
     $user->delete();
 }
Beispiel #4
0
/**
 * Add messageboard post
 *
 * @param ElggUser $poster User posting the message
 * @param ElggUser $owner User who owns the message board
 * @param string $message The posted message
 * @param int $access_id Access level (see defines in elgglib.php)
 * @return bool
 */
function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC)
{
    $result_id = $owner->annotate('messageboard', $message, $access_id, $poster->guid);
    if (!$result_id) {
        return false;
    }
    elgg_create_river_item(array('view' => 'river/object/messageboard/create', 'action_type' => 'messageboard', 'subject_guid' => $poster->guid, 'object_guid' => $owner->guid, 'access_id' => $access_id, 'annotation_id' => $result_id));
    // Send notification only if poster isn't the owner
    if ($poster->guid != $owner->guid) {
        $subject = elgg_echo('messageboard:email:subject', array(), $owner->language);
        $body = elgg_echo('messageboard:email:body', array($poster->name, $message, elgg_get_site_url() . "messageboard/owner/" . $owner->username, $poster->name, $poster->getURL()), $owner->language);
        $params = ['action' => 'create', 'object' => elgg_get_annotation_from_id($result_id)];
        notify_user($owner->guid, $poster->guid, $subject, $body, $params);
    }
    return $result_id;
}
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function get($uid = '')
 {
     switch ($uid) {
         case 'me':
             $uid = "ue" . elgg_get_logged_in_user_guid();
             break;
         case 'site':
             $uid = "se" . elgg_get_site_entity()->guid;
             break;
     }
     $abbr = substr($uid, 0, 2);
     switch ($abbr) {
         case 'an':
             $id = (int) substr($uid, 2);
             $object = elgg_get_annotation_from_id($id);
             break;
         case 'md':
             $id = (int) substr($uid, 2);
             $object = elgg_get_metadata_from_id($id);
             break;
         case 'rl':
             $id = (int) substr($uid, 2);
             $object = get_relationship($id);
             break;
         case 'rv':
             $id = (int) substr($uid, 2);
             $river = elgg_get_river(array('ids' => sanitize_int($id)));
             $object = $river ? $river[0] : false;
             break;
         case 'ue':
         case 'se':
         case 'oe':
         case 'ge':
             $id = (int) substr($uid, 2);
             $object = get_entity($id);
             break;
         default:
             $object = get_user_by_username($uid);
             if (!$object && is_numeric($uid)) {
                 $object = get_entity($uid);
             }
     }
     if (!$this->isExportable($object)) {
         return false;
     }
     return $object;
 }
Beispiel #6
0
 /**
  * Get the object of the event
  *
  * @return \ElggData
  */
 public function getObject()
 {
     switch ($this->object_type) {
         case 'object':
         case 'user':
         case 'site':
         case 'group':
             return get_entity($this->object_id);
             break;
         case 'relationship':
             return get_relationship($this->object_id);
             break;
         case 'annotation':
             return elgg_get_annotation_from_id($this->object_id);
             break;
     }
     return null;
 }
Beispiel #7
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)));
 }
Beispiel #8
0
<?php

/**
 * 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);
}
/**
 * Get a specific annotation.
 *
 * @param int $annotation_id Annotation ID
 *
 * @return ElggAnnotation
 * @deprecated 1.8 Use elgg_get_annotation_from_id()
 */
function get_annotation($annotation_id)
{
    elgg_deprecated_notice('get_annotation() is deprecated by elgg_get_annotation_from_id()', 1.8);
    return elgg_get_annotation_from_id($annotation_id);
}
Beispiel #10
0
<?php

/**
 * Elgg delete comment action
 *
 * @package Elgg
 */
// Make sure we can get the comment in question
$annotation_id = (int) get_input('annotation_id');
$comment = elgg_get_annotation_from_id($annotation_id);
if ($comment && $comment->canEdit()) {
    $comment->delete();
    system_message(elgg_echo("generic_comment:deleted"));
} else {
    register_error(elgg_echo("generic_comment:notdeleted"));
}
forward(REFERER);
Beispiel #11
0
         }
         $m = new \ElggMetadata();
         $m->value = $v;
         $m->name = $id_or_name;
         $m->entity_guid = $guid;
         $m->time_created = $entity->time_created;
         $m->time_updated = $entity->time_updated;
         $m->owner_guid = $entity->owner_guid;
         $m->id = $id_or_name;
         $m->type = "attr";
         break;
     case 'metadata':
         $m = elgg_get_metadata_from_id($id_or_name);
         break;
     case 'annotation':
         $m = elgg_get_annotation_from_id($id_or_name);
         break;
     case 'relationship':
         $r = get_relationship($id_or_name);
         break;
     case 'volatile':
         $m = elgg_trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name));
         break;
     default:
         $msg = "Sorry, I don't know how to export '" . $type . "'";
         throw new \InvalidParameterException($msg);
 }
 // Render metadata or relationship
 if (!$m && !$r) {
     throw new \InvalidParameterException("Could not find any data.");
 }
Beispiel #12
0
 /**
  * Create a new annotation.
  *
  * @param int    $entity_guid GUID of entity to be annotated
  * @param string $name        Name of annotation
  * @param string $value       Value of annotation
  * @param string $value_type  Type of value (default is auto detection)
  * @param int    $owner_guid  Owner of annotation (default is logged in user)
  * @param int    $access_id   Access level of annotation
  *
  * @return int|bool id on success or false on failure
  */
 function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE)
 {
     $result = false;
     $entity_guid = (int) $entity_guid;
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = _elgg_services()->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $time = time();
     $value_id = elgg_get_metastring_id($value);
     if (!$value_id) {
         return false;
     }
     $name_id = elgg_get_metastring_id($name);
     if (!$name_id) {
         return false;
     }
     // @todo we don't check that the entity is loaded which means the user may
     // not have access to the entity
     $entity = get_entity($entity_guid);
     if (_elgg_services()->events->trigger('annotate', $entity->type, $entity)) {
         $result = _elgg_services()->db->insertData("INSERT INTO {$this->CONFIG->dbprefix}annotations\n\t\t\t\t(entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES\n\t\t\t\t({$entity_guid}, {$name_id}, {$value_id}, '{$value_type}', {$owner_guid}, {$time}, {$access_id})");
         if ($result !== false) {
             $obj = elgg_get_annotation_from_id($result);
             if (_elgg_services()->events->trigger('create', 'annotation', $obj)) {
                 return $result;
             } else {
                 // plugin returned false to reject annotation
                 elgg_delete_annotation_by_id($result);
                 return false;
             }
         }
     }
     return $result;
 }
Beispiel #13
0
/**
 * Web service delete a reply
 *
 * @param string $username username
 * @param string $id       Annotation ID of reply
 *
 * @return bool
 */
function group_forum_delete_reply($id, $username)
{
    $reply = elgg_get_annotation_from_id($id);
    if (!$reply || $reply->name != 'group_topic_post') {
        $msg = elgg_echo('discussion:reply:error:notdeleted');
        throw new InvalidParameterException($msg);
    }
    if (!$username) {
        $user = get_loggedin_user();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    if (!$reply->canEdit($user->guid)) {
        $msg = elgg_echo('discussion:error:permissions');
        throw new InvalidParameterException($msg);
    }
    $result = $reply->delete();
    if ($result) {
        $return['success'] = true;
        $return['message'] = elgg_echo('discussion:reply:deleted');
    } else {
        $msg = elgg_echo('discussion:reply:error:notdeleted');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
Beispiel #14
0
 /**
  * Create a new annotation.
  *
  * @param int    $entity_guid GUID of entity to be annotated
  * @param string $name        Name of annotation
  * @param string $value       Value of annotation
  * @param string $value_type  Type of value (default is auto detection)
  * @param int    $owner_guid  Owner of annotation (default is logged in user)
  * @param int    $access_id   Access level of annotation
  *
  * @return int|bool id on success or false on failure
  */
 function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE)
 {
     $result = false;
     $entity_guid = (int) $entity_guid;
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     // @todo we don't check that the entity is loaded which means the user may
     // not have access to the entity
     $entity = get_entity($entity_guid);
     if ($this->events->trigger('annotate', $entity->type, $entity)) {
         $sql = "INSERT INTO {$this->db->prefix}annotations\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES\n\t\t\t\t(:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
         $result = $this->db->insertData($sql, [':entity_guid' => $entity_guid, ':name' => $name, ':value' => $value, ':value_type' => $value_type, ':owner_guid' => $owner_guid, ':time_created' => $this->getCurrentTime()->getTimestamp(), ':access_id' => $access_id]);
         if ($result !== false) {
             $obj = elgg_get_annotation_from_id($result);
             if ($this->events->trigger('create', 'annotation', $obj)) {
                 return $result;
             } else {
                 // plugin returned false to reject annotation
                 elgg_delete_annotation_by_id($result);
                 return false;
             }
         }
     }
     return $result;
 }
Beispiel #15
0
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = elgg_get_annotation_from_id($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = _elgg_services()->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $value_id = elgg_get_metastring_id($value);
     if (!$value_id) {
         return false;
     }
     $name_id = elgg_get_metastring_id($name);
     if (!$name_id) {
         return false;
     }
     $result = _elgg_services()->db->updateData("UPDATE {$this->CONFIG->dbprefix}annotations\n\t\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\t\tWHERE id = {$annotation_id}");
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = elgg_get_annotation_from_id($annotation_id);
         _elgg_services()->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
Beispiel #16
0
$user = elgg_get_logged_in_user_entity();
$page_owner = elgg_get_page_owner_entity();
if (empty($page_owner) || !(elgg_instanceof($page_owner, "site") || elgg_instanceof($page_owner, "group"))) {
    register_error(elgg_echo("pageownerunavailable", array(elgg_get_page_owner_guid())));
    forward(REFERER);
}
if (elgg_instanceof($page_owner, "group") && !$page_owner->canEdit()) {
    register_error(elgg_echo("user_support:page_owner:cant_edit"));
    forward(REFERER);
} elseif (elgg_instanceof($page_owner, "site")) {
    elgg_admin_gatekeeper();
}
$annotation = false;
if (elgg_is_admin_logged_in()) {
    if ($annotation_id = (int) get_input("annotation")) {
        if ($temp_anno = elgg_get_annotation_from_id($annotation_id)) {
            if (($entity = $temp_anno->getEntity()) && elgg_instanceof($entity, "object", UserSupportTicket::SUBTYPE)) {
                $annotation = $temp_anno;
            }
        }
    }
}
elgg_push_context("faq");
// make breadcrumb
if (elgg_instanceof($page_owner, "group")) {
    elgg_push_breadcrumb($page_owner->name, "user_support/faq/group/" . $page_owner->getGUID() . "/all");
}
elgg_push_breadcrumb(elgg_echo("user_support:faq:create:title"));
// page elements
$title_text = elgg_echo("user_support:faq:create:title");
$body_vars = array("help_context" => user_support_find_unique_help_context(), "annotation" => $annotation);
Beispiel #17
0
<?php

/**
 * Photo tag view
 *
 * @uses $vars['tag'] Tag object
 *
 * @author Cash Costello
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
 */
$coords = json_decode('{' . $vars['tag']->coords . '}');
$attributes = elgg_format_attributes(array('class' => 'tidypics-tag', 'data-x1' => $coords->x1, 'data-y1' => $coords->y1, 'data-width' => $coords->width, 'data-height' => $coords->height));
$annotation = elgg_get_annotation_from_id($vars['tag']->annotation_id);
if ($vars['tag']->type == 'user') {
    $user = get_entity($vars['tag']->value);
    $user_link = elgg_view('output/url', array('text' => $user->name, 'href' => $user->getURL()));
    $tagger = get_entity($annotation->owner_guid);
    $tagger_link = elgg_view('output/url', array('text' => $tagger->name, 'href' => $tagger->getURL()));
    $label = elgg_echo('tidypics:tags:membertag') . $user_link . elgg_echo('tidypics:tags:taggedby', array($tagger_link));
} else {
    $label = elgg_echo('tidypics:tags:wordtags') . $vars['tag']->value;
}
$delete = '';
if ($annotation->canEdit()) {
    $url = elgg_http_add_url_query_elements('action/photos/image/untag', array('annotation_id' => $vars['tag']->annotation_id));
    $delete = elgg_view('output/url', array('href' => $url, 'text' => elgg_view_icon('delete', 'float mas'), 'confirm' => elgg_echo('tidypics:phototagging:delete:confirm')));
}
echo <<<HTML
<div class="tidypics-tag-wrapper">
\t<div {$attributes}>{$delete}</div>
\t<div class="elgg-module-popup tidypics-tag-label">{$label}</div>
 /**
  * For a given ID, return the object associated with it.
  * This is used by the river functionality primarily.
  * This is useful for checking access permissions etc on objects.
  *
  * @param int $id An annotation ID.
  *
  * @return ElggAnnotation
  */
 public function getObjectFromID($id)
 {
     return elgg_get_annotation_from_id($id);
 }
Beispiel #19
0
/**
 * Get the URL for this annotation.
 *
 * @param int $id Annotation id
 *
 * @return string|bool False on failure
 * @deprecated 1.9 Use method getURL() on annotation object
 */
function get_annotation_url($id)
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \\ElggAnnotation::getURL()', 1.9);
    $id = (int) $id;
    if ($extender = elgg_get_annotation_from_id($id)) {
        return get_extender_url($extender);
    }
    return false;
}
Beispiel #20
0
 public static function getAnnotation(PropertyInterface $prop, $object)
 {
     $id = $prop->getAttributeName();
     return isset($object->{$id}) ? elgg_get_annotation_from_id($object->{$id}) : null;
 }
Beispiel #21
0
$guid = (int) get_input("guid");
$revision = get_input("revision");
$params = array('filter' => '');
$vars = array();
$vars['id'] = 'blog-post-edit';
$vars['name'] = 'blog_post';
$vars['class'] = 'elgg-form-alt';
$vars['enctype'] = 'multipart/form-data';
if ($page == 'edit') {
    $blog = get_entity((int) $guid);
    $title = elgg_echo('blog:edit');
    if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
        $vars['entity'] = $blog;
        $title .= ": \"{$blog->title}\"";
        if ($revision) {
            $revision = elgg_get_annotation_from_id((int) $revision);
            $vars['revision'] = $revision;
            $title .= ' ' . elgg_echo('blog:edit_revision_notice');
            if (!$revision || !($revision->entity_guid == $guid)) {
                $content = elgg_echo('blog:error:revision_not_found');
                $params['content'] = $content;
                $params['title'] = $title;
                return $params;
            }
        }
        $body_vars = blog_prepare_form_vars($blog, $revision);
        elgg_push_breadcrumb($blog->title, $blog->getURL());
        elgg_push_breadcrumb(elgg_echo('edit'));
        elgg_load_js('elgg.blog');
        $content = elgg_view_form('blog/save', $vars, $body_vars);
        $sidebar = elgg_view('blog/sidebar/revisions', $vars);
Beispiel #22
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $target_guid = sanitise_int($target_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    $dbprefix = elgg_get_config('dbprefix');
    $id = insert_data("INSERT INTO {$dbprefix}river " . " SET type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " target_guid = {$target_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Beispiel #23
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $values = array('type' => $object->getType(), 'subtype' => $object->getSubtype(), 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    $col_types = array('type' => 'string', 'subtype' => 'string', 'action_type' => 'string', 'access_id' => 'int', 'view' => 'string', 'subject_guid' => 'int', 'object_guid' => 'int', 'target_guid' => 'int', 'annotation_id' => 'int', 'posted' => 'int');
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    $dbprefix = elgg_get_config('dbprefix');
    // escape values array and build INSERT assignments
    $assignments = array();
    foreach ($col_types as $name => $type) {
        $values[$name] = $type === 'int' ? (int) $values[$name] : sanitize_string($values[$name]);
        $assignments[] = "{$name} = '{$values[$name]}'";
    }
    $id = insert_data("INSERT INTO {$dbprefix}river SET " . implode(',', $assignments));
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($values['object_guid'], $values['posted']);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Beispiel #24
0
/**
 * Get the URL for this item of metadata, by default this links to the
 * export handler in the current view.
 *
 * @param int $id Annotation id
 *
 * @return mixed
 */
function get_annotation_url($id)
{
    $id = (int) $id;
    if ($extender = elgg_get_annotation_from_id($id)) {
        return get_extender_url($extender);
    }
    return false;
}
Beispiel #25
0
<?php

/**
 * Remove photo tag action
 */
$annotation = elgg_get_annotation_from_id(get_input('annotation_id'));
if (!$annotation instanceof ElggAnnotation || $annotation->name != 'phototag') {
    register_error(elgg_echo("tidypics:phototagging:delete:error"));
    forward(REFERER);
}
if (!$annotation->canEdit()) {
    register_error(elgg_echo("tidypics:phototagging:delete:error"));
    forward(REFERER);
}
$entity_guid = $annotation->entity_guid;
$tag = unserialize($annotation->value);
if ($annotation->delete()) {
    if ($tag->type == 'user') {
        remove_entity_relationship($tag->value, 'phototag', $entity_guid);
    }
    system_message(elgg_echo("tidypics:phototagging:delete:success"));
} else {
    system_message(elgg_echo("tidypics:phototagging:delete:error"));
}
forward(REFERER);
Beispiel #26
0
/**
 * Web service delete a reply
 *
 * @param string $username username
 * @param string $id       Annotation ID of reply
 *
 * @return bool
 */
function group_forum_delete_reply($username, $id)
{
    $reply = elgg_get_annotation_from_id($id);
    $return['success'] = false;
    if (!$reply || $reply->name != 'group_topic_post') {
        $return['message'] = elgg_echo('discussion:reply:error:notdeleted');
        return $return;
    }
    $user = get_user_by_username($username);
    if (!$user) {
        $return['message'] = elgg_echo('registration:usernamenotvalid');
        return $return;
    }
    if (!$reply->canEdit($user->guid)) {
        $return['message'] = elgg_echo('discussion:error:permissions');
        return $return;
    }
    $result = $reply->delete();
    if ($result) {
        $return['success'] = true;
        $return['message'] = elgg_echo('discussion:reply:deleted');
        return $return;
    } else {
        $return['message'] = elgg_echo('discussion:reply:error:notdeleted');
        return $return;
    }
}
Beispiel #27
0
/**
 * Update an annotation.
 *
 * @param int    $annotation_id Annotation ID
 * @param string $name          Name of annotation
 * @param string $value         Value of annotation
 * @param string $value_type    Type of value
 * @param int    $owner_guid    Owner of annotation
 * @param int    $access_id     Access level of annotation
 *
 * @return bool
 */
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $annotation_id = (int) $annotation_id;
    $annotation = elgg_get_annotation_from_id($annotation_id);
    if (!$annotation) {
        return false;
    }
    if (!$annotation->canEdit()) {
        return false;
    }
    $name = trim($name);
    $value_type = detect_extender_valuetype($value, $value_type);
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    $value_id = elgg_get_metastring_id($value);
    if (!$value_id) {
        return false;
    }
    $name_id = elgg_get_metastring_id($name);
    if (!$name_id) {
        return false;
    }
    $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\tWHERE id = {$annotation_id}");
    if ($result !== false) {
        // @todo add plugin hook that sends old and new annotation information before db access
        $obj = elgg_get_annotation_from_id($annotation_id);
        elgg_trigger_event('update', 'annotation', $obj);
    }
    return $result;
}
Beispiel #28
0
/**
 * Get page components to edit/create a news post.
 *
 * @param string  $page     'edit' or 'new'
 * @param int     $guid     GUID of news post or container
 * @param int     $revision Annotation id for revision to edit (optional)
 * @return array
 */
function news_get_page_content_edit($page, $guid = 0, $revision = null)
{
    elgg_require_js('news/save_draft');
    $return = array('filter' => '');
    $vars = array();
    $vars['id'] = 'news-post-edit';
    $vars['class'] = 'elgg-form-alt';
    $sidebar = '';
    if ($page == 'edit') {
        $news = get_entity((int) $guid);
        $title = elgg_echo('news:edit');
        if (elgg_instanceof($news, 'object', 'news') && $news->canEdit()) {
            $vars['entity'] = $news;
            $title .= ": \"{$news->title}\"";
            if ($revision) {
                $revision = elgg_get_annotation_from_id((int) $revision);
                $vars['revision'] = $revision;
                $title .= ' ' . elgg_echo('news:edit_revision_notice');
                if (!$revision || !($revision->entity_guid == $guid)) {
                    $content = elgg_echo('news:error:revision_not_found');
                    $return['content'] = $content;
                    $return['title'] = $title;
                    return $return;
                }
            }
            $body_vars = news_prepare_form_vars($news, $revision);
            elgg_push_breadcrumb($news->title, $news->getURL());
            elgg_push_breadcrumb(elgg_echo('edit'));
            elgg_require_js('news/save_draft');
            $content = elgg_view_form('news/save', $vars, $body_vars);
            $sidebar = elgg_view('news/sidebar/revisions', $vars);
        } else {
            $content = elgg_echo('news:error:cannot_edit_post');
        }
    } else {
        elgg_push_breadcrumb(elgg_echo('news:add'));
        $body_vars = news_prepare_form_vars(null);
        $title = elgg_echo('news:add');
        $content = elgg_view_form('news/save', $vars, $body_vars);
    }
    $return['title'] = $title;
    $return['content'] = $content;
    $return['sidebar'] = $sidebar;
    return $return;
}
/**
 * Get page components to edit/create a blog post.
 *
 * @param string  $page     'edit' or 'new'
 * @param int     $guid     GUID of blog post or container
 * @param int     $revision Annotation id for revision to edit (optional)
 * @return array
 */
function blog_get_page_content_edit($page, $guid = 0, $revision = NULL)
{
    elgg_load_js('elgg.blog');
    $return = array('filter' => '');
    $vars = array();
    $vars['id'] = 'blog-post-edit';
    $vars['name'] = 'blog_post';
    $vars['class'] = 'elgg-form-alt';
    if ($page == 'edit') {
        $blog = get_entity((int) $guid);
        $title = elgg_echo('blog:edit');
        if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
            $vars['entity'] = $blog;
            $title .= ": \"{$blog->title}\"";
            if ($revision) {
                $revision = elgg_get_annotation_from_id((int) $revision);
                $vars['revision'] = $revision;
                $title .= ' ' . elgg_echo('blog:edit_revision_notice');
                if (!$revision || !($revision->entity_guid == $guid)) {
                    $content = elgg_echo('blog:error:revision_not_found');
                    $return['content'] = $content;
                    $return['title'] = $title;
                    return $return;
                }
            }
            $body_vars = blog_prepare_form_vars($blog, $revision);
            elgg_push_breadcrumb($blog->title, $blog->getURL());
            elgg_push_breadcrumb(elgg_echo('edit'));
            elgg_load_js('elgg.blog');
            $content = elgg_view_form('blog/save', $vars, $body_vars);
            $sidebar = elgg_view('blog/sidebar/revisions', $vars);
        } else {
            $content = elgg_echo('blog:error:cannot_edit_post');
        }
    } else {
        if (!$guid) {
            $container = elgg_get_logged_in_user_entity();
        } else {
            $container = get_entity($guid);
        }
        elgg_push_breadcrumb(elgg_echo('blog:add'));
        $body_vars = blog_prepare_form_vars($blog);
        $title = elgg_echo('blog:add');
        $content = elgg_view_form('blog/save', $vars, $body_vars);
    }
    $return['title'] = $title;
    $return['content'] = $content;
    $return['sidebar'] = $sidebar;
    return $return;
}
Beispiel #30
0
<?php

/**
 * Remove a page (revision) annotation
 *
 * @package ElggPages
 */
// Make sure we can get the annotations and entity in question
$annotation_id = (int) get_input('annotation_id');
$annotation = elgg_get_annotation_from_id($annotation_id);
if ($annotation) {
    $entity = get_entity($annotation->entity_guid);
    if (pages_is_page($entity) && $entity->canEdit() && $annotation->canEdit()) {
        $annotation->delete();
        system_message(elgg_echo("pages:revision:delete:success"));
        forward("pages/history/{$annotation->entity_guid}");
    }
}
register_error(elgg_echo("pages:revision:delete:failure"));
forward(REFERER);