root/branches/release-38/php/lib/block.mtarchivelist.php @ 2294

Revision 2294, 3.7 kB (checked in by takayama, 19 months ago)

Fixed BugId:79692
* Applied patch that provides loop meta variables to more block tags. Thanks Víctor R. Ruiz

  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2require_once "archive_lib.php";
3function smarty_block_mtarchivelist($args, $content, &$ctx, &$repeat) {
4    $localvars = array('current_archive_type', 'current_timestamp', 'current_timestamp_end', 'entries', 'archive_count', '_archive_list_num', '_archive_list_results','entry','ArchiveListHeader', 'ArchiveListFooter', 'inside_archive_list', 'category', 'author');
5    global $_archivers;
6
7    if (!isset($content)) {
8        require_once("archive_lib.php");
9        $blog = $ctx->stash('blog');
10        $at = $args['type'];
11        $at or $at = $args['archive_type'];
12        $at or $at = $ctx->stash('current_archive_type');
13        if ($at) {  # do nothing if we have an $at
14        } elseif ($blog_at = $blog['blog_archive_type_preferred']) {
15            $at = $blog_at;
16        } elseif (empty($at)) {
17            $types = explode(',', $blog['blog_archive_type']);
18            $at = $types[0];
19        }
20        if (empty($at) || $at == 'None') {
21            $repeat = false;
22            return '';
23        }
24        if (!isset($_archivers[$at]) && $at != 'Category') {
25          $repeat = false;
26          return '';
27        }
28        $ctx->localize($localvars);
29        $ctx->stash('current_archive_type', $at);
30        ## If we are producing a Category archive list, don't bother to
31        ## handle it here--instead hand it over to <MTCategories>.
32        if ($at == 'Category') {
33            require_once("block.mtcategories.php");
34            return smarty_block_mtcategories($args, $content, $ctx, $repeat);
35        }
36        $blog_id = $blog['blog_id'];
37        $args['sort'] = 'created_on';
38        $args['direction'] = 'descend';
39        $args['archive_type'] = $at;
40        $args['blog_id'] = $blog_id;
41
42        $archive_list_results =& $_archivers[$at]->get_archive_list($ctx, $args);
43        $ctx->stash('_archive_list_results', $archive_list_results);
44        # allow <MTEntries> to load them
45        $ctx->stash('entries', null);
46        $ctx->stash('inside_archive_list',true);
47        $i = 0;
48    } else {
49        $at = $ctx->stash('current_archive_type');
50        $archive_list_results = $ctx->stash('_archive_list_results');
51        $i = $ctx->stash('_archive_list_num');
52    }
53
54    if ($at == 'Category') {
55        $content = smarty_block_mtcategories($args, $content, $ctx, $repeat);
56        if (!$repeat)
57            $ctx->restore($localvars);
58        return $content;
59    }
60    if ($i < count($archive_list_results)) {
61        $grp = $archive_list_results[$i];
62        $_archivers[$at]->prepare_list($ctx, $grp);
63        if ($at == 'Individual') {
64            $cnt = 1;
65        } else {
66            $cnt = array_shift($grp);
67        }
68        if ($at == 'Individual' ) {
69            $entry = $ctx->stash('entry');
70            $start = $end = $entry['entry_authored_on'];
71        } else {
72            list($start, $end) = $_archivers[$at]->get_range($ctx, $grp);
73        }
74        $start = preg_replace('/[^0-9]/', '', $start);
75        $end = preg_replace('/[^0-9]/', '', $end);
76        $ctx->stash('current_timestamp', $start);
77        $ctx->stash('current_timestamp_end', $end);
78        $ctx->stash('archive_count', $cnt);
79        $ctx->stash('_archive_list_num', $i + 1);
80        $ctx->stash('ArchiveListHeader', $i == 0);
81        $ctx->stash('ArchiveListFooter', $i+1 == count($archive_list_results));
82        $repeat = true;
83        $count = $i + 1;
84        $ctx->__stash['vars']['__counter__'] = $count;
85        $ctx->__stash['vars']['__odd__'] = ($count % 2) == 1;
86        $ctx->__stash['vars']['__even__'] = ($count % 2) == 0;
87        $ctx->__stash['vars']['__first__'] = $count == 1;
88        $ctx->__stash['vars']['__last__'] = ($count == count($archive_list_results));
89    } else {
90        $ctx->restore($localvars);
91        $repeat = false;
92    }
93    return $content;
94}
Note: See TracBrowser for help on using the browser.