public function testElggEntityDisableAndEnable() { global $CONFIG; // add annotations and metadata to check if they're disabled. $annotation_id = create_annotation($this->entity->guid, 'test_annotation_' . rand(), 'test_value_' . rand()); $metadata_id = create_metadata($this->entity->guid, 'test_metadata_' . rand(), 'test_value_' . rand()); $this->assertTrue($this->entity->disable()); // ensure disabled by comparing directly with database $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'"); $this->assertIdentical($entity->enabled, 'no'); $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '{$annotation_id}'"); $this->assertIdentical($annotation->enabled, 'no'); $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '{$metadata_id}'"); $this->assertIdentical($metadata->enabled, 'no'); // re-enable for deletion to work $this->assertTrue($this->entity->enable()); // check enabled // check annotations and metadata enabled. $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'"); $this->assertIdentical($entity->enabled, 'yes'); $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '{$annotation_id}'"); $this->assertIdentical($annotation->enabled, 'yes'); $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '{$metadata_id}'"); $this->assertIdentical($metadata->enabled, 'yes'); $this->assertTrue($this->entity->delete()); $this->entity = null; }
/** *funtion to mark the visitor */ function izapMarkVisitor() { $ProfileEntity = elgg_get_page_owner_entity(); $ProfileName = $ProfileEntity->name; $ProfileGuid = $ProfileEntity->guid; $ProfileOwner = $ProfileEntity->owner_guid; $ProfileAccess = $ProfileEntity->access_id; $VisitorEntity = elgg_get_logged_in_user_entity(); $VisitorName = $VisitorEntity->name; $VisitorGuid = $VisitorEntity->guid; $VisitorsArray = array(); if ($VisitorGuid != $ProfileGuid && $VisitorEntity && $ProfileEntity) { $md = elgg_get_metadata(array('guid' => $ProfileGuid, 'metadata_name' => 'izapProfileVisitor', 'limit' => false)); $Metadata = array(); if ($md && count($md) == 1) { $Metadata = $md[0]; } else { $Metadata = $md; } if ($Metadata) { $Id = $Metadata->id; $VisitorsArray = unserialize($Metadata->value); array_unshift($VisitorsArray, $VisitorGuid); $InsertArray = array_slice(array_unique($VisitorsArray), 0, 10); $InsertArray = serialize($InsertArray); izap_update_metadata($Id, 'izapProfileVisitor', $InsertArray, 'text', $ProfileOwner, ACCESS_PUBLIC); } else { array_unshift($VisitorsArray, $VisitorGuid); $InsertArray = serialize($VisitorsArray); create_metadata($ProfileGuid, 'izapProfileVisitor', $InsertArray, 'text', $ProfileOwner, ACCESS_PUBLIC); } } }
public function testElggGetEntitiesFromMetadata() { global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; $METASTRINGS_CACHE = $METASTRINGS_DEADNAME_CACHE = array(); $this->object->title = 'Meta Unit Test'; $this->object->save(); $this->create_metastring('metaUnitTest'); $this->create_metastring('tested'); $this->assertTrue(create_metadata($this->object->guid, 'metaUnitTest', 'tested')); // check value with improper case $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE); $this->assertFalse(elgg_get_entities_from_metadata($options)); // compare forced case with ignored case $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'tested', 'limit' => 10, 'metadata_case_sensitive' => TRUE); $case_true = elgg_get_entities_from_metadata($options); $this->assertIsA($case_true, 'array'); $options = array('metadata_names' => 'metaUnitTest', 'metadata_values' => 'Tested', 'limit' => 10, 'metadata_case_sensitive' => FALSE); $case_false = elgg_get_entities_from_metadata($options); $this->assertIsA($case_false, 'array'); $this->assertIdentical($case_true, $case_false); // check deprecated get_entities_from_metadata() function $deprecated = get_entities_from_metadata('metaUnitTest', 'tested', '', '', 0, 10, 0, '', 0, FALSE, TRUE); $this->assertIdentical($deprecated, $case_true); // check entity list //$this->dump(list_entities_from_metadata('metaUnitTest', 'Tested', '', '', 0, 10, TRUE, TRUE, TRUE, FALSE)); // clean up $this->delete_metastrings(); $this->object->delete(); }
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; }
/** * Extend the create user function to include additional information * for invited authors * * @param string $event * @param string $object_type * @param ElggUser $object */ function publication_create_user($event, $object_type, $object) { $author = get_input($key); $publication = get_input($key); if (empty($author) || empty($publication)) { return; } create_metadata($object->getGUID(), "exauthor_name", $author, "", $object->getGUID(), ACCESS_PUBLIC); create_metadata($object->getGUID(), "firstpublication", $publication, "", $object->getGUID(), ACCESS_PUBLIC); }
/** * {@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); }
public function testElggGetMetadataCount() { $this->object->title = 'Meta Unit Test'; $this->object->save(); $guid = $this->object->getGUID(); create_metadata($guid, 'tested', 'tested1', 'text', 0, ACCESS_PUBLIC, true); create_metadata($guid, 'tested', 'tested2', 'text', 0, ACCESS_PUBLIC, true); $count = (int) elgg_get_metadata(array('metadata_names' => array('tested'), 'guid' => $guid, 'count' => true)); $this->assertIdentical($count, 2); $this->object->delete(); }
public function createMetadata($max = 1) { $metadata = array(); for ($i = 0; $i < $max; $i++) { $name = 'test_metadata_name' . rand(); $value = 'test_metadata_value' . rand(); $id = create_metadata($this->object->guid, $name, $value); $metadata[] = $id; } return $metadata; }
/** * Save metadata object * * @return int|bool the metadata object id or true if updated * * @throws IOException */ public function save() { if ($this->id > 0) { return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new \IOException("Unable to save new " . get_class()); } return $this->id; } }
/** * Save matadata object * * @return int the metadata object id */ function save() { if ($this->id > 0) { return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class()))); } return $this->id; } }
/** * Pull EXIF data from image file * * @param TidypicsImage $file */ function td_get_exif($file) { // catch for those who don't have exif module loaded if (!is_callable('exif_read_data')) { return; } $mime = $file->mimetype; if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') { return; } $filename = $file->getFilenameOnFilestore(); $exif = exif_read_data($filename); create_metadata($file->getGUID(), "tp_exif", serialize($exif), "text", $file->getOwnerGUID(), ACCESS_PUBLIC); }
function publication_create_user($event, $object_type, $object) { foreach ($_POST as $key => $value) { if ($key == 'author') { $author = $value; } if ($key == 'publication') { $publication = $value; } } if ($author && $publication) { create_metadata($object->guid, 'exauthor_name', $author, "", $object->guid, ACCESS_PUBLIC); create_metadata($object->guid, 'firstpublication', $publication, "", $object->guid, ACCESS_PUBLIC); } }
function elggpg_import_key($public_key, $user) { $gpg = new gnupg(); $info = $gpg->import($public_key); $new_fp = $info['fingerprint']; $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey'))); $access_id = ACCESS_LOGGED_IN; if ($user_fp && $user_fp->value != $new_fp) { update_metadata($user_fp->id, $user_fp->name, $new_fp, 'text', $user->guid, $access_id); $info['imported'] = 1; } elseif (!$user_fp) { create_metadata($user->guid, "openpgp_publickey", $new_fp, 'text', $user->guid, $access_id); $info['imported'] = 1; } $info['key_id'] = elggpg_fp2keyid($new_fp); return $info; }
/** * Check if the email of the user has already been associated with a Stripe customer * If so, map them * * @param string $event * @param string $type * @param ElggUser $user * @param true */ function stripe_register_user($event, $type, $user) { $customer_ref = elgg_get_plugin_setting($user->email, 'stripe'); if (!$customer_ref) { return; } $customer_ref = unserialize($customer_ref); if (is_array($customer_ref) && sizeof($customer_ref)) { $user->setPrivateSetting('stripe_customer_id', $customer_ref[0]); $customer_ref = array_reverse($customer_ref); foreach ($customer_ref as $c_ref) { create_metadata($user->guid, 'stripe_customer_id', $c_ref, '', $user->guid, ACCESS_PUBLIC, true); } } elgg_unset_plugin_setting($user->email, 'stripe'); return true; }
function group_icon_url_override($hook, $type, $returnvalue, $params) { $group = $params['entity']; $size = $params['size']; $icontime = $group->icontime; if (null === $icontime) { $file = new ElggFile(); $file->owner_guid = $group->owner_guid; $file->setFilename("groups/" . $group->guid . "large.jpg"); $icontime = $file->exists() ? time() : 0; create_metadata($group->guid, 'icontime', $icontime, 'integer', $group->owner_guid, ACCESS_PUBLIC); } if ($icontime) { // return thumbnail return "groupicon/{$group->guid}/{$size}/{$group->name}.jpg"; } return "mod/groups/graphics/default{$size}.gif"; }
/** * Sets the opengpg_publickey for users having a public key * * @param ElggObject $item * @return bool */ function elggpg_2012022501($user) { // it is necessary to load the gpg library to make sure gpg path is set. global $MIGRATED; $MIGRATED += 1; if ($MIGRATED % 100 == 0) { error_log(" * elggpg {$user->guid}"); } elgg_load_library('elggpg'); $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey'))); $gnupg = new gnupg(); if (!$user_fp && $user->email) { try { $info = $gnupg->keyinfo($user->email); $fingerprint = $info[0]['subkeys'][0]['fingerprint']; if ($fingerprint) { create_metadata($user->guid, "openpgp_publickey", $fingerprint, 'text', $user->guid, ACCESS_LOGGEDIN); } } catch (Exception $e) { // no encryption key } } return true; }
/** * Create a user account for the admin * * @param array $submissionVars Submitted vars * @param bool $login Login in the admin user? * * @return bool */ protected function createAdminAccount($submissionVars, $login = FALSE) { global $CONFIG; $guid = register_user($submissionVars['username'], $submissionVars['password1'], $submissionVars['displayname'], $submissionVars['email']); if (!$guid) { register_error(elgg_echo('install:admin:cannot_create')); return FALSE; } $user = get_entity($guid); if (!$user) { register_error(elgg_echo('install:error:loadadmin')); return FALSE; } elgg_set_ignore_access(TRUE); if ($user->makeAdmin() == FALSE) { register_error(elgg_echo('install:error:adminaccess')); } else { datalist_set('admin_registered', 1); } elgg_set_ignore_access(FALSE); // add validation data to satisfy user validation plugins create_metadata($guid, 'validated', TRUE, '', 0, ACCESS_PUBLIC); create_metadata($guid, 'validated_method', 'admin_user', '', 0, ACCESS_PUBLIC); if ($login) { if (login($user) == FALSE) { register_error(elgg_echo('install:error:adminlogin')); } } return TRUE; }
// 2. Brief description create_metadata($user->guid, "briefdescription", html_entity_decode(substr($user_profile->briefdescription, 0, 197), ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); // 3. Location create_metadata($user->guid, "location", html_entity_decode($user_profile->region, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); // 4. contactemail create_metadata($user->guid, "email", html_entity_decode($user_profile->email, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); // 5. website create_metadata($user->guid, "website", html_entity_decode($user_profile->profileURL, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); //6. Username create_metadata($user->guid, "username", html_entity_decode($user_profile->displayName, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); //7. Phone create_metadata($user->guid, "phone", html_entity_decode($user_profile->phone, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); //8. Twitter create_metadata($user->guid, "twitter", html_entity_decode($user_profile->twitter, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); //9. Specialties create_metadata($user->guid, "skills", html_entity_decode($user_profile->skills, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1); # }}} update user profile # {{{ user image if ($user_profile->photoURL) { $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE)); $filehandler = new ElggFile(); $filehandler->owner_guid = $user->guid; foreach ($sizes as $size => $dimensions) { $image = get_resized_image_from_existing_file($user_profile->photoURL, $dimensions[0], $dimensions[1], $dimensions[2]); $filehandler->setFilename("profile/{$user->guid}{$size}.jpg"); $filehandler->open('write'); $filehandler->write($image); $filehandler->close(); } $user->icontime = time(); }
/** * This function creates metadata from an associative array of "key => value" pairs. * * To achieve an array for a single key, pass in the same key multiple times with * allow_multiple set to true. This creates an indexed array. It does not support * associative arrays and there is no guarantee on the ordering in the array. * * @param int $entity_guid The entity to attach the metadata to * @param array $name_and_values Associative array - a value can be a string, number, bool * @param string $value_type 'text', 'integer', or '' for automatic detection * @param int $owner_guid GUID of entity that owns the metadata * @param int $access_id Default is ACCESS_PRIVATE * @param bool $allow_multiple Allow multiple values for one key. Default is false * * @return bool */ function create_metadata_from_array($entity_guid, array $name_and_values, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE, $allow_multiple = false) { foreach ($name_and_values as $k => $v) { $result = create_metadata($entity_guid, $k, $v, $value_type, $owner_guid, $access_id, $allow_multiple); if (!$result) { return false; } } return true; }
$datestamp = formatDatestamp($record[$SQL['datestamp']]); $setspec = $record[$SQL['set']]; // debug_var_dump('record', $record); if (isset($record[$SQL['deleted']]) && $record[$SQL['deleted']] === true && ($deletedRecord == 'transient' || $deletedRecord == 'persistent')) { $status_deleted = TRUE; } else { $status_deleted = FALSE; } //debug_var_dump('status_deleted', $status_deleted); if ($args['verb'] == 'ListRecords') { $cur_record = $outputObj->create_record(); $cur_header = $outputObj->create_header($oaiprefix . '-' . $identifier, $datestamp, $setspec, $cur_record); // return the metadata record itself if (!$status_deleted) { debug_var_dump('inc_record', $inc_record); create_metadata($outputObj, $cur_record, $identifier, $setspec, $db); } } else { // for ListIdentifiers, only identifiers will be returned. $cur_header = $outputObj->create_header($oaiprefix . '-' . $identifier, $datestamp, $setspec); } if ($status_deleted) { $cur_header->setAttribute("status", "deleted"); } } // ResumptionToken if (isset($restoken)) { if (isset($expirationdatetime)) { $outputObj->create_resumpToken($restoken, $expirationdatetime, $num_rows, $cursor); } else { $outputObj->create_resumpToken('', null, $num_rows, $deliveredrecords);
<?php /** * give a user the right to modify the translations */ $user_guid = (int) get_input('user'); $role = 'translation_editor'; $user = get_user($user_guid); if (empty($user)) { register_error(elgg_echo('translation_editor:action:make_translation_editor:error')); forward(REFERER); } if (create_metadata($user->getGUID(), $role, true, 'integer', $user->getGUID(), ACCESS_PUBLIC)) { system_message(elgg_echo('translation_editor:action:make_translation_editor:success')); } else { register_error(elgg_echo('translation_editor:action:make_translation_editor:error')); } forward(REFERER);
public function testCreateMetadataInvalidates() { $this->obj1->foo = 1; create_metadata($this->guid1, 'foo', 2, '', elgg_get_logged_in_user_guid(), ACCESS_FRIENDS); $this->assertEqual($this->obj1->foo, 2); }
/** * Disable an entity. * * Disabled entities do not show up in list or elgg_get_entity() * calls, but still exist in the database. * * Entities are disabled by setting disabled = yes in the * entities table. * * You can ignore the disabled field by using {@link access_show_hidden_entities()}. * * @note Use ElggEntity::disable() instead. * * @param int $guid The guid * @param string $reason Optional reason * @param bool $recursive Recursively disable all entities owned or contained by $guid? * * @return bool * @see access_show_hidden_entities() * @link http://docs.elgg.org/Entities * @access private */ function disable_entity($guid, $reason = "", $recursive = true) { global $CONFIG; $guid = (int) $guid; $reason = sanitise_string($reason); if ($entity = get_entity($guid)) { if (elgg_trigger_event('disable', $entity->type, $entity)) { if ($entity->canEdit()) { if ($reason) { create_metadata($guid, 'disable_reason', $reason, '', 0, ACCESS_PUBLIC); } if ($recursive) { // Temporary token overriding access controls // @todo Do this better. static $__RECURSIVE_DELETE_TOKEN; // Make it slightly harder to guess $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid()); $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities\n\t\t\t\t\t\tWHERE container_guid={$guid}\n\t\t\t\t\t\tor owner_guid={$guid}\n\t\t\t\t\t\tor site_guid={$guid}", 'entity_row_to_elggstar'); if ($sub_entities) { foreach ($sub_entities as $e) { $e->disable($reason); } } $__RECURSIVE_DELETE_TOKEN = null; } $entity->disableMetadata(); $entity->disableAnnotations(); // relationships can't be disabled. hope they join to the entities table. //$entity->disableRelationships(); $res = update_data("UPDATE {$CONFIG->dbprefix}entities\n\t\t\t\t\tset enabled='no'\n\t\t\t\t\twhere guid={$guid}"); return $res; } } } return false; }
if (!empty($metadata_value) || $metadata_value === 0) { if (!empty($use_default_access)) { // use create_metadata to listen to ACCESS_DEFAULT if (is_array($metadata_value)) { $i = 0; foreach ($metadata_value as $interval) { $i++; if ($i == 1) { $multiple = false; } else { $multiple = true; } create_metadata($new_user->guid, $metadata_name, $interval, 'text', $new_user->guid, get_default_access($new_user), $multiple); } } else { create_metadata($new_user->guid, $metadata_name, $metadata_value, 'text', $new_user->guid, get_default_access($new_user)); } } else { $new_user->{$metadata_name} = $metadata_value; } } } } system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name))); } else { register_error(elgg_echo("adduser:bad")); } } catch (RegistrationException $r) { register_error($r->getMessage()); } forward(REFERER);
function hj_forum_1361379905() { // set priority metadata on forum categories $subtype = get_subtype_id('object', 'hjforumcategory'); $dbprefix = elgg_get_config('dbprefix'); $query = "SELECT guid, owner_guid\n\t\t\t\tFROM {$dbprefix}entities e\n\t\t\t\tWHERE e.subtype IN ({$subtype})"; $data = get_data($query); foreach ($data as $e) { create_metadata($e->guid, 'priority', 0, '', $e->owner_guid, ACCESS_PUBLIC); } }
/** * Tag a previously created guid with the uuid it was imported on. * * @param int $guid A GUID * @param string $uuid A Unique ID * * @return bool * @deprecated 1.9 */ function add_uuid_to_guid($guid, $uuid) { elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); $guid = (int) $guid; $uuid = sanitise_string($uuid); $result = create_metadata($guid, "import_uuid", $uuid); return (bool) $result; }
/** * Tag a previously created guid with the uuid it was imported on. * * @param int $guid A GUID * @param string $uuid A Unique ID * * @return bool */ function add_uuid_to_guid($guid, $uuid) { $guid = (int) $guid; $uuid = sanitise_string($uuid); $result = create_metadata($guid, "import_uuid", $uuid); return (bool) $result; }
/** * Set the validation status for a user. * * @param bool $status Validated (true) or false * @param string $method Optional method to say how a user was validated * @return bool */ function set_user_validation_status($user_guid, $status, $method = '') { if (!$status) { $method = ''; } if ($status) { if (create_metadata($user_guid, 'validated', $status, '', 0, ACCESS_PUBLIC) && create_metadata($user_guid, 'validated_method', $method, '', 0, ACCESS_PUBLIC)) { return true; } } else { $validated = get_metadata_byname($user_guid, 'validated'); $validated_method = get_metadata_byname($user_guid, 'validated_method'); if ($validated && $validated_method && delete_metadata($validated->id) && delete_metadata($validated_method->id)) { return true; } } return false; }
/** * Override the default entity icon for groups * * @param string $hook * @param string $type * @param string $url * @param array $params * @return string Relative URL */ function groups_set_icon_url($hook, $type, $url, $params) { /* @var ElggGroup $group */ $group = $params['entity']; $size = $params['size']; $icontime = $group->icontime; // handle missing metadata (pre 1.7 installations) if (null === $icontime) { $file = new ElggFile(); $file->owner_guid = $group->owner_guid; $file->setFilename("groups/" . $group->guid . "large.jpg"); $icontime = $file->exists() ? time() : 0; create_metadata($group->guid, 'icontime', $icontime, 'integer', $group->owner_guid, ACCESS_PUBLIC); } if ($icontime) { // return thumbnail return "groupicon/{$group->guid}/{$size}/{$icontime}.jpg"; } return elgg_get_simplecache_url("groups/default{$size}.gif"); }
/** * 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()); } } } }