Exemplo n.º 1
0
function addTaggedWirePost($hook, $type, $params)
{
    global $CONFIG;
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '" . $params['type'] . "', " . " subtype = '" . $params['subtype'] . "', " . " action_type = '" . $params['action_type'] . "', " . " access_id = '" . $params['access_id'] . "', " . " view = '" . $params['view'] . "', " . " subject_guid = '" . $params['subject_guid'] . "', " . " object_guid = '" . $params['object_guid'] . "', " . " annotation_id = '" . $params['annotation_id'] . "', " . " posted = '" . $params['posted'] . "';");
    $tags = "";
    if (isset($_SESSION['role'])) {
        switch ($_SESSION['role']) {
            case "learner":
                $tags = "Learner-Apprenant";
                break;
            case "instructor":
                $tags = "Instructor-Instructeur";
                break;
            case "developer":
                $tags = "Developer-Développeur";
                break;
            case "trainingmgr":
                $tags = "trainingmgr";
                break;
        }
        $roleTags = $_SESSION['role'];
    }
    if ($roleTags) {
        $metaID = create_metadata($params['object_guid'], "tags", "{$tags}", "text", elgg_get_logged_in_user_guid(), 2, true);
    }
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
    }
    return false;
}
Exemplo n.º 2
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 one-word 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)
 * @return true|false Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    // Sanitise variables
    if (!elgg_view_exists($view)) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $annotation_id = (int) $annotation_id;
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    $insert_data = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted} ");
    //update the entities which had the action carried out on it
    if ($insert_data) {
        update_entity_last_action($object_guid, $posted);
        return $insert_data;
    }
}
Exemplo n.º 3
0
/**
 * 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;
}
Exemplo n.º 4
0
function upgrade_20141125()
{
    $version = (int) elgg_get_plugin_setting('version', PLUGIN_ID);
    if ($version == 2011111502) {
        // this didn't happen correctly in the last upgrade
        // due to some legacy setting
        elgg_set_plugin_setting('version', 20141121, PLUGIN_ID);
        $version = 20141121;
    }
    if ($version >= UPGRADE_VERSION) {
        return true;
    }
    $options = array('type' => 'object', 'subtype' => 'plugin_project', 'limit' => false);
    $batch = new ElggBatch('elgg_get_entities', $options);
    foreach ($batch as $plugin) {
        // get most recent release
        $releases = elgg_get_entities(array('type' => 'object', 'subtype' => 'plugin_release', 'container_guid' => $plugin->guid, 'limit' => 1, 'callback' => false));
        if ($releases[0]->time_created) {
            update_entity_last_action($plugin->guid, $releases[0]->time_created);
        } else {
            update_entity_last_action($plugin->guid, $plugin->time_created);
        }
    }
    elgg_set_plugin_setting('version', 20141125, PLUGIN_ID);
}
Exemplo n.º 5
0
 /**
  * Save entity
  * Add default priority and update last action on an album
  *
  * @return integer|false
  */
 public function save()
 {
     update_entity_last_action($this->container_guid);
     if (!isset($this->priority)) {
         $this->priority = 0;
     }
     return parent::save();
 }
 /**
  * Update container entity last action on successful save.
  *
  * @param bool $update_last_action Update the container entity's last_action field
  * @return bool|int
  */
 public function save($update_last_action = true)
 {
     $result = parent::save();
     if ($result && $update_last_action) {
         update_entity_last_action($this->container_guid, $this->time_updated);
     }
     return $result;
 }
Exemplo n.º 7
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
 *
 * @return int/bool River ID or false on failure
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    global $CONFIG;
    // use default viewtype for when called from web services api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    // Attempt to save river item; return success status
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be down elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Exemplo n.º 8
0
function update_parent_folder_last_action($parent_guid = null)
{
    if ($parent_guid) {
        $folder = get_entity($parent_guid);
        if ($folder) {
            update_entity_last_action($folder->guid);
            update_parent_folder_last_action($folder->parent_guid);
        }
    } else {
        return;
    }
}
Exemplo n.º 9
0
Arquivo: river.php Projeto: rasul/Elgg
/**
 * 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
 *
 * @return bool Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    // use default viewtype for when called from REST api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $annotation_id = (int) $annotation_id;
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    $params = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $params = elgg_trigger_plugin_hook('add', 'river', null, $params);
    if ($params == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($params);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    $insert_data = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    //update the entities which had the action carried out on it
    if ($insert_data) {
        update_entity_last_action($object_guid, $posted);
        return $insert_data;
    }
}
Exemplo n.º 10
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $values = array('type' => $object->getType(), 'subtype' => $object->getSubtype(), 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    $col_types = array('type' => 'string', 'subtype' => 'string', 'action_type' => 'string', 'access_id' => 'int', 'view' => 'string', 'subject_guid' => 'int', 'object_guid' => 'int', 'target_guid' => 'int', 'annotation_id' => 'int', 'posted' => 'int');
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    $dbprefix = elgg_get_config('dbprefix');
    // escape values array and build INSERT assignments
    $assignments = array();
    foreach ($col_types as $name => $type) {
        $values[$name] = $type === 'int' ? (int) $values[$name] : sanitize_string($values[$name]);
        $assignments[] = "{$name} = '{$values[$name]}'";
    }
    $id = insert_data("INSERT INTO {$dbprefix}river SET " . implode(',', $assignments));
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($values['object_guid'], $values['posted']);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Exemplo n.º 11
0
    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) || !elgg_instanceof($question, "object", "question")) {
    register_error(elgg_echo("ClassException:ClassnameNotClass", array($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) {
        update_entity_last_action($answer->container_guid, $answer->time_created);
        add_to_river("river/object/answer/create", "create", elgg_get_logged_in_user_guid(), $answer->guid, $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()));
Exemplo n.º 12
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $target_guid = sanitise_int($target_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    $dbprefix = elgg_get_config('dbprefix');
    $id = insert_data("INSERT INTO {$dbprefix}river " . " SET type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " target_guid = {$target_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Exemplo n.º 13
0
}
// Extract file and save to default filestore (for now)
$prefix = "plugins/";
$filestorename = $prefix . strtolower(time() . $_FILES['upload']['name']);
$release = new PluginRelease();
$release->title = $plugin_project->title;
$release->setFilename($filestorename);
$release->setMimetype($mimetype);
$release->originalfilename = $_FILES['upload']['name'];
$release->access_id = $access_id;
$release->owner_guid = $plugin_project->getGUID();
$release->container_guid = $plugin_project->getGUID();
$release->version = $version;
$release->release_notes = $release_notes;
$release->elgg_version = $elgg_version;
$release->comments = $comments;
if (!$release->save()) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward($plugin_project->getURL());
}
if ($release->saveArchive('upload') != TRUE) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward(REFERER);
}
$release->setRecommended($recommended);
$release->setHash();
elgg_create_river_item(array('view' => 'river/object/plugin_release/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $release->guid));
update_entity_last_action($plugin_project->guid);
system_message(elgg_echo("plugins:release:saved"));
elgg_clear_sticky_form('community_plugins');
forward($release->getURL());
Exemplo n.º 14
0
function copyGroup($guid, $name, $parentGroupGuid = null, array $options = null)
{
    $inheritMembers = $_POST['inheritMembers'];
    $inheritFiles = $_POST['inheritFiles'];
    $inheritForums = $_POST['inheritForums'];
    $inheritSubGroups = $_POST['subGroups'];
    if ($options) {
        $inheritMembers = $options['inheritMembers'];
        $inheritFiles = $options['inheritFiles'];
        $inheritForums = $options['inheritForums'];
        $inheritSubGroups = $options['inheritSubGroups'];
    }
    $groupOptions = array('inheritMembers' => $inheritMembers, 'inheritFiles' => $inheritFiles, 'inheritForums' => $inheritForums, 'inheritSubGroups' => $inheritSubGroups);
    //check if a sub-group when parentGroupGuid is null
    if (!isset($parentGroupGuid)) {
        $parentGroup = elgg_get_entities_from_relationship(array("relationship" => "au_subgroup_of", "relationship_guid" => $guid));
        $parentGroupGuid = $parentGroup[0]->guid;
    }
    //get group
    $oldGroup = get_entity($guid);
    //get user
    $user = get_user($oldGroup->owner_guid);
    //create new group
    $newGroup = clone $oldGroup;
    $newGroup->name = $name;
    $newGroup->save();
    //get all categories associated with the group and associate them with the copied group
    $groupCats = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjcategory', 'order_by' => 'e.last_action desc', 'limit' => 40, 'full_view' => false, 'container_guid' => $guid));
    foreach ($groupCats as $groupCat) {
        $newGroupCat = clone $groupCat;
        $newGroupCat->container_guid = $newGroup->guid;
        $newGroupCat->save();
    }
    if ($inheritFiles) {
        //clone files belonging to the old group add add them to their new categories
        $groupFiles = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'order_by' => 'e.last_action desc', 'limit' => 500, 'full_view' => false, 'container_guid' => $guid));
        foreach ($groupFiles as $groupFile) {
            $newGroupFile = clone $groupFile;
            $newGroupFile->container_guid = $newGroup->guid;
            $newGroupFile->access_id = $newGroup->group_acl;
            $date = new DateTime();
            $newTimeStamp = $date->getTimestamp();
            $newGroupFile->time_created = $newTimeStamp;
            $newGroupFile->time_updated = $newTimeStamp;
            $newGroupFile->last_action = $newTimeStamp;
            $newGroupFile->save();
            //copy file over on disk
            $prefix = "file/";
            $filestorename = elgg_strtolower(time() . $newGroupFile->originalfilename);
            $sourceDest = $newGroupFile->getFilenameOnFilestore();
            $newGroupFile->setFilename($prefix . $filestorename);
            $newGroupFile->open("write");
            $newGroupFile->close();
            if (!copy($sourceDest, $newGroupFile->getFilenameOnFilestore())) {
                error_log("couldn't copy");
            }
            //if file is tagged in a category, need to update to reflect copied groups category
            if ($newGroupFile->universal_categories) {
                $categories = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjcategory', 'order_by' => 'e.last_action desc', 'limit' => 40, 'full_view' => false, 'container_guid' => $newGroup->guid));
                $copyCategories = elgg_get_entities_from_relationship(array('relationship' => HYPECATEGORIES_RELATIONSHIP, 'relationship_guid' => $groupFile->guid, 'inverse_relationship' => false, 'limit' => 150));
                foreach ($categories as $category) {
                    foreach ($copyCategories as $c) {
                        if ($category->title == $c->title) {
                            add_entity_relationship($newGroupFile->guid, HYPECATEGORIES_RELATIONSHIP, $category->guid);
                        }
                    }
                }
            }
            //$newGroupFile->save();
        }
        //get all folders associated with the group and associate them with the new copied group
        $groupFolders = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 120, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => 0));
        foreach ($groupFolders as $groupFolder) {
            $newGroupFolder = clone $groupFolder;
            $newGroupFolder->container_guid = $newGroup->guid;
            $newGroupFolder->access_id = $newGroup->group_acl;
            $newGroupFolder->save();
            //get files associated with folder
            $files = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'order_by' => 'e.last_action desc', 'limit' => 500, 'full_view' => false, 'container_guid' => $newGroup->guid));
            $oldFolderFiles = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $groupFolder->guid, 'inverse_relationship' => false, 'limit' => 100));
            foreach ($oldFolderFiles as $f) {
                foreach ($files as $file) {
                    if ($file->title == $f->title) {
                        add_entity_relationship($newGroupFolder->guid, 'folder_of', $file->guid);
                    }
                }
            }
            //get sub folders
            $subFolders = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $groupFolder->guid));
            foreach ($subFolders as $subFolder) {
                $newSubFolder = clone $subFolder;
                $newSubFolder->container_guid = $newGroup->guid;
                $newSubFolder->access_id = $newGroup->group_acl;
                $newSubFolder->parent_guid = $newGroupFolder->guid;
                $newSubFolder->save();
                $oldSubFolderFiles = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder->guid, 'inverse_relationship' => false, 'limit' => 60));
                foreach ($oldSubFolderFiles as $f) {
                    foreach ($files as $file) {
                        if ($file->title == $f->title) {
                            add_entity_relationship($newSubFolder->guid, 'folder_of', $file->guid);
                        }
                    }
                }
                //get sub sub folders
                $subFolders2 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder->guid));
                foreach ($subFolders2 as $subFolder2) {
                    $newSubFolder2 = clone $subFolder2;
                    $newSubFolder2->container_guid = $newGroup->guid;
                    $newSubFolder2->access_id = $newGroup->group_acl;
                    $newSubFolder2->parent_guid = $newSubFolder->guid;
                    $newSubFolder2->save();
                    $oldSubFolder2Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder2->guid, 'inverse_relationship' => false, 'limit' => 60));
                    foreach ($oldSubFolder2Files as $f) {
                        foreach ($files as $file) {
                            if ($file->title == $f->title) {
                                add_entity_relationship($newSubFolder2->guid, 'folder_of', $file->guid);
                            }
                        }
                    }
                    //get sub sub folders
                    $subFolders3 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder2->guid));
                    foreach ($subFolders3 as $subFolder3) {
                        $newSubFolder3 = clone $subFolder3;
                        $newSubFolder3->container_guid = $newGroup->guid;
                        $newSubFolder3->access_id = $newGroup->group_acl;
                        $newSubFolder3->parent_guid = $newSubFolder2->guid;
                        $newSubFolder3->save();
                        $oldSubFolder3Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder3->guid, 'inverse_relationship' => false, 'limit' => 60));
                        foreach ($oldSubFolder3Files as $f) {
                            foreach ($files as $file) {
                                if ($file->title == $f->title) {
                                    add_entity_relationship($newSubFolder3->guid, 'folder_of', $file->guid);
                                }
                            }
                        }
                        //get sub sub folders
                        $subFolders4 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder3->guid));
                        foreach ($subFolders4 as $subFolder4) {
                            $newSubFolder4 = clone $subFolder4;
                            $newSubFolder4->container_guid = $newGroup->guid;
                            $newSubFolder4->access_id = $newGroup->group_acl;
                            $newSubFolder4->parent_guid = $newSubFolder3->guid;
                            $newSubFolder4->save();
                            $oldSubFolder4Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder4->guid, 'inverse_relationship' => false, 'limit' => 60));
                            foreach ($oldSubFolder4Files as $f) {
                                foreach ($files as $file) {
                                    if ($file->title == $f->title) {
                                        add_entity_relationship($newSubFolder4->guid, 'folder_of', $file->guid);
                                    }
                                }
                            }
                            //get sub sub sub folders
                            $subFolders5 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder4->guid));
                            foreach ($subFolders5 as $subFolder5) {
                                $newSubFolder5 = clone $subFolder5;
                                $newSubFolder5->container_guid = $newGroup->guid;
                                $newSubFolder5->access_id = $newGroup->group_acl;
                                $newSubFolder5->parent_guid = $newSubFolder5->guid;
                                $newSubFolder5->save();
                                $oldSubFolder5Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder5->guid, 'inverse_relationship' => false, 'limit' => 60));
                                foreach ($oldSubFolder5Files as $f) {
                                    foreach ($files as $file) {
                                        if ($file->title == $f->title) {
                                            add_entity_relationship($newSubFolder5->guid, 'folder_of', $file->guid);
                                        }
                                    }
                                }
                            }
                            //end 6th level folders
                        }
                        //end 5th level folders
                    }
                    //end 4th level folders
                }
                //end 3rd level folders
            }
            //end 2nd folders
        }
        //end group folders
    }
    //copy over forums
    if ($inheritForums) {
        $groupForums = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 100, 'full_view' => false, 'container_guid' => $guid));
        $i1 = 0;
        foreach ($groupForums as $groupForum) {
            $newGroupForum = clone $groupForum;
            $newGroupForum->container_guid = $newGroup->getGUID();
            $newGroupForum->access_id = $newGroup->group_acl;
            $newGroupForum->last_action = time();
            $newGroupForum->save();
            $subForums = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 150, 'full_view' => false, 'container_guid' => $groupForum->guid));
            $i2 = 0;
            foreach ($subForums as $subForum) {
                $newSubForum = clone $subForum;
                $newSubForum->container_guid = $newGroupForum->getGUID();
                $newSubForum->access_id = $newGroupForum->access_id;
                $newSubForum->last_action = time();
                $newSubForum->save();
                $subForums2 = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 150, 'full_view' => false, 'container_guid' => $subForum->guid));
                $i3 = 0;
                foreach ($subForums2 as $subForum2) {
                    $newSubForum2 = clone $subForum2;
                    $newSubForum2->container_guid = $newSubForum->getGUID();
                    $newSubForum2->access_id = $newSubForum->access_id;
                    $newSubForum2->save();
                    $time = time() + $i3;
                    update_entity_last_action($newSubForum2->guid, $time);
                    $i3++;
                }
                $time = time() + $i2;
                update_entity_last_action($newSubForum->guid, $time);
                $i2++;
            }
            $time = time() + $i1;
            update_entity_last_action($newGroupForum->guid, $time);
            $i1++;
        }
    }
    $newGroup->join($user);
    //get admins from old group and add them to the new one
    $oldAdmins = elgg_get_entities_from_relationship(array("relationship" => "group_admin", "relationship_guid" => $oldGroup->getGUID(), "inverse_relationship" => true));
    foreach ($oldAdmins as $admin) {
        $newGroup->join($admin);
        add_entity_relationship($admin->getGUID(), "group_admin", $newGroup->getGUID());
    }
    //get members from old group and add them to new group if specified by user
    if ($inheritMembers) {
        //get collection of old members
        $oldMembers = elgg_get_entities_from_relationship(array("relationship" => "member", "relationship_guid" => $oldGroup->getGUID(), "inverse_relationship" => true, 'limit' => 200));
        foreach ($oldMembers as $oldMember) {
            $newGroup->join($oldMember);
        }
    }
    if ($inheritSubGroups) {
        $subGroups = elgg_get_entities_from_relationship(array("relationship" => "au_subgroup_of", "relationship_guid" => $guid, "inverse_relationship" => true, 'limit' => false));
        foreach ($subGroups as $subGroup) {
            copyGroup($subGroup->guid, "Copy of " . $subGroup->name, $newGroup->guid, $groupOptions);
        }
    }
    if ($parentGroupGuid) {
        add_entity_relationship($newGroup->guid, 'au_subgroup_of', $parentGroupGuid);
    }
    add_to_river('river/group/create', 'create', $user->guid, $newGroup->guid, $newGroup->access_id);
    $newGroup->save();
    return $newGroup->getURL();
}
Exemplo n.º 15
0
 /**
  * Publish post also on frontend
  *
  * @return bool
  */
 public function publishOnFrontend()
 {
     if ($this->answerGuid == 1) {
         $answer = new ElggAnswer();
         $answer->description = $this->description;
         $answer->intanswerGuid = $this->guid;
         $answer->container_guid = $this->container_guid;
         $answer->access_id = $this->getQuestion()->access_id;
         $publish_user = elgg_get_plugin_setting('workflow_publishuser', 'questions');
         if ($publish_user && ($user = get_user_by_username($publish_user))) {
             $answer->owner_guid = $user->guid;
             // ignore access because we would maybe want to write in the name of publishuser.
             elgg_set_ignore_access(true);
             $answer->save();
             elgg_set_ignore_access(false);
         } else {
             $answer->save();
         }
         $this->answerGuid = $answer->guid;
         update_entity_last_action($answer->container_guid, $answer->time_created);
     } elseif (is_int($this->answerGuid)) {
         $answer = get_entity($this->answerGuid);
         if ($answer instanceof ElggAnswer) {
             // ignore access because we would maybe want to overwrite entity of publishuser.
             elgg_set_ignore_access(true);
             $answer->description = $this->description;
             $answer->save();
             elgg_set_ignore_access(false);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Set last action on an entity | helpful when updating a parent entity
  * @param int $timestamp
  */
 public function setLastAction($timestamp = null)
 {
     if (!$timestamp) {
         $timestamp = time();
     }
     update_entity_last_action($this->guid, $timestamp);
 }