root/branches/release-38/php/lib/function.mtauthoruserpic.php @ 2356

Revision 2356, 1.2 kB (checked in by takayama, 19 months ago)

Fixed BugId:79763
* When author object was not found in the context, try to load author object from entry in the context

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_function_mtauthoruserpic($args, &$ctx) {
9    $author = $ctx->stash('author');
10    if (empty($author)) {
11        $entry = $ctx->stash('entry');
12        if (!empty($entry)) {
13            $author = $ctx->mt->db->fetch_author($entry['entry_author_id']);
14        }
15    }
16    if (empty($author)) {
17        return $ctx->error("No author available");
18    }
19
20    $asset_id = isset($author['author_userpic_asset_id']) ? $author['author_userpic_asset_id'] : 0;
21    $asset = $ctx->mt->db->fetch_assets(array('id' => $asset_id));
22    if (!$asset) return '';
23
24    $blog =& $ctx->stash('blog');
25
26    require_once("MTUtil.php");
27    $userpic_url = userpic_url($asset[0], $blog, $author);
28    $asset_path = asset_path($asset[0]['asset_file_path'], $blog);
29    list($src_w, $src_h, $src_type, $src_attr) = getimagesize($asset_path);
30    $dimensions = sprintf('width="%s" height="%s"', $src_w, $src_h);
31
32    $link =sprintf('<img src="%s" %s alt="%s" />',
33                   encode_html($userpic_url), $dimensions, encode_html($asset['label']));
34
35    return $link;
36}
37?>
Note: See TracBrowser for help on using the browser.