Add individual RSS feeds for articles in sNews 1.7

Comments (13)

Today I was tinkering around with sNews and snooping through my EN.php language file, and to my surprise I noticed an unused language variable.

It appears as though at some point that was a plan to add RSS feeds for individual articles. This is a great idea in my opinion, so I decided tyo try and make it happen, without requiring too much hacking. This is the unused variable in EN.php here;


$l['rss_comments_article'] = 'RSS Comments for this article';

I was thinking about enabling this feature quite some time ago, and obviously someone else had the idea to add individual RSS feeds for each article before I did, so I figured it was time to code it in and make it available. I think this feature would be a great value to people wanting to track an article's comments to see if there has been a reply to a question or to just stay updated on bugs &/or changes.

I have made this as dead simple of a mod as I can, so backup your snews.php and work on a copy.

STEP 1) find function rss_contents, and add the following highlighted code, there are 2 small pieces, add them both;

    header('Content-type: text/xml; charset='.s('charset').'');
    $limit = s('rss_limit');
    $url = cleanXSS($_SERVER['REQUEST_URI']);
    $start = strpos($url,'?')+1;
    $aid = substr($url,$start);
    $aid = str_replace("/", '',$aid); 
    if (ctype_digit($aid)) {
        $extra_sql = "articleid = '".$aid."' AND ";
    }
    switch($rss_item) {
        case 'rss-articles':
            $heading = l('articles');
            $query = _PRE.'articles'.' WHERE position = 1 AND visible = \'YES\' AND published = 1 ORDER BY date';
            break;
        case 'rss-pages':
            $heading = l('pages');
            $query = _PRE.'articles'.' WHERE position = 3 AND visible = \'YES\' AND published = 1 ORDER BY date';
            break;
        case 'rss-comments':
            $heading = l('comments');
            $query = _PRE.'comments'." WHERE ".$extra_sql." approved = 'True' ORDER BY id";
            break;
    }

STEP 2) Now find the comment form in the function comment, and add the following highlighted code;

$art_value = empty($articleSEF) ? $subcatSEF : $articleSEF;
echo '<div class="commentsrss"><a href="'._SITE.'rss-comments?'.$_ID.'">'.l('rss_comments_article').'</a></div>'."\r\n";
echo '<br /><div class="commentsbox"><h2>'.l('addcomment').'</h2>'."\r\n";

STEP 3) Now style the commentsrss class however you like, this is basically what I use, feel free to copy;

.commentsrss {
clear: both;
padding: 4px 36px 0 0; 
margin-bottom: 4px; 
height: 32px;
color: #000; 
vertical-align: middle;
text-align: right;
}
.commentsrss a {
font-variant: small-caps;
font-size: 1.2em;
color: #000;
text-decoration: none;
}

That's it, upload snews.php and you should have a link above each comment form that will allow your users to subscribe to the individual articles.

An example? Just look down, I'm using it on my own site here.

bookmark / share this: Bookmark and Share
rated 3.75/5 (4 votes)


13 comments

Add a new comment »

Matt Matt said:
Nov 10th, 2009 at 12:20 pm

Adding a test comment to this article so you can see the individual article's RSS comments feed.


slemborg slemborg said:
Nov 11th, 2009 at 1:48 am

First of, it's been awhile since i've done any modding to my site, and then I find this, really nifty mod, gonna test it latet on today, thanks alot Matt


Sven - Philippe Sven - Philippe said:
Nov 11th, 2009 at 3:23 am

Good shot Matt! You got 1 more star.


slemborg slemborg said:
Nov 13th, 2009 at 4:37 am

Tested it now, and it's working nicely, thanks again Matt.


Different Different said:
Nov 22nd, 2009 at 12:27 pm

Hi Matt, Exelent work! You can specify the $articleSEF instead of numbers. For example:

<a href="'._SITE.'rss-comments?article='.$art_value.'">'.l('rss_comments_article').'</a>

IMHO, it looks more understandable to the user.


Different Different said:
Nov 22nd, 2009 at 12:39 pm

Or for better viewing: if ($numrows > 0) echo '<div class="commentsrss"><a href="'._SITE.'rss-comments?article='.$articleSEF.'">'.l('rss_comments_article').'</a></div>'."\r\n";


Matt Matt said:
Nov 23rd, 2009 at 9:02 am

Hi Different,

On your first point, that's definitely do-able, you'd need to join the category table in the first part of the switch statement, as of right now, it is pulled by the sNews retrieve function, which is quite inefficient actually.

On your second comment, you can do that, I like to keep the option always there in case someone may see an article and want to keep tabs on future comments even if there hasn't been any comments yet.


Different Different said:
Nov 24th, 2009 at 6:39 am

Hi, Matt! You are absolutely right, but I was mistaken a bit. Here's my corrected version for compensation:

$url = cleanXSS($_SERVER['REQUEST_URI']);
$start = strpos($url,'?id=') + 4;
$end = strpos($url,'&') + 2;
$aid = substr(substr($url,$start),0,$end);
if (ctype_digit($aid)) $extra_sql = "articleid = '".$aid."' AND ";

and

echo '<p class="commentsrss"><a href="'._SITE.'rss-comments?id='.$_ID.'&articleSEF='.$art_value.'" rel="nofollow">'.l('rss_comments_article').'</a></p>'."\r\n";



I added a tag rel="nofollow" for search engines only. I'll be glad if someone is needed.


Different Different said:
Nov 24th, 2009 at 7:43 am

Afraid that I was banned, but ... It works! :)

$limit = s('rss_limit');
$url = cleanXSS($_SERVER['REQUEST_URI']);
$start = strpos($url,'?id=') + 4;
$tail = substr($url,$start);
$lenght = strpos($tail,'&articleSEF=');
$aid = substr($tail,0,$lenght);
if (ctype_digit($aid)) $extra_sql = "articleid = '".$aid."' AND ";


Matt Matt said:
Nov 24th, 2009 at 9:06 am

lol, cool different, that's good stuff, I have codified your comment code for readability. I need to add a bbcode just for formatting code some time.


Patric Patric said:
Jan 25th, 2010 at 7:05 am

Now this one for categories would be just Dandy


Yule Yule said:
May 9th, 2010 at 4:39 am

Hello

Thank you for this mod!, However, is there a mod for the same classes, I look for how to make a
rss individually by category

In advance thank you for your help
Yule


Matt Matt said:
May 9th, 2010 at 7:35 am

Hi Yule & Patric,

I don't think their is a mod for category RSS feeds, it would probably require a much larger rewrite of the RSS function.

I may have a look at writing it some time, no promises right now though :)



Write a comment

* = required field

:

:

:

:

You may insert urls in plain text, urls will be automatically linkified for trusted users and on seasoned posts only. All first comments are moderated, so use your email if you want to be remembered.


Back to top