1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<?php
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: function.mtcommentauthorlink.php 2630 2008-06-23 10:30:58Z takayama $
function smarty_function_mtcommentauthorlink($args, &$ctx) {
global $mt;
$comment = $ctx->stash('comment');
$name = $comment['comment_author'];
if (!$name && isset($args['default_name']))
$name = $args['default_name'];
$name or $name = $mt->translate("Anonymous");
require_once "MTUtil.php";
$name = encode_html( $name );
$email = $comment['comment_email'];
$url = $comment['comment_url'];
if (isset($args['show_email']))
$show_email = $args['show_email'];
else
$show_email = 0;
if (isset($args['show_url']))
$show_url = $args['show_url'];
else
$show_url = 1;
$target = (isset($args['new_window']) && $args['new_window'])
? ' target="_blank"' : '';
_comment_follow($args, $ctx);
$cmntr = $ctx->stash('commenter');
if (!isset($cmntr) && isset($comment['comment_commenter_id']))
$cmntr = $ctx->mt->db->fetch_author($comment['comment_commenter_id']);
if ( $cmntr ) {
$name = isset($cmntr['author_nickname']) ? encode_html( $cmntr['author_nickname'] ) : $name;
if ($cmntr['author_url'])
return sprintf('<a title="%s" href="%s"%s>%s</a>', encode_html( $cmntr['author_url'] ), encode_html( $cmntr['author_url'] ), $target, $name);
return $name;
} elseif ($show_url && $url) {
require_once "function.mtcgipath.php";
$cgi_path = smarty_function_mtcgipath($args, $ctx);
$comment_script = $ctx->mt->config('CommentScript');
$name = strip_tags($name);
$url = encode_html( strip_tags($url) );
if ($comment['comment_id'] && !isset($args['no_redirect']) && !isset($args['nofollowfy']))
return sprintf('<a title="%s" href="%s%s?__mode=red;id=%d"%s>%s</a>', $url, $cgi_path, $comment_script, $comment['comment_id'], $target, $name);
else
return sprintf('<a title="%s" href="%s"%s>%s</a>', $url, $url, $target, $name);
} elseif ($show_email && $email && is_valid_email($email)) {
$email = encode_html( strip_tags($email) );
$str = 'mailto:' . $email;
if ($args['spam_protect']) {
$str = spam_protect($str);
}
return sprintf('<a href="%s">%s</a>', $str, $name);
}
return $name;
}
function _comment_follow (&$args, $ctx) {
$comment = $ctx->stash('comment');
if (empty($comment))
return;
$blog = $ctx->stash('blog');
if (!empty($blog) && $blog['blog_nofollow_urls']) {
if ($blog['blog_follow_auth_links']) {
$cmntr = $ctx->stash('commenter');
if (!isset($cmntr) && isset($comment['comment_commenter_id'])) {
$cmntr = $ctx->mt->db->fetch_author($comment['comment_commenter_id']);
if (!empty($cmntr))
$ctx->stash('commenter', $cmntr);
}
if (empty($cmntr) || (!empty($cmntr) && !is_trusted($cmntr, $ctx, $blog['blog_id'])))
$args['nofollowfy'] = 1;
} else {
$args['nofollowfy'] = 1;
}
}
}
function is_trusted ($cmntr, $ctx, $blog_id) {
if (empty($cmntr))
return false;
// commenter is superuser?
$perms = $ctx->mt->db->fetch_permission(array('blog_id' => 0, 'id' => $cmntr['author_id']));
if (!empty($perms)) {
$perms = $perms[0];
if (strstr($perms['permission_permissions'], '\'administer\''))
return true;
}
if (intval($ctx->mt->config['singlecommunity']))
$blog_id = 0;
// commenter has permission?
$perms = $ctx->mt->db->fetch_permission(array('blog_id' => $blog_id, 'id' => $cmntr['author_id']));
if (!empty($perms))
return false;
$perms = $perms[0];
if (strstr($perms['permission_restrictions'], "'comment'"))
return false;
elseif (strstr($perms['permission_permissions'], "'comment'") || strstr($perms['permission_permissions'], "'manage_feedback'"))
return true;
else
return false;
}
|