19 if (!(
$row instanceof stdClass)) {
81 $allow_multiple = (boolean)$allow_multiple;
91 $access_id = (int)$access_id;
93 $query =
"SELECT * from {$CONFIG->dbprefix}metadata" 97 if ($existing && !$allow_multiple) {
98 $id = (int)$existing->id;
122 $query =
"INSERT into {$CONFIG->dbprefix}metadata" 123 .
" (entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id)" 124 .
" VALUES ($entity_guid, '$name_id','$value_id','$value_type', $owner_guid, $time, $access_id)";
164 if (!$md->canEdit()) {
169 static $metabyname_memcache;
171 $metabyname_memcache =
new ElggMemcache(
'metabyname_memcache');
174 if ($metabyname_memcache) {
176 $metabyname_memcache->delete(
"{$md->entity_guid}:{$md->name_id}");
186 $access_id = (int)$access_id;
204 $query =
"UPDATE {$CONFIG->dbprefix}metadata" 205 .
" set name_id='$name_id', value_id='$value_id', value_type='$value_type', access_id=$access_id," 206 .
" owner_guid=$owner_guid where id=$id";
242 foreach ($name_and_values as $k => $v) {
244 $access_id, $allow_multiple);
287 $options[
'metadata_calculation'] =
'count';
291 $options[
'metastring_type'] =
'metadata';
310 $options[
'metastring_type'] =
'metadata';
340 $options[
'metastring_type'] =
'metadata';
357 if (!$options || !is_array($options)) {
363 $options[
'metastring_type'] =
'metadata';
437 'metadata_name_value_pairs_operator' =>
'AND',
438 'metadata_case_sensitive' =>
true,
439 'order_by_metadata' => array(),
446 $singulars = array(
'metadata_name',
'metadata_value',
447 'metadata_name_value_pair',
'metadata_owner_guid');
496 $pairs = null, $pair_operator =
'AND', $case_sensitive =
true, $order_by_metadata = null,
497 $owner_guids = null) {
505 if ((!$names && $names !== 0)
506 && (!$values && $values !== 0)
507 && (!$pairs && $pairs !== 0)
508 && (!$owner_guids && $owner_guids !== 0)
509 && !$order_by_metadata) {
519 $binary = ($case_sensitive) ?
' BINARY ' :
'';
530 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}{$n_table} n_table on 531 {$e_table}.guid = n_table.entity_guid";
537 if ($names !== null) {
538 if (!is_array($names)) {
539 $names = array($names);
542 $sanitised_names = array();
543 foreach ($names as
$name) {
551 if ($names_str = implode(
',', $sanitised_names)) {
552 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msn on n_table.name_id = msn.id";
553 $names_where =
"(msn.string IN ($names_str))";
559 if ($values !== null) {
560 if (!is_array($values)) {
561 $values = array($values);
564 $sanitised_values = array();
565 foreach ($values as
$value) {
573 if ($values_str = implode(
',', $sanitised_values)) {
574 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msv on n_table.value_id = msv.id";
575 $values_where =
"({$binary}msv.string IN ($values_str))";
579 if ($names_where && $values_where) {
580 $wheres[] =
"($names_where AND $values_where AND $access)";
581 } elseif ($names_where) {
582 $wheres[] =
"($names_where AND $access)";
583 } elseif ($values_where) {
584 $wheres[] =
"($values_where AND $access)";
589 if (is_array($pairs)) {
591 if (isset($pairs[
'name']) || isset($pairs[
'value'])) {
592 $pairs = array($pairs);
595 $pair_wheres = array();
600 foreach ($pairs as $index => $pair) {
603 if (!is_array($pair)) {
611 if (!isset($pair[
'name']) || !isset($pair[
'value'])) {
618 if (isset($pair[
'case_sensitive'])) {
619 $pair_binary = ($pair[
'case_sensitive']) ?
' BINARY ' :
'';
621 $pair_binary = $binary;
624 if (isset($pair[
'operand'])) {
631 $trimmed_operand = trim(strtolower($operand));
639 $num_safe_operands = array(
'>',
'<',
'>=',
'<=');
640 $num_test_operand = trim(strtoupper($operand));
642 if (is_numeric($pair[
'value']) && in_array($num_test_operand, $num_safe_operands)) {
644 }
else if (is_bool($pair[
'value'])) {
645 $value = (int) $pair[
'value'];
646 }
else if (is_array($pair[
'value'])) {
647 $values_array = array();
649 foreach ($pair[
'value'] as $pair_value) {
650 if (is_numeric($pair_value) && !in_array($num_test_operand, $num_safe_operands)) {
658 $value =
'(' . implode(
', ', $values_array) .
')';
664 }
else if ($trimmed_operand ==
'in') {
665 $value =
"({$pair['value']})";
673 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}{$n_table} n_table{$i} 674 on {$e_table}.guid = n_table{$i}.entity_guid";
675 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msn{$i} 676 on n_table{$i}.name_id = msn{$i}.id";
677 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msv{$i} 678 on n_table{$i}.value_id = msv{$i}.id";
680 $pair_wheres[] =
"(msn{$i}.string = '$name' AND {$pair_binary}msv{$i}.string 681 $operand $value AND $access)";
686 if ($where = implode(
" $pair_operator ", $pair_wheres)) {
687 $wheres[] =
"($where)";
693 if (is_array($owner_guids)) {
694 $sanitised = array_map(
'sanitise_int', $owner_guids);
695 $owner_str = implode(
',', $sanitised);
700 $wheres[] =
"(n_table.owner_guid IN ($owner_str))";
703 if ($where = implode(
' AND ', $wheres)) {
704 $return[
'wheres'][] =
"($where)";
707 if (is_array($order_by_metadata)) {
708 if ((count($order_by_metadata) > 0) && !isset($order_by_metadata[0])) {
710 $order_by_metadata = array($order_by_metadata);
712 foreach ($order_by_metadata as $order_by) {
713 if (is_array($order_by) && isset($order_by[
'name'])) {
715 if (isset($order_by[
'direction'])) {
720 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}{$n_table} n_table{$i} 721 on {$e_table}.guid = n_table{$i}.entity_guid";
722 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msn{$i} 723 on n_table{$i}.name_id = msn{$i}.id";
724 $return[
'joins'][] =
"JOIN {$CONFIG->dbprefix}metastrings msv{$i} 725 on n_table{$i}.value_id = msv{$i}.id";
729 $return[
'wheres'][] =
"(msn{$i}.string = '$name' AND $access)";
730 if (isset($order_by[
'as']) && $order_by[
'as'] ==
'integer') {
731 $return[
'orders'][] =
"CAST(msv{$i}.string AS SIGNED) $direction";
733 $return[
'orders'][] =
"msv{$i}.string $direction";
752 $valuearray = array();
754 if (is_array($array)) {
755 foreach ($array as $element) {
756 $valuearray[] = $element->value;
776 return $extender->getURL();
792 if (!isset($CONFIG->independents)) {
793 $CONFIG->independents = array();
809 if (empty($CONFIG->independents)) {
813 || !empty($CONFIG->independents[
$type][
'*'])) {
833 $access_id = (int)
$object->access_id;
835 $query =
"update {$db_prefix}metadata set access_id = {$access_id} where entity_guid = {$guid}";
851 if (empty($CONFIG->local_metadata_cache)) {
854 return $CONFIG->local_metadata_cache;
869 if (empty($options[
'guid'])) {
873 if (empty($options[
'metadata_name'])) {
875 $cache->clear($options[
'guid']);
879 $cache->markEmpty($options[
'guid'], $options[
'metadata_name']);
882 $cache->markUnknown($options[
'guid'], $options[
'metadata_name']);
904 $value[] = $CONFIG->path .
'engine/tests/ElggCoreMetadataAPITest.php';
905 $value[] = $CONFIG->path .
'engine/tests/ElggCoreMetadataCacheTest.php';
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
get_data_row($query, $callback="")
Retrieve a single row from the database.
_elgg_is_valid_options_for_batch_operation($options, $type)
Checks if there are some constraints on the options array for potentially dangerous operations...
if($guid==elgg_get_logged_in_user_guid()) $name
$guid
Removes an admin notice.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
update_data($query)
Update a row in the database.
sanitize_string($string)
Sanitize a string for database use.
insert_data($query)
Insert a row into the database.
detect_extender_valuetype($value, $value_type="")
Detect the value_type for a given value.
sanitise_string($string)
Wrapper function for alternate English spelling (.
const ELGG_ENTITIES_ANY_VALUE
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
elgg global
Pointer to the global context.
access_get_show_hidden_status()
Return current status of showing disabled entities.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
sanitise_int($int, $signed=true)
Sanitizes an integer for database use.
is_memcache_available()
Return true if memcache is available and configured.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
if(!$collection_name) $id
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
if(!$num_display) $db_prefix