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

Revision 1308, 5.3 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
2# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
3# This program is distributed under the terms of the
4# GNU General Public License, version 2.
5#
6# $Id$
7
8function smarty_block_mtentries($args, $content, &$ctx, &$repeat) {
9    $localvars = array('entry', '_entries_counter','entries','current_timestamp','modification_timestamp','_entries_lastn', 'current_timestamp_end', 'DateHeader', 'DateFooter', '_entries_glue', 'blog', 'blog_id', 'conditional', 'else_content');
10    if (isset($args['sort_by']) && $args['sort_by'] == 'score' && !isset($args['namespace'])) {
11        return $ctx->error($ctx->mt->translate('sort_by="score" must be used in combination with namespace.'));
12    }
13    if (!isset($content)) {
14        $ctx->localize($localvars);
15        // If we have a set of entries that were set based on context,
16        // but the user has specified attributes that effectively
17        // break that context, clear the stashed entries so fetch_entries
18        // can reselect.
19        if ($ctx->stash('entries') &&
20            (isset($args['category']) || isset($args['categories']) ||
21             isset($args['tag']) || isset($args['tags']) ||
22             isset($args['id']) ||
23             isset($args['author']) ||
24             isset($args['recently_commented_on']) ||
25             isset($args['include_subcategories']) ||
26             isset($args['days']) ))
27            $ctx->__stash['entries'] = null;
28        $counter = 0;
29        $lastn = $args['lastn'];
30        $ctx->stash('_entries_lastn', $lastn);
31    } else {
32        $lastn = $ctx->stash('_entries_lastn');
33        $counter = $ctx->stash('_entries_counter');
34    }
35    if (!isset($args['class'])) {
36        $args['class'] = 'entry';
37    }
38
39    $entries = $ctx->stash('entries');
40    if (!isset($entries)) {
41        global $_archivers;
42        if (!isset($_archivers)) {
43            require_once('archive_lib.php');
44        }
45        $at = $ctx->stash('current_archive_type');
46        $archiver = $_archivers[$at];
47        $args['blog_id'] = $ctx->stash('blog_id');
48        if (isset($args['id'])) {
49            $args['entry_id'] = $args['id'];
50        }
51        $ts = $ctx->stash('current_timestamp');
52        $tse = $ctx->stash('current_timestamp_end');
53        if ($ts && $tse) {
54            # assign date range if we have both
55            # start and end date
56            $args['current_timestamp'] = $ts;
57            $args['current_timestamp_end'] = $tse;
58        }
59        if (isset($archiver)) {
60            ($args['limit'] || $args['lastn']) or $args['lastn'] = -1;
61            $archiver->setup_args($ctx, $args);
62        }
63        if (($cat = $ctx->stash('category')) && ($args['class'] == 'entry' || $args['class'] == 'page')) {
64            $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
65            if ($ctx->stash('inside_mt_categories')) {
66                $args['category_id'] = $cat['category_id'];
67                $args['show_empty'] = $ctx->stash('show_empty');
68            } else {
69                $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
70            }
71        }
72
73        if ($tag = $ctx->stash('Tag')) {
74            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag;
75        }
76        $entries =& $ctx->mt->db->fetch_entries($args);
77        $ctx->stash('entries', $entries);
78    }
79
80    $ctx->stash('conditional', empty($entries) ? 0 : 1);
81    if (empty($entries)) {
82        $ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
83        if (!$repeat)
84              $ctx->restore($localvars);
85        return $ret;
86    }
87
88    $ctx->stash('_entries_glue', $args['glue']);
89    if (($lastn > count($entries)) || ($lastn == -1)) {
90        $lastn = count($entries);
91        $ctx->stash('_entries_lastn', $lastn);
92    }
93    if ($lastn ? ($counter < $lastn) : ($counter < count($entries))) {
94        $blog_id = $ctx->stash('blog_id');
95        $entry = $entries[$counter];
96        if ($blog_id != $entry['entry_blog_id']) {
97            $blog_id = $entry['entry_blog_id'];
98            $ctx->stash('blog_id', $blog_id);
99            $ctx->stash('blog', $ctx->mt->db->fetch_blog($blog_id));
100        }
101        if ($counter > 0) {
102            $last_entry_created_on = $entries[$counter-1]['entry_authored_on'];
103        } else {
104            $last_entry_created_on = '';
105        }
106        if ($counter < count($entries)-1) {
107            $next_entry_created_on = $entries[$counter+1]['entry_authored_on'];
108        } else {
109            $next_entry_created_on = '';
110        }
111        $ctx->stash('DateHeader', !(substr($entry['entry_authored_on'], 0, 8) == substr($last_entry_created_on, 0, 8)));
112        $ctx->stash('DateFooter', (substr($entry['entry_authored_on'], 0, 8) != substr($next_entry_created_on, 0, 8)));
113        $ctx->stash('entry', $entry);
114        $ctx->stash('current_timestamp', $entry['entry_authored_on']);
115        $ctx->stash('current_timestamp_end', null);
116        $ctx->stash('modification_timestamp', $entry['entry_modified_on']);
117        $ctx->stash('_entries_counter', $counter + 1);
118        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1;
119        $glue = $ctx->stash('_entries_glue');
120        if ($glue != '') $content = $content . $glue;
121        $repeat = true;
122    } else {
123        $ctx->restore($localvars);
124        $repeat = false;
125    }
126    return $content;
127}
128?>
Note: See TracBrowser for help on using the browser.