aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 13:23:25 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 13:23:25 +0000
commit3b384b7374fd44795d3ceb7c434630d1b4695750 (patch)
tree48d5e8dd8f1754646f85858d82db744483135e03
parentd90262f965c85c86d36944ff31754abf850512a7 (diff)
downloadelgg-3b384b7374fd44795d3ceb7c434630d1b4695750.tar.gz
elgg-3b384b7374fd44795d3ceb7c434630d1b4695750.tar.bz2
Added better support for arrays of metadata
git-svn-id: https://code.elgg.org/elgg/trunk@402 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php7
-rw-r--r--engine/lib/metadata.php38
2 files changed, 43 insertions, 2 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index e344968a9..92b658ef2 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -117,8 +117,11 @@
{
$md = get_metadata_byname($this->getGUID(), $name);
- if ($md)
- return $md->value;
+ if ($md && !is_array($md)) {
+ return $md->value;
+ } else if ($md && is_array($md)) {
+ return metadata_array_to_values($md);
+ }
return null;
}
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 92b683789..37a89f09e 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -375,6 +375,44 @@
return $returnvalue;
}
+
+ /**
+ * Takes in a comma-separated string and returns an array of tags which have been trimmed and set to lower case
+ *
+ * @param string $string Comma-separated tag string
+ * @return array|false An array of strings, or false on failure
+ */
+ function string_to_tag_array($string) {
+
+ if (is_string($string)) {
+ $ar = explode(",",$string);
+ array_walk($ar,'trim');
+ array_walk($ar,'strtolower');
+ return $ar;
+ }
+ return false;
+
+ }
+
+ /**
+ * Takes a metadata array (which has all kinds of properties) and turns it into a simple array of strings
+ *
+ * @param array $array Metadata array
+ * @return array Array of strings
+ */
+ function metadata_array_to_values($array) {
+
+ $valuearray = array();
+
+ if (is_array($array)) {
+ foreach($array as $element) {
+ $valuearray[] = $element->value;
+ }
+ }
+
+ return $valuearray;
+
+ }
/** Register the hook */
register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2);