root/branches/release-26/php/lib/block.mtauthorprevious.php @ 1174

Revision 1174, 1.5 kB (checked in by bchoate, 23 months ago)

Updated copyright year for source.

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_mtauthorprevious($args, $content, &$ctx, &$repeat) {
9    static $_prev_cache = array();
10    if (!isset($content)) {
11        $ctx->localize(array('author', 'conditional', 'else_content'));
12        $author = $ctx->stash('author');
13        if ($author) {
14            $author_id = $author['author_id'];
15            if (isset($_prev_cache[$author_id])) {
16                $prev_author = $_prev_cache[$author_id];
17            } else {
18                $name = $author['author_name'];
19                $blog_id = $ctx->stash('blog_id');
20                $args = array('sort_by' => 'author_name',
21                              'sort_order' => 'descend',
22                              'start_string' => $name,
23                              'lastn' => 1,
24                              'blog_id' => $blog_id,
25                              'need_entry' => 1);
26                list($prev_author) = $ctx->mt->db->fetch_authors($args);
27                if ($prev_author) $_prev_cache[$author_id] = $prev_author;
28            }
29            $ctx->stash('author', $prev_author);
30        }
31        $ctx->stash('conditional', isset($prev_author));
32        $ctx->stash('else_content', null);
33    } else {
34        if (!$ctx->stash('conditional')) {
35            $content = $ctx->stash('else_content');
36        }
37        $ctx->restore(array('author', 'conditional', 'else_content'));
38    }
39    return $content;
40}
41?>
Note: See TracBrowser for help on using the browser.