root/branches/release-26/php/lib/block.mttags.php @ 1174

Revision 1174, 2.7 kB (checked in by bchoate, 23 months ago)

Updated copyright year for source.

Line 
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
8function 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');
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        $counter = 0;
57    } else {
58        $tags = $ctx->stash('_tags');
59        $counter = $ctx->stash('_tags_counter');
60    }
61
62    if ($counter < count($tags)) {
63        $tag = $tags[$counter];
64        $ctx->stash('Tag', $tag);
65        $ctx->stash('_tags_counter', $counter + 1);
66        $repeat = true;
67        if (($counter > 0) && isset($args['glue'])) {
68            $content = $content . $args['glue'];
69        }
70    } else {
71        $ctx->restore($localvars);
72        $repeat = false;
73    }
74    return $content;
75}
76?>
Note: See TracBrowser for help on using the browser.