Exemple #1
0
 /**
  * Delete all votes associated with this poll, reset vote counters and delete associated vote river items
  */
 public function deleteVotes()
 {
     elgg_delete_river(array('view' => 'river/object/poll/vote', 'action_type' => 'vote', 'object_guid' => $this->guid));
     elgg_delete_annotations(array('guid' => $this->guid, 'type' => "object", 'subtype' => "poll", 'annotation_name' => "vote"));
     $this->responses_by_choice = array();
     $this->response_count = 0;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function delete(ParameterBag $params)
 {
     if (!elgg_is_admin_logged_in()) {
         throw new GraphException("You are not permitted to delete river items", 403);
     }
     return elgg_delete_river(array('ids' => sanitize_int($params->id)));
 }
Exemple #3
0
 /**
  * Remove river join event on site leave
  *
  * @param string           $event       Event name
  * @param string           $object_type Event type
  * @param ElggRelationship $object      Relationship object being removed
  *
  * @return void
  */
 public static function deleteMember($event, $object_type, $object)
 {
     if ($object->relationship !== 'member_of_site') {
         return;
     }
     elgg_delete_river(['view' => 'river/relationship/member_of_site/create', 'subject_guid' => $object->guid_one, 'object_guid' => $object->guid_two]);
 }
Exemple #4
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;
}
 /**
  * Delete the annotation.
  *
  * @return bool
  */
 public function delete()
 {
     $result = _elgg_delete_metastring_based_object_by_id($this->id, 'annotation');
     if ($result) {
         elgg_delete_river(array('annotation_id' => $this->id));
     }
     return $result;
 }
Exemple #6
0
 public function testElggCreateRiverItemWorks()
 {
     $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);
     $id = elgg_create_river_item($params);
     $this->assertTrue(is_int($id));
     $this->assertTrue(elgg_delete_river(array('id' => $id)));
 }
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;
}
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $relationship = check_entity_relationship($this->user->guid, 'tagged_in', $this->entity->guid);
     if ($relationship instanceof \ElggRelationship) {
         if ($relationship->delete()) {
             elgg_delete_river(array('subject_guids' => $this->user->guid, 'object_guids' => $this->entity->guid, 'action_types' => 'tagged'));
             /**
              * @todo: remove from access collection?
              */
             $this->result->addMessage(elgg_echo('wall:remove_tag:success'));
             return;
         }
     }
     $this->result->addError(elgg_echo('wall:remove_tag:error'));
 }
Exemple #9
0
 /**
  * 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);
 }
Exemple #10
0
 /**
  * Unpublish blogs based on advanced publication settings
  *
  * @return void
  */
 protected static function unpublishBlogs()
 {
     $dbprefix = elgg_get_config('dbprefix');
     $expiration_id = elgg_get_metastring_id('expiration_date');
     $unpublish_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_values_pairs' => [['name' => 'status', 'value' => 'published']], 'wheres' => ["((mdtime.name_id = {$expiration_id}) AND (DATE(mstime.string) = DATE(NOW())))"]];
     // 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(['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', [$entity->title, $entity->getURL()]));
         // save everything
         $entity->save();
     }
 }
Exemple #11
0
function tasks_2012100501($task)
{
    require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php';
    if ($task->long_description) {
        $task->description = $task->long_description;
        $task->deleteMetadata('long_description');
        $task->save();
    }
    if ($task->parent_guid) {
        $task->list_guid = $task->parent_guid;
        $task->deleteMetadata('parent_guid');
    } else {
        $task->list_guid = 0;
    }
    /* Active was set as default, so it is not indicative of which tasks are
    	really active */
    $task->deleteMetadata('active');
    if ($task->done) {
        $task->status = 'done';
        $task->deleteMetadata('done');
    } else {
        $task->status = 'new';
    }
    // reset priority since old system was a mess
    $task->priority = 2;
    upgrade_change_subtype($task, 'task');
    // update river
    $options = array('object_guid' => $task->guid);
    $items = elgg_get_river($options);
    foreach ($items as $item) {
        if ($item->action_type == 'create') {
            upgrade_update_river($item->id, 'river/object/task/create', $task->guid, 0);
        } elseif (in_array($item->action_type, array('done', 'undone', 'subscribe', 'unsubscribe'))) {
            elgg_delete_river(array('id' => $item->id));
        }
    }
    return true;
}
Exemple #12
0
        $params->{$key} = get_input($key);
    }
}
if (isset($params->container_guid)) {
    $container = get_entity($params->container_guid);
} else {
    $container = elgg_get_logged_in_user_entity();
}
if (!$container instanceof ElggEntity) {
    register_error(elgg_echo('avatars:error:not_found'));
    forward(REFERRER);
}
if (!$container->canEdit() || !$container->canWriteToContainer(0, 'object', hypeJunction\Images\Avatar::SUBTYPE)) {
    register_error(elgg_echo('avatars:error:permission_denied'));
    forward(REFERRER);
}
$avatar = avatars_create_avatar_from_upload($container, 'avatar');
if ($avatar) {
    $container->icontime = $avatar->time_created;
    if ($container instanceof ElggUser) {
        if (elgg_trigger_event('profileiconupdate', $container->type, $container)) {
            $view = 'river/user/default/profileiconupdate';
            elgg_delete_river(['subject_guid' => $container->guid, 'view' => $view]);
            elgg_create_river_item(['view' => $view, 'action_type' => 'update', 'subject_guid' => $container->guid, 'object_guid' => $avatar->guid]);
        }
    }
    system_message(elgg_echo('avatar:upload:success'));
} else {
    register_error(elgg_echo('avatar:upload:fail'));
}
forward(REFERRER);
Exemple #13
0
// Get the GUID of the user to friend
$friend_guid = (int) get_input("friend");
$errors = false;
// Get the user
if ($friend = get_user($friend_guid)) {
    $user = elgg_get_logged_in_user_entity();
    try {
        $user->removeFriend($friend->getGUID());
        // remove river items
        elgg_delete_river(array("view" => "river/relationship/friend/create", "subject_guid" => $user->getGUID(), "object_guid" => $friend->getGUID()));
        try {
            //V1.1 - Old relationships might not have the 2 as friends...
            $friend->removeFriend($user->getGUID());
            // remove river items
            elgg_delete_river(array("view" => "river/relationship/friend/create", "subject_guid" => $friend->getGUID(), "object_guid" => $user->getGUID()));
        } catch (Exception $e) {
            // do nothing
        }
    } catch (Exception $e) {
        register_error(elgg_echo("friends:remove:failure", array($friend->name)));
        $errors = true;
    }
} else {
    register_error(elgg_echo("friends:remove:failure", array($friend_guid)));
    $errors = true;
}
if (!$errors) {
    system_message(elgg_echo("friends:remove:successful", array($friend->name)));
}
forward(REFERER);
Exemple #14
0
/**
 * Delete an entity.
 *
 * Removes an entity and its metadata, annotations, relationships, river entries,
 * and private data.
 *
 * Optionally can remove entities contained and owned by $guid.
 *
 * @tip Use ElggEntity::delete() instead.
 *
 * @warning If deleting recursively, this bypasses ownership of items contained by
 * the entity.  That means that if the container_guid = $guid, the item will be deleted
 * regardless of who owns it.
 *
 * @param int  $guid      The guid of the entity to delete
 * @param bool $recursive If true (default) then all entities which are
 *                        owned or contained by $guid will also be deleted.
 *
 * @return bool
 * @access private
 */
function delete_entity($guid, $recursive = true)
{
    global $CONFIG, $ENTITY_CACHE;
    $guid = (int) $guid;
    if ($entity = get_entity($guid)) {
        if (elgg_trigger_event('delete', $entity->type, $entity)) {
            if ($entity->canEdit()) {
                // delete cache
                if (isset($ENTITY_CACHE[$guid])) {
                    invalidate_cache_for_entity($guid);
                }
                // If memcache is available then delete this entry from the cache
                static $newentity_cache;
                if (!$newentity_cache && is_memcache_available()) {
                    $newentity_cache = new ElggMemcache('new_entity_cache');
                }
                if ($newentity_cache) {
                    $newentity_cache->delete($guid);
                }
                // Delete contained owned and otherwise releated objects (depth first)
                if ($recursive) {
                    // Temporary token overriding access controls
                    // @todo Do this better.
                    static $__RECURSIVE_DELETE_TOKEN;
                    // Make it slightly harder to guess
                    $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
                    $entity_disable_override = access_get_show_hidden_status();
                    access_show_hidden_entities(true);
                    $ia = elgg_set_ignore_access(true);
                    $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities\n\t\t\t\t\t\tWHERE container_guid={$guid}\n\t\t\t\t\t\t\tor owner_guid={$guid}\n\t\t\t\t\t\t\tor site_guid={$guid}", 'entity_row_to_elggstar');
                    if ($sub_entities) {
                        foreach ($sub_entities as $e) {
                            // check for equality so that an entity that is its own
                            // owner or container does not cause infinite loop
                            if ($e->guid != $guid) {
                                $e->delete(true);
                            }
                        }
                    }
                    access_show_hidden_entities($entity_disable_override);
                    $__RECURSIVE_DELETE_TOKEN = null;
                    elgg_set_ignore_access($ia);
                }
                // Now delete the entity itself
                $entity->deleteMetadata();
                $entity->deleteOwnedMetadata();
                $entity->deleteAnnotations();
                $entity->deleteOwnedAnnotations();
                $entity->deleteRelationships();
                elgg_delete_river(array('subject_guid' => $guid));
                elgg_delete_river(array('object_guid' => $guid));
                remove_all_private_settings($guid);
                $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
                if ($res) {
                    $sub_table = "";
                    // Where appropriate delete the sub table
                    switch ($entity->type) {
                        case 'object':
                            $sub_table = $CONFIG->dbprefix . 'objects_entity';
                            break;
                        case 'user':
                            $sub_table = $CONFIG->dbprefix . 'users_entity';
                            break;
                        case 'group':
                            $sub_table = $CONFIG->dbprefix . 'groups_entity';
                            break;
                        case 'site':
                            $sub_table = $CONFIG->dbprefix . 'sites_entity';
                            break;
                    }
                    if ($sub_table) {
                        delete_data("DELETE from {$sub_table} where guid={$guid}");
                    }
                }
                return $res;
            }
        }
    }
    return false;
}
Exemple #15
0
        system_message(elgg_echo('blog:message:saved'));
        $status = $blog->status;
        // add to river if changing status or published, regardless of new post
        // because we remove it for drafts.
        if (($new_post || $old_status == 'draft') && $status == 'published') {
            add_to_river('river/object/blog/create', 'create', $blog->owner_guid, $blog->getGUID());
            // we only want notifications sent when post published
            register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
            elgg_trigger_event('publish', 'object', $blog);
            // reset the creation time for posts that move from draft to published
            if ($guid) {
                $blog->time_created = time();
                $blog->save();
            }
        } elseif ($old_status == 'published' && $status == 'draft') {
            elgg_delete_river(array('object_guid' => $blog->guid, 'action_type' => 'create'));
        }
        //Khang Added
        forward(REFERER);
        if ($blog->status == 'published' || $save == false) {
            forward($blog->getURL());
        } else {
            forward("blog/edit/{$blog->guid}");
        }
    } else {
        register_error(elgg_echo('blog:error:cannot_save'));
        forward($error_forward_url);
    }
} else {
    register_error($error);
    forward($error_forward_url);
Exemple #16
0
    if ($resized) {
        //@todo Make these actual entities.  See exts #348.
        $file = new ElggFile();
        $file->owner_guid = $guid;
        $file->setFilename("profile/{$guid}{$name}.jpg");
        $file->open('write');
        $file->write($resized);
        $file->close();
        $files[] = $file;
    } else {
        // cleanup on fail
        foreach ($files as $file) {
            $file->delete();
        }
        register_error(elgg_echo('avatar:resize:fail'));
        forward(REFERER);
    }
}
// reset crop coordinates
$owner->x1 = 0;
$owner->x2 = 0;
$owner->y1 = 0;
$owner->y2 = 0;
$owner->icontime = time();
if (elgg_trigger_event('profileiconupdate', $owner->type, $owner)) {
    system_message(elgg_echo("avatar:upload:success"));
    $view = 'river/user/default/profileiconupdate';
    elgg_delete_river(array('subject_guid' => $owner->guid, 'view' => $view));
    add_to_river($view, 'update', $owner->guid, $owner->guid);
}
forward(REFERER);
 /**
  * handles the extended garbage collection
  *
  * @param string $hook        hookname
  * @param string $type        hooktype
  * @param mixed  $returnvalue current return value
  * @param mixed  $params      original parameters
  *
  * @return void
  */
 public static function collect($hook, $type, $returnvalue, $params)
 {
     if (elgg_get_plugin_setting('enable_gc', 'garbagecollector_extended') !== 'yes') {
         return;
     }
     elgg_register_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue');
     $dbprefix = elgg_get_config('dbprefix');
     // overrule access settigns
     $ia = elgg_get_ignore_access();
     elgg_set_ignore_access(true);
     // cleanup entities
     if ($entity_guids = garbagecollector_extended_get_orphaned_entities()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['entities']);
         foreach ($entity_guids as $guid) {
             $entity = get_entity($guid);
             if ($entity) {
                 $entity->delete();
             }
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup access collections
     if ($acl_ids = garbagecollector_extended_get_orphaned_access_collections()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['access collections']);
         foreach ($acl_ids as $id) {
             delete_access_collection($id);
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup annotations
     if ($anno_ids = garbagecollector_extended_get_orphaned_annotations()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['annotations']);
         foreach ($anno_ids as $id) {
             elgg_delete_annotation_by_id($id);
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup metadata
     if ($meta_ids = garbagecollector_extended_get_orphaned_metadata()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['metadata']);
         foreach ($meta_ids as $id) {
             // We need to manualy delete metadata as the Elgg functions don't work because this is orphaned metadata
             // also we need to delete this one by one because of potential long query strings
             $sql = 'DELETE FROM ' . $dbprefix . 'metadata';
             $sql .= ' WHERE id = ' . $id;
             delete_data($sql);
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup private settings
     if ($private_ids = garbagecollector_extended_get_orphaned_private_settings()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['private settings']);
         foreach ($private_ids as $id) {
             // We need to manualy delete private settings as Elgg doesn't have a function fot this
             // also we need to delete this one by one because of potential long query strings
             $sql = 'DELETE FROM ' . $dbprefix . 'private_settings';
             $sql .= ' WHERE id = ' . $id;
             delete_data($sql);
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup relationships
     if ($rel_ids = garbagecollector_extended_get_orphaned_relationships()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['relationships']);
         foreach ($rel_ids as $id) {
             delete_relationship($id);
         }
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // cleanup river
     if ($river_ids = garbagecollector_extended_get_orphaned_river()) {
         echo elgg_echo('garbagecollector_extended:cleanup', ['river items']);
         elgg_delete_river(['ids' => $river_ids]);
         echo elgg_echo('garbagecollector_extended:done') . '\\n';
     }
     // because we cleaned up a lot, do metastrings again
     garbagecollector_orphaned_metastrings();
     // restore access settings
     elgg_set_ignore_access($ia);
     elgg_unregister_plugin_hook_handler('permissions_check', 'all', '\\Elgg\\Values::getTrue');
 }
Exemple #18
0
 /**
  * RSVP to the event
  *
  * @param string  $type           type of the rsvp
  * @param number  $user_guid      guid of the user for whom the rsvp is changed
  * @param boolean $reset_program  does the program need a reset with this rsvp
  * @param boolean $add_to_river   add an event to the river
  * @param boolean $notify_on_rsvp control if a (potential)notification is send
  *
  * @return boolean
  */
 public function rsvp($type = EVENT_MANAGER_RELATION_UNDO, $user_guid = 0, $reset_program = true, $add_to_river = true, $notify_on_rsvp = true)
 {
     $user_guid = sanitise_int($user_guid, false);
     if (empty($user_guid)) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     if (empty($user_guid)) {
         return false;
     }
     // check if it is a user
     $user_entity = get_user($user_guid);
     $event_guid = $this->getGUID();
     // remove registrations
     if ($type == EVENT_MANAGER_RELATION_UNDO) {
         $this->undoRegistration($user_guid, $reset_program);
     }
     // remove current relationships
     delete_data("DELETE FROM " . elgg_get_config("dbprefix") . "entity_relationships WHERE guid_one={$event_guid} AND guid_two={$user_guid}");
     // remove river events
     if ($user_entity) {
         elgg_delete_river(['subject_guid' => $user_guid, 'object_guid' => $event_guid, 'action_type' => 'event_relationship']);
     }
     // add the new relationship
     if ($type && $type != EVENT_MANAGER_RELATION_UNDO && in_array($type, event_manager_event_get_relationship_options())) {
         $result = $this->addRelationship($user_guid, $type);
         if ($result && $add_to_river) {
             if ($user_entity) {
                 // add river events
                 if ($type != 'event_waitinglist' && $type != 'event_pending') {
                     elgg_create_river_item(['view' => 'river/event_relationship/create', 'action_type' => 'event_relationship', 'subject_guid' => $user_guid, 'object_guid' => $event_guid]);
                 }
             }
         }
     } else {
         if ($this->hasEventSpotsLeft() || $this->hasSlotSpotsLeft()) {
             $this->generateNewAttendee();
         }
         $result = true;
     }
     if ($notify_on_rsvp) {
         $this->notifyOnRsvp($type, $user_guid);
     }
     return $result;
 }
Exemple #19
0
 /**
  * RSVP to the event
  *
  * @param string  $type          type of the rsvp
  * @param number  $user_guid     guid of the user for whom the rsvp is changed
  * @param boolean $reset_program does the program need a reset with this rsvp
  * @param boolean $add_to_river  add an event to the river
  *
  * @return boolean
  */
 public function rsvp($type = EVENT_MANAGER_RELATION_UNDO, $user_guid = 0, $reset_program = true, $add_to_river = true)
 {
     global $EVENT_MANAGER_UNDO_REGISTRATION;
     $user_guid = sanitise_int($user_guid, false);
     if (empty($user_guid)) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     if (empty($user_guid)) {
         return false;
     }
     // check if it is a user
     $user_entity = get_user($user_guid);
     $event_guid = $this->getGUID();
     // remove registrations
     if ($type == EVENT_MANAGER_RELATION_UNDO) {
         if (empty($user_entity)) {
             // make sure we can remove the registration object
             $EVENT_MANAGER_UNDO_REGISTRATION = true;
             $registration_object = get_entity($user_guid);
             $registration_object->delete();
             // undo overrides
             $EVENT_MANAGER_UNDO_REGISTRATION = false;
         } else {
             if ($reset_program) {
                 if ($this->with_program) {
                     $this->relateToAllSlots(false, $user_guid);
                 }
                 $this->clearRegistrations($user_guid);
             }
         }
     }
     // remove current relationships
     delete_data("DELETE FROM " . elgg_get_config("dbprefix") . "entity_relationships WHERE guid_one={$event_guid} AND guid_two={$user_guid}");
     // remove river events
     if ($user_entity) {
         $params = array("subject_guid" => $user_guid, "object_guid" => $event_guid, "action_type" => "event_relationship");
         elgg_delete_river($params);
     }
     // add the new relationship
     if ($type && $type != EVENT_MANAGER_RELATION_UNDO && in_array($type, event_manager_event_get_relationship_options())) {
         $result = $this->addRelationship($user_guid, $type);
         if ($result && $add_to_river) {
             if ($user_entity) {
                 // add river events
                 if ($type != "event_waitinglist" && $type != "event_pending") {
                     elgg_create_river_item(array('view' => 'river/event_relationship/create', 'action_type' => 'event_relationship', 'subject_guid' => $user_guid, 'object_guid' => $event_guid));
                 }
             }
         }
     } else {
         if ($this->hasEventSpotsLeft() || $this->hasSlotSpotsLeft()) {
             $this->generateNewAttendee();
         }
         $result = true;
     }
     if ($this->notify_onsignup && $type !== EVENT_MANAGER_RELATION_ATTENDING_PENDING) {
         $this->notifyOnRsvp($type, $user_guid);
     }
     return $result;
 }
Exemple #20
0
}
if ($new) {
    $poll->setChoices($new_choices);
} else {
    $choices_changed = $poll->updateChoices($new_choices, $former_access_id);
    // if poll choices have been modified and this poll has been created as multiple-anwer poll and
    // such polls are currently not allowed then reset the max number of allowed votes to 1
    if ($max_votes > 1 && $choices_changed) {
        $multiple_answer_polls = elgg_get_plugin_setting('multiple_answer_polls', 'poll');
        if ($multiple_answer_polls != "yes") {
            $poll->max_votes = 1;
        }
    }
}
poll_manage_front_page($poll, $front_page);
elgg_clear_sticky_form('poll');
$poll_create_in_river = elgg_get_plugin_setting('create_in_river', 'poll');
if ($poll_create_in_river != 'no') {
    if ($new) {
        elgg_create_river_item(array('view' => 'river/object/poll/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $poll->guid));
    } else {
        // first remove any previous river entries referring to updating this poll to avoid duplicate entries
        elgg_delete_river(array('view' => 'river/object/poll/update', 'action_type' => 'update', 'object_guid' => $poll->guid));
        // let the river entry on updating a poll be made in the name of the poll owner in any case
        $user = $poll->getOwnerEntity();
        elgg_create_river_item(array('view' => 'river/object/poll/update', 'action_type' => 'update', 'subject_guid' => $user->guid, 'object_guid' => $poll->guid));
    }
}
system_message($message);
// Forward to the poll page
forward($poll->getURL());
Exemple #21
0
 /**
  * Delete the annotation.
  *
  * @return bool
  */
 function delete()
 {
     elgg_delete_river(array('annotation_id' => $this->id));
     return elgg_delete_metastring_based_object_by_id($this->id, 'annotations');
 }
Exemple #22
0
$reply = get_entity($guid);
$original_topic = $reply->getContainerEntity();
$user_guid = $reply->getOwnerGUID();
$group_guid = $original_topic->getContainerGUID();
$grouptopic = new ElggObject();
$grouptopic->subtype = "discussion";
$grouptopic->owner_guid = $user_guid;
$grouptopic->container_guid = $group_guid;
$grouptopic->access_id = $original_topic->access_id;
$grouptopic->title = $title;
$grouptopic->description = $reply->description;
$grouptopic->status = 'open';
if (!$grouptopic->save()) {
    register_error(elgg_echo('discussion:error:notsaved'));
    forward(REFERER);
}
elgg_delete_river(array('object_guid' => $reply->guid));
elgg_create_river_item(array('view' => 'river/object/discussion/create', 'action_type' => 'create', 'subject_guid' => $user_guid, 'object_guid' => $grouptopic->guid, 'posted' => $reply->time_created));
// Replace the original content with a note and add a link that takes to the new topic
$link = elgg_view('output/url', array('href' => $grouptopic->getURL(), 'text' => elgg_echo('cg:form:offtopic:warning:link')));
$warning_text = elgg_echo('cg:form:offtopic:warning');
$reply->description = "[{$warning_text} {$link}]";
$reply->save();
$user = get_user($user_guid);
$site = elgg_get_site_entity();
$subject = elgg_echo('cg:forum:offtopic:notify:title', array(), $user->language);
$message = elgg_echo('cg:forum:offtopic:notify:body', array($user->name, $site->name, elgg_get_excerpt($grouptopic->description, 80), $grouptopic->getURL()), $user->language);
// Let the user know that the comment was moved
notify_user($user_guid, $site->guid, $subject, $message, array('action' => 'move', 'object' => $grouptopic));
system_message(elgg_echo('cg:forum:offtopic:success'));
forward($grouptopic->getURL());
Exemple #23
0
/**
 * Remove river join event on site leave
 * 
 * @param unknown_type $event
 * @param unknown_type $object_type
 * @param unknown_type $object
 */
function profile_manager_delete_member_of_site($event, $object_type, $object)
{
    // remove previous join events
    $user_guid = $object->guid_one;
    $site_guid = $object->guid_two;
    // clear current river events
    elgg_delete_river(array("view" => 'river/relationship/member_of_site/create', "subject_guid" => $user_guid, "object_guid" => $site_guid));
}
Exemple #24
0
 public function rsvp($type = ZHAOHU_MANAGER_RELATION_UNDO, $user_guid = 0, $add_to_river = true)
 {
     $result = false;
     if ($this->status == 'cancelled') {
         system_message(elgg_echo('zhaohu:rsvp:cancelled'));
         return $result;
     }
     $user_guid = sanitise_int($user_guid, false);
     if (empty($user_guid)) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     if (!empty($user_guid)) {
         $zhaohu_guid = $this->getGUID();
         // remove current relationships
         delete_data("DELETE FROM " . elgg_get_config("dbprefix") . "entity_relationships WHERE guid_one={$zhaohu_guid} AND guid_two={$user_guid}");
         // remove river
         if (get_entity($user_guid) instanceof ElggUser) {
             $params = array("subject_guid" => $user_guid, "object_guid" => $zhaohu_guid);
             elgg_delete_river($params);
         }
         // add the new relationship
         if ($type && $type != ZHAOHU_MANAGER_RELATION_UNDO && in_array($type, zhaohu_manager_zhaohu_get_relationship_options())) {
             if ($result = $this->addRelationship($user_guid, $type)) {
                 if ($add_to_river) {
                     if (get_entity($user_guid) instanceof ElggUser) {
                         // add river zhaohus
                         if ($type != "zhaohu_waitinglist" && $type != "zhaohu_pending") {
                             add_to_river('river/zhaohu_relationship/create', $type, $user_guid, $zhaohu_guid);
                         }
                     }
                 }
                 $this->notifyOnRsvp($type, $user_guid);
             }
         } else {
             $result = true;
         }
         //if ($this->notify_onsignup && ($type !== ZHAOHU_MANAGER_RELATION_ATTENDING_PENDING)) {
         //	$this->notifyOnRsvp($type, $user_guid);
         //}
     }
     return $result;
 }
Exemple #25
0
/**
 * Delete an entity.
 *
 * Removes an entity and its metadata, annotations, relationships, river entries,
 * and private data.
 *
 * Optionally can remove entities contained and owned by $guid.
 *
 * @tip Use ElggEntity::delete() instead.
 *
 * @warning If deleting recursively, this bypasses ownership of items contained by
 * the entity.  That means that if the container_guid = $guid, the item will be deleted
 * regardless of who owns it.
 *
 * @param int  $guid      The guid of the entity to delete
 * @param bool $recursive If true (default) then all entities which are
 *                        owned or contained by $guid will also be deleted.
 *
 * @return bool
 * @access private
 */
function delete_entity($guid, $recursive = true)
{
    global $CONFIG, $ENTITY_CACHE;
    $guid = (int) $guid;
    if ($entity = get_entity($guid)) {
        if (elgg_trigger_event('delete', $entity->type, $entity)) {
            if ($entity->canEdit()) {
                // delete cache
                if (isset($ENTITY_CACHE[$guid])) {
                    _elgg_invalidate_cache_for_entity($guid);
                }
                // If memcache is available then delete this entry from the cache
                static $newentity_cache;
                if (!$newentity_cache && is_memcache_available()) {
                    $newentity_cache = new ElggMemcache('new_entity_cache');
                }
                if ($newentity_cache) {
                    $newentity_cache->delete($guid);
                }
                // Delete contained owned and otherwise releated objects (depth first)
                if ($recursive) {
                    // Temporary token overriding access controls
                    // @todo Do this better.
                    static $__RECURSIVE_DELETE_TOKEN;
                    // Make it slightly harder to guess
                    $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
                    $entity_disable_override = access_get_show_hidden_status();
                    access_show_hidden_entities(true);
                    $ia = elgg_set_ignore_access(true);
                    // @todo there was logic in the original code that ignored
                    // entities with owner or container guids of themselves.
                    // this should probably be prevented in ElggEntity instead of checked for here
                    $options = array("limit" => 0, "order_by" => false, "site_guids" => false);
                    foreach (array("site_guid", "container_guid", "owner_guid") as $column) {
                        $options['wheres'] = array("(({$column} = {$guid}) AND guid != {$guid})");
                        $batch = new ElggBatch('elgg_get_entities', $options);
                        $batch->setIncrementOffset(false);
                        foreach ($batch as $e) {
                            $e->delete(true);
                        }
                    }
                    access_show_hidden_entities($entity_disable_override);
                    $__RECURSIVE_DELETE_TOKEN = null;
                    elgg_set_ignore_access($ia);
                }
                // Now delete the entity itself
                $entity->deleteMetadata();
                $entity->deleteOwnedMetadata();
                $entity->deleteAnnotations();
                $entity->deleteOwnedAnnotations();
                $entity->deleteRelationships();
                elgg_delete_river(array('subject_guid' => $guid));
                elgg_delete_river(array('object_guid' => $guid));
                remove_all_private_settings($guid);
                $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
                if ($res) {
                    $sub_table = "";
                    // Where appropriate delete the sub table
                    switch ($entity->type) {
                        case 'object':
                            $sub_table = $CONFIG->dbprefix . 'objects_entity';
                            break;
                        case 'user':
                            $sub_table = $CONFIG->dbprefix . 'users_entity';
                            break;
                        case 'group':
                            $sub_table = $CONFIG->dbprefix . 'groups_entity';
                            break;
                        case 'site':
                            $sub_table = $CONFIG->dbprefix . 'sites_entity';
                            break;
                    }
                    if ($sub_table) {
                        delete_data("DELETE from {$sub_table} where guid={$guid}");
                    }
                }
                return (bool) $res;
            }
        }
    }
    return false;
}
Exemple #26
0
function pages_tools_daily_cron_hook($hook, $type, $return_value, $params)
{
    if (pages_tools_use_advanced_publication_options()) {
        $publication_id = add_metastring("publication_date");
        $expiration_id = add_metastring("expiration_date");
        $dbprefix = elgg_get_config("dbprefix");
        $time = elgg_extract("time", $params, time());
        $publish_options = array("type" => "object", "subtype" => array("page_top"), "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("name" => "unpublished", "value" => true), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
        $expire_options = array("type" => "object", "subtypes" => array("page_top", "page"), "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "wheres" => pages_tools_get_publication_wheres());
        $expire_options["wheres"][] = "((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))";
        // ignore access
        $ia = elgg_set_ignore_access(true);
        // get unpublished pages that need to be published
        if ($entities = elgg_get_entities_from_metadata($publish_options)) {
            foreach ($entities as $entity) {
                // add river event
                add_to_river("river/object/page/create", "create", $entity->getOwner(), $entity->getGUID());
                // set time created
                $entity->time_created = $time;
                // make sure the page is listed
                unset($entity->unpublished);
                // notify the user
                notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:publish:subject"), elgg_echo("pages_tools:notify:publish:message", array($entity->title, $entity->getURL())));
                // save everything
                $entity->save();
            }
        }
        // get pages that have expired
        if ($entities = elgg_get_entities_from_metadata($expire_options)) {
            foreach ($entities as $entity) {
                // remove river event
                elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create"));
                // make sure the page is no longer listed
                $entity->unpublished = true;
                // notify the user
                notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:expire:subject"), elgg_echo("pages_tools:notify:expire:message", array($entity->title, $entity->getURL())));
                // save everything
                $entity->save();
            }
        }
        // reset access
        elgg_set_ignore_access($ia);
    }
}
Exemple #27
0
 /**
  * Deletes the entity.
  *
  * Removes the entity and its metadata, annotations, relationships,
  * river entries, and private data.
  *
  * Optionally can remove entities contained and owned by this entity.
  *
  * @warning If deleting recursively, this bypasses ownership of items contained by
  * the entity.  That means that if the container_guid = $this->guid, the item will
  * be deleted regardless of who owns it.
  *
  * @param bool $recursive If true (default) then all entities which are
  *                        owned or contained by $this will also be deleted.
  *
  * @return bool
  */
 public function delete($recursive = true)
 {
     global $CONFIG;
     $guid = $this->guid;
     if (!$guid) {
         return false;
     }
     // first check if we can delete this entity
     // NOTE: in Elgg <= 1.10.3 this was after the delete event,
     // which could potentially remove some content if the user didn't have access
     if (!$this->canDelete()) {
         return false;
     }
     // now trigger an event to let others know this entity is about to be deleted
     // so they can prevent it or take their own actions
     if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
         return false;
     }
     _elgg_invalidate_cache_for_entity($guid);
     // If memcache is available then delete this entry from the cache
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new \ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $newentity_cache->delete($guid);
     }
     // Delete contained owned and otherwise releated objects (depth first)
     if ($recursive) {
         // Temporarily overriding access controls
         $entity_disable_override = access_get_show_hidden_status();
         access_show_hidden_entities(true);
         $ia = elgg_set_ignore_access(true);
         // @todo there was logic in the original code that ignored
         // entities with owner or container guids of themselves.
         // this should probably be prevented in \ElggEntity instead of checked for here
         $options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid} OR site_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
         $batch = new \ElggBatch('elgg_get_entities', $options);
         $batch->setIncrementOffset(false);
         foreach ($batch as $e) {
             $e->delete(true);
         }
         access_show_hidden_entities($entity_disable_override);
         elgg_set_ignore_access($ia);
     }
     $entity_disable_override = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $ia = elgg_set_ignore_access(true);
     // Now delete the entity itself
     $this->deleteMetadata();
     $this->deleteOwnedMetadata();
     $this->deleteAnnotations();
     $this->deleteOwnedAnnotations();
     $this->deleteRelationships();
     $this->deleteAccessCollectionMemberships();
     $this->deleteOwnedAccessCollections();
     access_show_hidden_entities($entity_disable_override);
     elgg_set_ignore_access($ia);
     elgg_delete_river(array('subject_guid' => $guid));
     elgg_delete_river(array('object_guid' => $guid));
     elgg_delete_river(array('target_guid' => $guid));
     remove_all_private_settings($guid);
     $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = {$guid}");
     if ($res) {
         $sub_table = "";
         // Where appropriate delete the sub table
         switch ($this->type) {
             case 'object':
                 $sub_table = $CONFIG->dbprefix . 'objects_entity';
                 break;
             case 'user':
                 $sub_table = $CONFIG->dbprefix . 'users_entity';
                 break;
             case 'group':
                 $sub_table = $CONFIG->dbprefix . 'groups_entity';
                 break;
             case 'site':
                 $sub_table = $CONFIG->dbprefix . 'sites_entity';
                 break;
         }
         if ($sub_table) {
             $this->getDatabase()->deleteData("DELETE FROM {$sub_table} WHERE guid = {$guid}");
         }
     }
     _elgg_clear_entity_files($this);
     return (bool) $res;
 }
<?php

namespace hypeJunction\places;

$guid = get_input('guid');
$entity = get_entity($guid);
if (!$entity) {
    register_error(elgg_echo('places:error:not_found'));
    forward(REFERER);
}
if (check_entity_relationship(elgg_get_logged_in_user_guid(), 'bookmarked', $guid)) {
    remove_entity_relationship(elgg_get_logged_in_user_guid(), 'bookmarked', $guid);
    elgg_delete_river(array('action_type' => 'stream:places:bookmark', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $entity->guid));
    system_message(elgg_echo('places:bookmark:remove:success'));
    forward(REFERER);
}
register_error(elgg_echo('places:bookmark:remove:error'));
forward(REFERER);
/**
 * Removes a single river entry
 *
 * @param int $id The ID of the river entry
 *
 * @return bool Depending on success
 * @since 1.7.2
 * @deprecated 1.8 Use elgg_delete_river()
 */
function remove_from_river_by_id($id)
{
    elgg_deprecated_notice("remove_from_river_by_id() deprecated by elgg_delete_river()", 1.8);
    return elgg_delete_river(array('id' => $id));
}
Exemple #30
0
<?php

$user = get_user_by_username(get_input('username'));
if ($user) {
    unset($user->badges_badge);
    unset($user->badges_locked);
    elgg_delete_river(array("view" => 'river/object/badge/award', "subject_guid" => $user->guid, "object_guid" => $user->guid));
    elgg_delete_river(array("view" => 'river/object/badge/assign', "subject_guid" => $user->guid, "object_guid" => $user->guid));
    system_message(elgg_echo("badges:unassign:success"));
} else {
    system_message(elgg_echo("badges:unassign:nouser"));
}
forward(REFERER);