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

Revision 1335, 5.4 kB (checked in by takayama, 22 months ago)

Fixed BugId:66853
* Never use category filter when category class was not folder.

  • 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        $cat = $ctx->stash('category');
64        if (isset($cat) && (($args['class'] == 'entry' && $cat['category_class'] == 'category') || ($args['class'] == 'page' && $cat['category_class'] == 'folder'))) {
65            $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
66            if ($ctx->stash('inside_mt_categories')) {
67                $args['category_id'] = $cat['category_id'];
68                $args['show_empty'] = $ctx->stash('show_empty');
69            } else {
70                $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
71            }
72        }
73
74        if ($tag = $ctx->stash('Tag')) {
75            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag;
76        }
77        $entries =& $ctx->mt->db->fetch_entries($args);
78        $ctx->stash('entries', $entries);
79    }
80
81    $ctx->stash('conditional', empty($entries) ? 0 : 1);
82    if (empty($entries)) {
83        $ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
84        if (!$repeat)
85              $ctx->restore($localvars);
86        return $ret;
87    }
88
89    $ctx->stash('_entries_glue', $args['glue']);
90    if (($lastn > count($entries)) || ($lastn == -1)) {
91        $lastn = count($entries);
92        $ctx->stash('_entries_lastn', $lastn);
93    }
94    if ($lastn ? ($counter < $lastn) : ($counter < count($entries))) {
95        $blog_id = $ctx->stash('blog_id');
96        $entry = $entries[$counter];
97        if ($blog_id != $entry['entry_blog_id']) {
98            $blog_id = $entry['entry_blog_id'];
99            $ctx->stash('blog_id', $blog_id);
100            $ctx->stash('blog', $ctx->mt->db->fetch_blog($blog_id));
101        }
102        if ($counter > 0) {
103            $last_entry_created_on = $entries[$counter-1]['entry_authored_on'];
104        } else {
105            $last_entry_created_on = '';
106        }
107        if ($counter < count($entries)-1) {
108            $next_entry_created_on = $entries[$counter+1]['entry_authored_on'];
109        } else {
110            $next_entry_created_on = '';
111        }
112        $ctx->stash('DateHeader', !(substr($entry['entry_authored_on'], 0, 8) == substr($last_entry_created_on, 0, 8)));
113        $ctx->stash('DateFooter', (substr($entry['entry_authored_on'], 0, 8) != substr($next_entry_created_on, 0, 8)));
114        $ctx->stash('entry', $entry);
115        $ctx->stash('current_timestamp', $entry['entry_authored_on']);
116        $ctx->stash('current_timestamp_end', null);
117        $ctx->stash('modification_timestamp', $entry['entry_modified_on']);
118        $ctx->stash('_entries_counter', $counter + 1);
119        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1;
120        $glue = $ctx->stash('_entries_glue');
121        if ($glue != '') $content = $content . $glue;
122        $repeat = true;
123    } else {
124        $ctx->restore($localvars);
125        $repeat = false;
126    }
127    return $content;
128}
129?>
Note: See TracBrowser for help on using the browser.