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>