aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-12 22:23:38 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-02-12 22:23:38 +0000
commit9fbed88ef70966dd6075b40bd3a8ed4f609423e8 (patch)
tree95bfbeebc86761b0560bdd99065dde6813f6ced7 /engine
parent2d889a3cc9b92fdb1c000236e8953f9d16fe8840 (diff)
downloadelgg-9fbed88ef70966dd6075b40bd3a8ed4f609423e8.tar.gz
elgg-9fbed88ef70966dd6075b40bd3a8ed4f609423e8.tar.bz2
Closes #1506: Added elgg_register_tag_metadata_name(), elgg_get_registered_tag_metadata_names(), and ElggEntity::getTags(). Search on tags updated to use registered tag names instead of hard-coded 'tags' metadata name.
git-svn-id: http://code.elgg.org/elgg/trunk@3936 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php26
-rw-r--r--engine/lib/tags.php63
2 files changed, 81 insertions, 8 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 930772943..eb98d5949 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1121,6 +1121,32 @@ abstract class ElggEntity implements
return $this->owner_guid;
}
+ /**
+ * Returns tags for this entity using registered tag metadata names.
+ *
+ * @return array
+ */
+ public function getTags() {
+ global $CONFIG;
+
+ $valid_tags = elgg_get_registered_tag_metadata_names();
+ $entity_tags = array();
+
+ foreach ($valid_tags as $tag_name) {
+ if ($tags = $this->$tag_name) {
+ // if a single tag, metadata returns a string.
+ // if multiple tags, metadata returns an array.
+ if (is_array($tags)) {
+ $entity_tags = array_merge($entity_tags, $tags);
+ } else {
+ $entity_tags[] = $tags;
+ }
+ }
+ }
+
+ return $entity_tags;
+ }
+
// ITERATOR INTERFACE //////////////////////////////////////////////////////////////
/*
* This lets an entity's attributes be displayed using foreach as a normal array.
diff --git a/engine/lib/tags.php b/engine/lib/tags.php
index 6f0caf8af..ea8d3ebcc 100644
--- a/engine/lib/tags.php
+++ b/engine/lib/tags.php
@@ -15,7 +15,6 @@
* This is quick and dirty.
*/
function calculate_tag_size($min, $max, $number_of_tags, $buckets = 6) {
-
$delta = (($max - $min) / $buckets);
$thresholds = array();
@@ -90,6 +89,11 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
$threshold = (int) $threshold;
$limit = (int) $limit;
+ $registered_tags = elgg_get_registered_tag_metadata_names();
+ if (!in_array($metadata_name, $registered_tags)) {
+ elgg_deprecated_notice('Tag metadata names must be registered by elgg_register_tag_metadata_name()', 1.7);
+ }
+
if (!empty($metadata_name)) {
$metadata_name = (int) get_metastring_id($metadata_name);
// test if any metadata with that name
@@ -116,8 +120,6 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
$site_guid = $CONFIG->site_id;
}
- //$access = get_access_list();
-
$query = "SELECT msvalue.string as tag, count(msvalue.id) as total ";
$query .= "FROM {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid ";
if ($entity_subtype > 0) {
@@ -154,9 +156,8 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
$query .= " and e.time_created<=$end_ts";
}
- //$userid = get_loggedin_userid();
- //$query .= " and (e.access_id in {$access} or (e.access_id = " . ACCESS_PRIVATE . " and e.owner_guid = {$userid}))";
- $query .= ' and ' . get_access_sql_suffix("e"); // Add access controls
+ // Add access controls
+ $query .= ' and ' . get_access_sql_suffix("e");
$query .= " group by msvalue.string having total > {$threshold} order by total desc limit {$limit} ";
@@ -179,7 +180,53 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
*/
function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1, $start_ts = "", $end_ts = "") {
+
+ if (!in_array($metadata_name, $registered_tags)) {
+ elgg_deprecated_notice('Tag metadata names must be registered by elgg_register_tag_metadata_name()', 1.7);
+ }
+
return elgg_view("output/tagcloud",array('value' => get_tags($threshold, $limit, $metadata_name, $entity_type, $entity_subtype, $owner_guid, $site_guid, $start_ts, $end_ts),
- 'object' => $entity_type,
+ 'object' => $entity_type,
'subtype' => $entity_subtype));
-} \ No newline at end of file
+}
+
+/**
+ * Registers a metadata name as containing tags for an entity.
+ * This is required if you are using a non-standard metadata name
+ * for your tags.
+ *
+ * @since 1.7
+ *
+ * @param string $name
+ * @return TRUE
+ */
+function elgg_register_tag_metadata_name($name) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->registered_tag_metadata_names)) {
+ $CONFIG->registered_tag_metadata_names = array();
+ }
+
+ if (!in_array($name, $CONFIG->registered_tag_metadata_names)) {
+ $CONFIG->registered_tag_metadata_names[] = $name;
+ }
+
+ return TRUE;
+}
+
+/**
+ * Returns an array of valid metadata names for tags.
+ *
+ * @since 1.7
+ *
+ * @return array
+ */
+function elgg_get_registered_tag_metadata_names() {
+ global $CONFIG;
+
+ $names = (isset($CONFIG->registered_tag_metadata_names)) ? $CONFIG->registered_tag_metadata_names : array();
+ return $names;
+}
+
+// register the standard tags metadata name
+elgg_register_tag_metadata_name('tags'); \ No newline at end of file