| 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 | |
|---|
| 8 | function 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 | |
|---|
| 22 | function smarty_block_mtparentcategories($args, $content, &$ctx, &$repeat) { |
|---|
| 23 | $localvars = array('_categories', 'category', '_categories_counter','glue', '__out'); |
|---|
| 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 | $ctx->stash('__out', false); |
|---|
| 42 | $counter = 0; |
|---|
| 43 | } else { |
|---|
| 44 | $parents = $ctx->stash('_categories'); |
|---|
| 45 | $counter = $ctx->stash('_categories_counter'); |
|---|
| 46 | $glue = $ctx->stash('glue'); |
|---|
| 47 | $out = $ctx->stash('__out'); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | if ($counter < count($parents)) { |
|---|
| 51 | $ctx->stash('category', $parents[$counter]); |
|---|
| 52 | $ctx->stash('_categories_counter', $counter + 1); |
|---|
| 53 | $repeat = true; |
|---|
| 54 | if (!empty($glue) && !empty($content)) { |
|---|
| 55 | if ($out) |
|---|
| 56 | $content = $glue . $content; |
|---|
| 57 | else |
|---|
| 58 | $ctx->stash('__out', true); |
|---|
| 59 | } |
|---|
| 60 | } else { |
|---|
| 61 | if (!empty($glue) && $out && !empty($content)) |
|---|
| 62 | $content = $glue . $content; |
|---|
| 63 | $repeat = false; |
|---|
| 64 | $glue = ''; |
|---|
| 65 | $ctx->restore($localvars); |
|---|
| 66 | } |
|---|
| 67 | return $content; |
|---|
| 68 | } |
|---|
| 69 | ?> |
|---|