1

Topic: RSS 2.0 export of latest POSTS (not topics)

here it goes, only for MySQL though:

<?php

/***********************************************************************

  Copyright (C) 2004  Radek HULAN (http://hulan.info/)

  This file is part of PunBB.

************************************************************************/

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

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

// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);

// Attempt to load the common language file
@include $pun_root.'lang/'.$language.'/'.$language.'_common.php';
if (!isset($lang_common)) exit('There is no valid language pack \''.$language.'\' installed.');

// Load the functions and parser 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 have permission to read the forums
if ($pun_config['p_guests_read'] == '0') exit('No permission');


// parse RSS
ob_start();

// make feed
putHeader();
$result = mysql_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,20"
                      );
while ($row = mysql_fetch_object($result)) putPost($row);
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;
}


function encode_xml($data){
  return strip_tags(str_replace('</p>',"\n",str_replace('<br />',"\n",$data)));
}

function putHeader()
{   
    global $lang_common,$pun_config;
      echo '<'.'?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?'.'>'."\n";
    echo "<rss version=\"2.0\">\n";
    echo "<channel>\n";
    echo "<title>".pun_htmlspecialchars($pun_config['o_board_title'])."</title>\n";
    echo "<link>".$pun_config['o_base_url']."</link>\n";
    echo "<description>".pun_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($post) {
    global $pun_config;
    echo "<item>\n";
    echo "<title>".encode_xml($post->subject)."</title>\n";
    $link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($post->id).'#'.strval($post->id);
    echo "<link>".encode_xml($link)."</link>\n";
    $data = "<![CDATA[Topic: ".parse_message($post->subject,0)."<br /><br />Message: ".parse_message($post->message,0)."<br /><br />Link: <a href='$link'>$link</a>]]>";
    echo "<description>".$data."</description>\n";
    echo "<pubDate>".strval(date("r",$post->postposted))."</pubDate>\n";
    echo "</item>\n";
}


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


?>

2

Re: RSS 2.0 export of latest POSTS (not topics)

example's here:

http://forum.blogcms.com/rss.php

3

Re: RSS 2.0 export of latest POSTS (not topics)

how to make it work with user groups 1.2 mod?

it is showing all messages even if i close forum for special gorup!

can you check it please for me?

4

Re: RSS 2.0 export of latest POSTS (not topics)

Rado how to make it works only with selected forums?

i suppose i need to add topics.forum_id somewhere but i don't know how!

5

Re: RSS 2.0 export of latest POSTS (not topics)

how to show username like Author: Blah ?

it's just me...

6

Re: RSS 2.0 export of latest POSTS (not topics)

do you place this in extern.php? just wondering