Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

JoomlaTune Support Forum    JComments component    Bug-reports    Topic: Support BBCodes in RSS
Pages: [1]   Go Down
  Print  
Author Topic: Support BBCodes in RSS  (Read 3708 times)
0 Members and 1 Guest are viewing this topic.
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« on: April 17, 2010, 16:58:46 »

Well, that was easy. I'd forgotten that I'd commented out the rss case in jcomments.class.php when I was working on the appearance.

Took about 30 seconds to fix.

But now that I've started this thread I can maybe save some time and digging by asking another question.

I'd like to have images posted in the feeds displayed inline in the feed. At the moment the image url appears (no img tags come through). I know this is most likely the bbcode formatting created in the comment editor.

Where's the best place to do a preg_replace to strip out the bbcode img tags and replace them with html image tags?

I'd rather stay within jcomments code and not dig into any other modules.

Update: I changed the bbcode img tags to html codes in the database and it has no effect. Which portion of Joomla itself or jcomments handles these?
« Last Edit: April 17, 2010, 17:15:11 by AlanR » Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #1 on: April 18, 2010, 14:25:08 »

Where's the best place to do a preg_replace to strip out the bbcode img tags and replace them with html image tags?
I think more appropriate place for that - /components/com_jcomments/jcomments.rss.php. This file is responsable for RSS generation. You need replace strings like:

Code:
$comment = JCommentsText::cleanText($row->comment);
with processing BBCode. Something like this:
Code: (php)
$bbcode = & JCommentsFactory::getBBCode();
$comment = $bbcode->replace($comment);
But I've never tested this modification so I'm not sure that it is workable.
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #2 on: April 18, 2010, 16:47:02 »

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('/&nbsp;/', ' ', $text);
   $text = preg_replace('/&amp;/', ' ', $text);
   $text = preg_replace('/&quot;/', ' ', $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);
« Last Edit: April 18, 2010, 17:22:36 by AlanR » Logged
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #3 on: April 19, 2010, 06:26:43 »

Here's the Feed Validation Service validated result.

I left small comments in jcomments.rss.php to note where I made additions and commented out lines which I replaced, I think I marked most changes but may have missed one or two. The thing which took longest was digging up the correct references within the Jcomments system.

* Jcomments_rss_changes.zip (14.89 KB - downloaded 224 times.)
Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #4 on: April 19, 2010, 14:20:44 »

It is unclear why replace the UTC at UT as a function toRFC822. It implementation was taken from JDate class and it correctly work in Joomla. In your implementation don't used Joomla's timezone settings...
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #5 on: April 19, 2010, 16:35:49 »

It is unclear why replace the UTC at UT as a function toRFC822. It implementation was taken from JDate class and it correctly work in Joomla. In your implementation don't used Joomla's timezone settings...
That one I learned from experience, I can't remember the sources right now but the php UTC designation is not valid for the RFC format, it must be UT.

I have a post in my RSS feed dev forum about it, I'll go and look for it.

see: http://simbalala.com/devforum

Here's the post: http://simbalala.com/devforum/viewtopic.php?f=5&t=30&p=333&hilit=UTC#p333

Quote
It implementation was taken from JDate class and it correctly work in Joomla. In your implementation don't used Joomla's timezone settings...

I don't calculate the date at all, I'm just using your original $date, your calculations are untouched, all I do is reformat it.

BTW: I noticed after I uploaded the files that urls in the feeds are not clickable, one thing I never checked. I'll fix that later today.
« Last Edit: April 19, 2010, 16:48:41 by AlanR » Logged
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #6 on: April 21, 2010, 16:55:38 »

I like to work in Firefox (Minefield actually) and preview RSS feeds in Minefield before I subscribe to them with my newsreader, Vienna (Mac only). The issue with clickable links in RSS feeds was due to me being logged into the site and previewing the feed in a new tab.

Since I was logged in and my Jcomments pref (Super Administrator) for URL recognition is set to on I was getting the URL recognition link (no <a href="http://****.com" rel="nofollow" target="_blank">, not clickable) in my feeds. Logged out from the site it was fine since unregistered users don't have URL recognition set to on.

My solution for this is to pre-process the BBCode for urls in jcomments.rss.php before the rest of the BBCode translation takes place.

Snip...
Code:
foreach ($rows as $row) {
$comment = JCommentsText::rss_cleanText($row->comment);
// ignore URL recognition settings, makes links clickable in all cases, add http:// in front of links
$comment = preg_replace('#\[url\](http:\/\/)?([^\s<\"\']*?)\[\/url\]#', '<a href="http://\\2" rel="nofollow">\\1\\2</a>', $comment);
$comment = preg_replace('#\[url=([^\s\(\<\"\'\]]*?)\]([^\[]*?)\[\/url\]#iU', '<a href="\\1" rel="nofollow">\\2</a>', $comment);
$comment = $bbcode->replace($comment);
$author = JComments::getCommentAuthorName($row);

You'll notice I also add the http:// back into the link, I like links to have the prefix, people expect them.

That's the \\1 in this snip.

rel="nofollow">\\1\\2</a>

I also made the same small change in jcomments.class.php, (line 1010 in my file) so regular links show the http:// in regular Joomla comments views.

I'm attaching a copy of my revised jcomments.rss.php

* jcomments.rss.php.zip (3.66 KB - downloaded 214 times.)
Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #7 on: April 21, 2010, 20:23:36 »

I've splitted topic into 2 parts and move this topic to "Suggestions, Wishlists & Feature Requests".

In my mind I could add extra parameter to JComments to enable supporting BBCodes in JComments RSS feeds. It could be added in some of minor releases of upcoming JComments version (I can't made this in upcoming version because all language files already freezed).

Thank you, AlanR for your work!
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #8 on: April 21, 2010, 23:24:46 »

In my mind I could add extra parameter to JComments to enable supporting BBCodes in JComments RSS feeds. It could be added in some of minor releases of upcoming JComments version (I can't made this in upcoming version because all language files already freezed).
I originally cloned the JCommentsBBCode class to a new RSS class and used the new class but after thinking about it, I was changing two files instead of one and adding a lot of duplicate lines to jcomments.class.php when I could add two lines (actually only one is needed) to one file - jcomments.rss.php. So I decided to do it this way.
Logged
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #9 on: April 23, 2010, 17:12:34 »

I knew this function...

function feedLastCommentsGlobal()

existed in jcomments.rss.php but I saw no way to call it and still don't so I didn't make any changes to it so as to correct any problems there may be with it.

How did you intend to enable a global feed?
Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #10 on: April 23, 2010, 17:15:31 »

How did you intend to enable a global feed?
JComments Latest module has link to global comments feed (this could be enabled in module parameters).


By default this link looks like: index.php?option=com_jcomments&task=rss_full&tmpl=component

BTW, I think that more correct is create descendant class for JCommentsBBCode and use it in JComments RSS instead basic class. You could override some methods and this will be more correct...
« Last Edit: April 23, 2010, 17:20:51 by smart » Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #11 on: April 23, 2010, 17:39:48 »

So right now the way to get a global feed is to create a link or button to get it, there is no setting in the administration to enable or disable such a link. Correct?

I had already found the link by looking at jcomments.php.
« Last Edit: April 23, 2010, 17:43:11 by AlanR » Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #12 on: April 23, 2010, 17:44:55 »

Link to global feed is displayed in JComments Latest module only.
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #13 on: April 26, 2010, 22:48:45 »

I went ahead and installed “latest” then I finished com_jcomments-rss (mostly, didn't define a class for the url bbcodes yet, they're still handled directly in com_jcomments-rss).

Both the article and global feeds fully validate and I added site and article info to the title.

You don't need “latest” installed to access the global feed, all it does is provide a nice link to the feed. You can link to it using any method you like.

Once again, you can visit http://owensdaniels.com to see the feeds in action.

I attach a zip file with the new version of com_jcomments-rss and a copy of language/en-GB/en-GB.mod_jcomments.ini. The language file is needed because I added two new, small language definitions to account for the new title format. Users can use it as an example to define the terms in their own language.

I decided to upload now because I have other things I need to do and I'm not sure when I'll have the time to handle creating a new class. That could take some time because I need to think about custom BBCodes as well if I'm going to do it.

* com_jcomments-rss.zip (5.32 KB - downloaded 194 times.)
Logged
AlanR
Newbie
*

Karma: 1
Offline Offline

Posts: 19


Email
« Reply #14 on: April 26, 2010, 23:44:00 »

One further note.

You can access the global feed with a shorter url than the one in the standard “latest” file.

the default one is...

Code:
http://yoursite.com/component/jcomments/?task=rss_full&tmpl=component

That's what is in mod_jcomments.php.

The shorter version is...

Code:
http://yoursite.com/component/jcomments/?task=rss_full

which works just as well.

The jcomments.rss.php that I included in the set assumes you are using the longer (standard) link and sets the Atom link to that.

If you want to use the shorter url you'll need to edit line 123 in jcomments.rss.php to set that link as the Atom self reference link, just remove a little at the end of the link.

Keeping both links, the one in mod_jcomments.php and the one in jcomments.rss.php the same ensures that the feed will validate with no cautions.
Logged
Pages: [1]   Go Up
  Print  
JoomlaTune Support Forum    JComments component    Bug-reports    Topic: Support BBCodes in RSS
 
Jump to: