summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/tag/helpers/tag.php34
-rw-r--r--modules/tag/helpers/tag_block.php12
-rw-r--r--modules/tag/views/tag_block.html.php19
3 files changed, 26 insertions, 39 deletions
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 8057379b..0ca86dc8 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class tag_Core {
- public static $NUMBER_OF_BUCKETS = 7;
-
/**
* Associate a tag with an item. Create the tag if it doesn't already exist.
*
@@ -51,36 +49,14 @@ class tag_Core {
}
/**
- * Assign a css class to the tags based on frequency of use. This code is based on the code
- * from: http://www.hawkee.com/snippet/1485/
+ * Return the N most popular tags.
*
- * @return array List of tags each entry has the following format:
- * array("id" => "tag_id", "name" => "tag_name", "count" => "frequency",
- * "class" => "bucket")
+ * @return ORM_Iterator of Tag_Model in descending tag count order
*/
- public static function load_buckets() {
- $tag_list = array();
- $tags = ORM::factory("tag")
+ public static function popular_tags($count) {
+ return ORM::factory("tag")
->orderby("count", "DESC")
- ->limit(30)
+ ->limit($count)
->find_all();
- if ($tags->count() > 0) {
- $max_count = $tags[0]->count;
- foreach($tags as $key => $tag) {
- // Set the tag to the current class
- $size = (int)(($tag->count / $max_count) * (self::$NUMBER_OF_BUCKETS - 1));
- $tag_list[$key] = array("id" => $tag->id, "name" => $tag->name, "count" => $tag->count,
- "class" => "$size");
- }
- usort($tag_list, array("tag", "alphasort"));
- }
- return $tag_list;
- }
-
- public static function alphasort($tag1, $tag2) {
- if ($tag1["name"] == $tag2["name"]) {
- return 0;
- }
- return $tag1["name"] < $tag2["name"] ? -1 : 1;
}
}
diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php
index 629008b6..4b74c4d7 100644
--- a/modules/tag/helpers/tag_block.php
+++ b/modules/tag/helpers/tag_block.php
@@ -24,7 +24,17 @@ class tag_block_Core {
$block->id = "gTag";
$block->title = _("Tags");
$block->content = new View("tag_block.html");
- $block->content->tag_list = tag::load_buckets();
+
+ $tags = tag::popular_tags(30)->as_array();
+ $block->content->max_count = $tags[0]->count;
+
+ usort($tags, array("tag_block", "sort_by_name"));
+ $block->content->tags = $tags;
+
return $block;
}
+
+ public static function sort_by_name($tag1, $tag2) {
+ return strcmp($tag1->name, $tag2->name);
+ }
} \ No newline at end of file
diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php
index a949182b..3e45bdba 100644
--- a/modules/tag/views/tag_block.html.php
+++ b/modules/tag/views/tag_block.html.php
@@ -1,17 +1,18 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
<ul>
- <? foreach ($tag_list as $tag): ?>
- <li class="size<?=$tag["class"] ?>">
- <span><?= $tag["count"] ?> photos are tagged with </span>
- <a href="<?=url::site("/tag/{$tag["id"]}") ?>"><?=$tag["name"] ?></a>
- </li>
- <? endforeach; ?>
+ <? foreach ($tags as $tag): ?>
+ <li class="size<?=(int)(($tag->count / $max_count) * 7) ?>">
+ <span><?= $tag->count ?> photos are tagged with </span>
+ <a href="<?=url::site("tag/$tag->id") ?>"><?= $tag->name ?></a>
+ </li>
+ <? endforeach ?>
</ul>
<form id="gAddTag">
- <ul class="gInline">
+ <ul>
<li><input type="text" class="text" value="add new tags..." id="gNewTags" /></li>
- <li class="gNoLabels"><input type="submit" value="add" /></li>
+ <li><input type="submit" value="add" /></li>
</ul>
- <label for="gNewTags" class="gUnderState">(separated by commas)</label>
+ <label for="gNewTags" class="gUnderState"><?= _("(separated by commas)") ?></label>
</form>
+