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

Revision 1174, 1.8 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_mtassettags($args, $content, &$ctx, &$repeat) {
9    $localvars = array('_tags', 'Tag', '_tags_counter', 'tag_min_count', 'tag_max_count','all_tag_count');
10    if (!isset($content)) {
11        $ctx->localize($localvars);
12        require_once("MTUtil.php");
13        $asset = $ctx->stash('asset');
14        $blog_id = $asset['asset_blog_id'];
15        $tags = $ctx->mt->db->fetch_asset_tags(array('blog_id' => $blog_id));
16        if (!is_array($tags)) $tags = array();
17
18        $min = 0; $max = 0;
19        $all_count = 0;
20        $tagnames = '';
21        foreach ($tags as $tag) {
22            $count = $tag['tag_count'];
23            if ($count > $max) $max = $count;
24            if ($count < $min or $min == 0) $min = $count;
25            $all_count += $count;
26        }
27        $ctx->stash('tag_min_count', $min);
28        $ctx->stash('tag_max_count', $max);
29        $ctx->stash('all_tag_count', $all_count);
30
31        $tags = $ctx->mt->db->fetch_asset_tags(array('asset_id' => $asset['asset_id'], 'blog_id' => $blog_id));
32        if (!is_array($tags)) $tags = array();
33        $ctx->stash('_tags', $tags);
34       
35        $counter = 0;
36    } else {
37        $tags = $ctx->stash('_tags');
38        $counter = $ctx->stash('_tags_counter');
39    }
40    if ($counter < count($tags)) {
41        $tag = $tags[$counter];
42        $ctx->stash('Tag', $tag);
43        $ctx->stash('_tags_counter', $counter + 1);
44        $repeat = true;
45        if (($counter > 0) && isset($args['glue'])) {
46            $content = $content . $args['glue'];
47        }
48    } else {
49        $ctx->restore($localvars);
50        $repeat = false;
51    }
52    return $content;
53}
54?>
Note: See TracBrowser for help on using the browser.