root/branches/release-35/php/lib/block.mtentries.php @ 1926

Revision 1926, 5.7 kB (checked in by takayama, 20 months ago)

Fixed BugId:76389
* Loop tags does not add 'glue', if row in loop tag was empty

  • MTFor
  • MTLoop
  • MTTags
  • MTEntryTags
  • MTEntries
  • MTEntryCategories
  • MTCategories
  • MTEntryAdditionalCategories
  • MTParentCategories
  • MTAssetTags
  • MTPagerBlock
  • 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', '__out');
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        $ctx->stash('__out', false);
32    } else {
33        $lastn = $ctx->stash('_entries_lastn');
34        $counter = $ctx->stash('_entries_counter');
35        $out = $ctx->stash('__out');
36    }
37    if (!isset($args['class'])) {
38        $args['class'] = 'entry';
39    }
40
41    $entries = $ctx->stash('entries');
42    if (!isset($entries)) {
43        global $_archivers;
44        if (!isset($_archivers)) {
45            require_once('archive_lib.php');
46        }
47        $at = $ctx->stash('current_archive_type');
48        $archiver = $_archivers[$at];
49        $args['blog_id'] = $ctx->stash('blog_id');
50        if (isset($args['id'])) {
51            $args['entry_id'] = $args['id'];
52        }
53        $ts = $ctx->stash('current_timestamp');
54        $tse = $ctx->stash('current_timestamp_end');
55        if ($ts && $tse) {
56            # assign date range if we have both
57            # start and end date
58            $args['current_timestamp'] = $ts;
59            $args['current_timestamp_end'] = $tse;
60        }
61        if (isset($archiver)) {
62            ($args['limit'] || $args['lastn']) or $args['lastn'] = -1;
63            $archiver->setup_args($ctx, $args);
64        }
65        $cat = $ctx->stash('category');
66        if (isset($cat) && (($args['class'] == 'entry' && $cat['category_class'] == 'category') || ($args['class'] == 'page' && $cat['category_class'] == 'folder'))) {
67            $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
68            if ($ctx->stash('inside_mt_categories')) {
69                $args['category_id'] = $cat['category_id'];
70                $args['show_empty'] = $ctx->stash('show_empty');
71            } else {
72                $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
73            }
74        }
75
76        if ($tag = $ctx->stash('Tag')) {
77            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag;
78        }
79        $entries =& $ctx->mt->db->fetch_entries($args);
80        $ctx->stash('entries', $entries);
81    }
82
83    $ctx->stash('conditional', empty($entries) ? 0 : 1);
84    if (empty($entries)) {
85        $ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
86        if (!$repeat)
87              $ctx->restore($localvars);
88        return $ret;
89    }
90
91    $ctx->stash('_entries_glue', $args['glue']);
92    if (($lastn > count($entries)) || ($lastn == -1)) {
93        $lastn = count($entries);
94        $ctx->stash('_entries_lastn', $lastn);
95    }
96    if ($lastn ? ($counter < $lastn) : ($counter < count($entries))) {
97        $blog_id = $ctx->stash('blog_id');
98        $entry = $entries[$counter];
99        if ($blog_id != $entry['entry_blog_id']) {
100            $blog_id = $entry['entry_blog_id'];
101            $ctx->stash('blog_id', $blog_id);
102            $ctx->stash('blog', $ctx->mt->db->fetch_blog($blog_id));
103        }
104        if ($counter > 0) {
105            $last_entry_created_on = $entries[$counter-1]['entry_authored_on'];
106        } else {
107            $last_entry_created_on = '';
108        }
109        if ($counter < count($entries)-1) {
110            $next_entry_created_on = $entries[$counter+1]['entry_authored_on'];
111        } else {
112            $next_entry_created_on = '';
113        }
114        $ctx->stash('DateHeader', !(substr($entry['entry_authored_on'], 0, 8) == substr($last_entry_created_on, 0, 8)));
115        $ctx->stash('DateFooter', (substr($entry['entry_authored_on'], 0, 8) != substr($next_entry_created_on, 0, 8)));
116        $ctx->stash('entry', $entry);
117        $ctx->stash('current_timestamp', $entry['entry_authored_on']);
118        $ctx->stash('current_timestamp_end', null);
119        $ctx->stash('modification_timestamp', $entry['entry_modified_on']);
120        $ctx->stash('_entries_counter', $counter + 1);
121        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1;
122        $glue = $ctx->stash('_entries_glue');
123        if (isset($glue) && !empty($content)) {
124            if ($out)
125                $content = $glue . $content;
126            else
127                $ctx->stash('__out', true);
128        }
129        $repeat = true;
130    } else {
131        $glue = $ctx->stash('_entries_glue');
132        if (isset($glue) && $out && !empty($content))
133            $content = $glue . $content;
134        $ctx->restore($localvars);
135        $repeat = false;
136    }
137    return $content;
138}
139?>
Note: See TracBrowser for help on using the browser.