root/branches/release-38/php/lib/function.mtcommentauthorlink.php @ 2411

Revision 2411, 2.1 kB (checked in by bchoate, 19 months ago)

Fix for CommentAuthorLink tag. BugId:79856

  • 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_function_mtcommentauthorlink($args, &$ctx) {
9    global $mt;
10    $comment = $ctx->stash('comment');
11    $name = $comment['comment_author'];
12    if (!$name && isset($args['default_name'])) {
13        $name = $args['default_name'];
14    }
15    $name or $name = $mt->translate("Anonymous");
16    $email = $comment['comment_email'];
17    $url = $comment['comment_url'];
18    if (isset($args['show_email']))
19        $show_email = $args['show_email'];
20    else
21        $show_email = 0;
22    if (isset($args['show_url']))
23        $show_url = $args['show_url'];
24    else
25        $show_url = 1;
26
27    $cmntr = $ctx->stash('commenter');
28    if (is_array($cmntr))
29        $cmntr = $cmntr[0];
30    if (!isset($cmntr)) {
31        if (isset($comment['comment_commenter_id'])) {
32            $cmntr = $ctx->mt->db->fetch_author($comment['comment_commenter_id']);
33        }
34    }
35
36    if ( $cmntr ) {
37        if ($cmntr['author_url']) {
38            return sprintf('<a title="%s" href="%s">%s</a>', $cmntr['author_url'], $cmntr['author_url'], $name);
39        }
40        return $name;
41    } elseif ($show_url && $url) {
42        require_once "function.mtcgipath.php";
43        $cgi_path = smarty_function_mtcgipath($args, $ctx);
44        $comment_script = $ctx->mt->config('CommentScript');
45        $name = strip_tags($name);
46        $url = strip_tags($url);
47        $url = preg_replace('/>/', '&gt;', $url);
48        if ($comment['comment_id'] && !isset($args['no_redirect'])) {
49            return sprintf('<a title="%s" href="%s%s?__mode=red;id=%d">%s</a>', $url, $cgi_path, $comment_script, $comment['comment_id'], $name);
50        } else {
51            return sprintf('<a title="%s" href="%s">%s</a>', $url, $url, $name);
52        }
53    } elseif ($show_email && $email && is_valid_email($email)) {
54        $email = strip_tags($email);
55        $str = 'mailto:' . $email;
56        if ($args['spam_protect']) {
57            $str = spam_protect($str);
58        }
59        return sprintf('<a href="%s">%s</a>', $str, $name);
60    }
61    return $name;
62}
Note: See TracBrowser for help on using the browser.