Exemple #1
0
function file_tools_object_handler($event, $type, $object)
{
    if (!empty($object) && elgg_instanceof($object, "object", "file")) {
        $folder_guid = (int) get_input("folder_guid", 0);
        if (!empty($folder_guid)) {
            if ($folder = get_entity($folder_guid)) {
                if (!elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
                    unset($folder_guid);
                }
            } else {
                unset($folder_guid);
            }
        }
        // remove old relationships
        remove_entity_relationships($object->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
        if (!empty($folder_guid)) {
            add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $object->getGUID());
            //update parent folders last_action attribute
            update_entity_last_action($folder_guid);
            $parent_guid = get_entity($folder_guid)->parent_guid;
            if ($parent_guid) {
                update_parent_folder_last_action($parent_guid);
            }
        }
    }
}
/**
 * Retrieve ancestry relationships / update if they have changed
 *
 * @param int $guid
 * @param mixed $subtypes
 * @return boolean|array
 */
function hj_framework_set_ancestry($guid)
{
    $entity = get_entity($guid);
    if (!$entity) {
        return false;
    }
    $ia = elgg_set_ignore_access(true);
    // Build an hierarchy from [0]highest to [X]lowest
    $ancestry = array();
    $ancestry_guids = array();
    $container = $entity->getContainerEntity();
    while (elgg_instanceof($container)) {
        array_unshift($ancestry, $container);
        array_unshift($ancestry_guids, $container->guid);
        $container = $container->getContainerEntity();
    }
    // Store as a hash so we don't unnecessarily update the hierarchy every time save() is calleed
    if (!isset($entity->hierarchy_hash) || $entity->hierarchy_hash != sha1(serialize($ancestry_guids))) {
        remove_entity_relationships($entity->guid, 'descendant', false);
        foreach ($ancestry as $ancestor) {
            if (elgg_instanceof($ancestor, 'object')) {
                update_entity_last_action($ancestor->guid, $entity->time_created);
            }
            if (!check_entity_relationship($entity->guid, 'descendant', $ancestor->guid)) {
                add_entity_relationship($entity->guid, 'descendant', $ancestor->guid);
            }
        }
        $entity->hierarchy_hash = sha1(serialize($ancestry_guids));
    }
    elgg_set_ignore_access($ia);
    return $ancestry;
}
Exemple #3
0
/**
 * Assigns a role to a particular user
 *
 * @param ElggRole $role The role to be assigned
 * @param ElggUser $user The user the role needs to be assigned to
 * @return mixed True if the role change was successful, false if could not update user role, and null if there was no change in user role
 */
function roles_set_role($role, $user = null)
{
    if (!elgg_instanceof($role, 'object', 'role')) {
        return false;
        // Couldn't set new role
    }
    $user = $user ? $user : elgg_get_logged_in_user_entity();
    if (!elgg_instanceof($user, 'user')) {
        return false;
        // Couldn't set new role
    }
    $current_role = roles_get_role($user);
    if ($role != $current_role) {
        remove_entity_relationships($user->guid, 'has_role');
        if ($role->name != DEFAULT_ROLE && $role->name != ADMIN_ROLE) {
            if (!add_entity_relationship($user->guid, 'has_role', $role->guid)) {
                return false;
                // Couldn't set new role
            }
        }
        return true;
        // Role has been changed
    }
    return null;
    // There was no change necessary, old and new role are the same
}
Exemple #4
0
 /**
  * Unmark answer as correct
  *
  * @return bool
  */
 public function unmarkCorrect()
 {
     if ($this->getQuestion()->getStatus() == 'closed') {
         $this->getQuestion()->setStatus('open');
     }
     return remove_entity_relationships($this->getQuestion()->guid, "correctAnswer");
 }
Exemple #5
0
function entity_admins_manage_admins($event, $object_type, $object)
{
    if (get_input('entity-admins-support') && $object instanceof ElggEntity) {
        remove_entity_relationships($object->guid, 'entity_admin_for', true);
        // currently the userpicker name is hardcoded to "members"
        $members = get_input('members');
        if ($members) {
            foreach ($members as $guid) {
                add_entity_relationship($guid, 'entity_admin_for', $object->guid);
            }
        }
    }
    return true;
}
Exemple #6
0
 /**
  * Migrate old tree structure to new structure
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $entity supplied entity
  *
  * @return void
  */
 public static function migrateTreeStructure($event, $type, $entity)
 {
     // this process could take a while
     set_time_limit(0);
     // set entity options
     $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'metadata_name' => 'parent_guid', 'site_guids' => false, 'limit' => false];
     // set default metadata options
     $metadata_options = ['metadata_name' => 'parent_guid', 'site_guids' => false, 'limit' => false];
     // make sure we can get all entities
     $ia = elgg_set_ignore_access(true);
     // create a batch for processing
     $batch = new \ElggBatch('elgg_get_entities_from_metadata', $options);
     $batch->setIncrementOffset(false);
     foreach ($batch as $entity) {
         $metadata_options['guid'] = $entity->getGUID();
         $parent_guid = (int) $entity->parent_guid;
         if (empty($parent_guid)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         $parent = get_entity($parent_guid);
         if (empty($parent)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         // set correct container
         $entity->container_guid = $parent->getGUID();
         $entity->save();
         // find the root page for the tree
         $root = self::findOldRootPage($entity);
         if (empty($root)) {
             // workaround for multi-site
             elgg_delete_metadata($metadata_options);
             continue;
         }
         // add relationship to the correct tree
         remove_entity_relationships($entity->getGUID(), 'subpage_of');
         $entity->addRelationship($root->getGUID(), 'subpage_of');
         // workaround for multi-site
         elgg_delete_metadata($metadata_options);
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
Exemple #7
0
function bookmark_tools_object_handler($event, $type, $object)
{
    if (!empty($object) && elgg_instanceof($object, "object", "bookmarks")) {
        $folder_guid = (int) get_input("bmfolder_guid", 0);
        if (!empty($folder_guid)) {
            if ($folder = get_entity($folder_guid)) {
                if (!elgg_instanceof($folder, "object", BOOKMARK_TOOLS_SUBTYPE)) {
                    unset($folder_guid);
                }
            } else {
                unset($folder_guid);
            }
        }
        // remove old relationships
        remove_entity_relationships($object->getGUID(), BOOKMARK_TOOLS_RELATIONSHIP, true);
        if (!empty($folder_guid)) {
            add_entity_relationship($folder_guid, BOOKMARK_TOOLS_RELATIONSHIP, $object->getGUID());
        }
    }
}
Exemple #8
0
 /**
  * Set the folder for the file
  *
  * @param \ElggFile $entity the file to edit
  *
  * @return void
  */
 protected static function setFolderGUID(\ElggFile $entity)
 {
     $folder_guid = get_input('folder_guid', false);
     if ($folder_guid === false) {
         // folder_input was not present in form/action
         // maybe someone else did something with a file
         return;
     }
     $folder_guid = (int) $folder_guid;
     if (!empty($folder_guid)) {
         $folder = get_entity($folder_guid);
         if (!elgg_instanceof($folder, 'object', FILE_TOOLS_SUBTYPE)) {
             unset($folder_guid);
         }
     }
     // remove old relationships
     remove_entity_relationships($entity->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
     if (!empty($folder_guid)) {
         add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $entity->getGUID());
     }
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function unsetUserRole(\ElggUser $user)
 {
     return (bool) remove_entity_relationships($user->guid, 'has_role');
 }
Exemple #10
0
 /**
  * Cleanup some stuff
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param null   $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function afterCleanup($hook, $type, $return_value, $params)
 {
     if (!self::validateNotificationEvent($params)) {
         // not the correct notification event
         return;
     }
     /* @var $event \Elgg\Notifications\Event */
     $event = elgg_extract('event', $params);
     /* @var $relationship \ElggRelationship */
     $relationship = $event->getObject();
     $entity = get_entity($relationship->guid_two);
     // cleanup the relationship
     remove_entity_relationships($entity->getGUID(), 'tag_tools:notification', true);
     // save the newly sent tags
     $sending_tags = tag_tools_get_unsent_tags($entity);
     if (empty($sending_tags)) {
         return;
     }
     tag_tools_add_sent_tags($entity, $sending_tags);
 }
    update_user_friends_notifications_settings($user->guid, get_input('friends_batch_method'));
    // actualizo las relaciones de notificacion entre un usuario y todos sus amigos
    $friends_method = get_input('friends_batch_method');
    if ($friends_method != 'nocambiar') {
        $friends = get_user_friends($user->guid);
        foreach ($friends as $friend) {
            switch (get_input('friends_batch_method')) {
                case 'email':
                    add_entity_relationship($user->guid, 'notifyemail', $friend->guid);
                    remove_entity_relationships($user->guid, 'notifysite', false, 'user');
                    break;
                case 'site':
                    add_entity_relationship($user->guid, 'notifysite', $friend->guid);
                    remove_entity_relationships($user->guid, 'notifyemail', false, 'user');
                    break;
                case 'todos':
                    add_entity_relationship($user->guid, 'notifyemail', $friend->guid);
                    add_entity_relationship($user->guid, 'notifysite', $friend->guid);
                    break;
                case 'ninguno':
                    remove_entity_relationships($user->guid, 'notifyemail', false, 'user');
                    remove_entity_relationships($user->guid, 'notifysite', false, 'user');
                default:
                    // metodo (nocambiar)
                    break;
            }
        }
    }
}
system_message(elgg_echo("notifications_tools:done"));
forward("admin/batch_update&personal_batch_method=" . get_input('personal_batch_method') . "&friends_batch_method=" . get_input('friends_batch_method'));
Exemple #12
0
 * Elgg notifications
 * 
 * @package ElggNotifications
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.com/
 */
// Restrict to logged in users
gatekeeper();
global $SESSION;
global $NOTIFICATION_HANDLERS;
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
    $subscriptions[$method] = get_input($method . 'subscriptions');
    $personal[$method] = get_input($method . 'personal');
    $collections[$method] = get_input($method . 'collections');
    $metaname = 'collections_notifications_preferences_' . $method;
    $_SESSION['user']->{$metaname} = $collections[$method];
    set_user_notification_setting($_SESSION['user']->guid, $method, $personal[$method] == '1' ? true : false);
    remove_entity_relationships($SESSION['user']->guid, 'notify' . $method, false, 'user');
}
// Add new ones
foreach ($subscriptions as $key => $subscription) {
    if (is_array($subscription) && !empty($subscription)) {
        foreach ($subscription as $subscriptionperson) {
            add_entity_relationship($_SESSION['user']->guid, 'notify' . $key, $subscriptionperson);
        }
    }
}
system_message(elgg_echo('notifications:subscriptions:success'));
forward($_SERVER['HTTP_REFERER']);
Exemple #13
0
/**
 * Make sure all the children are in the correct tree
 *
 * @param ElggObject $entity    the entity to check the children from
 * @param int        $tree_guid the correct tree guid (will default to the given entity)
 *
 * @return bool
 */
function static_check_children_tree(ElggObject $entity, $tree_guid = 0)
{
    if (!elgg_instanceof($entity, 'object', 'static')) {
        return false;
    }
    $tree_guid = sanitise_int($tree_guid, false);
    if (empty($tree_guid)) {
        $tree_guid = $entity->getGUID();
    }
    // ignore access for this part
    $ia = elgg_set_ignore_access(true);
    $batch = new ElggBatch('elgg_get_entities', ['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'owner_guid' => $entity->getOwnerGUID(), 'container_guid' => $entity->getGUID(), 'limit' => false]);
    foreach ($batch as $static) {
        // remove old tree
        remove_entity_relationships($static->getGUID(), 'subpage_of');
        // add new tree
        add_entity_relationship($static->getGUID(), 'subpage_of', $tree_guid);
        // check children
        static_check_children_tree($static, $tree_guid);
    }
    // restore access
    elgg_set_ignore_access($ia);
    return true;
}
Exemple #14
0
        add_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid);
        break;
    case 'assign_and_activate':
        add_entity_relationship(elgg_get_logged_in_user_guid(), 'subscribes', $entity_guid);
        add_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid);
        break;
    case 'deactivate':
        remove_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid);
        break;
    case 'leave':
        remove_entity_relationship(elgg_get_logged_in_user_guid(), 'is_doing', $entity_guid);
        remove_entity_relationship(elgg_get_logged_in_user_guid(), 'subscribes', $entity_guid);
        break;
    case 'reopen':
        remove_entity_relationships($entity_guid, 'is_doing', true);
        remove_entity_relationships($entity_guid, 'subscribes', true);
        break;
}
if (in_array($state_action, array('activate', 'assign_and_activate'))) {
    if ($active_task = tasks_get_user_active_task($user->guid)) {
        $active_task->status = 'assigned';
        create_annotation($active_task->guid, 'task_state_changed', 'assigned', "", $user->guid, $active_task->access_id);
    }
}
$new_state = tasks_get_state_from_action($state_action);
if ($state_action == 'leave') {
    $have_participants_yet = elgg_get_entities_from_relationship(array('relationship' => 'subscribes', 'relationship_guid' => $entity->guid, 'inverse_relationship' => true, 'count' => true));
    if ($have_participants_yet) {
        $new_state = $entity->status;
    }
}
Exemple #15
0
$file_guid = (int) get_input("file_guid", 0);
$folder_guid = (int) get_input("folder_guid", 0);
if (!empty($file_guid)) {
    if ($file = get_entity($file_guid)) {
        $container_entity = $file->getContainerEntity();
        if ($file->canEdit() || elgg_instanceof($container_entity, "group") && $container_entity->isMember()) {
            if (elgg_instanceof($file, "object", "file")) {
                // check if a given guid is a folder
                if (!empty($folder_guid)) {
                    if (!($folder = get_entity($folder_guid)) || !elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
                        unset($folder_guid);
                    }
                }
                // remove old relationships
                remove_entity_relationships($file->getGUID(), FILE_TOOLS_RELATIONSHIP, true);
                if (!empty($folder_guid)) {
                    add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $file_guid);
                }
                system_message(elgg_echo("file_tools:action:move:success:file"));
            } elseif (elgg_instanceof($file, "object", FILE_TOOLS_SUBTYPE)) {
                $file->parent_guid = $folder_guid;
                system_message(elgg_echo("file_tools:action:move:success:folder"));
            }
        } else {
            register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
        }
    } else {
        register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
    }
} else {
Exemple #16
0
 * @package ElggNotifications
 */
$current_user = elgg_get_logged_in_user_entity();
$guid = (int) get_input('guid', 0);
if (!$guid || !($user = get_entity($guid))) {
    forward();
}
if ($user->guid != $current_user->guid && !$current_user->isAdmin()) {
    forward();
}
$NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
$subscriptions = array();
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
    $personal[$method] = get_input($method . 'personal');
    set_user_notification_setting($user->guid, $method, $personal[$method] == '1' ? true : false);
    $collections[$method] = get_input($method . 'collections');
    $metaname = 'collections_notifications_preferences_' . $method;
    $user->{$metaname} = $collections[$method];
    $subscriptions[$method] = get_input($method . 'subscriptions');
    remove_entity_relationships($user->guid, 'notify' . $method, false, 'user');
}
// Add new ones
foreach ($subscriptions as $method => $subscription) {
    if (is_array($subscription) && !empty($subscription)) {
        foreach ($subscription as $subscriptionperson) {
            elgg_add_subscription($user->guid, $method, $subscriptionperson);
        }
    }
}
system_message(elgg_echo('notifications:subscriptions:success'));
forward(REFERER);
<?php

$event_guid = get_input('event_guid');
$event = get_entity($event_guid);
$event_calendar_add_users = elgg_get_plugin_setting('add_users', 'event_calendar');
if ($event_calendar_add_users == 'yes' && elgg_instanceof($event, 'object', 'event_calendar') && $event->canEdit()) {
    $members = get_input('members');
    // clear the event from all personal calendars
    remove_entity_relationships($event_guid, 'personal_event', true);
    // add event to personal calendars
    $event_calendar_add_users_notify = elgg_get_plugin_setting('add_users_notify', 'event_calendar');
    foreach ($members as $user_guid) {
        add_entity_relationship($user_guid, 'personal_event', $event_guid);
        if ($event_calendar_add_users_notify == 'yes') {
            if ($user_guid != elgg_get_logged_in_user_guid()) {
                $user = get_user($user_guid);
                $user_language = $user->language ? $user->language : (($site_language = elgg_get_config('language')) ? $site_language : 'en');
                $subject = elgg_echo('event_calendar:add_users_notify:subject', array(), $user_language);
                $message = elgg_echo('event_calendar:add_users_notify:body', array($user->name, $event->title, $event->getURL()), $user_language);
                notify_user($user_guid, elgg_get_logged_in_user_guid(), $subject, $message, array('object' => $event, 'action' => 'subscribe', 'summary' => $subject));
            }
        }
    }
    system_message(elgg_echo('event_calendar:manage_subscribers:success'));
    forward($event->getURL());
} else {
    register_error(elgg_echo('event_calendar:manage_subscribers:error'));
    forward();
}
     }
 }
 if (empty($entity)) {
     $entity = new ProfileManagerCustomFieldCategory();
     $entity->save();
     $add = true;
 }
 if (!empty($entity)) {
     $entity->metadata_name = $name;
     if (!empty($label)) {
         $entity->metadata_label = $label;
     } else {
         unset($entity->metadata_label);
     }
     // add relationship
     remove_entity_relationships($entity->guid, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, true);
     if (!empty($profile_types) && is_array($profile_types)) {
         foreach ($profile_types as $type) {
             add_entity_relationship($type, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, $entity->guid);
         }
     }
     // add correct order
     $options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_CATEGORY_SUBTYPE, "count" => true, "owner_guid" => $CONFIG->site_guid);
     $count = elgg_get_entities($options);
     if ($add) {
         $entity->order = $count;
     }
     if ($entity->save()) {
         system_message(elgg_echo("profile_manager:action:category:add:succes"));
     } else {
         register_error(elgg_echo("profile_manager:action:category:add:error:save"));
Exemple #19
0
<?php

$widget_guid = (int) get_input("widget_guid");
$multi_dashboard_guid = (int) get_input("multi_dashboard_guid");
if (!empty($widget_guid)) {
    if (($widget = get_entity($widget_guid)) && elgg_instanceof($widget, "object", "widget", "ElggWidget")) {
        // remove widget from any other multi dashboard
        remove_entity_relationships($widget->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP);
        // check if we dropped on a multi dashboard
        if (!empty($multi_dashboard_guid)) {
            if (($dashboard = get_entity($multi_dashboard_guid)) && elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) {
                // we need to drop the widget on the first column, last position
                $pos = 10;
                if ($widgets = $dashboard->getWidgets()) {
                    if (isset($widgets[1])) {
                        $max_pos = max(array_keys($widgets[1]));
                        if ($max_pos >= $pos) {
                            $pos = $max_pos + 10;
                        }
                    }
                }
                $widget->column = 1;
                $widget->order = $pos;
                $widget->save();
                // add the widget to the dashboard
                $widget->addRelationship($dashboard->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP);
            } else {
                register_error(elgg_echo("InvalidClassException:NotValidElggStar", array($multi_dashboard_guid, "MultiDashboard")));
            }
        }
        system_message(elgg_echo("widget_manager:actions:multi_dashboard:drop:success"));
Exemple #20
0
function elgg_poll_set_poll($guid, $poll, $event_length)
{
    $event = get_entity($guid);
    if (elgg_instanceof($event, 'object', 'event_calendar') && $event->canEdit()) {
        // TODO as workaround simply remove database entries related to any former event poll votings in case it is an existing poll that gets edited
        // long time solution for editing polls might be to keep voting data if appropriate and former poll details are preserved
        elgg_delete_annotations(array('guid' => $event->guid, 'annotation_name' => 'event_poll_vote', 'limit' => false));
        remove_entity_relationships($event->guid, 'event_poll_voted', true);
        // sort the poll by time within date
        event_poll_set_time_limits($event, $poll, $event_length);
        $event->event_poll = serialize($poll);
        $event->is_event_poll = 1;
    }
    return '';
}
Exemple #21
0
 /**
  * Remove all relationships to and from this entity.
  *
  * @return true
  * @todo This should actually return if it worked.
  * @see ElggEntity::addRelationship()
  * @see ElggEntity::removeRelationship()
  */
 public function deleteRelationships()
 {
     remove_entity_relationships($this->getGUID());
     remove_entity_relationships($this->getGUID(), "", true);
     return true;
 }
Exemple #22
0
function pleio_api_save_file($data = "", $file_name = "", $title = "", $description = "", $tags = "", $file_id = null, $folder_id = 0, $group_id = 0, $access_id = "", $wiki_id = "", $mimetype = "")
{
    $file_id = $file_id ? $file_id : null;
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    if (!$data && !$file_id) {
        return new ErrorResult(elgg_echo("file:uploadfailed"));
    }
    $swordfish_group = $group_id ? pleio_api_swordfish_group($group_id) : false;
    if ($swordfish_group) {
        $group = get_entity($group_id);
        $url = pleio_api_swordfish_baseurl($group->site_guid) . "post-file";
        $swordfish_name = pleio_api_swordfish_username($user->username);
        $params = array("data" => $data, "title" => $title);
        if ($file_id) {
            $params["fileId"] = $file_id;
        } elseif ($folder_id) {
            $params["folderId"] = $folder_id;
        } elseif ($group_id) {
            $params["groupId"] = $swordfish_group;
        } else {
            return new ErrorResult("Vul minimaal een bestand, folder of groep in");
        }
        if ($wiki_id) {
            $params["wikiId"] = $wiki_id;
        }
        if ($access_id != ACCESS_PRIVATE) {
            $params["visibility"] = "internally_published";
        } else {
            $params["visibility"] = "private";
        }
        $params["filename"] = $file_name;
        $result = pleio_api_call_swordfish_api($swordfish_name, $url, "POST", $params);
        if ($result->ok) {
            if (strpos($result->headers["CONTENT-TYPE"], "json")) {
                $response = json_decode($result->response);
                return new SaveSuccessResult(elgg_echo("file:saved"), $response->id);
            } else {
                return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]);
            }
        } else {
            return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]);
        }
    } else {
        if ($file_id) {
            $file = get_entity($file_id);
        }
        if (!$file) {
            $file = new ElggFile();
            $file->owner_guid = $user_id;
        }
        if ($title) {
            $file->title = $title;
        }
        if ($description) {
            $file->setDescription($description);
        }
        if ($tags) {
            $file->setMetaData("tags", $tags);
        }
        if ($group_id) {
            $file->setContainerGUID($group_id);
        }
        if ($access_id) {
            $file->access_id = $access_id;
        }
        if ($data) {
            $file->setFilename(basename($file_name));
            $data = base64_decode($data);
            $fh = $file->open("write");
            if ($fh) {
                $file->write($data);
                $file->close();
            }
            if (!$mimetype) {
                $mimetype = $file->detectMimeType($file->getFilenameOnFilestore());
            }
            $file->setMimeType($mimetype);
            $file->simpletype = file_get_simple_type($mimetype);
        }
        if (!$file->save()) {
            return new ErrorResult(elgg_echo("file:uploadfailed"));
        }
        if ($folder_id) {
            remove_entity_relationships($file->guid, "folder_of", 1);
            add_entity_relationship($folder_id, "folder_of", $file->guid);
        }
        if (!$file_id) {
            add_to_river('river/object/file/create', 'create', $user_id, $file->guid);
        }
        return new SaveSuccessResult(elgg_echo("file:saved"), $file->guid);
    }
    return new ErrorResult(elgg_echo("file:uploadfailed"));
}
Exemple #23
0
<?php

namespace hypeJunction\Faker;

use ElggBatch;
set_time_limit(0);
$rels = $collections = 0;
$max = (int) get_input('max', 20);
$friends_count = rand(1, $max);
$users = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'user', 'metadata_names' => '__faker', 'limit' => 0));
$dbprefix = elgg_get_config('dbprefix');
foreach ($users as $user) {
    remove_entity_relationships($user->guid, 'friend');
    $query = "SELECT ag.id FROM {$dbprefix}access_collections ag WHERE ag.owner_guid = {$user->guid}";
    $acls = get_data($query);
    foreach ($acls as $col) {
        delete_access_collection($col->id);
    }
    $friends = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => $friends_count, 'order_by' => 'RAND()', 'wheres' => array("e.guid != {$user->guid}"), 'metadata_names' => '__faker'));
    $rand_friends = false;
    $collection_id = create_access_collection('Best Fake Friends Collection', $user->guid);
    if ($collection_id) {
        $rand_friends = array_rand($friends, rand(2, $friends_count));
        $collections++;
    }
    foreach ($friends as $friends_key => $friend) {
        if ($user->addFriend($friend->guid)) {
            $rels++;
            elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid));
            if ($rand_friends && array_key_exists($friends_key, $rand_friends)) {
                add_user_to_access_collection($friend->guid, $collection_id);
Exemple #24
0
$bookmark_guid = (int) get_input("bookmark_guid", 0);
$folder_guid = (int) get_input("bmfolder_guid", 0);
if (!empty($bookmark_guid)) {
    if ($bookmark = get_entity($bookmark_guid)) {
        $container_entity = $bookmark->getContainerEntity();
        if ($bookmark->canEdit() || elgg_instanceof($container_entity, "group") && $container_entity->isMember()) {
            if (elgg_instanceof($bookmark, "object", "bookmarks")) {
                // check if a given guid is a folder
                if (!empty($folder_guid)) {
                    if (!($folder = get_entity($folder_guid)) || !elgg_instanceof($folder, "object", BOOKMARK_TOOLS_SUBTYPE)) {
                        unset($folder_guid);
                    }
                }
                // remove old relationships
                remove_entity_relationships($bookmark->getGUID(), BOOKMARK_TOOLS_RELATIONSHIP, true);
                if (!empty($folder_guid)) {
                    add_entity_relationship($folder_guid, BOOKMARK_TOOLS_RELATIONSHIP, $bookmark_guid);
                }
                system_message(elgg_echo("bookmark_tools:action:move:success:bookmark"));
            } elseif (elgg_instanceof($bookmark, "object", BOOKMARK_TOOLS_SUBTYPE)) {
                $bookmark->parent_guid = $folder_guid;
                system_message(elgg_echo("bookmark_tools:action:move:success:folder"));
            }
        } else {
            register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
        }
    } else {
        register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
    }
} else {
Exemple #25
0
     }
 }
 if (empty($object)) {
     $object = new ProfileManagerCustomFieldCategory();
     $object->save();
     $add = true;
 }
 if (!empty($object)) {
     $object->metadata_name = $name;
     if (!empty($label)) {
         $object->metadata_label = $label;
     } else {
         unset($object->metadata_label);
     }
     // add relationship
     remove_entity_relationships($object->guid, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP);
     if (!empty($profile_types) && is_array($profile_types)) {
         foreach ($profile_types as $type) {
             add_entity_relationship($type, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, $object->guid);
         }
     }
     // add correct order
     $count = get_entities("object", CUSTOM_PROFILE_FIELDS_CATEGORY_SUBTYPE, null, null, null, null, true);
     if ($add) {
         $object->order = $count;
     }
     if ($object->save()) {
         system_message(elgg_echo("profile_manager:action:category:add:succes"));
     } else {
         register_error(elgg_echo("profile_manager:action:category:add:error:save"));
     }
Exemple #26
0
 /**
  * Remove all relationships to and from this entity.
  * If you pass a relationship name, only relationships matching that name
  * will be deleted.
  *
  * @warning Calling this with no $relationship will clear all relationships
  * for this entity.
  *
  * @param null|string $relationship The name of the relationship to remove.
  * @return bool
  * @see \ElggEntity::addRelationship()
  * @see \ElggEntity::removeRelationship()
  */
 public function deleteRelationships($relationship = null)
 {
     $relationship = (string) $relationship;
     $result = remove_entity_relationships($this->getGUID(), $relationship);
     return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
 }
<?php

set_time_limit(0);
$rel_member = $rel_invited = $rel_membership_request = 0;
$member_count_max = (int) get_input('max');
$groups = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'group', 'metadata_names' => '__faker', 'limit' => 0));
foreach ($groups as $group) {
    remove_entity_relationships($group->guid, 'member', true);
    remove_entity_relationships($group->guid, 'membership_request', true);
    remove_entity_relationships($group->guid, 'invited');
    update_access_collection($group->group_acl, array($group->owner_guid));
    $group->join(get_entity($group->owner_guid));
    $members_count = rand(1, $member_count_max);
    $members = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => $members_count, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
    foreach ($members as $member) {
        if ($group->join($member)) {
            $rel_member++;
        }
    }
    if (!$group->isPublicMembership()) {
        $invites_count = rand(1, $member_count_max);
        $invitees = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => $invites_count, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
        foreach ($invitees as $invitee) {
            if (!check_entity_relationship($invitee->guid, 'member', $group->guid)) {
                if (add_entity_relationship($group->guid, 'invited', $invitee->guid)) {
                    $rel_invited++;
                }
            }
        }
        $requests_count = rand(1, $member_count_max);
        $requestors = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => $requests_count, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
Exemple #28
0
function shoutout_edit($guid, $attached_guid, $text, $access_id, $attachments, $video_url = '')
{
    // TODO: handle video URL if any
    $user_guid = elgg_get_logged_in_user_guid();
    if ($guid) {
        $shoutout = get_entity($guid);
        if (!elgg_instanceof($shoutout, 'object', 'shoutout')) {
            return FALSE;
        }
    } else {
        $shoutout = new ElggObject();
        $shoutout->subtype = 'shoutout';
        $shoutout->owner_guid = $user_guid;
        $shoutout->container_guid = $user_guid;
        $shoutout->title = elgg_echo('shoutout:entity_title');
    }
    $shoutout->access_id = $access_id;
    $shoutout->description = $text;
    shoutout_handle_video($shoutout, $video_url);
    if ($shoutout->save()) {
        if ($guid) {
            // clear attachment annotations
            elgg_delete_annotations(array('guid' => $guid, 'annotation_name' => 'shoutout_attachment'));
            // clear attached entity
            remove_entity_relationships($guid, 'shoutout_attached_entity');
        }
        if ($attachments) {
            foreach ($attachments as $a) {
                $time_bit = $a['timeBit'];
                $file_name = urldecode($a['fileName']);
                $value = "{$time_bit}|{$file_name}";
                create_annotation($shoutout->guid, 'shoutout_attachment', $value, '', $user_guid, ACCESS_PUBLIC);
            }
        }
        if ($attached_guid) {
            add_entity_relationship($shoutout->guid, 'shoutout_attached_entity', $attached_guid);
        }
        if (!$guid) {
            add_to_river('river/object/shoutout/create', 'create', elgg_get_logged_in_user_guid(), $shoutout->guid);
        }
        return TRUE;
    } else {
        return FALSE;
    }
}
Exemple #29
0
/**
 * Block an email address from all newsletters
 *
 * @param string $email The email address to block
 *
 * @return boolean True on success, false on failure
 */
function newsletter_unsubscribe_all_email($email)
{
    $result = false;
    if (!empty($email) && newsletter_is_email_address($email)) {
        // get subscription
        $subscription = newsletter_get_subscription($email);
        if (empty($subscription)) {
            $subscription = new NewsletterSubscription();
            $subscription->title = $email;
            if (!$subscription->save()) {
                return false;
            }
            // remove all existing subscriptions
            remove_entity_relationships($subscription->getGUID(), NewsletterSubscription::SUBSCRIPTION);
            // add to general blacklist
            $site = elgg_get_site_entity();
            $result = (bool) add_entity_relationship($subscription->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID());
        }
    }
    return $result;
}
Exemple #30
0
    $parent = get_entity($parent_guid);
    elgg_set_ignore_access($ia);
    if (elgg_instanceof($parent, 'object', 'static')) {
        if ($parent->container_guid == $owner->getGUID()) {
            // parent is a top page
            $subpage_relationship_guid = $parent_guid;
        } else {
            // further in the tree, so find out which tree
            $relations = $parent->getEntitiesFromRelationship(['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'relationship' => 'subpage_of', 'limit' => 1]);
            if ($relations) {
                $subpage_relationship_guid = $relations[0]->getGUID();
            }
        }
        if ($subpage_relationship_guid) {
            // remove old tree relationships
            remove_entity_relationships($entity->getGUID(), 'subpage_of');
            // add new tree relationship
            $entity->addRelationship($subpage_relationship_guid, 'subpage_of');
        }
    }
}
// check the children for the correct tree
if (!$new_entity) {
    static_check_children_tree($entity, $subpage_relationship_guid);
}
$ia = elgg_set_ignore_access(true);
// save all the content
$entity->title = $title;
$entity->description = $description;
$entity->access_id = $access_id;
$entity->container_guid = $parent_guid;