Swisslinux.org

− Le carrefour GNU/Linux en Suisse −

 

Langue

 

Punbb new RSS script

Idea

The goal of this rewrite was to get a RSS fedd with the 15 last posts, with the content of the message, to allow user to read the entire forum from a RSS Reader. This script use the image from the icons hack.

License

According to the license of punbb the following idea and code are subject to the GPL.

See the result in live

How to use this script

Edit extern.php, and write put between :

	// Should we output this as RSS?
... and 
	// Output regular HTML 

those lines :

// ***** BEGIN rewritten by fbianco for Swisslinux.org *****//
	if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS')
	{
		$rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc New'];
		$url_action = ($_GET['action'] == 'active') ? '&action=new' : '';
 
		// Send header rss+xml, encoding and no cache
		header('Content-Type: application/rss+xml; charset=UTF-8');
		header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: public');
 
		// It's time for some syndication! rss 2.0 valid output !
		echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\r\n";
		echo '<rss version="2.0">'."\r\n";
		echo '<channel>'."\r\n";
		echo "\t".'<title>'.pun_htmlspecialchars($pun_config['o_board_title']).'</title>'."\r\n";
		echo "\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n";
		echo "\t".'<description>'.pun_htmlspecialchars($rss_description.' '.$pun_config['o_board_title']).'</description>'."\r\n";
		echo "\t".'<language>en-us</language>'."\r\n";
 
		// *** Added for Swisslinux.org ***** //
		echo "\t".'<image>'."\r\n";
		echo "\t\t".'<url>http://static.swisslinux.org/images/logo.png</url>'."\r\n";
		echo "\t\t".'<title>Swisslinux.org\'s Logo</title>'."\r\n";
		echo "\t\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n";
		echo "\t".'</image>'."\r\n";
 
		// get the 15 newest post, and other usefull stuff
		$result = $db->query('
SELECT t.id, p.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name, p.id AS pid, p.message, fi.icon
FROM
'.$db->prefix.'posts AS p
LEFT JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id
INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id
LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3)
LEFT JOIN '.$db->prefix.'forum_icon AS fi ON fi.forum_id=f.id
WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY p.posted DESC LIMIT 15
') or error('Unable to fetch post list', __FILE__, __LINE__, $db->error());
 
		// we want to be able to parse the message
		include('include/parser.php');
 
		// let's write the items
		while ($cur_topic = $db->fetch_assoc($result))
		{
			if ($pun_config['o_censoring'] == '1') {
				$cur_topic['subject'] = censor_words($cur_topic['subject']);
				$cur_topic['message'] = censor_words($cur_topic['message']);
				}
 
			echo "\t".'<item>'."\r\n";
			echo "\t\t".'<title>'.pun_htmlspecialchars($cur_topic['subject']).'</title>'."\r\n";
			echo "\t\t".'<link>'.$pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_topic['pid'].'#p'.$cur_topic['pid'].'</link>'."\r\n";
			echo "\t\t".'<description><![CDATA['.escape_cdata($lang_common['Forum']).':'."\r\n";
 			echo "\t\t\t".escape_cdata('<img src="'.$pun_config['o_base_url'].'/img/icons/'.$cur_topic['icon'].'" alt="'.$cur_topic['icon'].'" />'."\r\n");
			echo "\t\t\t".escape_cdata('<a href="'.$pun_config['o_base_url'].'/viewforum.php?id='.$cur_topic['fid'].'">'.$cur_topic['forum_name'].'</a><br />'."\r\n".$lang_common['Author'].': '.$cur_topic['poster'].'<br />'."\r\n".$lang_common['Posted'].': '.date('r', $cur_topic['last_post'])."\r\n");
 			echo "\t\t\t".'<br />'."\r\n";
			echo escape_cdata(parse_message($cur_topic['message'],FALSE));
			echo ']]>'."\r\n"."\t\t".'</description>'."\r\n";
			echo "\t\t".escape_cdata('<guid>'.$pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_topic['pid'].'#p'.$cur_topic['pid'].'</guid>'."\r\n");
			echo "\t".'</item>'."\r\n";
		}
 
		echo '</channel>'."\r\n";
		echo '</rss>';
	}
 
// ***** END rewritten by fbianco for Swisslinux.org *****//

Do not forget to edit the part of the script after :

// *** Added for Swisslinux.org ***** //

else you will get the Swisslinux.org's logo on your rss feed.

Powered by Dokuwiki - fr/association/projets/siteweb/punbb/rss.txt · Dernière modification: 2011/07/18 08:44 (modification externe)