~ubuntu-branches/debian/squeeze/movabletype-opensource/squeeze

« back to all changes in this revision

Viewing changes to php/lib/block.mtentries.php

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves
  • Date: 2008-06-13 23:28:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080613232840-ya4jfxv1jgl45a3d
Tags: 4.2~rc2-1
* New upstream release candidate
* Update Standards-Version (no changes)
* Ensure that schema upgrade message is always seen

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# This program is distributed under the terms of the
4
4
# GNU General Public License, version 2.
5
5
#
6
 
# $Id: block.mtentries.php 1301 2008-01-21 10:05:43Z takayama $
 
6
# $Id: block.mtentries.php 2496 2008-06-03 22:02:56Z bchoate $
7
7
 
8
8
function 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');
 
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
10
    if (isset($args['sort_by']) && $args['sort_by'] == 'score' && !isset($args['namespace'])) {
11
11
        return $ctx->error($ctx->mt->translate('sort_by="score" must be used in combination with namespace.'));
12
12
    }
16
16
        // but the user has specified attributes that effectively
17
17
        // break that context, clear the stashed entries so fetch_entries
18
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']) ||
 
19
        $this_tag = strtolower($ctx->this_tag());
 
20
        if (($this_tag == 'mtentries') || ($this_tag == 'mtpages')) {
 
21
            if ($ctx->stash('entries') &&
 
22
                (isset($args['category']) || isset($args['categories']) ||
 
23
                 isset($args['tag']) || isset($args['tags']) ||
 
24
                 isset($args['author']) ))
 
25
                $ctx->__stash['entries'] = null;
 
26
        }
 
27
        if ($ctx->__stash['entries'] &&
 
28
            (isset($args['id']) ||
24
29
             isset($args['recently_commented_on']) ||
25
30
             isset($args['include_subcategories']) ||
26
31
             isset($args['days']) ))
28
33
        $counter = 0;
29
34
        $lastn = $args['lastn'];
30
35
        $ctx->stash('_entries_lastn', $lastn);
 
36
        $ctx->stash('__out', false);
31
37
    } else {
32
38
        $lastn = $ctx->stash('_entries_lastn');
33
39
        $counter = $ctx->stash('_entries_counter');
 
40
        $out = $ctx->stash('__out');
34
41
    }
35
42
    if (!isset($args['class'])) {
36
43
        $args['class'] = 'entry';
37
44
    }
38
45
 
 
46
    if ( isset($args['offset']) && ($args['offset'] == 'auto') ) {
 
47
        $l = 0;
 
48
        if ( $args['limit'] ) {
 
49
            if ( $args['limit'] == 'auto' ) {
 
50
                if ( $_REQUEST['limit'] )
 
51
                    $l = $_REQUEST['limit'];
 
52
                else {
 
53
                    $blog_id = intval($ctx->stash('blog_id'));
 
54
                    $blog = $ctx->mt->db->fetch_blog($blog_id);
 
55
                    $l = $blog['blog_entries_on_index'];
 
56
                }
 
57
            }
 
58
            else
 
59
                $l = $args['limit'];
 
60
        }
 
61
        if ( !$l )
 
62
            $l = 20;
 
63
        $ctx->stash('__pager_limit', $l);
 
64
        if ( $_REQUEST['offset'] )
 
65
            $ctx->stash('__pager_offset', $_REQUEST['offset']);
 
66
    }
 
67
 
39
68
    $entries = $ctx->stash('entries');
40
69
    if (!isset($entries)) {
41
70
        global $_archivers;
60
89
            ($args['limit'] || $args['lastn']) or $args['lastn'] = -1;
61
90
            $archiver->setup_args($ctx, $args);
62
91
        }
63
 
        if (($cat = $ctx->stash('category')) && ($args['class'] == 'entry' || $args['class'] == 'page')) {
 
92
        $cat = $ctx->stash('category');
 
93
        if (isset($cat) && (($args['class'] == 'entry' && $cat['category_class'] == 'category') || ($args['class'] == 'page' && $cat['category_class'] == 'folder'))) {
64
94
            $args['category'] or $args['categories'] or $args['category_id'] = $cat['category_id'];
65
95
            if ($ctx->stash('inside_mt_categories')) {
66
96
                $args['category_id'] = $cat['category_id'];
73
103
        if ($tag = $ctx->stash('Tag')) {
74
104
            $args['tag'] or $args['tags'] or $args['tags'] = is_array($tag) ? $tag['tag_name'] : $tag;
75
105
        }
76
 
        $entries =& $ctx->mt->db->fetch_entries($args);
 
106
        if ( isset($args['offset']) && ($args['offset'] == 'auto') )
 
107
            $total_count = 0;
 
108
        $entries =& $ctx->mt->db->fetch_entries($args, &$total_count);
 
109
        if ( isset($args['offset']) && ($args['offset'] == 'auto') )
 
110
            $ctx->stash('__pager_total_count', $total_count);
77
111
        $ctx->stash('entries', $entries);
78
112
    }
79
113
 
117
151
        $ctx->stash('_entries_counter', $counter + 1);
118
152
        $_REQUEST['entry_ids_published'][$entry['entry_id']] = 1;
119
153
        $glue = $ctx->stash('_entries_glue');
120
 
        if ($glue != '') $content = $content . $glue;
 
154
        if (isset($glue) && !empty($content)) {
 
155
            if ($out)
 
156
                $content = $glue . $content;
 
157
            else
 
158
                $ctx->stash('__out', true);
 
159
        }
 
160
        $count = $counter + 1;
 
161
        $ctx->__stash['vars']['__counter__'] = $count;
 
162
        $ctx->__stash['vars']['__odd__'] = ($count % 2) == 1;
 
163
        $ctx->__stash['vars']['__even__'] = ($count % 2) == 0;
 
164
        $ctx->__stash['vars']['__first__'] = $count == 1;
 
165
        $ctx->__stash['vars']['__last__'] = ($count == count($entries));
121
166
        $repeat = true;
122
167
    } else {
 
168
        $glue = $ctx->stash('_entries_glue');
 
169
        if (isset($glue) && $out && !empty($content))
 
170
            $content = $glue . $content;
123
171
        $ctx->restore($localvars);
124
172
        $repeat = false;
125
173
    }
126
174
    return $content;
127
175
}
128
 
?>