| 1 | <?php |
|---|
| 2 | # Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd. |
|---|
| 3 | # This program is distributed under the terms of the |
|---|
| 4 | # GNU General Public License, version 2. |
|---|
| 5 | # |
|---|
| 6 | # $Id$ |
|---|
| 7 | |
|---|
| 8 | function smarty_block_mttags($args, $content, &$ctx, &$repeat) { |
|---|
| 9 | $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count', 'all_tag_count', 'include_blogs', 'exclude_blogs', 'blog_ids', '__out'); |
|---|
| 10 | if (!isset($content)) { |
|---|
| 11 | $ctx->localize($localvars); |
|---|
| 12 | $ctx->stash('include_blogs', $args['include_blogs']); |
|---|
| 13 | $ctx->stash('exclude_blogs', $args['exclude_blogs']); |
|---|
| 14 | $ctx->stash('blog_ids', $args['blog_ids']); |
|---|
| 15 | $blog_id = $ctx->stash('blog_id'); |
|---|
| 16 | $args['blog_id'] = $ctx->stash('blog_id'); |
|---|
| 17 | if (isset($args['sort_by'])) { |
|---|
| 18 | $s = $args['sort_by']; |
|---|
| 19 | if (($s == 'rank') || ($s == 'count')) { // Aliased |
|---|
| 20 | $args['sort_by'] = 'count'; |
|---|
| 21 | $args['sort_order'] or $args['sort_order'] = 'descend'; // Inverted default |
|---|
| 22 | } elseif (($s != 'name') && ($s != 'id')) { |
|---|
| 23 | $args['sort_by'] = NULL; |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | $type = 'entry'; |
|---|
| 27 | if (isset($args['type'])) { |
|---|
| 28 | $type = strtolower($args['type']); |
|---|
| 29 | } |
|---|
| 30 | if ('page' == $type) { |
|---|
| 31 | $args['class'] = 'page'; |
|---|
| 32 | $tags = $ctx->mt->db->fetch_entry_tags($args); |
|---|
| 33 | } elseif ('asset' == $type) { |
|---|
| 34 | $tags = $ctx->mt->db->fetch_asset_tags($args); |
|---|
| 35 | } else { |
|---|
| 36 | $args['class'] = 'entry'; |
|---|
| 37 | $tags = $ctx->mt->db->fetch_entry_tags($args); |
|---|
| 38 | } |
|---|
| 39 | $min = 0; $max = 0; |
|---|
| 40 | $all_count = 0; |
|---|
| 41 | if ($tags) { |
|---|
| 42 | foreach ($tags as $tag) { |
|---|
| 43 | $count = $tag['tag_count']; |
|---|
| 44 | if ($count > $max) $max = $count; |
|---|
| 45 | if ($count < $min or $min == 0) $min = $count; |
|---|
| 46 | $all_count += $count; |
|---|
| 47 | } |
|---|
| 48 | if (isset($args['limit'])) { |
|---|
| 49 | $tags = array_slice($tags, 0, $args['limit']); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | $ctx->stash('tag_min_count', $min); |
|---|
| 53 | $ctx->stash('tag_max_count', $max); |
|---|
| 54 | $ctx->stash('all_tag_count', $all_count); |
|---|
| 55 | $ctx->stash('_tags', $tags); |
|---|
| 56 | $ctx->stash('__out', false); |
|---|
| 57 | $counter = 0; |
|---|
| 58 | } else { |
|---|
| 59 | $tags = $ctx->stash('_tags'); |
|---|
| 60 | $counter = $ctx->stash('_tags_counter'); |
|---|
| 61 | $out = $ctx->stash('__out'); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | if ($counter < count($tags)) { |
|---|
| 65 | $tag = $tags[$counter]; |
|---|
| 66 | $ctx->stash('Tag', $tag); |
|---|
| 67 | $ctx->stash('_tags_counter', $counter + 1); |
|---|
| 68 | $repeat = true; |
|---|
| 69 | if (isset($args['glue'])) { |
|---|
| 70 | if ($out && !empty($content)) |
|---|
| 71 | $content = $args['glue'] . $content; |
|---|
| 72 | if (!$out && !empty($content)) |
|---|
| 73 | $ctx->stash('__out', true); |
|---|
| 74 | } |
|---|
| 75 | } else { |
|---|
| 76 | if (isset($args['glue'])) { |
|---|
| 77 | if ($out && !empty($content)) |
|---|
| 78 | $content = $args['glue'] . $content; |
|---|
| 79 | } |
|---|
| 80 | $ctx->restore($localvars); |
|---|
| 81 | $repeat = false; |
|---|
| 82 | } |
|---|
| 83 | return $content; |
|---|
| 84 | } |
|---|
| 85 | ?> |
|---|