News: When asking for support, it helps us and you, if you read the Posting Guidelines

Login  |  Register
* *
TinyPortal on Twitter
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 19, 2018, 06:49:03 AM

Login with username, password and session length

Recent

Members
Stats
  • Total Posts: 185057
  • Total Topics: 20531
  • Online Today: 33
  • Online Ever: 383
  • (January 02, 2015, 05:58:49 AM)
Users Online
Users: 1
Guests: 12
Total: 13

Skinz





amazon.com

Author Topic: [Code] RSS Feed for TinyPortal Articles  (Read 8867 times)

0 Members and 1 Guest are viewing this topic.

Offline DistantJ

  • Jr. Member
  • **
  • Posts: 16
[Code] RSS Feed for TinyPortal Articles
« on: October 19, 2010, 07:39:04 PM »
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':

Code: [Select]
<?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.

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: [Code] RSS Feed for TinyPortal Articles
« Reply #1 on: October 20, 2010, 12:16:39 PM »
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. :)
« Last Edit: October 20, 2010, 12:56:21 PM by IchBin »

Offline Putoguiri

  • Jr. Member
  • **
  • Posts: 11
Re: [Code] RSS Feed for TinyPortal Articles
« Reply #2 on: January 13, 2012, 08:38:21 AM »
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)

Offline IchBin™

  • Developer
  • *
  • Posts: 16228
    • My Website
Re: [Code] RSS Feed for TinyPortal Articles
« Reply #3 on: January 13, 2012, 12:34:05 PM »
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.

Offline Putoguiri

  • Jr. Member
  • **
  • Posts: 11
Re: [Code] RSS Feed for TinyPortal Articles
« Reply #4 on: January 13, 2012, 12:36:29 PM »
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.

 :)

Offline tino

  • Developer
  • *
  • Posts: 960
Re: [Code] RSS Feed for TinyPortal Articles
« Reply #5 on: March 04, 2018, 03:21:23 PM »
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

Code: [Select]
<?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;
?>