root/branches/release-29/php/lib/block.mtarchivelist.php @ 1308

Revision 1308, 3.4 kB (checked in by bsmith, 22 months ago)

Merging commits from release-28 changesets 1274 to 1306

  • 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');
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    if ($i < count($archive_list_results)) {
60        $grp = $archive_list_results[$i];
61        $_archivers[$at]->prepare_list($ctx, $grp);
62        if ($at == 'Individual') {
63            $cnt = 1;
64        } else {
65            $cnt = array_shift($grp);
66        }
67        if ($at == 'Individual' ) {
68            $entry = $ctx->stash('entry');
69            $start = $end = $entry['entry_authored_on'];
70        } else {
71            list($start, $end) = $_archivers[$at]->get_range($ctx, $grp);
72        }
73        $start = preg_replace('/[^0-9]/', '', $start);
74        $end = preg_replace('/[^0-9]/', '', $end);
75        $ctx->stash('current_timestamp', $start);
76        $ctx->stash('current_timestamp_end', $end);
77        $ctx->stash('archive_count', $cnt);
78        $ctx->stash('_archive_list_num', $i + 1);
79        $ctx->stash('ArchiveListHeader', $i == 0);
80        $ctx->stash('ArchiveListFooter', $i+1 == count($archive_list_results));
81        $repeat = true;
82    } else {
83        $ctx->restore($localvars);
84        $repeat = false;
85    }
86    return $content;
87}
88
89?>
Note: See TracBrowser for help on using the browser.