root/branches/release-36/php/lib/block.mtsubcategories.php @ 2100

Revision 2100, 3.7 kB (checked in by fumiakiy, 19 months ago)

Fixed SubCategories behavior when category filter is specified in dynamic publishing. BugId:60763

  • 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 = isset($args['sort_order']) ? $args['sort_order'] : '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                if ( is_array( $current_cat ) )
37                    $current_cat = $current_cat[0];
38            }
39            if ($current_cat == NULL) {
40                $current_cat = $ctx->stash('category') or $ctx->stash('archive_category');
41            }
42        }
43        if (!$top && !$args['top_level_categories'] && $current_cat) {
44            if ($include_current) {
45                # If we're to include it, just use it to seed the category list
46                $cats = array($current_cat);
47            } else {
48                # Otherwise, use its children
49                $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));
50            }
51        }
52        if (($top || $args['top_level_categories']) && !$cats) {
53            # Otherwise, use the top level categories
54            $cats = $ctx->mt->db->fetch_categories(array('blog_id' => $blog_id, 'top_level_categories' => 1, 'show_empty' => 1, 'sort_order' => $sort_order, 'class' => $class));
55        }
56
57        if (!$cats) {
58            $ctx->restore($localvars);
59            $repeat = false;
60            return '';
61        }
62
63        $ctx->stash('__categories', $cats);
64        # Be sure the regular MT tags know we're in a category context
65        $ctx->stash('inside_mt_categories', 1);
66        $ctx->stash('subCatsSortOrder', $sort_order);
67        $ctx->stash('subCatsSortMethod', $sort_method);
68        $ctx->stash('_subcats_counter', 0);
69        $count = 0;
70    } else {
71        # Init variables
72        $cats = $ctx->stash('__categories');
73        $count = $ctx->stash('_subcats_counter');
74    }
75
76    # Loop through the immediate children (or the current cat,
77    # depending on the arguments
78    if ($count < count($cats)) {
79        $category = $cats[$count];
80        $ctx->stash('category', $category);
81        $ctx->stash('entries', null);
82        $ctx->stash('subCatIsFirst', $count == 0);
83        $ctx->stash('subCatIsLast', $count == (count($cats) - 1));
84        $ctx->stash('subFolderHead', $count == 0);
85        $ctx->stash('subFolderFoot', $count == (count($cats) - 1));
86        $ctx->stash('_subcats_counter', $count + 1);
87        $repeat = true;
88    } else {
89        $ctx->restore($localvars);
90        $repeat = false;
91    }
92    return $content;
93}
94?>
Note: See TracBrowser for help on using the browser.