root/branches/release-35/php/lib/block.mtassettags.php @ 1926

Revision 1926, 2.1 kB (checked in by takayama, 20 months ago)

Fixed BugId:76389
* Loop tags does not add 'glue', if row in loop tag was empty

  • MTFor
  • MTLoop
  • MTTags
  • MTEntryTags
  • MTEntries
  • MTEntryCategories
  • MTCategories
  • MTEntryAdditionalCategories
  • MTParentCategories
  • MTAssetTags
  • MTPagerBlock
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', '__out');
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        $ctx->stash('__out', false);
35       
36        $counter = 0;
37    } else {
38        $tags = $ctx->stash('_tags');
39        $counter = $ctx->stash('_tags_counter');
40        $out = $ctx->stash('__out');
41    }
42    if ($counter < count($tags)) {
43        $tag = $tags[$counter];
44        $ctx->stash('Tag', $tag);
45        $ctx->stash('_tags_counter', $counter + 1);
46        $repeat = true;
47        if (isset($args['glue']) && !empty($content)) {
48            if ($out)
49                $content = $args['glue'] . $content;
50            else
51                $ctx->stash('__out', true);
52        }
53    } else {
54        if (isset($args['glue']) && $out && !empty($content))
55            $content = $args['glue'] . $content;
56        $ctx->restore($localvars);
57        $repeat = false;
58    }
59    return $content;
60}
61?>
Note: See TracBrowser for help on using the browser.