/** * Unserializes the event object stored in the database * * @param string $serialized Serialized string * @return string */ public function unserialize($serialized) { $data = unserialize($serialized); if (isset($data->action)) { $this->action = $data->action; } if (isset($data->object_id) && isset($data->object_type)) { switch ($data->object_type) { case 'object': case 'user': case 'group': case 'site': $this->object = get_entity($data->object_id); break; case 'annotation': $this->object = elgg_get_annotation_from_id($data->object_id); break; case 'metadata': $this->object = elgg_get_metadata_from_id($data->object_id); break; case 'relationship': $this->object = get_relationship($data->object_id); } } if (isset($data->actor_guid)) { $this->actor = get_entity($data->actor_guid); } }
/** * {@inheritdoc} */ public function get($uid = '') { switch ($uid) { case 'me': $uid = "ue" . elgg_get_logged_in_user_guid(); break; case 'site': $uid = "se" . elgg_get_site_entity()->guid; break; } $abbr = substr($uid, 0, 2); switch ($abbr) { case 'an': $id = (int) substr($uid, 2); $object = elgg_get_annotation_from_id($id); break; case 'md': $id = (int) substr($uid, 2); $object = elgg_get_metadata_from_id($id); break; case 'rl': $id = (int) substr($uid, 2); $object = get_relationship($id); break; case 'rv': $id = (int) substr($uid, 2); $river = elgg_get_river(array('ids' => sanitize_int($id))); $object = $river ? $river[0] : false; break; case 'ue': case 'se': case 'oe': case 'ge': $id = (int) substr($uid, 2); $object = get_entity($id); break; default: $object = get_user_by_username($uid); if (!$object && is_numeric($uid)) { $object = get_entity($uid); } } if (!$this->isExportable($object)) { return false; } return $object; }
/** * Get a specific metadata object. * * @param int $id The id of the metadata being retrieved. * * @return mixed False on failure or ElggMetadata * @deprecated 1.8 Use elgg_get_metadata_from_id() */ function get_metadata($id) { elgg_deprecated_notice('get_metadata() is deprecated by elgg_get_metadata_from_id()', 1.8); return elgg_get_metadata_from_id($id); }
/** * For a given ID, return the object associated with it. * This is used by the river functionality primarily. * This is useful for checking access permissions etc on objects. * * @param int $id Metadata ID * * @return ElggMetadata */ public function getObjectFromID($id) { return elgg_get_metadata_from_id($id); }
/** * Get the URL for this metadata * * By default this links to the export handler in the current view. * * @param int $id Metadata ID * * @return mixed */ function get_metadata_url($id) { $id = (int) $id; if ($extender = elgg_get_metadata_from_id($id)) { return $extender->getURL(); } return false; }
if (!$v) { $msg = "Sorry, '" . $id_or_name . "' does not exist for guid:" . $guid; throw new \InvalidParameterException($msg); } $m = new \ElggMetadata(); $m->value = $v; $m->name = $id_or_name; $m->entity_guid = $guid; $m->time_created = $entity->time_created; $m->time_updated = $entity->time_updated; $m->owner_guid = $entity->owner_guid; $m->id = $id_or_name; $m->type = "attr"; break; case 'metadata': $m = elgg_get_metadata_from_id($id_or_name); break; case 'annotation': $m = elgg_get_annotation_from_id($id_or_name); break; case 'relationship': $r = get_relationship($id_or_name); break; case 'volatile': $m = elgg_trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name)); break; default: $msg = "Sorry, I don't know how to export '" . $type . "'"; throw new \InvalidParameterException($msg); } // Render metadata or relationship
public function test_elgg_metadata_multiple_values() { $u1 = new ElggUser(); $u1->username = rand(); $u1->save(); $u2 = new ElggUser(); $u2->username = rand(); $u2->save(); $obj = new ElggObject(); $obj->owner_guid = $u1->guid; $obj->container_guid = $u1->guid; $obj->access_id = ACCESS_PUBLIC; $obj->save(); $md_values = array('one', 'two', 'three'); // need to fake different logins. // good times without mocking. $original_user = elgg_get_logged_in_user_entity(); $_SESSION['user'] = $u1; elgg_set_ignore_access(false); // add metadata as one user $obj->test = $md_values; // check only these md exists $db_prefix = elgg_get_config('dbprefix'); $q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}"; $data = get_data($q); $this->assertEqual(count($md_values), count($data)); foreach ($data as $md_row) { $md = elgg_get_metadata_from_id($md_row->id); $this->assertTrue(in_array($md->value, $md_values)); $this->assertEqual('test', $md->name); } // add md w/ same name as a different user $_SESSION['user'] = $u2; $md_values2 = array('four', 'five', 'six', 'seven'); $obj->test = $md_values2; $q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}"; $data = get_data($q); $this->assertEqual(count($md_values2), count($data)); foreach ($data as $md_row) { $md = elgg_get_metadata_from_id($md_row->id); $this->assertTrue(in_array($md->value, $md_values2)); $this->assertEqual('test', $md->name); } $_SESSION['user'] = $original_user; $obj->delete(); $u1->delete(); $u2->delete(); }
/** *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; }
} } if (count($images)) { system_message(elgg_echo('gallery:upload:imagesuploaded', array(count($images)))); } if ($failed) { system_message(elgg_echo('gallery:upload:unsupportedtype', array($failed))); } if (count($images_pending)) { system_message(elgg_echo('gallery:upload:pending', array(count($images_pending)))); } $metadata_id = create_metadata($album->guid, "river_{$posted}", serialize($images), '', $album->owner_guid, $album->access_id, true); if (count($images) && !$requires_approval) { elgg_create_river_item(array('view' => 'river/object/hjalbum/update', 'action_type' => 'update', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $album->guid, 'access_id' => $album->access_id, 'posted' => $posted)); } else { $metadata = elgg_get_metadata_from_id($metadata_id); // make sure we have sufficient privileges $ia = elgg_set_ignore_access(true); $metadata->disable(); elgg_set_ignore_access($ia); } if (count($images_pending)) { $to = $album->owner_guid; $from = elgg_get_logged_in_user_guid(); $subject = elgg_echo('gallery:upload:pending', array(count($images_pending))); $album_link = elgg_view('output/url', array('text' => $album->title, 'href' => $album->getURL(), 'is_trusted' => true)); $manage_link = elgg_view('output/url', array('text' => elgg_echo('gallery:manage:album'), 'href' => "gallery/manage/{$album->guid}", 'is_trusted' => true)); $message = elgg_echo('gallery:upload:pending:message', array(count($images_pending), $album_link, $manage_link)); notify_user($to, $from, $subject, $message); } if (elgg_is_xhr()) {
/** * Returns a node from it's uid * * @param string $uid UID of the resource * @return mixed */ public function get($uid = '') { switch ($uid) { case 'me': $uid = "ue" . elgg_get_logged_in_user_guid(); break; case 'site': $uid = "se" . elgg_get_site_entity()->guid; break; } if (substr($uid, 0, 2) == 'an') { $id = (int) substr($uid, 2); $node = elgg_get_annotation_from_id($id); } else { if (substr($uid, 0, 2) == 'md') { $id = (int) substr($uid, 2); $node = elgg_get_metadata_from_id($id); } else { if (substr($uid, 0, 2) == 'rl') { $id = (int) substr($uid, 2); $node = get_relationship($id); } else { if (substr($uid, 0, 2) == 'rv') { $id = (int) substr($uid, 2); $river = elgg_get_river(array('ids' => sanitize_int($id))); $node = $river ? $river[0] : false; } else { if (in_array(substr($uid, 0, 2), array('ue', 'se', 'oe', 'ge'))) { $id = (int) substr($uid, 2); $node = get_entity($id); } else { if (is_numeric($uid)) { $node = get_entity($uid); } else { $node = get_user_by_username($uid); } } } } } } if (!$this->isExportable($node)) { return false; } return $node; }
public function testCanDisableMetadata() { $owner = $this->mocks()->getUser(); _elgg_services()->session->setLoggedInUser($owner); $object = $this->mocks()->getObject(['owner_guid' => $owner->guid]); $id = create_metadata($object->guid, 'foo', 'bar', '', $owner->guid); $metadata = elgg_get_metadata_from_id($id); $this->assertTrue($metadata->disable()); $this->assertEquals('no', $metadata->enabled); $this->assertTrue($metadata->enable()); $this->assertEquals('yes', $metadata->enabled); _elgg_services()->session->removeLoggedInUser(); }
public function prepareTestObjects() { $this->setupServices(); $object = $this->mocks()->getObject(['owner_guid' => $this->actor->guid, 'container_guid' => $this->actor->guid, 'access_id' => ACCESS_LOGGED_IN, 'subtype' => 'test_subtype']); $group = $this->mocks()->getGroup(['owner_guid' => $this->actor->guid, 'container_guid' => $this->actor->guid, 'access_id' => ACCESS_LOGGED_IN]); $user = $this->actor; $metadata_id = create_metadata($object->guid, 'test_metadata_name', 'test_metadata_value', 'text', $this->actor->guid, ACCESS_PUBLIC); $metadata = elgg_get_metadata_from_id($metadata_id); $annotation_id = $object->annotate('test_annotation_name', 'test_annotation_value', 'text', $this->actor->guid, ACCESS_PUBLIC); $annotation = elgg_get_annotation_from_id($annotation_id); add_entity_relationship($object->guid, 'test_relationship', $user->guid); $relationship = check_entity_relationship($object->guid, 'test_relationship', $user->guid); return [$object, $group, $user, $metadata, $annotation, $relationship]; }