File: block.mtpagerblock.php

package info (click to toggle)
movabletype-opensource 4.2.3-1%2Blenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 21,268 kB
  • ctags: 15,862
  • sloc: perl: 178,892; php: 26,178; sh: 161; makefile: 82
file content (54 lines) | stat: -rw-r--r-- 2,029 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
54
<?php
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: block.mtpagerblock.php 2103 2008-04-25 11:36:53Z fumiakiy $

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;
}
?>