本文整理汇总了PHP中elgg_delete_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_delete_metadata函数的具体用法?PHP elgg_delete_metadata怎么用?PHP elgg_delete_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_delete_metadata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* {@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);
}
示例2: testElggDeleteMetadata
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();
}
示例3: migrateTreeStructure
/**
* 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);
}
示例4: autosubscribegroup_join
/**
* 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));
}
}
}
}
}
示例5: izap_update_metadata
/**
*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;
}
示例6: elgg_echo
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
示例7: deleteOwnedMetadata
/**
* 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;
}
示例8: array
<?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);
示例9: socialink_linkedin_sync_profile_metadata
/**
* 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());
}
}
}
}
示例10: socialink_facebook_sync_profile_metadata
/**
* 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());
}
}
示例11: hj_framework_process_tags_input
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;
}
示例12: testWritesInvalidate
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));
}
示例13: user_save_profile
/**
* 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";
}
示例14: ElggFile
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")) {
示例15: get_input
$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;