Hi everyone :)
One thing I've found lacking from TinyPortal (as AMAZING as it is!) is an RSS Feed for articles, so that your visitors can subscribe to articles rather than forum posts, so I decided to make one, and share it with you all.
Paste the following code into a text or html editor and save it as 'rss.php':
<?php
//Article RSS Feed for TinyPortal by DistantJ
//Created originally for http://www.hooplanet.co.uk/
//Replace 'database.server', 'username' and 'password' with the appropriate values
mysql_connect('database.server', 'username', 'password');
//Replace 'database_name' with the name of your database
mysql_select_db('database_name');
$query = "SELECT id, subject, intro FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY date DESC";
$result = mysql_query($query);
while ($line = mysql_fetch_assoc($result))
{
$return[] = $line;
}
$now = date("D, d M Y H:i:s T");
//Change the details below to match your site.
$output = "<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title>Your Feed Name</title>
<link>http://www.yourdomain.co.uk/rss.php</link>
<description>Your Feed Description</description>
<language>en-us</language>
<pubDate>$now</pubDate>
<lastBuildDate>$now</lastBuildDate>
";
//Replace path.to/smf/ with the path to your SMF installation.
foreach ($return as $line)
{
$output .= "<item><title>".htmlentities($line['subject'])."</title>
<link>http://www.path.to/smf/index.php?page=".htmlentities($line['link'])."</link>
<description>".htmlentities(strip_tags($line['intro']))."</description>
</item>";
}
$output .= "</channel></rss>";
header("Content-Type: text/xml");
echo $output;
?>
Change the variables to match your database and site, upload it anywhere you want on the domain and voila, a perfect working RSS feed for your TinyPortal articles! From there you can add a link to it in one of your blocks or menus. :)
Note: You may want to disable RSS feeds of your forum posts (in Admin>News & Newsletters>Settings) to avoid confusion in browsers which detect RSS feeds etc.
You can remove all of the database functions you used at the top if you just use tpdb_query() or $smcFunc['db_query() to execute your query. SMF/TP will already handle all of that if you include SSI.php. Just some food for thought. I actually did something similar a long time ago, but never finished doing everything I wanted to. Thanks for sharing!
--edit--
FYI, you might want to NOT select any articles that are php/import type. That won't display well in your feed. :)
Hello, I've been using this rss.php (well, a modified version) in my website for some time now.
Recently (with the latest update) we've been starting to include news from our forum (selected topics + promote to frontpage) in the frontpage too (it's easier and more consistent).
Now I want the rss.php to include both, frontpage articles and selected topics. Any ideas were I should look/start? Ie, how does Tinyportal know when a topic has to go to frontpage, I've been looking in the database and couldn't find a clue.
Thanks!
(If I'm able to do it, I'll share my rss.php once done)
If you look in the TPortal.php file you'll find the section that deals with pulling topics and articles together. It's quite complicated, and not something I want to digest on the forum really.
Thanks, that'll get me started.
I have to go there anyways to see if I can't add a little "read more..." link that sends users to the topic in question.
:)
You can do this with a php article, just remember to turn it off being displayed on the front page and all the other settings need to be disabled also.
I configured my test page to have the shortname rss
<?php
// Clean the output buffer
ob_clean();
global $boarddir;
global $smcFunc;
global $boardurl;
global $mbname;
$request = $smcFunc['db_query']('',
'SELECT id, subject, intro, shortname FROM {db_prefix}tp_articles WHERE approved = 1 AND off = 0 ORDER BY date DESC'
);
$return = array();
if($smcFunc['db_num_rows']($request) > 0) {
while ($line = $smcFunc['db_fetch_assoc']($request)) {
if(empty($line['shortname'])) {
$line['link'] = $line['id'];
}
else {
$line['link'] = $line['shortname'];
}
$return[] = $line;
}
$smcFunc['db_free_result']($request);
}
$now = date("D, d M Y H:i:s T");
//Change the details below to match your site.
$output = "<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title>$mbname</title>
<link>$boardurl/index.php?page=rss</link>
<description>$mbname RSS Feed</description>
<language>en-us</language>
<pubDate>$now</pubDate>
<lastBuildDate>$now</lastBuildDate>
";
foreach ($return as $line) {
$output .= "
<item><title>".htmlentities($line['subject'])."</title>
<link>$boardurl/index.php?page=".htmlentities($line['link'])."</link>
<description>".htmlentities(strip_tags($line['intro']))."</description>
</item>";
}
$output .= "</channel></rss>";
header("Content-Type: text/xml");
echo $output;
// end without continuing.
die;
?>