1 (edited by alexkingorg 2005-03-06 02:38)

Topic: RSS Feeds for Categories, Forums, Topics and Latest Posts

I've modified this RSS mod found here:

http://punbb.org/forums/viewtopic.php?id=5100

to support RSS feeds for Categories, Forums and Topics (Latest Posts is still included of course). I also added code to exclude posts that are not visible to guests (I think, someone may want to check this).

Download

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I was checking this out on your site, and it seemed pretty cool, except for the RSS Forums feed.
It was showing every post topic, instead of just a generalized topic...

Such as:

Main topic
Re: Main Topic
Re: Main Topic
Next Topic
Re: Next Topic...

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I'm sorry, I don't understand. When I look at the feed for Tasks Pro : Installation Support:

http://www.alexking.org/forums/rss.php?fid=10

It shows the most recent posts in Tasks Pro : Installation Support as expected.

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Ok:
I click on the RSS feed for your "Installation" forum.
Instead of showing the topics in order, is shows every post in topic order:

As in, instead of showing a single post for a topic in a forum, it shows every post to every topic...
Shouldn't it only do that for the feed for each topic?

http://www.alexking.org/forums/rss.php?fid=10
vs.
http://www.alexking.org/forums/rss.php?tid=620

5 (edited by alexkingorg 2005-03-06 17:47)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

No, RSS feeds are generally 'latest items'. It is working as intended.

For example, I might have someone who wants to follow the localization forum for one of my products. They subscribe to the feed for the appropriate localization forum and they can see all new posts that get added in that forum, regardless of the thread. Then if they want to chime in, they can.

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Gotcha...That does help if that's what you're looking for.

Awesome mod. big_smile

7 (edited by Slaver 2005-03-08 09:05)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

This plugin doesn't work with Easy Smiles 1.0.5. The error in parser.php at the beginning of code.

//
    // Get smilies from database
    //
    $smiley_text = array();
    $smiley_img = array();
    $result = $db->query('SELECT * FROM '.$db->prefix.'smilies') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error()); // ERROR HERE!!!
    while ($db_smilies = $db->fetch_assoc($result))
    {
        $smiley_text_array = array($db_smilies['text']);
        $smiley_text = array_merge($smiley_text, $smiley_text_array);
    
        $smiley_img_array = array($db_smilies['image']);
        $smiley_img = array_merge($smiley_img, $smiley_img_array);
    }

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I think is a stupid question but :

How can we read XML-RSS with punbb ?

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

tuyau45: http://punbb.org/docs/faq.html#faq3_6

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Thanx

11

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Is it possbile to get this RSS feed working without having Guests enabled to read to forums?

Hmmm.

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

It would be possible to build authentication into the feed, but there are several isssues with this.

If you don't have any authentication and remove the guest allowance code, then guests would be able to read the forums through the RSS feeds even if not allowed through the main interface.

13

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Damn. smile

Hmmm.

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

if you remove

// Make sure we (guests) have permission to read the forums
$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
if ($db->result($result) == '0')
    exit('No permission');

then it will work although anyone who knows how will be able to read posts without logging in, but i don't suppose thats a major issue

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Actually, that is a very major issue. How do they log in?

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

they don't i don't suppose its serious as only users of the forum will want to use the rss and unless your content is sensitive its not a problem is it?

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Let me re-phrase: How would *anyone* access the RSS feeds?

18 (edited by tz 2005-03-24 09:03)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I've installed your mod and I like it very much (I'm using feedreader to get instant notifies when something new is posted on our forum).

Here's a simple (and ugly) hack I made, to allow ALL forums to be RSS-fed if you're logged in as an administrator. This isn't very secure, but I make do with it. I'm sure you can modify it for more security.

After the lines

if ($pun_user['g_read_board'] == '0') 
        message($lang_common['No view'])

in index.php, viewtopic.php and viewforum.php put:

// hack for allowing the administrators to RSS feed every topic, forum and category
if ($pun_user['group_id']=='1') {
        $rssadm='readall=1&';
} else {
        $rssadm="";
}

and in every instance of the RSS-tag put like this:

<a href="rss.php?<?=$rssadm?>cid=<?php echo $cur_forum['cid'] ?>">

(you've added <?=$rssadm?>).

in rss.php, find this:

$result = $db->query("
        SELECT p.id AS id, p.message AS message, p.posted AS postposted, t.subject AS subject, f.forum_name, c.cat_name
        FROM ".$db->prefix."posts p
        LEFT JOIN ".$db->prefix."topics t
        ON p.topic_id=t.id
        INNER JOIN ".$db->prefix."forums AS f
        ON f.id=t.forum_id
        LEFT JOIN ".$db->prefix."categories AS c
        ON f.cat_id = c.id
        LEFT JOIN ".$db->prefix."forum_perms AS fp
        ON (
                fp.forum_id=f.id
                AND fp.group_id=3
        )
        WHERE (
                fp.read_forum IS NULL
                OR fp.read_forum=1
        )
        $where
        ORDER BY postposted DESC
        LIMIT 0,15
") or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;

and replace it with this:

if($readall=="1") {
$result = $db->query("
        SELECT p.id AS id, p.message AS message, p.posted AS postposted, t.subject AS subject, f.forum_name, c.cat_name
        FROM ".$db->prefix."posts p
        LEFT JOIN ".$db->prefix."topics t
        ON p.topic_id=t.id
        INNER JOIN ".$db->prefix."forums AS f
        ON f.id=t.forum_id
        LEFT JOIN ".$db->prefix."categories AS c
        ON f.cat_id = c.id
        LEFT JOIN ".$db->prefix."forum_perms AS fp
        ON (
                fp.forum_id=f.id
                AND fp.group_id=3
        )
        $where
        ORDER BY postposted DESC
        LIMIT 0,15
") or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
} else {
$result = $db->query("
        SELECT p.id AS id, p.message AS message, p.posted AS postposted, t.subject AS subject, f.forum_name, c.cat_name
        FROM ".$db->prefix."posts p
        LEFT JOIN ".$db->prefix."topics t
        ON p.topic_id=t.id
        INNER JOIN ".$db->prefix."forums AS f
        ON f.id=t.forum_id
        LEFT JOIN ".$db->prefix."categories AS c
        ON f.cat_id = c.id
        LEFT JOIN ".$db->prefix."forum_perms AS fp
        ON (
                fp.forum_id=f.id
                AND fp.group_id=3
        )
        WHERE (
                fp.read_forum IS NULL
                OR fp.read_forum=1
        )
        $where
        ORDER BY postposted DESC
        LIMIT 0,15
") or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
}

Also, I've commented out the "check for guest access" lines in rss.php.

Like I said, this is ugly and unsecure, but it works for me.

Thanks for the mod!

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

The proper way to secure RSS feeds is with 401 authentication, because that is what the feed readers support. However getting 401 authentication information to PHP is problematic in some PHP configurations. You want to avoid it if you can.

20

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Slaver wrote:

This plugin doesn't work with Easy Smiles 1.0.5. The error in parser.php at the beginning of code.

//
    // Get smilies from database
    //
    $smiley_text = array();
    $smiley_img = array();
    $result = $db->query('SELECT * FROM '.$db->prefix.'smilies') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error()); // ERROR HERE!!!
    while ($db_smilies = $db->fetch_assoc($result))
    {
        $smiley_text_array = array($db_smilies['text']);
        $smiley_text = array_merge($smiley_text, $smiley_text_array);
    
        $smiley_img_array = array($db_smilies['image']);
        $smiley_img = array_merge($smiley_img, $smiley_img_array);
    }

You find a solution for that ?? i have the problem hmm

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

This is a simple mod to this existing mod to add categories to your messages based on your Category/Forums structure. Category will be in the form:

<category>Category/Forum</category>

TO DO: add a category listing to the <channel> header function, so when you do a rss.php?cid=3 or rss.php?fid=1, the appropriate category/forum is listed, otherwise the default category is picked.

Other possible mod: add an array to translate your cat_id's and forum_id's to standardized category descriptions


after:

    $data = "Topic: ".parse_message($cur['subject'],0)."\n\nMessage: ".parse_message($cur['message'],0);
    echo "<description>".encode_xml($data)."</description>\n";
//    echo "<content:encoded><![CDATA[".$data."]]></content:encoded>\n";
    echo "<pubDate>".strval(date("r",$cur['postposted']))."</pubDate>\n";

add:


    $cat2=trim(preg_replace('/\s\s+/', ' ', $cur['forum_name']));
    $cat2=str_replace("&", "and", $cat2);
    echo "<category>".$cur['cat_name']."/".$cat2."</category>\n";

22 (edited by qu1j0t3 2005-05-16 03:31)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

Here is an alternative modification to rss.php, for PunBB 1.2.1, written independently. Supports "latest posts", forum, and topic feeds. Quite a few other changes have been made to better support requirements of our site, including citing poster usernames in message titles, abbreviation of message in titles, etc.

With the following patch to header.php, the feeds are also advertised in the document HEAD so can be automatically found by Firefox, Safari, etc. Add the following after "<?php" on line 66:

    $rss = "rss.php";
    $rsstype = "latest posts";
    if(strpos($_SERVER['REQUEST_URI'],"viewforum")){
        $rss .= "?forum=".$_GET['id'];
        $rsstype = "forum";
    }else if(strpos($_SERVER['REQUEST_URI'],"viewtopic")){
        $rsstype = "topic";
        if(array_key_exists('id',$_GET))
            $rss .= "?topic=".$_GET['id'] ;
        else 
            $rss = "";
    }
    if($rss) echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$rsstype: $page_title (RSS 2.0)\" href=\"$rss\">\n";

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I don't understand what this does differently/better than the one I posted, can you elaborate?

24 (edited by qu1j0t3 2005-05-16 14:14)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

I haven't tested yours, because by the time I found it I had already done this, and I don't claim this is better. For instance mine does not yet do Category feeds. It is likely to differ in details.

The things I found lacking in the original script were (apart from adding Topic and Forum support):
* it did not advertise feeds (this requires a change to header.php)
* "smart" abbreviation of messages to form titles in "topic" feeds
* it did not mention user names
* it needed tweaks to work with 1.2.1 which is what I happened to have installed
* it didn't strip BBCode in a couple of places it should, etc

It's simply provided as an alternative on a "take it or leave it" basis. Any further improvements or ideas I have will be committed to that source.

25 (edited by dss 2005-05-17 23:22)

Re: RSS Feeds for Categories, Forums, Topics and Latest Posts

If you would like to style your feeds like mine

I wrote up a little tutorial on how to do it here

: )