Example #1
0
 /**
  * {@inheritdoc}
  */
 public function put(ParameterBag $params)
 {
     $owner = get_entity($params->guid);
     if (!$owner->canEdit()) {
         throw new GraphException("You are not allowed to modify this user's profile", HttpResponse::HTTP_FORBIDDEN);
     }
     $profile_fields = (array) elgg_get_config('profile_fields');
     $access_id = $params->access_id !== null ? $params->access_id : get_default_access($owner);
     $input = array();
     foreach ($profile_fields as $field => $valuetype) {
         // Making sure the consumer has sent these fields with the request
         if (isset($params->{$field}) && $this->request->get($field) !== null) {
             $value = $params->{$field};
             $value = _elgg_html_decode($value);
             if (!is_array($value) && $valuetype != 'longtext' && elgg_strlen($value) > 250) {
                 throw new GraphException(elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$field}")), HttpResponse::HTTP_BAD_REQUEST));
             }
             if ($value && $valuetype == 'url' && !preg_match('~^https?\\://~i', $value)) {
                 $value = "http://{$value}";
             }
             if ($valuetype == 'tags') {
                 $value = string_to_tag_array($value);
             }
             if ($valuetype == 'email' && !empty($value) && !is_email_address($value)) {
                 throw new GraphException(elgg_echo('profile:invalid_email', array(elgg_echo("profile:{$field}"))), HttpResponse::HTTP_BAD_REQUEST);
             }
             $input[$field] = $value;
         }
     }
     // go through custom fields
     if (sizeof($input) > 0) {
         foreach ($input as $shortname => $value) {
             $options = array('guid' => $owner->guid, 'metadata_name' => $shortname, 'limit' => false);
             elgg_delete_metadata($options);
             if (!is_null($value) && $value !== '') {
                 // only create metadata for non empty values (0 is allowed) to prevent metadata records
                 // with empty string values #4858
                 if (is_array($value)) {
                     $i = 0;
                     foreach ($value as $interval) {
                         $i++;
                         $multiple = $i > 1 ? TRUE : FALSE;
                         create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
                     }
                 } else {
                     create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id);
                 }
             }
         }
         $owner->save();
         // Notify of profile update
         elgg_trigger_event('profileupdate', $owner->type, $owner);
     }
     return $this->get($params);
 }
Example #2
0
 public function testElggDeleteMetadata()
 {
     $e = new \ElggObject();
     $e->save();
     for ($i = 0; $i < 30; $i++) {
         $name = "test_metadata{$i}";
         $e->{$name} = rand(0, 10000);
     }
     $options = array('guid' => $e->getGUID(), 'limit' => 0);
     $md = elgg_get_metadata($options);
     $this->assertIdentical(30, count($md));
     $this->assertTrue(elgg_delete_metadata($options));
     $md = elgg_get_metadata($options);
     $this->assertTrue(empty($md));
     $e->delete();
 }
Example #3
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);
 }
Example #4
0
/**
 * auto join group define in plugin settings
 *
 */
function autosubscribegroup_join($event, $object_type, $object)
{
    if ($object instanceof ElggUser && $event == 'create' && $object_type == 'user') {
        //auto submit relationships between user & groups
        //retrieve groups ids from plugin
        $groups = elgg_get_plugin_setting('systemgroups', 'autosubscribegroup');
        $groups = split(',', $groups);
        //for each group ids
        foreach ($groups as $groupId) {
            $ia = elgg_set_ignore_access(true);
            $groupEnt = get_entity($groupId);
            elgg_set_ignore_access($ia);
            //if group exist : submit to group
            if ($groupEnt) {
                //join group succeed?
                if ($groupEnt->join($object)) {
                    // Remove any invite or join request flags
                    elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_invite', 'metadata_value' => $groupEnt->guid, 'limit' => false));
                    elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_join_request', 'metadata_value' => $groupEnt->guid, 'limit' => false));
                }
            }
        }
    }
}
/**
*function to update the metadata
*same as the update_metadata, only made metadata editable
*/
function izap_update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
    $id = (int) $id;
    if (!($md = elgg_get_metadata_from_id($id))) {
        return false;
    }
    // If memcached then we invalidate the cache for this entry
    static $metabyname_memcache;
    if (!$metabyname_memcache && is_memcache_available()) {
        $metabyname_memcache = new ElggMemcache('metabyname_memcache');
    }
    if ($metabyname_memcache) {
        $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
    }
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    // Support boolean types (as integers)
    if (is_bool($value)) {
        if ($value) {
            $value = 1;
        } else {
            $value = 0;
        }
    }
    // Add the metastring
    $value = elgg_get_metastring_id($value);
    if (!$value) {
        return false;
    }
    $name = elgg_get_metastring_id($name);
    if (!$name) {
        return false;
    }
    // If ok then add it
    $db_prefix = elgg_get_config('dbprefix');
    $result = update_data("UPDATE {$db_prefix}metadata set value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid} where id={$id} and name_id='{$name}'");
    if ($result !== false) {
        $obj = elgg_get_metadata_from_id($id);
        if (elgg_trigger_event('update', 'metadata', $obj)) {
            return true;
        } else {
            elgg_delete_metadata(array('metadata_id' => $id));
        }
    }
    return $result;
}
Example #6
0
            continue;
        }
        if (empty($value)) {
            $label = $metadata_name;
            if (elgg_language_key_exists("profile:{$metadata_name}")) {
                $label = elgg_echo("profile:{$metadata_name}");
            }
            register_error(elgg_echo('wizard:action:steps:error:profile_field', [$label]));
            forward(REFERER);
        }
        $type = elgg_extract($metadata_name, $profile_fields);
        if ($type === 'tags') {
            $value = string_to_tag_array($value);
        }
        // cleanup existing metadata
        elgg_delete_metadata(['guid' => $user->getGUID(), 'metadata_name' => $metadata_name, 'limit' => false]);
        // save profile field
        if (!is_array($value)) {
            create_metadata($user->getGUID(), $metadata_name, $value, '', $user->getGUID(), ACCESS_LOGGED_IN);
        } else {
            // correctly save tag/array values
            foreach ($value as $v) {
                create_metadata($user->getGUID(), $metadata_name, $v, '', $user->getGUID(), ACCESS_LOGGED_IN, true);
            }
        }
    }
}
elgg_clear_sticky_form('wizard');
// user did this wizard
$entity->addRelationship($user->getGUID(), 'done');
// cleanup session
Example #7
0
 /**
  * Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
  * If you pass a name, only metadata matching that name will be deleted.
  *
  * @param null|string $name The name of metadata to delete.
  * @return bool
  * @since 1.8
  */
 public function deleteOwnedMetadata($name = null)
 {
     // access is turned off for this because they might
     // no longer have access to an entity they created metadata on.
     $ia = elgg_set_ignore_access(true);
     $options = array('metadata_owner_guid' => $this->guid, 'limit' => 0);
     if ($name) {
         $options['metadata_name'] = $name;
     }
     $r = elgg_delete_metadata($options);
     elgg_set_ignore_access($ia);
     return $r;
 }
Example #8
0
<?php

$options = array('type' => 'user', 'limit' => false);
$all_users = new ElggBatch('elgg_get_entities', $options);
foreach ($all_users as $user) {
    $options = array('guid' => $user->guid, 'metadata_name' => 'userpoints_points');
    elgg_delete_metadata($options);
    $users_points = userpoints_get($user->guid);
    $users_approved_points = $users_points['approved'];
    $user->userpoints_points = (int) $users_approved_points;
}
system_message(elgg_echo("elggx_userpoints:restore_all:success"));
forward(REFERER);
Example #9
0
/**
 * Update the Elgg profile with LinkedIn data
 *
 * @param int $user_guid the user_guid of the profile to update
 *
 * @return void
 */
function socialink_linkedin_sync_profile_metadata($user_guid = 0)
{
    global $CONFIG;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // can we get a user
    if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
        // does the user allow sync
        if (elgg_get_plugin_user_setting("linkedin_sync_allow", $user->getGUID(), "socialink") != "no") {
            // get configured fields and network fields
            if (($configured_fields = socialink_get_configured_network_fields("linkedin")) && ($network_fields = socialink_get_network_fields("linkedin"))) {
                // ask the api for all fields
                if ($api_result = socialink_linkedin_get_profile_information($user->getGUID())) {
                    $api_result = json_decode($api_result);
                    // check settings for each field
                    foreach ($configured_fields as $setting_name => $profile_field) {
                        $setting = "linkedin_sync_" . $setting_name;
                        if (elgg_get_plugin_user_setting($setting, $user->getGUID(), "socialink") != "no") {
                            $api_setting = $network_fields[$setting_name];
                            // get the correct value from api result
                            if (stristr($api_setting, "->")) {
                                $temp_fields = explode("->", $api_setting);
                                $temp_result = $api_result;
                                for ($i = 0; $i < count($temp_fields); $i++) {
                                    $temp_result = $temp_result->{$temp_fields}[$i];
                                }
                            } else {
                                $temp_result = $api_result->{$api_setting};
                            }
                            // are we dealing with a tags profile field type
                            if (!empty($CONFIG->profile) && is_array($CONFIG->profile)) {
                                if (array_key_exists($profile_field, $CONFIG->profile) && $CONFIG->profile[$profile_field] == "tags") {
                                    $temp_result = string_to_tag_array($temp_result);
                                }
                            }
                            // check if the user has this metadata field, to get access id
                            $params = array("guid" => $user->getGUID(), "metadata_name" => $profile_field, "limit" => false);
                            if ($metadata = elgg_get_metadata($params)) {
                                if (is_array($metadata)) {
                                    $access_id = $metadata[0]->access_id;
                                } else {
                                    $access_id = $metadata->access_id;
                                }
                            } else {
                                $access_id = get_default_access($user);
                            }
                            // remove metadata to set new values
                            elgg_delete_metadata($params);
                            // make new metadata field
                            if (!empty($temp_result)) {
                                if (is_array($temp_result)) {
                                    foreach ($temp_result as $index => $temp_value) {
                                        if ($index > 0) {
                                            $multiple = true;
                                        } else {
                                            $multiple = false;
                                        }
                                        create_metadata($user->getGUID(), $profile_field, $temp_value, 'text', $user->getGUID(), $access_id, $multiple);
                                    }
                                } else {
                                    create_metadata($user->getGUID(), $profile_field, $temp_result, 'text', $user->getGUID(), $access_id);
                                }
                            }
                        }
                    }
                }
            }
            // sync profile icon, only if the user has no icon
            if (empty($user->icontime)) {
                socialink_linkedin_sync_profile_icon($user->getGUID());
            }
        }
    }
}
Example #10
0
/**
 * Update the Elgg profile with Facebook data
 *
 * @param int $user_guid the user_guid of the profile to update
 *
 * @return void
 */
function socialink_facebook_sync_profile_metadata($user_guid = 0)
{
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return;
    }
    $user = get_user($user_guid);
    if (empty($user) || !socialink_facebook_is_connected($user_guid)) {
        return;
    }
    // does the user allow sync
    if (elgg_get_plugin_user_setting("facebook_sync_allow", $user->getGUID(), "socialink") === "no") {
        return;
    }
    // get configured fields and network fields
    $profile_fields = elgg_get_config("profile_fields");
    $configured_fields = socialink_get_configured_network_fields("facebook");
    $network_fields = socialink_get_network_fields("facebook");
    if (empty($profile_fields) || empty($configured_fields) || empty($network_fields)) {
        return;
    }
    // ask the api for all fields
    $api_result = socialink_facebook_get_profile_information($user->getGUID());
    if (!empty($api_result)) {
        // check settings for each field
        foreach ($configured_fields as $setting_name => $profile_field) {
            $setting = "facebook_sync_" . $setting_name;
            if (elgg_get_plugin_user_setting($setting, $user->getGUID(), "socialink") === "no") {
                continue;
            }
            $api_setting = $network_fields[$setting_name];
            $temp_result = call_user_func(array($api_result, $api_setting));
            // are we dealing with a tags profile field type
            $field_type = elgg_extract($profile_field, $profile_fields);
            if ($field_type === "tags") {
                $temp_result = string_to_tag_array($temp_result);
            }
            // check if the user has this metadata field, to get access id
            $params = array("guid" => $user->getGUID(), "metadata_name" => $profile_field, "limit" => false);
            if ($metadata = elgg_get_metadata($params)) {
                if (is_array($metadata)) {
                    $access_id = $metadata[0]->access_id;
                } else {
                    $access_id = $metadata->access_id;
                }
            } else {
                $access_id = get_default_access($user);
            }
            // remove metadata to set new values
            elgg_delete_metadata($params);
            // make new metadata field
            if (empty($temp_result)) {
                continue;
            }
            if (is_array($temp_result)) {
                foreach ($temp_result as $index => $temp_value) {
                    if ($index > 0) {
                        $multiple = true;
                    } else {
                        $multiple = false;
                    }
                    create_metadata($user->getGUID(), $profile_field, $temp_value, 'text', $user->getGUID(), $access_id, $multiple);
                }
            } else {
                create_metadata($user->getGUID(), $profile_field, $temp_result, 'text', $user->getGUID(), $access_id);
            }
        }
    }
    // sync profile icon, only if the user has no icon
    if (empty($user->icontime)) {
        socialink_facebook_sync_profile_icon($user->getGUID());
    }
}
Example #11
0
function hj_framework_process_tags_input($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params, false);
    if (!elgg_instanceof($entity)) {
        return false;
    }
    $name = elgg_extract('name', $params, 'tags');
    $access_id = elgg_extract('access_id', $params);
    $value = get_input($name, '');
    $value = string_to_tag_array($value);
    elgg_delete_metadata(array('guid' => $entity->guid, 'metadata_names' => $name));
    if ($value) {
        foreach ($value as $val) {
            create_metadata($entity->guid, $name, $val, '', $entity->owner_guid, $access_id, true);
        }
    }
    return true;
}
Example #12
0
 public function testWritesInvalidate()
 {
     // elgg_delete_metadata
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->cache->inject($this->guid2, ['bing' => 'bar']);
     elgg_delete_metadata(array('guid' => $this->guid1));
     $this->assertFalse($this->cache->isLoaded($this->guid1));
     $this->assertTrue($this->cache->isLoaded($this->guid2));
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->cache->inject($this->guid2, ['bing' => 'bar']);
     elgg_delete_metadata(['guids' => [$this->guid1, $this->guid2]]);
     $this->assertFalse($this->cache->isLoaded($this->guid1));
     $this->assertFalse($this->cache->isLoaded($this->guid2));
     // setMetadata
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->obj1->setMetadata($this->name, $this->value);
     $this->assertFalse($this->cache->isLoaded($this->obj1));
     // deleteMetadata
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->obj1->deleteMetadata($this->name);
     $this->assertFalse($this->cache->isLoaded($this->guid1));
     // create_metadata
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     create_metadata($this->guid1, 'foo', 'bar', 'text');
     $this->assertFalse($this->cache->isLoaded($this->guid1));
     // disableMetadata
     $this->obj1->setMetadata($this->name, $this->value);
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->obj1->disableMetadata($this->name);
     $this->assertFalse($this->cache->isLoaded($this->guid1));
     // enableMetadata
     $this->cache->inject($this->guid1, ['foo' => 'bar']);
     $this->obj1->enableMetadata($this->name);
     $this->assertFalse($this->cache->isLoaded($this->guid1));
 }
Example #13
0
/**
 * Web service to update profile information
 *
 * @param string $username username to update profile information
 *
 * @param $profile
 * @return bool
 * @throws InvalidParameterException
 */
function user_save_profile($username, $profile)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
    }
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $owner = get_entity($user->guid);
    $profile_fields = elgg_get_config('profile_fields');
    foreach ($profile_fields as $shortname => $valuetype) {
        $value = $profile[$shortname];
        $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
        if ($valuetype != 'longtext' && elgg_strlen($value) > 250) {
            $error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}")));
            return $error;
        }
        if ($valuetype == 'tags') {
            $value = string_to_tag_array($value);
        }
        $input[$shortname] = $value;
    }
    $name = strip_tags($profile['name']);
    if ($name) {
        if (elgg_strlen($name) > 50) {
            return elgg_echo('user:name:fail');
        } elseif ($owner->name != $name) {
            $owner->name = $name;
            return $owner->save();
        }
    }
    if (sizeof($input) > 0) {
        foreach ($input as $shortname => $value) {
            $options = array('guid' => $owner->guid, 'metadata_name' => $shortname);
            elgg_delete_metadata($options);
            if (isset($accesslevel[$shortname])) {
                $access_id = (int) $accesslevel[$shortname];
            } else {
                // this should never be executed since the access level should always be set
                $access_id = ACCESS_DEFAULT;
            }
            if (is_array($value)) {
                $i = 0;
                foreach ($value as $interval) {
                    $i++;
                    $multiple = $i > 1 ? TRUE : FALSE;
                    create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
                }
            } else {
                create_metadata($owner->guid, $shortname, $value, 'text', $owner->guid, $access_id);
            }
        }
    }
    return "Success";
}
Example #14
0
    if ($file->releaseDate < date("Y-m-d")) {
        $releaseFlag = true;
    }
    if ($file->releaseDate == date("Y-m-d")) {
        if ($file->releaseTime <= date('H:i', time())) {
            $releaseFlag = true;
        }
    }
    if ($releaseFlag === true) {
        $fileObj = new ElggFile($file->guid);
        $fileObj->access_id = $fileObj->releasedAccessId;
        if ($fileObj->save()) {
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'isTimeReleased'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releaseDate'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releaseTime'));
            elgg_delete_metadata(array('guid' => $file->guid, 'metadata_name' => 'releasedAccessId'));
        } else {
        }
    }
}
$wheres = array("msv.string = 'isClosable'");
//get all files ready to be closed / deleted
$content = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'limit' => 5000, 'joins' => $joins, 'wheres' => $wheres));
foreach ($content as $file) {
    $deleteFlag = false;
    if ($file->closeDate == date("Y-m-d")) {
        if ($file->closeTime <= date('H:i', time())) {
            $deleteFlag = true;
        }
    }
    if ($file->closeDate < date("Y-m-d")) {
Example #15
0
        $repeat_weekly_days = get_input('repeat_weekly_days');
        $repeat_weekly_days = is_array($repeat_weekly_days) ? $repeat_weekly_days : date('D', $event->getStartTimestamp());
        $event->repeat_weekly_days = $repeat_weekly_days;
        break;
    case Util::FREQUENCY_MONTHLY:
        $repeat_monthly_by = get_input('repeat_monthly_by', Util::REPEAT_MONTHLY_BY_DATE);
        $event->repeat_monthly_by = $repeat_monthly_by;
        break;
}
$event->repeat_end_timestamp = $event->calculateRepeatEndTimestamp();
if (!$event->save()) {
    register_error(elgg_echo('events:error:save'));
    forward(REFERER);
}
$event->setLocation($location);
elgg_delete_metadata(array('guids' => $event->guid, 'metadata_names' => 'reminder', 'limit' => 0));
$has_reminders = get_input('has_reminders');
$reminders = get_input('reminders', array());
if ($has_reminders && !empty($reminders)) {
    $size = count($reminders['value']) - 1;
    // last one is the template
    for ($i = 0; $i < $size; $i++) {
        $reminder_value = round($reminders['value'][$i]);
        switch ($reminders['increment'][$i]) {
            default:
            case 'minute':
                $reminder_value *= Util::SECONDS_IN_A_MINUTE;
                break;
            case 'hour':
                $reminder_value *= Util::SECONDS_IN_AN_HOUR;
                break;
Example #16
0
 $container = get_entity($page->container_guid);
 // Bring all child elements forward
 $parent = $page->parent_guid;
 $children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID()));
 if ($children) {
     $db_prefix = elgg_get_config('dbprefix');
     $subtype_id = (int) get_subtype_id('object', 'page_top');
     $newentity_cache = is_memcache_available() ? new ElggMemcache('new_entity_cache') : null;
     foreach ($children as $child) {
         if ($parent) {
             $child->parent_guid = $parent;
         } else {
             // If no parent, we need to transform $child to a page_top
             $child_guid = (int) $child->guid;
             update_data("UPDATE {$db_prefix}entities\n\t\t\t\t\t\tSET subtype = {$subtype_id} WHERE guid = {$child_guid}");
             elgg_delete_metadata(array('guid' => $child_guid, 'metadata_name' => 'parent_guid'));
             _elgg_invalidate_cache_for_entity($child_guid);
             if ($newentity_cache) {
                 $newentity_cache->delete($child_guid);
             }
         }
     }
 }
 if ($page->delete()) {
     system_message(elgg_echo('pages:delete:success'));
     if ($parent) {
         if ($parent = get_entity($parent)) {
             forward($parent->getURL());
         }
     }
     if (elgg_instanceof($container, 'group')) {
 /**
  * {@inheritdoc}
  */
 public function handle(\ElggEntity $entity)
 {
     $shortname = $this->getShortname();
     if ($entity->guid) {
         $current_metadata = elgg_get_metadata(array('guids' => (int) $entity->guid, 'metadata_names' => $shortname, 'limit' => 0));
         if (!empty($current_metadata)) {
             foreach ($current_metadata as $md) {
                 $current_metadata_ids[] = $md->id;
             }
         }
     }
     if (empty($current_metadata_ids)) {
         $current_metadata_ids = array();
     }
     $future_metadata = get_input($this->getShortname(), array());
     $params = array('field' => $this, 'entity' => $entity, 'metadata_name' => $shortname, 'value' => $current_metadata, 'future_value' => $future_metadata);
     // Allow plugins to prevent metadata from being changed
     if (!elgg_trigger_plugin_hook('handle:metadata:before', 'prototyper', $params, true)) {
         return $entity;
     }
     $future_metadata_ids = elgg_extract('id', $future_metadata, array());
     $to_delete = array_diff($current_metadata_ids, $future_metadata_ids);
     if (!empty($to_delete)) {
         elgg_delete_metadata(array('guids' => (int) $entity->guid, 'metadata_ids' => $to_delete, 'limit' => 0));
     }
     $keys = array_keys(elgg_extract('name', $future_metadata, array()));
     $ids = array();
     foreach ($keys as $i) {
         $id = $future_metadata['id'][$i];
         $name = $future_metadata['name'][$i];
         $value = $future_metadata['value'][$i];
         $value_type = $this->getValueType();
         $input_type = $this->getType();
         if ($value_type == 'tags' || !$value_type && $input_type == 'tags') {
             $value = string_to_tag_array($value);
         }
         $access_id = $future_metadata['access_id'][$i];
         $owner_guid = $future_metadata['owner_guid'][$i];
         if (!is_array($value)) {
             if ($id) {
                 update_metadata($id, $name, $value, '', $owner_guid, $access_id);
             } else {
                 $id = create_metadata($entity->guid, $name, $value, '', $owner_guid, $access_id, true);
             }
             $ids[] = $id;
         } else {
             if ($id) {
                 elgg_delete_metadata_by_id($id);
             }
             foreach ($value as $val) {
                 $ids[] = create_metadata($entity->guid, $name, $val, '', $owner_guid, $access_id, true);
             }
         }
     }
     $params = array('field' => $this, 'entity' => $entity, 'metadata_name' => $shortname, 'value' => count($ids) ? elgg_get_metadata(array('metadata_ids' => $ids)) : array(), 'previous_value' => $current_metadata);
     elgg_trigger_plugin_hook('handle:metadata:after', 'prototyper', $params, true);
     return $entity;
 }
Example #18
0
/**
 * Unsets entity coordinates
 *
 * @param integer $entity_guid
 * @return boolean
 */
function unset_entity_coordinates($entity_guid = 0, $lat = 0, $long = 0)
{
    $entity = get_entity($entity_guid);
    if (!elgg_instanceof($entity)) {
        return false;
    }
    elgg_delete_metadata(array('guids' => $entity->guid, 'metadata_names' => array('geo:lat', 'geo:long'), 'limit' => 0));
    $dbprefix = elgg_get_config('dbprefix');
    $query = "DELETE LOW_PRIORITY FROM {$dbprefix}entity_geometry WHERE entity_guid = {$entity->guid}";
    return delete_data($query);
}
 public function testWritesAreCached()
 {
     // delete should mark cache as known to be empty
     $this->obj1->deleteMetadata($this->name);
     $this->assertTrue($this->cache->isKnown($this->guid1, $this->name));
     $this->assertNull($this->cache->load($this->guid1, $this->name));
     // without name, delete should invalidate the entire entity
     $this->cache->save($this->guid1, $this->name, $this->value);
     elgg_delete_metadata(array('guid' => $this->guid1));
     $this->assertFalse($this->cache->isKnown($this->guid1, $this->name));
     // test set
     $this->obj1->setMetadata($this->name, $this->value);
     $this->assertIdentical($this->cache->load($this->guid1, $this->name), $this->value);
     // test set multiple
     $this->obj1->setMetadata($this->name, 1, 'integer', true);
     $this->assertIdentical($this->cache->load($this->guid1, $this->name), array($this->value, 1));
     // writes when access is ignore should invalidate
     $tmp_ignore = elgg_set_ignore_access(true);
     $this->obj1->setMetadata($this->name, $this->value);
     $this->assertFalse($this->cache->isKnown($this->guid1, $this->name));
     elgg_set_ignore_access($tmp_ignore);
 }
Example #20
0
/**
 * Check for an existing pending invite for the given email address.
 *
 * @param string   $email The amail address of the invited user
 * @return Bool    Return true/false on pending record found or not
 */
function elggx_userpoints_registration_award($email)
{
    $access = elgg_set_ignore_access(true);
    $guids = elggx_userpoints_invite_status(null, $email);
    if (!empty($guids)) {
        foreach ($guids as $guid) {
            $entity = get_entity($guid);
            $entity->meta_moderate = 'approved';
            $user = get_user($entity->owner_guid);
            if (is_int($user->userpoints_points)) {
                $user->userpoints_points = (int) $user->userpoints_points + (int) $entity->meta_points;
            } else {
                $options = array('guid' => $user->guid, 'metadata_name' => 'userpoints_points');
                elgg_delete_metadata($options);
                $users_points = userpoints_get($user->guid);
                $users_approved_points = $users_points['approved'];
                $user->userpoints_points = (int) $users_approved_points;
            }
            if (!elgg_trigger_plugin_hook('userpoints:update', 'object', array('entity' => $user), true)) {
                $user->userpoints_points = (int) $user->userpoints_points - (int) $entity->meta_points;
            }
        }
    }
    elgg_set_ignore_access($access);
    return;
}
Example #21
0
function hj_forum_1360948621()
{
    $dbprefix = elgg_get_config('dbprefix');
    /**
     * Upgrade :
     * 1. Former hjAnnotation's description is stored in annotation_value metadata. Needs updating
     */
    $subtypeIdForumPost = get_subtype_id('object', 'hjforumpost');
    $query = "\tUPDATE {$dbprefix}objects_entity oe\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = oe.guid\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\n\t\t\t\tJOIN {$dbprefix}entities e on oe.guid = e.guid\n\t\t\t\tSET oe.description = msv.string\n\t\t\t\tWHERE e.subtype = {$subtypeIdForumPost} AND msn.string = 'annotation_value'";
    update_data($query);
    elgg_delete_metadata(array('types' => 'object', 'subtypes' => 'hjforumpost', 'metadata_names' => array('annotation_name', 'annotation_value')));
}
Example #22
0
 $user = get_user($faq->owner_guid);
 // Was the question adjusted?
 if ($question == $orgQuestion) {
     $same = true;
 } else {
     $same = false;
 }
 if (!$same) {
     $faq->question = $question;
 }
 $faq->answer = $answer;
 $faq->category = $cat;
 $faq->access_id = $access;
 $faq->container_guid = elgg_get_config('site_guid');
 $faq->owner_guid = elgg_get_config('site_guid');
 if (elgg_delete_metadata(array('guid' => $faq->guid, 'metadata_name' => "userQuestion", 'metadata_value' => true, 'limit' => 0))) {
     if ($faq->save()) {
         $url = elgg_get_site_url() . "faq/list?categoryId=" . elgg_get_metastring_id($faq->category) . "#qID" . $faq->guid;
         $user_language = $user->language ? $user->language : (($site_language = elgg_get_config('language')) ? $site_language : 'en');
         if ($same) {
             // notify user, question added and not adjusted
             $subject = elgg_echo("faq:answer:notify:subject", array(), $user_language);
             $body = elgg_echo("faq:answer:notify:message:added:same", array($question, $url), $user_language);
         } else {
             // notify user, question added and adjusted
             $subject = elgg_echo("faq:answer:notify:subject", array(), $user_language);
             $body = elgg_echo("faq:answer:notify:message:added:adjusted", array($orgQuestion, $question, $url), $user_language);
         }
         $result = array();
         $result[$user->guid]['message'] = messages_send($subject, $body, $user->guid, elgg_get_logged_in_user_guid(), 0, false, false);
         $result[] = notify_user($user->guid, elgg_get_logged_in_user_guid(), $subject, $body, array(), 'email');
Example #23
0
/**
 * Removes metadata on an entity with a particular name, optionally with a given value.
 *
 * @param int    $guid  The entity GUID
 * @param string $name  The name of the metadata
 * @param string $value The value of the metadata (useful to remove a single item of a set)
 *
 * @return bool Depending on success
 * @deprecated 1.8 Use elgg_delete_metadata()
 */
function remove_metadata($guid, $name, $value = "")
{
    elgg_deprecated_notice('delete_metadata() is deprecated by elgg_delete_metadata()', 1.8);
    // prevent them from deleting everything
    if (!$guid) {
        return false;
    }
    $options = array('guid' => $guid, 'metadata_name' => $name, 'limit' => 0);
    if ($value) {
        $options['metadata_value'] = $value;
    }
    return elgg_delete_metadata($options);
}
Example #24
0
/**
 * Removes an expiration date for an entry.
 *
 * @param $guid
 * @param $type
 * @return unknown_type
 */
function expirationdate_unset($id, $type = 'entities')
{
    $access = elgg_set_ignore_access(true);
    if ($type == 'entities') {
        elgg_delete_metadata(array('guid' => $id, 'metadata_name' => 'expirationdate'));
        elgg_delete_metadata(array('guid' => $id, 'metadata_name' => 'expirationdate_disable_only'));
    }
    elgg_set_ignore_access($access);
    return true;
}