root/branches/release-40/php/lib/block.mtarchivelist.php @ 2606

Revision 2606, 3.9 kB (checked in by takayama, 18 months ago)

Fixed BugId:80147
* The archive type without a mapping was disabled.

  • 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        $map = $ctx->mt->db->fetch_templatemap(
29            array('type' => $at, 'blog_id' => $blog['blog_id']));
30        if (empty($map)) {
31            $repeat = false;
32            return '';
33        }
34        $ctx->localize($localvars);
35        $ctx->stash('current_archive_type', $at);
36        ## If we are producing a Category archive list, don't bother to
37        ## handle it here--instead hand it over to <MTCategories>.
38        if ($at == 'Category') {
39            require_once("block.mtcategories.php");
40            return smarty_block_mtcategories($args, $content, $ctx, $repeat);
41        }
42        $blog_id = $blog['blog_id'];
43        $args['sort'] = 'created_on';
44        $args['direction'] = 'descend';
45        $args['archive_type'] = $at;
46        $args['blog_id'] = $blog_id;
47
48        $archive_list_results =& $_archivers[$at]->get_archive_list($ctx, $args);
49        $ctx->stash('_archive_list_results', $archive_list_results);
50        # allow <MTEntries> to load them
51        $ctx->stash('entries', null);
52        $ctx->stash('inside_archive_list',true);
53        $i = 0;
54    } else {
55        $at = $ctx->stash('current_archive_type');
56        $archive_list_results = $ctx->stash('_archive_list_results');
57        $i = $ctx->stash('_archive_list_num');
58    }
59
60    if ($at == 'Category') {
61        $content = smarty_block_mtcategories($args, $content, $ctx, $repeat);
62        if (!$repeat)
63            $ctx->restore($localvars);
64        return $content;
65    }
66    if ($i < count($archive_list_results)) {
67        $grp = $archive_list_results[$i];
68        $_archivers[$at]->prepare_list($ctx, $grp);
69        if ($at == 'Individual') {
70            $cnt = 1;
71        } else {
72            $cnt = array_shift($grp);
73        }
74        if ($at == 'Individual' ) {
75            $entry = $ctx->stash('entry');
76            $start = $end = $entry['entry_authored_on'];
77        } else {
78            list($start, $end) = $_archivers[$at]->get_range($ctx, $grp);
79        }
80        $start = preg_replace('/[^0-9]/', '', $start);
81        $end = preg_replace('/[^0-9]/', '', $end);
82        $ctx->stash('current_timestamp', $start);
83        $ctx->stash('current_timestamp_end', $end);
84        $ctx->stash('archive_count', $cnt);
85        $ctx->stash('_archive_list_num', $i + 1);
86        $ctx->stash('ArchiveListHeader', $i == 0);
87        $ctx->stash('ArchiveListFooter', $i+1 == count($archive_list_results));
88        $repeat = true;
89        $count = $i + 1;
90        $ctx->__stash['vars']['__counter__'] = $count;
91        $ctx->__stash['vars']['__odd__'] = ($count % 2) == 1;
92        $ctx->__stash['vars']['__even__'] = ($count % 2) == 0;
93        $ctx->__stash['vars']['__first__'] = $count == 1;
94        $ctx->__stash['vars']['__last__'] = ($count == count($archive_list_results));
95    } else {
96        $ctx->restore($localvars);
97        $repeat = false;
98    }
99    return $content;
100}
Note: See TracBrowser for help on using the browser.