aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/tags.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
commit7ddd9521b3f3a397da3b0a6b56238d31414eb4be (patch)
tree6eb6a9a51db5fa0f5d3cc2ec6de29b9e258b12a1 /engine/lib/tags.php
parentbd3484417d170e62bc94e9db81d4ad37e8ddee6a (diff)
downloadelgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.gz
elgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.bz2
Standardized code in all of core, not including language files, tests, or core mods.
git-svn-id: http://code.elgg.org/elgg/trunk@7124 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/tags.php')
-rw-r--r--engine/lib/tags.php114
1 files changed, 72 insertions, 42 deletions
diff --git a/engine/lib/tags.php b/engine/lib/tags.php
index e4b59b573..02c8e433c 100644
--- a/engine/lib/tags.php
+++ b/engine/lib/tags.php
@@ -3,25 +3,32 @@
* Elgg tags
* Functions for managing tags and tag clouds.
*
- * @package Elgg
- * @subpackage Core
+ * @package Elgg.Core
+ * @subpackage Tags
*/
/**
* The algorithm working out the size of font based on the number of tags.
* This is quick and dirty.
+ *
+ * @param int $min Min size
+ * @param int $max Max size
+ * @param int $number_of_tags The number of tags
+ * @param int $buckets The number of buckets
+ *
+ * @return int
*/
function calculate_tag_size($min, $max, $number_of_tags, $buckets = 6) {
- $delta = (($max - $min) / $buckets);
+ $delta = (($max - $min) / $buckets);
$thresholds = array();
- for ($n=1; $n <= $buckets; $n++) {
- $thresholds[$n-1] = ($min + $n) * $delta;
+ for ($n = 1; $n <= $buckets; $n++) {
+ $thresholds[$n - 1] = ($min + $n) * $delta;
}
// Correction
- if ($thresholds[$buckets-1]>$max) {
- $thresholds[$buckets-1] = $max;
+ if ($thresholds[$buckets - 1] > $max) {
+ $thresholds[$buckets - 1] = $max;
}
$size = 0;
@@ -37,7 +44,9 @@ function calculate_tag_size($min, $max, $number_of_tags, $buckets = 6) {
/**
* This function generates an array of tags with a weighting.
*
- * @param array $tags The array of tags.
+ * @param array $tags The array of tags.
+ * @param int $buckets The number of buckets
+ *
* @return An associated array of tags with a weighting, this can then be mapped to a display class.
*/
function generate_tag_cloud(array $tags, $buckets = 6) {
@@ -49,11 +58,11 @@ function generate_tag_cloud(array $tags, $buckets = 6) {
foreach ($tags as $tag) {
$cloud[$tag]++;
- if ($cloud[$tag]>$max) {
+ if ($cloud[$tag] > $max) {
$max = $cloud[$tag];
}
- if ($cloud[$tag]<$min) {
+ if ($cloud[$tag] < $min) {
$min = $cloud[$tag];
}
}
@@ -70,7 +79,6 @@ function generate_tag_cloud(array $tags, $buckets = 6) {
*
* Supports similar arguments as elgg_get_entities()
*
- *
* @param array $options Array in format:
*
* threshold => INT minimum tag count
@@ -83,7 +91,8 @@ function generate_tag_cloud(array $tags, $buckets = 6) {
*
* subtypes => NULL|STR entity subtype (SQL: subtype = '$subtype')
*
- * type_subtype_pairs => NULL|ARR (array('type' => 'subtype')) (SQL: type = '$type' AND subtype = '$subtype') pairs
+ * type_subtype_pairs => NULL|ARR (array('type' => 'subtype'))
+ * (SQL: type = '$type' AND subtype = '$subtype') pairs
*
* owner_guids => NULL|INT entity guid
*
@@ -168,7 +177,8 @@ function elgg_get_tags(array $options = array()) {
$tags_in = implode(',', $sanitised_tags);
$wheres[] = "(msn.string IN ($tags_in))";
- $wheres[] = elgg_get_entity_type_subtype_where_sql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']);
+ $wheres[] = elgg_get_entity_type_subtype_where_sql('e', $options['types'],
+ $options['subtypes'], $options['type_subtype_pairs']);
$wheres[] = elgg_get_entity_site_where_sql('e', $options['site_guids']);
$wheres[] = elgg_get_entity_owner_where_sql('e', $options['owner_guids']);
$wheres[] = elgg_get_entity_container_where_sql('e', $options['container_guids']);
@@ -240,19 +250,23 @@ function elgg_get_tags(array $options = array()) {
*
* @deprecated 1.8 Use elgg_get_tags().
*
- * @param int $threshold Get the threshold of minimum number of each tags to bother with (ie only show tags where there are more than $threshold occurances)
- * @param int $limit Number of tags to return
- * @param string $metadata_name Optionally, the name of the field you want to grab for
- * @param string $entity_type Optionally, the entity type ('object' etc)
+ * @param int $threshold Get the threshold of minimum number of each tags to
+ * bother with (ie only show tags where there are more
+ * than $threshold occurances)
+ * @param int $limit Number of tags to return
+ * @param string $metadata_name Optionally, the name of the field you want to grab for
+ * @param string $entity_type Optionally, the entity type ('object' etc)
* @param string $entity_subtype The entity subtype, optionally
- * @param int $owner_guid The GUID of the tags owner, optionally
- * @param int $site_guid Optionally, the site to restrict to (default is the current site)
- * @param int $start_ts Optionally specify a start timestamp for tags used to generate cloud.
- * @param int $ent_ts Optionally specify an end timestamp for tags used to generate cloud.
+ * @param int $owner_guid The GUID of the tags owner, optionally
+ * @param int $site_guid Optionally, the site to restrict to (default is the current site)
+ * @param int $start_ts Optionally specify a start timestamp for tags used to
+ * generate cloud.
+ * @param int $end_ts Optionally specify an end timestamp for tags used to generate cloud
+ *
* @return array|false Array of objects with ->tag and ->total values, or false on failure
*/
-
-function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1, $start_ts = "", $end_ts = "") {
+function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object",
+$entity_subtype = "", $owner_guid = "", $site_guid = -1, $start_ts = "", $end_ts = "") {
elgg_deprecated_notice('get_tags() has been replaced by elgg_get_tags()', 1.8);
@@ -303,7 +317,6 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
/**
* Returns viewable tagcloud
*
- *
* @see elgg_get_tags
*
* @param array $options Any elgg_get_tags() options except:
@@ -324,9 +337,9 @@ function elgg_view_tagcloud(array $options = array()) {
if (isset($options['subtype'])) {
$subtype = $options['subtype'];
}
-
+
$tag_data = elgg_get_tags($options);
- return elgg_view("output/tagcloud",array('value' => $tag_data,
+ return elgg_view("output/tagcloud", array('value' => $tag_data,
'type' => $type,
'subtype' => $subtype));
@@ -337,23 +350,30 @@ function elgg_view_tagcloud(array $options = array()) {
*
* @deprecated 1.8 use elgg_view_tagcloud()
*
- * @param int $threshold Get the threshold of minimum number of each tags to bother with (ie only show tags where there are more than $threshold occurances)
- * @param int $limit Number of tags to return
- * @param string $metadata_name Optionally, the name of the field you want to grab for
- * @param string $entity_type Optionally, the entity type ('object' etc)
+ * @param int $threshold Get the threshold of minimum number of each tags
+ * to bother with (ie only show tags where there are
+ * more than $threshold occurances)
+ * @param int $limit Number of tags to return
+ * @param string $metadata_name Optionally, the name of the field you want to grab for
+ * @param string $entity_type Optionally, the entity type ('object' etc)
* @param string $entity_subtype The entity subtype, optionally
- * @param int $owner_guid The GUID of the tags owner, optionally
- * @param int $site_guid Optionally, the site to restrict to (default is the current site)
- * @param int $start_ts Optionally specify a start timestamp for tags used to generate cloud.
- * @param int $ent_ts Optionally specify an end timestamp for tags used to generate cloud.
+ * @param int $owner_guid The GUID of the tags owner, optionally
+ * @param int $site_guid Optionally, the site to restrict to (default is the current site)
+ * @param int $start_ts Optionally specify a start timestamp for tags used to
+ * generate cloud.
+ * @param int $end_ts Optionally specify an end timestamp for tags used to generate
+ * cloud.
+ *
* @return string The HTML (or other, depending on view type) of the tagcloud.
*/
-
-function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1, $start_ts = "", $end_ts = "") {
+function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object",
+$entity_subtype = "", $owner_guid = "", $site_guid = -1, $start_ts = "", $end_ts = "") {
elgg_deprecated_notice('display_cloud() was deprecated by elgg_view_tagcloud()!', 1.8);
-
- $tags = get_tags($threshold, $limit, $metadata_name, $entity_type, $entity_subtype, $owner_guid, $site_guid, $start_ts, $end_ts);
+
+ $tags = get_tags($threshold, $limit, $metadata_name, $entity_type,
+ $entity_subtype, $owner_guid, $site_guid, $start_ts, $end_ts);
+
return elgg_view('output/tagcloud', array(
'value' => $tags,
'type' => $entity_type,
@@ -366,8 +386,8 @@ function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $ent
* This is required if you are using a non-standard metadata name
* for your tags.
*
+ * @param string $name Tag name
*
- * @param string $name
* @return bool
* @since 1.7.0
*/
@@ -394,7 +414,9 @@ function elgg_register_tag_metadata_name($name) {
function elgg_get_registered_tag_metadata_names() {
global $CONFIG;
- $names = (isset($CONFIG->registered_tag_metadata_names)) ? $CONFIG->registered_tag_metadata_names : array();
+ $names = (isset($CONFIG->registered_tag_metadata_names))
+ ? $CONFIG->registered_tag_metadata_names : array();
+
return $names;
}
@@ -402,15 +424,23 @@ function elgg_get_registered_tag_metadata_names() {
elgg_register_tag_metadata_name('tags');
register_page_handler('tags', 'elgg_tagcloud_page_handler');
+
+/**
+ * Page hander for tags
+ *
+ * @param array $page Page array
+ *
+ * @return void
+ */
function elgg_tagcloud_page_handler($page) {
global $CONFIG;
-
+
switch ($page[0]) {
default:
$title = elgg_view_title(elgg_echo('tags:site_cloud'));
$tags = display_tagcloud(0, 100, 'tags');
$body = elgg_view_layout('one_column_with_sidebar', $title . $tags);
-
+
page_draw(elgg_echo('tags:site_cloud'), $body);
break;
}