示例#1
0
 /**
  * Publish blogs based on advanced publication settings
  *
  * @param int $time the timestamp the entity was published
  *
  * @return void
  */
 protected static function publishBlogs($time)
 {
     $dbprefix = elgg_get_config('dbprefix');
     $publication_id = elgg_get_metastring_id('publication_date');
     $publish_options = ['type' => 'object', 'subtype' => 'blog', 'limit' => false, 'joins' => ["JOIN {$dbprefix}metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN {$dbprefix}metastrings mstime ON mdtime.value_id = mstime.id"], 'metadata_name_value_pairs' => [['name' => 'status', 'value' => 'draft']], 'wheres' => ["((mdtime.name_id = {$publication_id}) AND (DATE(mstime.string) = DATE(NOW())))"]];
     // get unpublished blogs that need to be published
     $entities = new \ElggBatch('elgg_get_entities_from_metadata', $publish_options);
     foreach ($entities as $entity) {
         // add river item
         elgg_create_river_item(['view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $entity->getOwnerGUID(), 'object_guid' => $entity->getGUID()]);
         // set correct time created
         $entity->time_created = $time;
         // publish blog
         $entity->status = 'published';
         // revert access
         $entity->access_id = $entity->future_access;
         unset($entity->future_access);
         // send notifications when post published
         elgg_trigger_event('publish', 'object', $entity);
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo('blog_tools:notify:publish:subject'), elgg_echo('blog_tools:notify:publish:message', [$entity->title, $entity->getURL()]));
         // save everything
         $entity->save();
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $user = elgg_get_logged_in_user_entity();
     $object = get_entity($params->guid);
     if (!$object || !$object->canWriteToContainer(0, 'object', 'comment')) {
         throw new GraphException("You are not allowed to comment on this object", 403);
     }
     $comment_text = $params->comment;
     $comment = new ElggComment();
     $comment->owner_guid = $user->guid;
     $comment->container_guid = $object->guid;
     $comment->description = $comment_text;
     $comment->access_id = $object->access_id;
     if (!$comment->save()) {
         throw new GraphException(elgg_echo("generic_comment:failure"));
     }
     // Notify if poster wasn't owner
     if ($object->owner_guid != $user->guid) {
         $owner = $object->getOwnerEntity();
         notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($object->title, $user->name, $comment->description, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create'));
     }
     $return = array('nodes' => array('comment' => $comment));
     // Add to river
     $river_id = elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $comment->guid, 'target_guid' => $object->guid));
     if ($river_id) {
         $river = elgg_get_river(array('ids' => $river_id));
         $return['nodes']['activity'] = $river ? $river[0] : $river_id;
     }
     return $return;
 }
示例#3
0
function app2_blog_save($title, $text, $excerpt, $tags, $access, $container_guid)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->container_guid = $container_guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
    if ($guid) {
        return true;
    } else {
        return false;
    }
}
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $user = get_entity($params->guid);
     $friend = $params->friend_uid ? $this->graph->get($params->friend_uid) : null;
     if (!$user instanceof ElggUser || !$friend instanceof ElggUser) {
         throw new GraphException("User or friend not found", HttpResponse::HTTP_NOT_FOUND);
     }
     if (!$user->canEdit()) {
         throw new GraphException("You are not allowed to modify this user's friends list", HttpResponse::HTTP_FORBIDDEN);
     }
     if ($user->guid == $friend->guid) {
         throw new GraphException("You are trying to friend yourself", HttpResponse::HTTP_BAD_REQUEST);
     }
     if (check_entity_relationship($user->guid, 'friend', $friend->guid)) {
         throw new GraphException("Already a friend", HttpResponse::HTTP_BAD_REQUEST);
     }
     if (!add_entity_relationship($user->guid, 'friend', $friend->guid)) {
         throw new GraphException("Unable to create friendship");
     }
     $river_id = elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid));
     $return = array('nodes' => array('friend' => check_entity_relationship($user->guid, 'friend', $friend->guid), 'friend_of' => check_entity_relationship($friend->guid, 'friend', $user->guid)));
     if (!empty($river_id)) {
         $river = elgg_get_river(array('ids' => $river_id));
         $return['nodes']['activity'] = $river ? $river[0] : $river_id;
     }
     return $return;
 }
示例#5
0
/**
 * This method is called when a users points are updated.
 * We check to see what the users current balance is and
 * assign the appropriate badge.
 */
function badges_userpoints($hook, $type, $return, $params)
{
    if ($params['entity']->badges_locked) {
        return true;
    }
    $points = $params['entity']->userpoints_points;
    $badge = get_entity($params['entity']->badges_badge);
    $options = array('type' => 'object', 'subtype' => 'badge', 'limit' => false, 'order_by_metadata' => array('name' => 'badges_userpoints', 'direction' => DESC, 'as' => integer));
    $options['metadata_name_value_pairs'] = array(array('name' => 'badges_userpoints', 'value' => $points, 'operand' => '<='));
    $entities = elgg_get_entities_from_metadata($options);
    if ((int) elgg_get_plugin_setting('lock_high', 'elggx_badges')) {
        if ($badge->badges_userpoints > $entities[0]->badges_userpoints) {
            return true;
        }
    }
    if ($badge->guid != $entities[0]->guid) {
        $params['entity']->badges_badge = $entities[0]->guid;
        if (!elgg_trigger_plugin_hook('badges:update', 'object', array('entity' => $user), true)) {
            $params['entity']->badges_badge = $badge->guid;
            return false;
        }
        // Announce it on the river
        $user_guid = $params['entity']->getGUID();
        elgg_delete_river(array("view" => 'river/object/badge/assign', "subject_guid" => $user_guid, "object_guid" => $user_guid));
        elgg_delete_river(array("view" => 'river/object/badge/award', "subject_guid" => $user_guid, "object_guid" => $user_guid));
        elgg_create_river_item(array('view' => 'river/object/badge/award', 'action_type' => 'award', 'subject_guid' => $user_guid, 'object_guid' => $user_guid));
    }
    return true;
}
示例#6
0
function profile_river_updates($event, $type, $object)
{
    $user = get_entity($object->guid);
    if ($user instanceof ElggUser) {
        $view = 'river/user/default/profileupdate';
        elgg_delete_river(array('subject_guid' => $user->guid, 'view' => $view));
        elgg_create_river_item(array('view' => $view, 'action_type' => 'update', 'subject_guid' => $user->guid, 'object_guid' => $user->guid, 'access_id' => get_default_access($user)));
    }
    return true;
}
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $subject = $this->graph->get($params->subject_uid);
     if (!$subject || !$subject->canEdit()) {
         throw new GraphException('You are not allowed to create new activity items with this subject', 403);
     }
     $id = elgg_create_river_item(array_filter(array('view' => $params->view, 'subject_guid' => $this->graph->get($params->subject_uid)->guid ?: ELGG_ENTITIES_ANY_VALUE, 'object_guid' => $this->graph->get($params->object_uid)->guid ?: ELGG_ENTITIES_ANY_VALUE, 'target_guid' => $this->graph->get($params->target_uid)->guid ?: ELGG_ENTITIES_ANY_VALUE, 'action_type' => $params->action, 'annotation_id' => $this->graph->get($params->annotation_uid)->id)));
     if (!$id) {
         throw new GraphException('Unable to create a new activity item with such parameters', 400);
     }
     $params->id = $id;
     $ctrl = new RiverItem($this->request, $this->graph);
     return $ctrl->get($params);
 }
示例#8
0
 public function testElggCreateRiverItemBadEntity()
 {
     $entity = elgg_get_entities(array('limit' => 1));
     $entity = $entity[0];
     $params = array('view' => 'river/relationship/friend/create', 'action_type' => 'create', 'subject_guid' => $entity->guid, 'object_guid' => $entity->guid, 'target_guid' => $entity->guid);
     $bad_subject = $params;
     $bad_subject['subject_guid'] = -1;
     $this->assertFalse(elgg_create_river_item($bad_subject));
     $bad_object = $params;
     $bad_object['object_guid'] = -1;
     $this->assertFalse(elgg_create_river_item($bad_object));
     $bad_target = $params;
     $bad_target['target_guid'] = -1;
     $this->assertFalse(elgg_create_river_item($bad_target));
 }
示例#9
0
文件: start.php 项目: cyrixhero/Elgg
/**
 * 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);
        notify_user($owner->guid, $poster->guid, $subject, $body);
    }
    return $result_id;
}
示例#10
0
文件: Cron.php 项目: lorea/Hydra-dev
 /**
  * Publish blogs based on advanced publication options
  *
  * @param string $hook         'cron'
  * @param string $type         'daily'
  * @param string $return_value optional stdout text
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function daily($hook, $type, $return_value, $params)
 {
     // only do if this is configured
     if (!blog_tools_use_advanced_publication_options()) {
         return $return_value;
     }
     $dbprefix = elgg_get_config("dbprefix");
     $publication_id = elgg_get_metastring_id("publication_date");
     $expiration_id = elgg_get_metastring_id("expiration_date");
     $time = elgg_extract("time", $params, time());
     $publish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array(array("name" => "status", "value" => "draft")), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
     $unpublish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_values_pairs" => array(array("name" => "status", "value" => "published")), "wheres" => array("((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
     // ignore access
     $ia = elgg_set_ignore_access(true);
     // get unpublished blogs that need to be published
     $entities = new \ElggBatch("elgg_get_entities_from_metadata", $publish_options);
     foreach ($entities as $entity) {
         // add river item
         elgg_create_river_item(array("view" => "river/object/blog/create", "action_type" => "create", "subject_guid" => $entity->getOwnerGUID(), "object_guid" => $entity->getGUID()));
         // set correct time created
         $entity->time_created = $time;
         // publish blog
         $entity->status = "published";
         // revert access
         $entity->access_id = $entity->future_access;
         unset($entity->future_access);
         // send notifications when post published
         elgg_trigger_event('publish', 'object', $entity);
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:publish:subject"), elgg_echo("blog_tools:notify:publish:message", array($entity->title, $entity->getURL())));
         // save everything
         $entity->save();
     }
     // get published blogs that need to be unpublished
     $entities = new \ElggBatch("elgg_get_entities_from_metadata", $unpublish_options);
     foreach ($entities as $entity) {
         // remove river item
         elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create"));
         // unpublish blog
         $entity->status = "draft";
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:expire:subject"), elgg_echo("blog_tools:notify:expire:message", array($entity->title, $entity->getURL())));
         // save everything
         $entity->save();
     }
     // reset access
     elgg_set_ignore_access($ia);
 }
示例#11
0
 /**
  * Adds a river event when a user joins the site
  *
  * @param string           $event       Event name
  * @param string           $object_type Event type
  * @param ElggRelationship $object      Relationship object being created
  *
  * @return void
  */
 public static function createMember($event, $object_type, $object)
 {
     if ($object->relationship !== 'member_of_site') {
         return;
     }
     $enable_river_event = elgg_get_plugin_setting('enable_site_join_river_event', 'profile_manager');
     if ($enable_river_event == 'no') {
         return;
     }
     $user_guid = $object->guid_one;
     $site_guid = $object->guid_two;
     // clear current river events
     elgg_delete_river(['view' => 'river/relationship/member_of_site/create', 'subject_guid' => $user_guid, 'object_guid' => $site_guid]);
     // add new join river event
     elgg_create_river_item(['view' => 'river/relationship/member_of_site/create', 'action_type' => 'join', 'subject_guid' => $user_guid, 'object_guid' => $site_guid]);
 }
示例#12
0
/**
 * Create river events when a friend is added
 *
 * @param int $user_guid   the user who is accepting
 * @param int $friend_guid the friend who he accepted
 *
 * @return bool
 */
function friend_request_create_river_events($user_guid, $friend_guid)
{
    $user_guid = sanitise_int($user_guid, false);
    $friend_guid = sanitise_int($friend_guid, false);
    if (empty($user_guid) || empty($friend_guid)) {
        return false;
    }
    // check plugin setting
    if (elgg_get_plugin_setting('add_river', 'friend_request') === 'no') {
        // no event are to be created
        return true;
    }
    // add to river
    elgg_create_river_item(['view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user_guid, 'object_guid' => $friend_guid]);
    elgg_create_river_item(['view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $friend_guid, 'object_guid' => $user_guid]);
    return true;
}
/**
 * Add friends if invite code was set
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param bool   $result Whether to allow registration
 * @param array  $params Hook params
 * @return void
 */
function invitefriends_add_friends($hook, $type, $result, $params)
{
    $user = $params['user'];
    $friend_guid = $params['friend_guid'];
    $invite_code = $params['invitecode'];
    // If $friend_guid has been set, make mutual friends
    if ($friend_guid) {
        if ($friend_user = get_user($friend_guid)) {
            if ($invite_code == generate_invite_code($friend_user->username)) {
                $user->addFriend($friend_guid);
                $friend_user->addFriend($user->guid);
                // @todo Should this be in addFriend?
                elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->getGUID(), 'object_guid' => $friend_guid));
                elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $friend_guid, 'object_guid' => $user->getGUID()));
            }
        }
    }
}
示例#14
0
function hypefaker_add_page($owner, $container, $parent = null)
{
    $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
    $faker = Factory::create($locale);
    $access_array = get_write_access_array($owner->guid);
    $access_id = array_rand($access_array, 1);
    $write_access_array = get_write_access_array($owner->guid);
    unset($write_access_array[ACCESS_PUBLIC]);
    $write_access_id = array_rand($write_access_array, 1);
    $page = new ElggObject();
    $page->subtype = $parent ? 'page' : 'page_top';
    $page->owner_guid = $owner->guid;
    $page->container_guid = $container->guid;
    $page->title = $faker->sentence(6);
    $page->description = $faker->text(500);
    $page->tags = $faker->words(5);
    $page->access_id = $access_id;
    $page->write_access_id = $write_access_id;
    $page->__faker = true;
    if ($parent) {
        $page->parent_guid = $parent->guid;
    }
    if ($page->save()) {
        $page->annotate('page', $page->description, $page->access_id, $page->owner_guid);
        elgg_create_river_item(array('view' => 'river/object/page/create', 'action_type' => 'create', 'subject_guid' => $page->owner_guid, 'object_guid' => $page->getGUID()));
        // add some revisions
        $users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => rand(1, 10), 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
        foreach ($users as $user) {
            if ($page->canAnnotate($user->guid, 'page')) {
                $last_revision = $faker->text(500);
                $page->annotate('page', $last_annotation, $page->access_id, $user->guid);
            }
        }
        if (!empty($last_revision)) {
            $page->description = $last_revision;
            $page->save();
        }
        return $page;
    }
    return false;
}
示例#15
0
function hypefaker_add_wire($owner, $parent = null)
{
    $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
    $faker = Factory::create($locale);
    $wire = new ElggObject();
    $wire->subtype = 'thewire';
    $wire->owner_guid = $owner->guid;
    $tags = $faker->words(5);
    $text = $faker->text(80);
    foreach ($tags as $tag) {
        $text .= " #{$tag}";
    }
    if ($parent) {
        $wire->reply = true;
        $username = $parent->getOwnerEntity()->username;
        $text = "@{$username} {$text}";
    }
    $limit = elgg_get_plugin_setting('limit', 'thewire');
    if ($limit > 0) {
        $text = elgg_substr($text, 0, $limit);
    }
    $wire->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    $wire->tags = $tags;
    $wire->method = 'faker';
    $wire->access_id = ACCESS_PUBLIC;
    $wire->__faker = true;
    if ($wire->save()) {
        if ($parent) {
            $wire->addRelationship($parent->guid, 'parent');
            $wire->wire_thread = $parent->wire_thread;
        } else {
            $wire->wire_thread = $wire->guid;
        }
        elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $wire->owner_guid, 'object_guid' => $wire->guid));
        $params = array('entity' => $wire, 'user' => $owner, 'message' => $wire->description, 'url' => $wire->getURL(), 'origin' => 'thewire');
        elgg_trigger_plugin_hook('status', 'user', $params);
        return $wire;
    }
    return false;
}
示例#16
0
/**
 * 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");
}
示例#17
0
 public function testElggRiverDisableEnable()
 {
     $user = new \ElggUser();
     $user->save();
     $entity = new \ElggObject();
     $entity->save();
     $params = array('view' => 'river/relationship/friend/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $entity->guid);
     $id = elgg_create_river_item($params);
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river[0]->enabled, 'yes');
     $user->disable();
     // should no longer be able to get the river
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river, array());
     // renabling the user should re-enable the river
     access_show_hidden_entities(true);
     $user->enable();
     access_show_hidden_entities(false);
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river[0]->enabled, 'yes');
     $user->delete();
     $entity->delete();
 }
示例#18
0
文件: save.php 项目: lorea/Hydra-dev
    register_error(elgg_echo('questions:action:answer:save:error:body', [$container_guid, $description]));
    forward(REFERER);
}
if ($adding && !can_write_to_container(0, $container_guid, 'object', 'answer')) {
    register_error(elgg_echo('questions:action:answer:save:error:container'));
    forward(REFERER);
}
$question = get_entity($container_guid);
if (empty($question) || !$question instanceof ElggQuestion) {
    register_error(elgg_echo('ClassException:ClassnameNotClass', [$container_guid, elgg_echo('item:object:question')]));
    forward(REFERER);
}
if ($question->getStatus() != 'open') {
    elgg_clear_sticky_form('answer');
    register_error(elgg_echo('questions:action:answer:save:error:question_closed'));
    forward(REFERER);
}
$answer->description = $description;
$answer->access_id = $question->access_id;
$answer->container_guid = $container_guid;
try {
    $answer->save();
    if ($adding) {
        elgg_create_river_item(['view' => 'river/object/answer/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $answer->getGUID(), 'access_id' => $answer->access_id]);
    }
} catch (Exception $e) {
    register_error(elgg_echo('questions:action:answer:save:error:save'));
    register_error($e->getMessage());
}
elgg_clear_sticky_form('answer');
forward(get_input('forward', $answer->getURL()));
示例#19
0
$publication->tags = $tags;
$publication->pubtype = $type;
// save custom data
foreach ($data as $key => $value) {
    $publication->{$key} = $value;
}
// trigger event to save other custom data
elgg_trigger_event('save:data', 'publications', $publication);
// files
$file_contents = get_uploaded_file('attachment');
if (!empty($file_contents)) {
    $fh = new ElggFile();
    $fh->owner_guid = $publication->getGUID();
    $file_name = $_FILES['attachment']['name'];
    $mime = $_FILES['attachment']['type'];
    $fh->setFilename($file_name);
    if ($fh->open('write')) {
        $fh->write($file_contents);
        $fh->close();
        $publication->attached_file = $file_name;
        $publication->attached_file_mime_type = $mime;
    }
}
$publication->save();
if ($new_entity) {
    elgg_create_river_item(['view' => 'river/object/publication/create', 'action_type' => 'create', 'subject_guid' => $publication->getOwnerGUID(), 'object_guid' => $publication->getGUID(), 'target_guid' => $publication->getContainerGUID(), 'access_id' => $publication->access_id]);
}
system_message(elgg_echo('publication:posted'));
/* todo: activate add_to_river on settings */
#add_to_river('river/object/publication/update','update',$_SESSION['user']->guid,$publication->guid);
forward($publication->getURL());
示例#20
0
文件: save.php 项目: ibou77/elgg
    $topic = new ElggObject();
    $topic->subtype = 'groupforumtopic';
} else {
    // load original file object
    $topic = get_entity($guid);
    if (!elgg_instanceof($topic, 'object', 'groupforumtopic') || !$topic->canEdit()) {
        register_error(elgg_echo('discussion:topic:notfound'));
        forward(REFERER);
    }
}
$topic->title = $title;
$topic->description = $desc;
$topic->status = $status;
$topic->access_id = $access_id;
$topic->container_guid = $container_guid;
$topic->tags = string_to_tag_array($tags);
$result = $topic->save();
if (!$result) {
    register_error(elgg_echo('discussion:error:notsaved'));
    forward(REFERER);
}
// topic saved so clear sticky form
elgg_clear_sticky_form('topic');
// handle results differently for new topics and topic edits
if ($new_topic) {
    system_message(elgg_echo('discussion:topic:created'));
    elgg_create_river_item(array('view' => 'river/object/groupforumtopic/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $topic->guid));
} else {
    system_message(elgg_echo('discussion:topic:updated'));
}
forward($topic->getURL());
示例#21
0
文件: edit.php 项目: lorea/Hydra-dev
    // Initialise a new Poll
    $poll = new Poll();
    // Set its owner to the current user
    $poll->owner_guid = $user->guid;
    $poll->container_guid = $container_guid;
    // Success message
    $message = elgg_echo("poll:added");
}
$poll->access_id = $access_id;
$poll->question = $question;
$poll->title = $question;
$poll->description = $description;
$poll->open_poll = $open_poll ? 1 : 0;
$poll->close_date = empty($close_date) ? null : $close_date;
$poll->tags = string_to_tag_array($tags);
if (!$poll->save()) {
    register_error(elgg_echo("poll:error"));
    forward(REFERER);
}
$poll->setChoices($new_choices);
poll_manage_front_page($poll, $front_page);
elgg_clear_sticky_form('poll');
if ($new) {
    $poll_create_in_river = elgg_get_plugin_setting('create_in_river', 'poll');
    if ($poll_create_in_river != 'no') {
        elgg_create_river_item(array('view' => 'river/object/poll/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $poll->guid));
    }
}
system_message($message);
// Forward to the poll page
forward($poll->getURL());
示例#22
0
文件: edit.php 项目: tjcaverly/Elgg
    if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
        $visibility = $group->group_acl;
    }
    if ($group->access_id != $visibility) {
        $group->access_id = $visibility;
    }
}
$group->save();
// group saved so clear sticky form
elgg_clear_sticky_form('groups');
// group creator needs to be member of new group and river entry created
if ($is_new_group) {
    // @todo this should not be necessary...
    elgg_set_page_owner_guid($group->guid);
    $group->join($user);
    elgg_create_river_item(array('view' => 'river/group/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $group->guid));
}
$has_uploaded_icon = !empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/');
if ($has_uploaded_icon) {
    $icon_sizes = elgg_get_config('icon_sizes');
    $prefix = "groups/" . $group->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write(get_uploaded_file('icon'));
    $filehandler->close();
    $filename = $filehandler->getFilenameOnFilestore();
    $sizes = array('tiny', 'small', 'medium', 'large');
    $thumbs = array();
    foreach ($sizes as $size) {
示例#23
0
文件: save.php 项目: ibou77/elgg
} else {
    // Create a new comment on the target entity
    $entity = get_entity($entity_guid);
    if (!$entity) {
        register_error(elgg_echo("generic_comment:notfound"));
        forward(REFERER);
    }
    $user = elgg_get_logged_in_user_entity();
    $comment = new ElggComment();
    $comment->description = $comment_text;
    $comment->owner_guid = $user->getGUID();
    $comment->container_guid = $entity->getGUID();
    $comment->access_id = $entity->access_id;
    $guid = $comment->save();
    if (!$guid) {
        register_error(elgg_echo("generic_comment:failure"));
        forward(REFERER);
    }
    // Notify if poster wasn't owner
    if ($entity->owner_guid != $user->guid) {
        $owner = $entity->getOwnerEntity();
        notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($entity->title, $user->name, $comment_text, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create'));
    }
    // Add to river
    elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $guid, 'target_guid' => $entity_guid));
    system_message(elgg_echo('generic_comment:posted'));
}
if ($is_edit_page) {
    forward($comment->getURL());
}
forward(REFERER);
示例#24
0
 /**
  * Saves discussion from form input
  * @return \hypeJunction\Discussion|false
  */
 public static function saveAction()
 {
     $guid = get_input('topic_guid');
     if (!$guid) {
         $action = 'create';
         $entity = new \hypeJunction\Discussion();
         $container_guid = get_input('container_guid');
         $container = get_entity($container_guid);
     } else {
         $action = 'update';
         $entity = get_entity($guid);
         if (!$entity instanceof \hypeJunction\Discussion || !$entity->canEdit()) {
             register_error(elgg_echo('discussion:topic:notfound'));
             return false;
         }
         $container = $entity->getContainerEntity();
     }
     if (!$container || !$container->canWriteToContainer(0, 'object', \hypeJunction\Discussion::SUBTYPE)) {
         register_error(elgg_echo('discussion:error:permissions'));
         return false;
     }
     $title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
     $description = get_input('description');
     if (!$title || !$description) {
         register_error(elgg_echo('discussion:error:missing'));
         return false;
     }
     $entity->title = $title;
     $entity->description = $description;
     $entity->status = get_input('status', 'open');
     $entity->access_id = get_input('access_id', $container->access_id);
     $entity->container_guid = $container->guid;
     $entity->threads = (bool) get_input('threads');
     $entity->tags = string_to_tag_array(get_input('tags', ''));
     $result = $entity->save();
     if (!$result) {
         register_error(elgg_echo('discussion:error:notsaved'));
         return false;
     }
     if (elgg_is_active_plugin('hypeAttachments')) {
         hypeapps_attach_uploaded_files($entity, 'uploads', ['origin' => 'discussion', 'container_guid' => $entity->guid, 'access_id' => $entity->access_id]);
     }
     if ($action == 'update') {
         system_message(elgg_echo('discussion:topic:updated'));
     } else {
         system_message(elgg_echo('discussion:topic:created'));
         elgg_create_river_item(['view' => 'river/object/discussion/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $entity->guid, 'target_guid' => $entity->container_guid]);
     }
     return $entity;
 }
示例#25
0
function blog_save_json($title, $text, $excerpt, $tags, $access, $container_guid)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->container_guid = $container_guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
    if ($guid) {
        $return['addblog'] = true;
        $return['message'] = elgg_echo('blog:message:saved');
        return json_encode($return, true);
        //$return="saved";
        //return true;
    } else {
        $return['addblog'] = false;
        $return['message'] = elgg_echo('blog:error:cannot_save');
        return json_encode($return, true);
        //$return="not saved!";
        //return false;
    }
    //return $return;
}
示例#26
0
 $album->prependImageList($uploaded_images);
 // "added images to album" river
 if ($img_river_view == "batch" && $album->new_album == false) {
     elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create', 'action_type' => 'create', 'subject_guid' => $batch->getOwnerGUID(), 'object_guid' => $batch->getGUID(), 'target_guid' => $album->getGUID()));
 } else {
     if ($img_river_view == "1" && $album->new_album == false) {
         elgg_create_river_item(array('view' => 'river/object/tidypics_batch/create_single_image', 'action_type' => 'create', 'subject_guid' => $batch->getOwnerGUID(), 'object_guid' => $batch->getGUID(), 'target_guid' => $album->getGUID()));
     }
 }
 // "created album" river
 if ($album->new_album) {
     $album->new_album = false;
     $album->first_upload = true;
     $album_river_view = elgg_get_plugin_setting('album_river_view', 'tidypics');
     if ($album_river_view != "none") {
         elgg_create_river_item(array('view' => 'river/object/album/create', 'action_type' => 'create', 'subject_guid' => $album->getOwnerGUID(), 'object_guid' => $album->getGUID(), 'target_guid' => $album->getGUID()));
     }
     // "created album" notifications
     // we throw the notification manually here so users are not told about the new album until
     // there are at least a few photos in it
     if ($album->shouldNotify()) {
         elgg_trigger_event('album_first', 'album', $album);
         $album->last_notified = time();
     }
 } else {
     // "added image to album" notifications
     if ($album->first_upload) {
         $album->first_upload = false;
     }
     if ($album->shouldNotify()) {
         elgg_trigger_event('album_more', 'album', $album);
示例#27
0
文件: save.php 项目: ibou77/elgg
    $bookmark = get_entity($guid);
    if (!$bookmark->canEdit()) {
        system_message(elgg_echo('bookmarks:save:failed'));
        forward(REFERRER);
    }
}
$tagarray = string_to_tag_array($tags);
$bookmark->title = $title;
$bookmark->address = $address;
$bookmark->description = $description;
$bookmark->access_id = $access_id;
$bookmark->tags = $tagarray;
if ($bookmark->save()) {
    elgg_clear_sticky_form('bookmarks');
    // @todo
    if (is_array($shares) && sizeof($shares) > 0) {
        foreach ($shares as $share) {
            $share = (int) $share;
            add_entity_relationship($bookmark->getGUID(), 'share', $share);
        }
    }
    system_message(elgg_echo('bookmarks:save:success'));
    //add to river only if new
    if ($new) {
        elgg_create_river_item(array('view' => 'river/object/bookmarks/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $bookmark->getGUID()));
    }
    forward($bookmark->getURL());
} else {
    register_error(elgg_echo('bookmarks:save:failed'));
    forward("bookmarks");
}
示例#28
0
if (!$album) {
    echo elgg_echo('tidypics:baduploadform');
    exit;
}
// probably POST limit exceeded
if (empty($_FILES)) {
    trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING);
    register_error(elgg_echo('tidypics:exceedpostlimit'));
    exit;
}
$file = $_FILES[$file_var_name];
$image = new TidypicsImage();
$image->container_guid = $album->getGUID();
$image->setMimeType($file['type']);
$image->access_id = $album->access_id;
$image->batch = $batch;
try {
    $result = $image->save($file);
} catch (Exception $e) {
    // remove the bits that were saved
    $image->delete();
    $result = false;
    echo $e->getMessage();
}
if ($result) {
    $album->prependImageList(array($image->guid));
    if (elgg_get_plugin_setting('img_river_view', 'tidypics') === "all") {
        elgg_create_river_item(array('view' => 'river/object/image/create', 'action_type' => 'create', 'subject_guid' => $image->getOwnerGUID(), 'object_guid' => $image->getGUID()));
    }
}
exit;
示例#29
0
/**
 * Join a user to a group, add river event, clean-up invitations
 *
 * @param ElggGroup $group
 * @param ElggUser  $user
 * @return bool
 */
function groups_join_group($group, $user)
{
    // access ignore so user can be added to access collection of invisible group
    $ia = elgg_set_ignore_access(TRUE);
    $result = $group->join($user);
    elgg_set_ignore_access($ia);
    if ($result) {
        // flush user's access info so the collection is added
        get_access_list($user->guid, 0, true);
        // Remove any invite or join request flags
        remove_entity_relationship($group->guid, 'invited', $user->guid);
        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
        elgg_create_river_item(array('view' => 'river/relationship/member/create', 'action_type' => 'join', 'subject_guid' => $user->guid, 'object_guid' => $group->guid));
        return true;
    }
    return false;
}
示例#30
0
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 * @param int    $target_guid   The GUID of the the object entity's container
 *
 * @return int/bool River ID or false on failure
 * @deprecated 1.9 Use elgg_create_river_item()
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0, $target_guid = 0)
{
    elgg_deprecated_notice('add_to_river was deprecated in favor of elgg_create_river_item', '1.9');
    // Make sure old parameters are passed in correct format
    $access_id = $access_id == '' ? null : $access_id;
    $posted = $posted == 0 ? null : $posted;
    return elgg_create_river_item(array('view' => $view, 'action_type' => $action_type, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'access_id' => $access_id, 'posted' => $posted, 'annotation_id' => $annotation_id));
}