I was messing around with the database for SMF to get a list of upcoming events on the front page of my site.
Whilst doing a bit of research on how to do it I spent quite a while searching the forums here in case someone else had done the leg work for me. What I noticed is a general interest in a RSS feed for upcoming events in the calendar so I adapted my PHP file to generate a RSS feed for no other reason than to see if I could.
I thought I would share it with you, it's a bit rough and ready but I am pretty sure people can edit it to suit their needs if they wanted to use it.
Any comments on how it could be improved would be appreciated as this is my first stab at creating RSS feeds.
My setup is very simple, all my events go into a single board so I don't really need to tie the board IDs up. So far by only using the topic ID I haven't had a bogus feed but I guess it's possible. Not sure I am going to use this much as I already have working system for my front page but it might be worth investigating checking on the board id between the tables. If you have a particularly busy calendar you might want to use the LIMIT SQL statment to stop your RSS being huge.
Oh one side note, probably not the most secure PHP file in the world so I created a SQL user with only select rights just in case some git managed to get hold of the PHP.
Items in Red will need to be changed to match your setup.
Tim
Lainaa
<?php
mysql_connect("localhost", "YOUR DATABASE USERNAME", "YOUR DATABASE PASSWORD");
mysql_select_db("YOUR SQL DATABASE NAME");
$result = mysql_query("select startDate, endDate, smf_calendar.ID_BOARD, smf_calendar.ID_TOPIC, smf_messages.ID_TOPIC, title, body from smf_calendar,smf_messages WHERE (smf_calendar.ID_TOPIC=smf_messages.ID_TOPIC AND smf_calendar.startDate >= now()) order by startDate;");
$numrows = mysql_num_rows($result);
print "<?xml version='1.0' encoding='UTF-8'?>";
print "<rss version='0.92' xml:lang='en-US.utf8'>";
print " <channel>";
print " <title>TITLE FOR YOUR RSS FEED</title>";
print " <link>http://YOURSITE.COM/FORUM/index.php?action=calendar</link>";
print " <description><![CDATA[live information from YOUR SITE Calendar]]></description>";
if (mysql_num_rows($result)) {
While ($row = mysql_fetch_assoc($result)) {
extract($row);
print "<item>";
print "<title><![CDATA[$title]]></title>";
print "<link>http://YOURSITE.COM/FORUM/index.php/topic,$ID_TOPIC.0.html</link>";
print "<description><![CDATA[$body]]></description>";
print "</item>";
}
print "</channel>";
print "</rss>";
}
?>