aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/metadata.php93
1 files changed, 48 insertions, 45 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 063188a47..fe83e15d8 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -256,7 +256,7 @@
$id = $existing->id;
delete_metadata($id);
- }
+ }
return $id;
}
@@ -311,7 +311,7 @@
$name = add_metastring($name);
if (!$name) return false;
-
+
// If ok then add it
$result = update_data("UPDATE {$CONFIG->dbprefix}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) {
@@ -355,7 +355,7 @@
$id = (int)$id;
$metadata = get_metadata($id);
-
+
if ($metadata) {
// Tidy up if memcache is enabled.
static $metabyname_memcache;
@@ -364,9 +364,9 @@
if ($metabyname_memcache) $metabyname_memcache->delete("{$metadata->entity_guid}:{$metadata->name_id}");
if (($metadata->canEdit()) && (trigger_elgg_event('delete', 'metadata', $metadata)))
- return delete_data("DELETE from {$CONFIG->dbprefix}metadata where id=$id");
+ return delete_data("DELETE from {$CONFIG->dbprefix}metadata where id=$id");
}
-
+
return false;
}
@@ -513,7 +513,10 @@
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$limit = (int)$limit;
$offset = (int)$offset;
- if ($order_by == "") $order_by = "e.time_created desc";
+ if ($order_by == "")
+ $order_by = "e.time_created desc";
+ else
+ $order_by = "e.time_created {$order_by}";
$order_by = sanitise_string($order_by);
$site_guid = (int) $site_guid;
if ((is_array($owner_guid) && (count($owner_guid)))) {
@@ -604,7 +607,7 @@
* @param int $offset
* @param string $order_by Optional ordering.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
* @param string $meta_array_operator Operator used for joining the metadata array together
* @return int|array List of ElggEntities, or the total number if count is set to false
*/
@@ -619,8 +622,8 @@
$where = array();
$mindex = 1;
- $join = "";
- $metawhere = array();
+ $join = "";
+ $metawhere = array();
$meta_array_operator = sanitise_string($meta_array_operator);
foreach($meta_array as $meta_name => $meta_value) {
$meta_n = get_metastring_id($meta_name);
@@ -629,10 +632,10 @@
/*if ($meta_name!=="")
$where[] = "m{$mindex}.name_id='$meta_n'";
if ($meta_value!=="")
- $where[] = "m{$mindex}.value_id='$meta_v'";*/
+ $where[] = "m{$mindex}.value_id='$meta_v'";*/
$metawhere[] = "(m{$mindex}.name_id='$meta_n' AND m{$mindex}.value_id='$meta_v')";
$mindex++;
- }
+ }
$where[] = "(".implode($meta_array_operator, $metawhere).")";
$entity_type = sanitise_string($entity_type);
@@ -641,12 +644,12 @@
$offset = (int)$offset;
if ($order_by == "") $order_by = "e.time_created desc";
$order_by = sanitise_string($order_by);
- if ((is_array($owner_guid) && (count($owner_guid)))) {
- foreach($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
- }
- } else {
- $owner_guid = (int) $owner_guid;
+ if ((is_array($owner_guid) && (count($owner_guid)))) {
+ foreach($owner_guid as $key => $guid) {
+ $owner_guid[$key] = (int) $guid;
+ }
+ } else {
+ $owner_guid = (int) $owner_guid;
}
$site_guid = (int) $site_guid;
@@ -660,10 +663,10 @@
if ($entity_subtype)
$where[] = "e.subtype = {$entity_subtype}";
if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
- } else if ($owner_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
+ if (is_array($owner_guid)) {
+ $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
+ } else if ($owner_guid > 0)
$where[] = "e.container_guid = {$owner_guid}";
//if ($owner_guid > 0)
// $where[] = "e.container_guid = {$owner_guid}";
@@ -738,29 +741,29 @@
return delete_data("DELETE from {$CONFIG->dbprefix}metadata where entity_guid={$entity_guid}");
}
return false;
- }
-
- /**
- * Clear all annotations belonging to a given owner_guid
- *
- * @param int $owner_guid The owner
- */
- function clear_metadata_by_owner($owner_guid)
- {
- global $CONFIG;
-
- $owner_guid = (int)$owner_guid;
-
- $metas = get_data("SELECT id from {$CONFIG->dbprefix}metadata WHERE owner_guid=$owner_guid");
- $deleted = 0;
-
- foreach ($metas as $id)
- {
- if (delete_metadata($id->id)) // Is this the best way?
- $deleted++;
- }
-
- return $deleted;
+ }
+
+ /**
+ * Clear all annotations belonging to a given owner_guid
+ *
+ * @param int $owner_guid The owner
+ */
+ function clear_metadata_by_owner($owner_guid)
+ {
+ global $CONFIG;
+
+ $owner_guid = (int)$owner_guid;
+
+ $metas = get_data("SELECT id from {$CONFIG->dbprefix}metadata WHERE owner_guid=$owner_guid");
+ $deleted = 0;
+
+ foreach ($metas as $id)
+ {
+ if (delete_metadata($id->id)) // Is this the best way?
+ $deleted++;
+ }
+
+ return $deleted;
}
/**
@@ -799,7 +802,7 @@
if (is_string($string)) {
$ar = explode(",",$string);
- $ar = array_map('trim', $ar); // trim blank spaces
+ $ar = array_map('trim', $ar); // trim blank spaces
$ar = array_map('elgg_strtolower', $ar); // make lower case : [Marcus Povey 20090605 - Using mb wrapper function using UTF8 safe function where available]
$ar = array_filter($ar, 'is_not_null'); // Remove null values
return $ar;