File: block.mtpagerblock.php

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (53 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$

function smarty_block_mtpagerblock($args, $content, &$ctx, &$repeat) {
    $localvars = array('__out', '__pager_limit', '__pager_count', '__pager_pages', '__first__', '__last__', '__odd__', '__even__', '__value__', '__counter__');

    if (!isset($content)) {
        $ctx->localize($localvars);
        // first invocation; setup loop
        $limit = $ctx->stash('__pager_limit');
        $offset = $ctx->stash('__pager_offset');
        $count = $ctx->stash('__pager_total_count');
        $pages = $limit ? ceil( $count / $limit ) : 1;
        $counter = 1;
        $ctx->stash('__pager_pages', $pages);
        $ctx->stash('__out', false);
    } else {
        $counter = $ctx->__stash['vars']['__counter__'] + 1;
        $limit = $ctx->stash('__pager_limit');
        $offset = $ctx->stash('__pager_offset');
        $count = $ctx->stash('__pager_total_count');
        $pages = $ctx->stash('__pager_pages');
        $out = $ctx->stash('__out');
    }

    if ($counter <= $pages) {
        $ctx->__stash['vars']['__value__'] = $counter;
        $ctx->__stash['vars']['__counter__'] = $counter;
        $ctx->__stash['vars']['__odd__'] = ($counter % 2) == 1;
        $ctx->__stash['vars']['__even__'] = ($counter % 2) == 0;
        $ctx->__stash['vars']['__first__'] = $counter == 1;
        $ctx->__stash['vars']['__last__'] = $counter == $pages;
        if (isset($args['glue']) && !empty($content)) {
            if ($out)
                $content = $args['glue'] . $content;
            else
                $ctx->stash('__out', true);
        }
        $repeat = true;
    } else {
        if (isset($args['glue']) && $out && !empty($content))
            $content = $args['glue'] . $content;
        $ctx->restore($localvars);
        $repeat = false;
    }

    return $content;
}
?>