root/branches/release-35/php/lib/block.mtfor.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_mtfor($args, $content, &$ctx, &$repeat) {
9    $localvars = array('__for_end', '__for_var', '__out');
10
11    if (!isset($content)) {
12        $ctx->localize($localvars);
13        // first invocation; setup loop
14        $start = array_key_exists('start', $args) ?
15            $args['start']
16            : (array_key_exists('from', $args) ?
17               $args['from']
18               : 0);
19        $end = array_key_exists('end', $args) ? $args['end']
20            : (array_key_exists('to', $args) ? $args['to'] : null);
21        $var = $args['var'];
22
23        if ($end === null) {
24            $content = '';
25            $repeat = false;
26        }
27
28        $index = $start;
29        $counter = 1;
30        $ctx->stash('__for_end', $end);
31        $ctx->stash('__for_var', $var);
32        $ctx->stash('__out', false);
33    } else {
34        $index = $ctx->__stash['vars']['__index__'] + 1;
35        $counter = $ctx->__stash['vars']['__counter__'] + 1;
36        $end = $ctx->stash('__for_end');
37        $var = $ctx->stash('__for_var');
38        $out = $ctx->stash('__out');
39    }
40
41    if ($index <= $end) {
42        $ctx->__stash['vars']['__index__'] = $index;
43        $ctx->__stash['vars']['__counter__'] = $counter;
44        $ctx->__stash['vars']['__odd__'] = ($counter % 2) == 1;
45        $ctx->__stash['vars']['__even__'] = ($counter % 2) == 0;
46        $ctx->__stash['vars']['__first__'] = $counter == 1;
47        $ctx->__stash['vars']['__last__'] = $index == $end;
48        if ($var)
49            $ctx->__stash['vars'][$var] = $index;
50        if (isset($args['glue']) && !empty($content)) {
51            if ($out)
52                $content = $args['glue'] . $content;
53            else
54                $ctx->stash('__out', true);
55        }
56        $repeat = true;
57    } else {
58        if (isset($args['glue']) && $out && !empty($content))
59            $content = $args['glue'] . $content;
60        $ctx->restore($localvars);
61        $repeat = false;
62    }
63
64    return $content;
65}
66?>
Note: See TracBrowser for help on using the browser.