root/branches/release-34/php/lib/block.mtparentcategories.php @ 1800

Revision 1800, 1.9 kB (checked in by takayama, 20 months ago)

Fixed BugId:77293
* Changed to respect a class attribute

  • Property svn:keywords set to Author Date Id Revision
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 get_parent_categories(&$cat, &$ctx, &$list, $class = 'category') {
9    if ($cat['category_parent']) {
10        if ($class == 'folder')
11            $parent = $ctx->mt->db->fetch_folder($cat['category_parent']);
12        else
13            $parent = $ctx->mt->db->fetch_category($cat['category_parent']);
14        if ($parent) {
15            $cat['_parent'] =& $parent;
16            array_unshift($list, 0); $list[0] =& $parent;
17            get_parent_categories($parent, $ctx, $list);
18        }
19    }
20}
21
22function smarty_block_mtparentcategories($args, $content, &$ctx, &$repeat) {
23    $localvars = array('_categories', 'category', '_categories_counter','glue');
24    if (!isset($content)) {
25        $ctx->localize($localvars);
26        require_once("MTUtil.php");
27        $class = isset($args) && isset($args['class']) ? $args['class'] : 'category';
28        $cat = get_category_context($ctx, $class);
29        $parents = array();
30        get_parent_categories($cat, $ctx, $parents, $class);
31        if (!isset($args['exclude_current'])) {
32            $parents[] = $cat;
33        }
34        if (isset($args['glue'])) {
35            $glue = $args['glue'];
36        } else {
37            $glue = '';
38        }
39        $ctx->stash('_categories', $parents);
40        $ctx->stash('glue', $glue);
41        $counter = 0;
42    } else {
43        $parents = $ctx->stash('_categories');
44        $counter = $ctx->stash('_categories_counter');
45        $glue = $ctx->stash('glue');
46    }
47
48    if ($counter < count($parents)) {
49        $ctx->stash('category', $parents[$counter]);
50        $ctx->stash('_categories_counter', $counter + 1);
51        $repeat = true;
52    } else {
53        $repeat = false;
54        $glue = '';
55        $ctx->restore($localvars);
56    }
57    return $content.$glue;
58}
59?>
Note: See TracBrowser for help on using the browser.