root/branches/release-36/php/lib/block.mtentries.php @ 2129

Revision 2129, 6.7 kB (checked in by fumiakiy, 19 months ago)

Rewrote the function signature and the call to it in PHP4-friendly way. BugId:79535

  • 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    if ( isset($args['offset']) && ($args['offset'] == 'auto') ) {
42        $l = 0;
43        if ( $args['limit'] ) {
44            if ( $args['limit'] == 'auto' ) {
45                if ( $_REQUEST['limit'] )
46                    $l = $_REQUEST['limit'];
47                else {
48                    $blog_id = intval($ctx->stash('blog_id'));
49                    $blog = $ctx->mt->db->fetch_blog($blog_id);
50                    $l = $blog['blog_entries_on_index'];
51                }
52            }
53            else
54                $l = $args['limit'];
55        }
56        if ( !$l )
57            $l = 20;
58        $ctx->stash('__pager_limit', $l);
59        if ( $_REQUEST['offset'] )
60            $ctx->stash('__pager_offset', $_REQUEST['offset']);
61    }
62
63    $entries = $ctx->stash('entries');
64    if (!isset($entries)) {
65        global $_archivers;
66        if (!isset($_archivers)) {
67            require_once('archive_lib.php');
68        }
69        $at = $ctx->stash('current_archive_type');
70        $archiver = $_archivers[$at];
71        $args['blog_id'] = $ctx->stash('blog_id');
72        if (isset($args['id'])) {
73            $args['entry_id'] = $args['id'];
74        }
75        $ts = $ctx->stash('current_timestamp');
76        $tse = $ctx->stash('current_timestamp_end');
77        if ($ts && $tse) {
78            # assign date range if we have both
79            # start and end date
80            $args['current_timestamp'] = $ts;
81            $args['current_timestamp_end'] = $tse;
82        }
83        if (isset($archiver)) {
84            ($args['limit'] || $args['lastn']) or $args['lastn'] = -1;
85            $archiver->setup_args($ctx, $args);
86        }
87        $cat = $ctx->stash('category');
88        if (isset($cat) && (($args['class'] == 'entry' && $cat['category_class'] == 'category') || ($args['class'] == 'page' && $cat['category_class'] == 'folder'))) {
89            $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
90            if ($ctx->stash('inside_mt_categories')) {
91                $args['category_id'] = $cat['category_id'];
92                $args['show_empty'] = $ctx->stash('show_empty');
93            } else {
94                $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
95            }
96        }
97
98        if ($tag = $ctx->stash('Tag')) {
99            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag;
100        }
101        if ( isset($args['offset']) && ($args['offset'] == 'auto') )
102            $total_count = 0;
103        $entries =& $ctx->mt->db->fetch_entries($args, &$total_count);
104        if ( isset($args['offset']) && ($args['offset'] == 'auto') )
105            $ctx->stash('__pager_total_count', $total_count);
106        $ctx->stash('entries', $entries);
107    }
108
109    $ctx->stash('conditional', empty($entries) ? 0 : 1);
110    if (empty($entries)) {
111        $ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
112        if (!$repeat)
113              $ctx->restore($localvars);
114        return $ret;
115    }
116
117    $ctx->stash('_entries_glue', $args['glue']);
118    if (($lastn > count($entries)) || ($lastn == -1)) {
119        $lastn = count($entries);
120        $ctx->stash('_entries_lastn', $lastn);
121    }
122    if ($lastn ? ($counter < $lastn) : ($counter < count($entries))) {
123        $blog_id = $ctx->stash('blog_id');
124        $entry = $entries[$counter];
125        if ($blog_id != $entry['entry_blog_id']) {
126            $blog_id = $entry['entry_blog_id'];
127            $ctx->stash('blog_id', $blog_id);
128            $ctx->stash('blog', $ctx->mt->db->fetch_blog($blog_id));
129        }
130        if ($counter > 0) {
131            $last_entry_created_on = $entries[$counter-1]['entry_authored_on'];
132        } else {
133            $last_entry_created_on = '';
134        }
135        if ($counter < count($entries)-1) {
136            $next_entry_created_on = $entries[$counter+1]['entry_authored_on'];
137        } else {
138            $next_entry_created_on = '';
139        }
140        $ctx->stash('DateHeader', !(substr($entry['entry_authored_on'], 0, 8) == substr($last_entry_created_on, 0, 8)));
141        $ctx->stash('DateFooter', (substr($entry['entry_authored_on'], 0, 8) != substr($next_entry_created_on, 0, 8)));
142        $ctx->stash('entry', $entry);
143        $ctx->stash('current_timestamp', $entry['entry_authored_on']);
144        $ctx->stash('current_timestamp_end', null);
145        $ctx->stash('modification_timestamp', $entry['entry_modified_on']);
146        $ctx->stash('_entries_counter', $counter + 1);
147        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1;
148        $glue = $ctx->stash('_entries_glue');
149        if (isset($glue) && !empty($content)) {
150            if ($out)
151                $content = $glue . $content;
152            else
153                $ctx->stash('__out', true);
154        }
155        $repeat = true;
156    } else {
157        $glue = $ctx->stash('_entries_glue');
158        if (isset($glue) && $out && !empty($content))
159            $content = $glue . $content;
160        $ctx->restore($localvars);
161        $repeat = false;
162    }
163    return $content;
164}
165?>
Note: See TracBrowser for help on using the browser.