/**
 * syndication_comments_feed_link: Escape XML special characters in comments
 * feed links 
 *
 * @param string $link
 * @return string
 *
 * @uses is_syndicated()
 * @uses FeedWordPress::munge_permalinks()
 */
function syndication_comments_feed_link($link)
{
    global $feedwordpress_the_original_permalink, $id;
    if (is_syndicated() and FeedWordPress::munge_permalinks()) {
        // If the source post provided a comment feed URL using
        // wfw:commentRss or atom:link/@rel="replies" we can make use of
        // that value here.
        $source = get_syndication_feed_object();
        $replacement = NULL;
        if ($source->setting('munge comments feed links', 'munge_comments_feed_links', 'yes') != 'no') {
            $commentFeeds = get_post_custom_values('wfw:commentRSS');
            if (is_array($commentFeeds) and count($commentFeeds) > 0 and strlen($commentFeeds[0]) > 0) {
                $replacement = $commentFeeds[0];
                // This is a foreign link; WordPress can't vouch for its not
                // having any entities that need to be &-escaped. So we'll do it
                // here.
                $replacement = esc_html($replacement);
            }
        }
        if (is_null($replacement)) {
            // Q: How can we get the proper feed format, since the
            // format is, stupidly, not passed to the filter?
            // A: Kludge kludge kludge kludge!
            $fancy_permalinks = '' != get_option('permalink_structure');
            if ($fancy_permalinks) {
                preg_match('|/feed(/([^/]+))?/?$|', $link, $ref);
                $format = isset($ref[2]) ? $ref[2] : '';
                if (strlen($format) == 0) {
                    $format = get_default_feed();
                }
                $replacement = trailingslashit($feedwordpress_the_original_permalink) . 'feed';
                if ($format != get_default_feed()) {
                    $replacement .= '/' . $format;
                }
                $replacement = user_trailingslashit($replacement, 'single_feed');
            } else {
                // No fancy permalinks = no problem
                // WordPress doesn't call get_permalink() to
                // generate the comment feed URL, so the
                // comments feed link is never munged by FWP.
            }
        }
        if (!is_null($replacement)) {
            $link = $replacement;
        }
    }
    return $link;
}