diff options
-rw-r--r-- | modules/tag/helpers/tag.php | 34 | ||||
-rw-r--r-- | modules/tag/helpers/tag_block.php | 12 | ||||
-rw-r--r-- | modules/tag/views/tag_block.html.php | 19 | ||||
-rw-r--r-- | themes/default/css/screen.css | 15 |
4 files changed, 33 insertions, 47 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> + diff --git a/themes/default/css/screen.css b/themes/default/css/screen.css index 52ad3fd9..492e0929 100644 --- a/themes/default/css/screen.css +++ b/themes/default/css/screen.css @@ -357,43 +357,43 @@ table.gMetadata td.toggle { display: none; } -#gTag ul li.size0 { +#gTag ul li.size1 { color: #9cf; font-size: 80%; font-weight: 100; } -#gTag ul li.size1 { +#gTag ul li.size2 { color: #69f; font-size: 90%; font-weight: 300; } -#gTag ul li.size2 { +#gTag ul li.size3 { color: #69c; font-size: 100%; font-weight: 500; } -#gTag ul li.size3 { +#gTag ul li.size4 { color: #369; font-size: 110%; font-weight: 700; } -#gTag ul li.size4 { +#gTag ul li.size5 { color: #0e2b52; font-size: 120%; font-weight: 900; } -#gTag ul li.size5 { +#gTag ul li.size6 { color: #0e2b52; font-size: 130%; font-weight: 900; } -#gTag ul li.size6 { +#gTag ul li.size7 { color: #0e2b52; font-size: 140%; font-weight: 900; @@ -406,7 +406,6 @@ table.gMetadata td.toggle { #gTag form { margin-top: 10px; -} /* Tags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |