root/branches/release-27/php/lib/block.mtsubcategories.php @ 1231

Revision 1231, 3.6 kB (checked in by takayama, 23 months ago)

Fixed BugId:65442
* Added restore localvars.

  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2function smarty_block_mtsubcategories($args, $content, &$ctx, &$repeat) {
3    $localvars = array('subCatTokens', 'subCatsSortOrder', 'subCatsSortMethod', '__categories', 'inside_mt_categories', '_subcats_counter', 'entries', 'subCatIsFirst', 'subCatIsLast', 'category','current_archive_type');
4    if (!isset($content)) {
5        $ctx->localize($localvars);
6        $token_fn = $args['token_fn'];
7
8        $blog_id = $ctx->stash('blog_id');
9
10        $class = 'category';
11        if (isset($args['class'])) {
12            $class = $args['class'];
13        }
14
15        # Do we want the current category?
16        $include_current = $args['include_current'];
17
18        $top = $args['top'];
19
20        # Sorting information#   sort_order ::= 'ascend' | 'descend'
21        #   sort_method ::= method name (e.g. package::method)
22        #
23        # sort_method takes precedence
24        $sort_order = $args['sort_order'] or 'ascend';
25        $sort_method = $args['sort_method'];
26
27        # Store the tokens for recursion
28        $ctx->stash('subCatTokens', $token_fn);
29        $ctx->stash('current_archive_type', 'Category');
30
31        # If we find ourselves in a category context
32        if (!$top) {
33            if ($args['category']) {
34                require_once("MTUtil.php");
35                $current_cat = cat_path_to_category($args['category'], $blog_id);
36            }
37            if ($current_cat == NULL) {
38                $current_cat = $ctx->stash('category') or $ctx->stash('archive_category');
39            }
40        }
41        if (!$top && !$args['top_level_categories'] && $current_cat) {
42            if ($include_current) {
43                # If we're to include it, just use it to seed the category list
44                $cats = array($current_cat);
45            } else {
46                # Otherwise, use its children
47                $cats = $ctx->mt->db->fetch_categories(array('blog_id' => $blog_id, 'category_id' => $current_cat['category_id'], 'children' => 1, 'show_empty' => 1, 'sort_order' => $sort_order, 'class' => $class));
48            }
49        }
50        if (($top || $args['top_level_categories']) && !$cats) {
51            # Otherwise, use the top level categories
52            $cats = $ctx->mt->db->fetch_categories(array('blog_id' => $blog_id, 'top_level_categories' => 1, 'show_empty' => 1, 'sort_order' => $sort_order, 'class' => $class));
53        }
54
55        if (!$cats) {
56            $ctx->restore($localvars);
57            $repeat = false;
58            return '';
59        }
60
61        $ctx->stash('__categories', $cats);
62        # Be sure the regular MT tags know we're in a category context
63        $ctx->stash('inside_mt_categories', 1);
64        $ctx->stash('subCatsSortOrder', $sort_order);
65        $ctx->stash('subCatsSortMethod', $sort_method);
66        $ctx->stash('_subcats_counter', 0);
67        $count = 0;
68    } else {
69        # Init variables
70        $cats = $ctx->stash('__categories');
71        $count = $ctx->stash('_subcats_counter');
72    }
73
74    # Loop through the immediate children (or the current cat,
75    # depending on the arguments
76    if ($count < count($cats)) {
77        $category = $cats[$count];
78        $ctx->stash('category', $category);
79        $ctx->stash('entries', null);
80        $ctx->stash('subCatIsFirst', $count == 0);
81        $ctx->stash('subCatIsLast', $count == (count($cats) - 1));
82        $ctx->stash('subFolderHead', $count == 0);
83        $ctx->stash('subFolderFoot', $count == (count($cats) - 1));
84        $ctx->stash('_subcats_counter', $count + 1);
85        $repeat = true;
86    } else {
87        $ctx->restore($localvars);
88        $repeat = false;
89    }
90    return $content;
91}
92?>
Note: See TracBrowser for help on using the browser.