/**
 * Add link to more comments by author
 *
 * @uses	_btc_is_btc_comment()
 *
 * @param	string	$link	Reply link
 * @return	string			Adjusted link
 */
function btc_comment_reply_link($link)
{
    $author_url = get_comment_author_url();
    if (!$author_url || strlen($author_url) <= 7) {
        return $link;
    }
    if ($comment_ID = get_comment_ID()) {
        if ($comment = get_comment($comment_ID)) {
            switch ($comment->comment_agent) {
                case 'btc_' . BTC_SRC_DIGG:
                    $profile_url = $comment->comment_author_url . '/history/comments';
                    break;
                case 'btc_' . BTC_SRC_REDDIT:
                    $profile_url = $comment->comment_author_url . 'comments';
                    break;
                case 'btc_' . BTC_SRC_FRIENDFEED:
                    $profile_url = $comment->comment_author_url . '/comments';
                    break;
                case 'btc_' . BTC_SRC_YC:
                    $profile_url = 'http://news.ycombinator.com/threads?id=' . $comment->comment_author;
                    break;
                case 'btc_' . BTC_SRC_TWITTER:
                    $profile_url = $comment->comment_author_url;
                    break;
                default:
                    $profile_url = substr($author_url, 0, 7) == 'http://' ? 'http://www.backtype.com/url/' . _btc_url_encode($author_url) : '';
                    break;
            }
        }
    }
    if ($profile_url) {
        return ($link == '' ? '' : $link . ' &nbsp; ') . '<a href="' . $profile_url . '">More from author</a>';
    } else {
        return $link;
    }
}
if (($btc_summary = btc_db_get_comment_summary($post->ID)) === false) {
    $btc_summary = btc_db_comment_summary($post->ID);
    btc_db_set_comment_summary($post->ID, $btc_summary);
}
if ($btc_summary) {
    $summary_html = '';
    if ($btc_summary[0]->comment_src == 'blog') {
        array_push($btc_summary, array_shift($btc_summary));
    }
    if ($src = array_shift($btc_summary)) {
        $plural = $src->cnt != 1 ? 's' : '';
        $summary_html .= ' <img src="' . WP_PLUGIN_URL . '/backtype-connect/images/' . $src->comment_src . '-16.gif" alt=""/> <a href="http://www.backtype.com/connect/' . _btc_url_encode(get_permalink($post->ID));
        $summary_html .= $src->comment_src == 'twitter' ? '/tweets" title="' . $src->cnt . ' tweet' . $plural . ' on ' . $src->comment_src . '">' . $src->cnt . ' Tweet' : '?src=' . $src->comment_src . '" title="' . $src->cnt . ' comment' . $plural . ' on ' . ($src->comment_src == 'blog' ? 'other sites' : $src->comment_src) . '">' . $src->cnt . ($src->comment_src == 'blog' ? ' Other' : '') . ' Comment';
        $summary_html .= $plural . '</a>';
    }
    foreach ($btc_summary as $src) {
        $plural = $src->cnt != 1 ? 's' : '';
        $summary_html .= ' <img src="' . WP_PLUGIN_URL . '/backtype-connect/images/' . $src->comment_src . '-16.gif" style="margin-left:1em" alt=""/> <a href="http://www.backtype.com/connect/' . _btc_url_encode(get_permalink($post->ID));
        $summary_html .= $src->comment_src == 'twitter' ? '/tweets" title="' . $src->cnt . ' tweet' . $plural . ' on ' . $src->comment_src . '">' . $src->cnt . ' Tweet' : '?src=' . $src->comment_src . '" title="' . $src->cnt . ' comment' . $plural . ' on ' . ($src->comment_src == 'blog' ? 'other sites' : $src->comment_src) . '">' . $src->cnt . ($src->comment_src == 'blog' ? ' Other' : '') . ' Comment';
        $summary_html .= $plural . '</a>';
    }
    echo '<p class="btc-summary">' . $summary_html . '</p>';
}
if (file_exists(STYLESHEETPATH . $file)) {
    require STYLESHEETPATH . $file;
} elseif (file_exists(TEMPLATEPATH . $file)) {
    require TEMPLATEPATH . '/comments.php';
} else {
    require get_theme_root() . '/default/comments.php';
}
echo '<p class="btc-powered">Additional comments powered by <a href="http://www.backtype.com/search?q=' . get_permalink($post->ID) . '">BackType</a></p>';