| 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 smarty_block_mtpagerblock($args, $content, &$ctx, &$repeat) { |
|---|
| 9 | $localvars = array('__out', '__pager_limit', '__pager_count', '__pager_pages', '__first__', '__last__', '__odd__', '__even__', '__value__', '__counter__'); |
|---|
| 10 | |
|---|
| 11 | if (!isset($content)) { |
|---|
| 12 | $ctx->localize($localvars); |
|---|
| 13 | // first invocation; setup loop |
|---|
| 14 | $limit = $ctx->stash('__pager_limit'); |
|---|
| 15 | $offset = $ctx->stash('__pager_offset'); |
|---|
| 16 | $count = $ctx->stash('__pager_total_count'); |
|---|
| 17 | $pages = $limit ? ceil( $count / $limit ) : 1; |
|---|
| 18 | $counter = 1; |
|---|
| 19 | $ctx->stash('__pager_pages', $pages); |
|---|
| 20 | $ctx->stash('__out', false); |
|---|
| 21 | } else { |
|---|
| 22 | $counter = $ctx->__stash['vars']['__counter__'] + 1; |
|---|
| 23 | $limit = $ctx->stash('__pager_limit'); |
|---|
| 24 | $offset = $ctx->stash('__pager_offset'); |
|---|
| 25 | $count = $ctx->stash('__pager_total_count'); |
|---|
| 26 | $pages = $ctx->stash('__pager_pages'); |
|---|
| 27 | $out = $ctx->stash('__out'); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | if ($counter <= $pages) { |
|---|
| 31 | $ctx->__stash['vars']['__value__'] = $counter; |
|---|
| 32 | $ctx->__stash['vars']['__counter__'] = $counter; |
|---|
| 33 | $ctx->__stash['vars']['__odd__'] = ($counter % 2) == 1; |
|---|
| 34 | $ctx->__stash['vars']['__even__'] = ($counter % 2) == 0; |
|---|
| 35 | $ctx->__stash['vars']['__first__'] = $counter == 1; |
|---|
| 36 | $ctx->__stash['vars']['__last__'] = $counter == $pages; |
|---|
| 37 | if (isset($args['glue']) && !empty($content)) { |
|---|
| 38 | if ($out) |
|---|
| 39 | $content = $args['glue'] . $content; |
|---|
| 40 | else |
|---|
| 41 | $ctx->stash('__out', true); |
|---|
| 42 | } |
|---|
| 43 | $repeat = true; |
|---|
| 44 | } else { |
|---|
| 45 | if (isset($args['glue']) && $out && !empty($content)) |
|---|
| 46 | $content = $args['glue'] . $content; |
|---|
| 47 | $ctx->restore($localvars); |
|---|
| 48 | $repeat = false; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | return $content; |
|---|
| 52 | } |
|---|
| 53 | ?> |
|---|
| 54 | |
|---|