Is there a way to limit RSS feeds?

Creating and modifying plugins.
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Is there a way to limit RSS feeds?

Post by schimanke »

Hi there,

I'm wondering if there was a way to offer RSS feeds with different numbers of entries. I know that there is an option in the admin-panel to set the number of entries in the feed. What I would like to do is to offer the user to decide how many entries they want to see. An example would be the following feed from Apple: http://ax.itunes.apple.com/WebObjects/M ... 15/rss.xml

There you can alter the "limit=" part to decide how many entries (here 15) the feed should contain. Is something like that possible with the RSS feeds in s9y?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by garvinhicking »

Hi!

Actually this is pretty easy to hack, but s9y usually delibaretly does not allow this to leave the power of bandwidth consumption up to the blog owner, not the user.

You can pretty easily patch it into the rss.php file though, if you add this:

Code: Select all

$serendipity['RSSfetchLimit'] = (int)$_REQUEST['limit'];
just after the line

Code: Select all

@define('IN_RSS', true);
include('serendipity_config.inc.php');
Basically, you could also create a simple plugin that sets this variable, but that would be more overhead and more for me to type ;)

Then you can call the feed via http://url/rss.php?version=2.0&limit=42 for example.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

Hi Garvin,

thanks for your help. That works pretty good. Unfortunately with this solution you always have to set the limit variable. Otherwise you end up with a mistake. That leads me to another question. Is there a way to set a default value that is used when no limit variable is set?

Regards,
Flo
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by garvinhicking »

Hi!

Ah, of course. You could then use:

Code: Select all

if (isset($_REQUEST['limit'])) {
  $serendipity['RSSfetchLimit'] =(int)$_REQUEST['limit'];
}
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

Thanks, Garvin!
Now it works just perfectly!!!
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

Sorry to bring this issue back up but the solution does no longer work since my last s9y update to version 2.1.4. When adding that code block to the rss.php I get an error on loading my RSS feed. Any way to get it working again? Thanks!
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Is there a way to limit RSS feeds?

Post by onli »

Which error do you get exactly?
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

The exact error message is
Parse error: syntax error, unexpected '$serendipity' (T_VARIABLE) in /[...]/rss.php on line 41
This is the section in which I added the code:

Code: Select all

if (isset($_GET['category'])) {
    $serendipity['GET']['category'] = $_GET['category'];
}

if (isset($_GET['viewAuthor'])) {
    $serendipity['GET']['viewAuthor'] = $_GET['viewAuthor'];
}
    
if (isset($_REQUEST['limit'])) {
   $serendipity['RSSfetchLimit'] =(int)$_REQUEST['limit'];
}

if (!isset($_GET['type'])) {
    $_GET['type'] = 'content';
}
And line 41 from the error message is this one:

Code: Select all

$serendipity['RSSfetchLimit'] =(int)$_REQUEST['limit'];
Thanks for your help!
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Is there a way to limit RSS feeds?

Post by onli »

There is a syntax error somewhere in the code, and in the code you showed I do not notice one. And I did just test the line, the code works fine/does not throw an error

How do you upload the changed code? Are you absolutely certain there are no other modifications?
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

Yes I am. I have uploaded the rss.php file via FTP. If the code above is included I get the error on accessing the RSS feed. If the code lines are commented out in the rss.php file, the feed is displayed correctly.
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Is there a way to limit RSS feeds?

Post by onli »

FTP has transport modes which can introduce errors like that, but I guess commenting out the code wouldn't fix it then. Could you please upload the complete file somewhere? I'll have a closer look.
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

Sure, here you go: https://www.dropbox.com/s/msldx59mxouuni6/rss.zip?dl=0
The relevant code is in line 40 to 42.

Thanks again!
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Is there a way to limit RSS feeds?

Post by onli »

That works fine.

I got an error in line 6:

Code: Select all

session_cache_limiter('public');
That had to be commented out. But line 40 to 42 are valud PHP and do not cause errors.

I'd try to add those lines with ssh, does your hoster give you ssh access?
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Is there a way to limit RSS feeds?

Post by schimanke »

I got an error in line 6.
That's even more weird... :?

I have tried changing the lines via SSH but to no avail. The error remains the same. :(
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Is there a way to limit RSS feeds?

Post by onli »

That's utterly strange. Which PHP version do you use? Are there error messages in the webserver log?
Post Reply