51

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

This is a very useful add-on - thanks! However I think there might be a bug in entity_to_decimal_value ($data). Sometimes (unfortunately, I can't pinpoint the situation), URLs in posts get mangled up. because of rss.php.

I replaced the contents of encode_xml ($data) with just

return htmlspecialchars (strip_tags ($data));

and it seems to work for now. I'll report back if there's anything new.

52

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

Also, at least in our setup, the post links come out wrong. Here's a fix - on line 222:

$link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($cur['id']).'#'.strval($cur['id']);

it should say this instead:

$link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($cur['id']).'#p'.strval($cur['id']);

... note the "p".

53 (edited by cal 2007-02-07 16:37)

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

1.

I have modified this mod to suite our site. I use <[CDATA! -tags and plain html instead of the "encode_xml($data)"-solution.

But I am having problems with the titles. Swedish characters like å ä ö doesnt work. The rss.php will remove any blank spaces before any of those characters.

If the title is; "Downhill åska"
Then it will be like this in the RSS; "Downhillåska"

Could anyone help?

The feed is on our frontpage at http://www.nolltid.se/

This is the rss.php code: http://www.nolltid.se/rss.zip

---

2.

I would like to show the first post in every thread only. The original post.
When using this call:  http://www.example.com/punbb/rss.php?fid=16

How can I modify the RSS.php to do that?

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

Hi.

My rss feed is crushing at this line:

$data = "Topic: ".parse_message($cur['subject'],0)."\n\nMessage: ".parse_message($cur['message'],0);

When I comment it it works pretty fine showing only topic name, but I really need the description. Do you have any ideas why?

55 (edited by cal 2007-02-28 22:05)

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

Okey. I understand that showing the first post only in every thread is a bit hard because of how the database structure is made.

So I came up with a new idea.

1) I will use 2 separate forum-ids and post one copy of each news-thread in both of them.
2) One of them is invisible for guests, this one is the one that creates the RSS.
3) The other one is visible for guests. This is where the news can be discussed / commented.

But I am encountering a problem when trying to export RSS from a forum where guests have no "read access".

This is the error I get when trying to create the RSS from "http://www.example.com/forum/rss.php?fid=4"

This page contains the following errors:

error on line 1 at column 2: xmlParseStartTag: invalid element name

Below is a rendering of the page up to the first error.

I replaced this code in the rss.php:

$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');

with

$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=2') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
   if ($db->result($result) == '0')
   exit('No permission');

56 (edited by bingiman 2007-03-11 20:27)

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

adding RSS to the sub-forum mod.

Open viewforum.php and look for:

        $forum_field = '<h3><a href="viewforum.php?id='.$cur_subforum['id'].'">'.pun_htmlspecialchars($cur_subforum['forum_name']).'</a></h3>

replace with:

        $forum_field = '<h3><a href="viewforum.php?id='.$cur_subforum['id'].'">'.pun_htmlspecialchars($cur_subforum['forum_name']).'</a></h3><div style="float:right;"><a href="extern.php?type=rss&action=active&fid='.$cur_subforum['id'].'"><img style="vertical-align: middle;" src="img/rss.png" border="0" height="15" width="27" alt="RSS" align="middle" /></a></div>';

57

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

heddesheimer,
There is an alternative enhanced RSS-feed generator for PunBB:
http://letmeseetheart.tripod.com/files/ … 16.php.txt

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

Hi.

I'm looking for a way to generate an RSS feed of just new threads with the first posts' content, I don't want replies in the feed. Can this be done with a similar RSS mod?

Thanks!

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

NetworkShadow wrote:

Hi.

I'm looking for a way to generate an RSS feed of just new threads with the first posts' content, I don't want replies in the feed. Can this be done with a similar RSS mod?

Thanks!

A friend of mine took a crack at my feature requests and the end result works great. Be advised that it searches the entire database for the first post of the newest threads. It might be a bit slow on some large databases.

Here's a modified RSS.php

<?php
/**
  * BLOG:CMS: PHP/MySQL Personal Content Management System 
  * http://blogcms.com/
  * http://forum.blogcms.com/
  *
  * 2003-2004, (c) Radek HULAN 
  * http://hulan.cz/
  *
  * Mod by Bert Garcia for PunBB 1.2.1
  * http://nupusi.com
  *
  * Additional changes Copyright 2005 by Alex King
  * Now creates feeds for categories, forums, topics
  * http://www.alexking.org/software/
  *
  * Modified by Daniel Jalkut to eliminate redundant Topic and 
  * Message prefixes is the description output, and to include
  * content in a content:encoded namespace for better formatting
  * preservation. http://www.red-sweater.com/.
  * 
  * Please see the enclosed readme.txt file for usage
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.

// **********************************************************************
// 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. 
// *****************************************************************

**/


define('PUN_ROOT', './');
@include PUN_ROOT.'config.php';

// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
    exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

// Disable error reporting for uninitialized variables
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);


// Load the functions script
require PUN_ROOT.'include/functions.php';
require PUN_ROOT.'include/parser.php';

// Load DB abstraction layer and try to connect
require PUN_ROOT.'include/dblayer/common_db.php';

// Get the forum config
$result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());
while ($cur_config_item = $db->fetch_row($result))
    $pun_config[$cur_config_item[0]] = $cur_config_item[1];

// 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');


// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
if (!isset($lang_common)) exit('There is no valid language pack \''.$pun_config['o_default_lang'].'\' installed. Please reinstall a language of that name.');

// parse RSS
ob_start();

// make feed
/* original query
$result = $db->query(
    "select p.id as id, p.message as message, p.posted as postposted, t.subject as subject ".
    "from ".$db->prefix."posts as p, ".$db->prefix."topics as t ".
    "where p.topic_id=t.id ".
    "order by postposted desc ".
    "limit 0,15") 
    or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
*/

if (!empty($_GET["cid"])) {
    $where = "    AND c.id = '".intval($_GET['cid'])."'";
    $title = 'cid';
}
else if (!empty($_GET["fid"])) {
    $where = "    AND f.id = '".intval($_GET['fid'])."'";
    $title = 'fid';
}
else if (!empty($_GET["tid"])) {
    $where = "    AND t.id = '".intval($_GET['tid'])."'";
    $title = 'tid';
}
else {
    $where = '';
    $title = '';
}
$result = $db->query("
    CREATE TEMPORARY TABLE rsstmp 
    SELECT p.id AS id, p.topic_id AS topic_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");
    $result = $db->query("SELECT * FROM rsstmp GROUP BY topic_id ORDER BY postposted DESC LIMIT 15
") or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
$i = 0;
while ($cur = $db->fetch_assoc($result)) {
    if ($i == 0) {
        putHeader($cur, $title);
        $i++;
    }
    putPost($cur);
}
putEnd();

// get feed into $feed
$feed = ob_get_contents();
ob_end_clean();

// create ETAG (hash of feed)
$eTag = '"'.md5($feed).'"';
header('Etag: '.$eTag);

// compare Etag to what we got
if ($eTag == $_SERVER['HTTP_IF_NONE_MATCH']) {    
    header("HTTP/1.0 304 Not Modified");
    header('Content-Length: 0');
} else {
    // dump feed
    header ("Content-type: text/xml");
    echo $feed;
}

/* entity to unicode decimal value */
function entity_to_decimal_value($string){
    static $entities_dec = false;
    if (!is_array($entities_dec)) {
        $entities_named       = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","•","…","?","?","?","?","?","?","?","™","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜","?","?","?","?","?","?","?","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","&apos;");
        $entities_decimal     = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","•","…","?","?","?","?","?","?","?","™","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜","?","?","?","?","?","?","?","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","'");
        if (function_exists('array_combine')) 
            $entities_dec=array_combine($entities_named,$entities_decimal);
        else {
            $i=0;
            foreach ($entities_named as $_entities_named) $entities_dec[$_entities_named]=$entities_decimal[$i++];
        }
    }
    return preg_replace( "/&[A-Za-z]+;/", " ", strtr($string,$entities_dec) );
}

function encode_xml($data){
    // line breaks
    $data=str_replace('<br(.*?)>',"\n\n",$data);
    // ending html tags into line breaks
    $data=preg_replace("/<\/(pre|ul|li|p|table|tr)>/","\n\n",$data);
    // remove other html tags
    $data=preg_replace("/<(.*?)>/","",$data);
    // remove multiple newlines
    //$data=preg_replace("/\n\n+/","\n\n",$data);
    return entity_to_decimal_value($data);
}

function putHeader($cur, $title) { 
    switch ($title) {
        case "cid":
            $title = ' : '.$cur['cat_name'];
            break;
        case "fid":
            $title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'];
            break;
        case "tid":
            $title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'].' : '.$cur['subject'];
            break;
        default:
            $title = '';
            break;
    }
    global $lang_common,$pun_config;
    echo '<'.'?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?'.'>'."\n";
    echo "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
    echo "<channel>\n";
    echo "<title>".entity_to_decimal_value(htmlspecialchars($pun_config['o_board_title'].$title))."</title>\n";
    echo "<link>".$pun_config['o_base_url']."</link>\n";
    echo "<description>".entity_to_decimal_value(htmlspecialchars($rss_description.' '.$pun_config['o_board_title']))."</description>\n";
    echo "<language>en</language>\n";
    echo "<docs>http://backend.userland.com/rss</docs>\n";
} 

function putPost($cur) {
    global $pun_config;
    echo "<item>\n";
    echo "<title>".entity_to_decimal_value(htmlspecialchars($cur['subject'].' in '.$cur['cat_name'].' : '.$cur['forum_name']))."</title>\n";
    $link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($cur['id']).'#'.strval($cur['id']);
    echo "<link>".entity_to_decimal_value(htmlspecialchars($link))."</link>\n";
    echo '<guid isPermaLink="false">'.strval($cur['id']).'@'.$pun_config['o_base_url'].'</guid>'."\n";
    $data = 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";
    echo "</item>\n";
}


function putEnd() {
    echo "</channel>\n";
    echo "</rss>\n";
} 

?>

60

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

go to http://bunpai.com look at my site.. it is running rss feed to forum post... over 17k of them...


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

61 (edited by cal 2007-07-20 20:55)

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

Connorhd wrote:

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

I am trying to create a RSS feed from one of my forums with no read priviligies for guests.

I removed the code above but I just get this error when trying to create the feed.

How can I create the RSS feed without having guests reading that part of the forum?

This page contains the following errors:

error on line 1 at column 2: xmlParseStartTag: invalid element name
Below is a rendering of the page up to the first error.

62 (edited by hurry 2007-12-15 03:29)

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

I have a line break problem with this Alex's mod. I have trying to find a solution for the last 24 hours but nothing till now. Please help.

<description>".encode_xml($data)."</description>

The above code displays all the html perfectly in the RSS feed including flash objects, img src, ahref links etc. which is great. But all the post content is jumbled up in a big paragraph i.e. it strips out all the line breaks in the posts. I tried the changes suggested in this topic but they lead to another problem. The line breaks are displayed but then all the html appears only in the post body as code and does not display the flash objects, photos etc. Alex says he has modified to support the formatting but he has not published an update. I know the solution must be simple but I don't know what it is. Please help!

63

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

cal wrote:

I have modified this mod to suite our site. I use <[CDATA! -tags and plain html instead of the "encode_xml($data)"-solution.

The feed is on our frontpage at http://www.nolltid.se/
This is the rss.php code: http://www.nolltid.se/rss.zip

Cal, I see your forum rss feed works nicely with proper link breaks and html display. The above rss.zip url is broken. Can you please give us another url to download your rss.zip so that we can use it? I am so much in need of it. Thanks.

64 (edited by hurry 2008-01-01 12:50)

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

I still have a line break problem with this Alex's mod. I have trying to find a solution for weeks but nothing till now. Please help.

<description>".encode_xml($data)."</description>

The above code displays all the html perfectly in the RSS feed including flash objects, img src, ahref links etc. which is great. But all the post content is jumbled up in a big paragraph i.e. it strips out all the line breaks in the posts. I tried the changes suggested in this topic but they lead to another problem. The line breaks are displayed but then all the html appears only in the post body as code and does not display the flash objects, photos etc. Alex says he has modified to support the formatting but he has not published an update. I know the solution must be simple but I don't know what it is. Can anyone please help! I have been waiting for weeks. Eagerly awaiting some help.

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

I'm very new to punbb here and I've got the forum up and going. What I'm wanting to do is is syndicate the newest forum topics and then use my CMS's MagPie plugin to pull the last 10 or so topics into my homepage template. I see where it says in the readme file that you can grab the last 15 posts, but nothing about the last 10 or 15 topics from all forums?

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

I want a simple RSS feed for display first 15 post's topic name and category name in bracket,

RSS like: topic name (category name)

i read this topic but can't understand how to make as my choice

help me please, i started my first forum today:)

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

neutralsad:(:(