root/branches/athena/php/lib/block.mtarchivelist.php @ 1092

Revision 1092, 3.4 kB (checked in by hachi, 2 years ago)

Merging release-15 to athena branch. svn merge -r59987:60375 http://svn.sixapart.com/repos/eng/movabletype/branches/release-15 .

  • 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');
5    global $_archivers;
6    if (!isset($content)) {
7        require_once("archive_lib.php");
8        $blog = $ctx->stash('blog');
9        $at = $args['type'];
10        $at or $at = $args['archive_type'];
11        $at or $at = $ctx->stash('current_archive_type');
12        if ($at) {  # do nothing if we have an $at
13        } elseif ($blog_at = $blog['blog_archive_type_preferred']) {
14            $at = $blog_at;
15        } elseif (empty($at)) {
16            $types = explode(',', $blog['blog_archive_type']);
17            $at = $types[0];
18        }
19        if (empty($at) || $at == 'None') {
20            $repeat = false;
21            return '';
22        }
23        if (!isset($_archivers[$at]) && $at != 'Category') {
24          $repeat = false;
25          return '';
26        }
27        $ctx->localize($localvars);
28        $ctx->stash('current_archive_type', $at);
29        ## If we are producing a Category archive list, don't bother to
30        ## handle it here--instead hand it over to <MTCategories>.
31        if ($at == 'Category') {
32            require_once("block.mtcategories.php");
33            return smarty_block_mtcategories($args, $content, $ctx, $repeat);
34        }
35        $blog_id = $blog['blog_id'];
36        $args['sort'] = 'created_on';
37        $args['direction'] = 'descend';
38        $args['archive_type'] = $at;
39        $args['blog_id'] = $blog_id;
40
41        $archive_list_results =& $_archivers[$at]->get_archive_list($ctx, $args);
42        $ctx->stash('_archive_list_results', $archive_list_results);
43        # allow <MTEntries> to load them
44        $ctx->stash('entries', null);
45        $ctx->stash('inside_archive_list',true);
46        $i = 0;
47    } else {
48        $at = $ctx->stash('current_archive_type');
49        $archive_list_results = $ctx->stash('_archive_list_results');
50        $i = $ctx->stash('_archive_list_num');
51    }
52
53    if ($at == 'Category') {
54        $content = smarty_block_mtcategories($args, $content, $ctx, $repeat);
55        if (!$repeat)
56            $ctx->restore($localvars);
57        return $content;
58    }
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    } else {
84        $ctx->restore($localvars);
85        $repeat = false;
86    }
87    return $content;
88}
89
90?>
Note: See TracBrowser for help on using the browser.