I've developed rss feed systems before and it was pretty clear that we could not simply discard the BBCode formatting, we need html formatting for the feed.
I had already made these changes:
jcomments.rss.php
From:
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$comment = JCommentsText::cleanText($row->comment);
$author = JComments::getCommentAuthorName($row);
To:
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$bbcode = & JCommentsFactory::getBBCode();
foreach ($rows as $row) {
$comment = JCommentsText::rss_cleanText($row->comment);
$comment = $bbcode->replace($comment);
$author = JComments::getCommentAuthorName($row);
The rss_cleanText function is a weakened clone of the cleanText function. I'm not sure it's required at all since you sanitize the comment before it's stored in the db but it can't hurt. I may weaken it further if I'm not happy with the feeds.
jcomments.class.php
/**
* Cleans text of some formatting and all scripting code for rss output
*/
function rss_cleanText( $text )
{
$bbcode = & JCommentsFactory::getBBCode();
$config = & JCommentsFactory::getConfig();
if ($config->getInt('enable_custom_bbcode')) {
$customBBCode = & JCommentsFactory::getCustomBBCode();
$text = $customBBCode->filter($text, true);
}
$text = preg_replace('/(\s){2,}/i', '\\1', $text);
$text = preg_replace("'<script[^>]*>.*?</script>'si" . JCOMMENTS_PCRE_UTF8, '', $text);
$text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is' . JCOMMENTS_PCRE_UTF8, '\2 (\1)', $text);
$text = preg_replace('/<!--.+?-->/' . JCOMMENTS_PCRE_UTF8, '', $text);
$text = preg_replace('/{.+?}/', '', $text);
$text = preg_replace('/ /', ' ', $text);
$text = preg_replace('/&/', ' ', $text);
$text = preg_replace('/"/', ' ', $text);
return $text;
}
It's working well now but I don't have it fully validating with
http://validator.w3.org/feed/check.cgi yet, I'm working on that now.
I'll post back with my changes.
Update:
In this case I'm not interested in custom BBCodes, I don't want youtube or other things like that for this site.
If someone does they may want to remove these lines from the rss_cleanText function...
if ($config->getInt('enable_custom_bbcode')) {
$customBBCode = & JCommentsFactory::getCustomBBCode();
$text = $customBBCode->filter($text, true);