
I've created these two PHP scripts for outputting RSS from the data in your News Aggregator. One is for RSS 1.0, the other for RSS 2.0. They both work great, but if someone can suggest a way to include a published date, it would help. It seems that the news aggregator uses a timestamp function that doesn't translate into a good pubdate. When I place the feeds into MyYahoo, it says there are no new feeds (within the last 3 days). Feed free to play with these and mark them up as you see fit.
What you will need to change in the scripts are:
RSS 1.0 Script:
"title" "description," "link," and "items" information.
Database "username," "password," and "database name."
RSS 2.0 Script:
"title," "link," "description," and "language" (if other than English).
I've included a badge for my site - and feel free to leave it there :) - but if you want to use your own, change the image "url," "link," "title," "height," and "width" information. You can also leave this information blank between the tags.
Database "username," "password," and "database name."
Save the script of your choice as "rss.php" and upload it to the main directory. I went into CPanel and redirected "index.rdf," "index.xml," and "rss.xml" to this page, since this is what search engines crawl for when looking for an RSS file.
Here are the scripts, and like I said, please offer any suggestions for fixes or better usability:
RSS 1.0
<?php
/**********************************************************************************
* rss.php
* Version: 1.00
* Author: Jeffrey Smith
* Date: 03/19/2001
* http://www.bloggator.com
*
**********************************************************************************
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This work is hereby released into the Public Domain. To view a copy of the public
domain dedication, visit http://creativecommons.org/licenses/publicdomain/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.
**********************************************************************************/
//create header information and call the database
header ("");
echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:hr="http://www.w3.org/2000/08/w3c-synd/#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://www.bloggator.com/rss.php">
<title>Put Title Here</title>
<description>Put Description Here</description>
<link>Put Link Here</link>
<items>Put Item Description Here</items>
</channel>
<?php
mysql_connect ("localhost", "username", "password") or die ("Cannot
connect to database server.");
mysql_select_db ("database name") or die ("Cannot connect to database.");
// change the sql look up so that you can format the date correctly//
// $result = mysql_query ("select * from aggregator_item order by iid desc limit 0,10") or die (mysql_error());
$myq = 'SELECT iid, title, link, description, DATE_FORMAT( timestamp, \'%Y-%m-%d\' ) AS mydate'
. ' FROM aggregator_item'
. ' ORDER BY timestamp DESC '
. ' LIMIT 0 , 15';
$result = mysql_query($myq) or die (mysql_error());
// change the item to items as directed by the RSS Validator//
while ($row = mysql_fetch_array ($result)) {
echo ("<item rdf:about><title>");
echo $row['title'];
echo ("</title>
<description>");
echo $row['description'];
echo ("</description><link>");
echo $row['link'];
echo ("</link><date>");
echo $row['timestamp'];
echo ("</date>");
echo ("</item>\n\n");
}
mysql_free_result ($result);
?></rdf:RDF>
RSS 2.0
<?php
/**********************************************************************************
* rss.php
* Version: 2.00
* Author: Jeffrey Smith
* Date: 03/19/2001
* http://www.bloggator.com
*
**********************************************************************************
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This work is hereby released into the Public Domain. To view a copy of the public
domain dedication, visit http://creativecommons.org/licenses/publicdomain/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.
**********************************************************************************/
//create header information and call the database
header ("");
echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:itms="Website Address">
<channel>
<title>Put Title Here</title>
<link>Put your URL Here</link>
<description>Put Description Here</description>
<language>en</language>
<ttl>60</ttl>
<dc:creator>Bloggator.com</dc:creator>
<dc:date>2002-10-02T10:00:00-05:00</dc:date>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2003-09-01T12:00+00:00</sy:updateBase>
<image>
<url>http://www.bloggator.com/images/bloggator_badges/bloggator_88x31.gif</url>
<link>http://www.bloggator.com</link>
<title>Bloggator.com</title>
<height>31</height>
<width>88</width>
</image>
<?php
mysql_connect ("localhost", "username", "password") or die ("Cannot
connect to database server.");
mysql_select_db ("database name") or die ("Cannot connect to database.");
// change the sql look up so that you can format the date correctly//
// $result = mysql_query ("select * from aggregator_item order by iid desc limit 0,10") or die (mysql_error());
$myq = 'SELECT iid, title, link, description, DATE_FORMAT( timestamp, \'%Y-%m-%d\' ) AS mydate'
. ' FROM aggregator_item'
. ' ORDER BY timestamp DESC '
. ' LIMIT 0 , 15';
$result = mysql_query($myq) or die (mysql_error());
// change the item to items as directed by the RSS Validator//
while ($row = mysql_fetch_array ($result)) {
echo ("<item><title>");
echo $row['title'];
echo ("</title>
<description>");
echo $row['description'];
echo ("</description><link>");
echo $row['link'];
echo ("</link><date>");
echo $row['timestamp'];
echo ("</date>");
echo ("</item>\n\n");
}
mysql_free_result ($result);
?></channel></rss>
Comments
Working fine now
Actually, they're working fine now in My Yahoo, it must have been a cache issue with Yahoo. I'm using the RSS 2.0 on my site.
Jeff
Bloggator.com
Get your blog on.
Cool
As a semantic web person, I'm more interested in the RSS 1.0 version. It would be good to add some DC (dc:subject) and FOAF data there too...
Edit: My mistake, I thought this was for syndicating Drupal content.
I found an error (for me)
this is a great script, but for working I had to change:
to:
I hope this will help others
Thanks
That's what I needed to make it work. I don't know php, rss, xml, etc, so easy cut paste and voila! works.
Perfecto!
My Fix for Arabic
I changed it to this:
Header( "Content-type: text/xml");
echo '<'; ?>?xml version="1.0" encoding="UTF-8"?>
This way it will render arabic text correctly.
Drupal 4.7
FYI, Drupal 4.7 will have this built-in.
Drupal 4.7
Fantastic! Will each category have its own feed?
Jeff
Read blogs at Bloggator.com
Yes. Uwe. -- hermann-uwe.de
Yes.
Uwe.
--
hermann-uwe.de | crazy-hacks.org | unmaintained-free-software.org
error with some content
The xml is failing (if I'm using the right wording...) if a feed item has the '&' symbol. If someone has a title like "this & that", it bombs out.
Doing basic search I see that the '&' symbols need to be "escaped". Can that be put into this code?
I see that this feature (rss feed of aggregator) will be in 4.7... but in the mean time it would be nice to get this working in the mean time.
Ugly fix
I took this section of the RSS 2.0 feed code:
And modified to this:
While it makes something pretty turn into ugly html code, it keeps the RSS feed validated when various blog writers use ampersands. I never realized just how much writers did until the feed broke every day.
To make it easier for me to understand, I did break apart some of the lines. I'm not a php person... not even close.
I also removed the date item. I'm not sure why, but it was always popping as bad ( and empty...? ) on the feed validators.
I look forward to version 4.7, but fear the upgrade....
Publishing Date
I was using FeedDemon to aggregate the feed, and the dates were not coming through correctly.
I made the following changes for each item in the feed:
From:
To:
This meant that when the feed was going through to FeedDemon, it was sorting the items on the feed correctly into date order.
All in all, a fantatic script, and I'm very pleased to have found it !
________________
http://skeddy.net