[MODDB] simple syndication

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Get Involved
Skywalker1970
Registered User
Posts: 7
Joined: Mon Sep 08, 2008 11:56 am

Re: [BETA] simple syndication

Post by Skywalker1970 »

wouterv wrote:Your "syndication_rss2.xml" template file start wrong:
Make sure it starts like this:
{HEADER}
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
...

Yours seems to start with the file name.
Oh no, that is my fault.
I remove te file name at the start and now works with Firefox.
Thanx.
Last edited by Skywalker1970 on Tue Sep 09, 2008 5:35 am, edited 1 time in total.
cesare2008
Registered User
Posts: 22
Joined: Thu Sep 04, 2008 8:40 am

Re: [BETA] simple syndication

Post by cesare2008 »

Thanks a lot Wouter - you are the best! Didn't notice that there was a new version.

I validated the feed with http://feedvalidator.org - the feed is actually a VALID RSS feed. I just wanted to let you know about one warning that was displayed:

Code: Select all

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

line 168, column 3: Missing atom:link with rel="self" [help]

			</channel>
Thanks a lot again.
Cheers,
Cesare
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication

Post by wouterv »

It seems to be that you have not updated the "syndication_rss2.xml" template.
See the post with the 1.1.1i version.
yakafaucon
Registered User
Posts: 7
Joined: Sun Sep 07, 2008 10:30 pm

Re: [BETA] simple syndication

Post by yakafaucon »

I modified th etemplate file too, and did not succeed in refresh it when I refreshed the cache
What's going wrong ?
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication

Post by wouterv »

Did you do both steps:
To refresh the Template if you replaced the original one:
1) In the ACP: General>Purge cache
2) Open in MySQL the "phpbb_styles_template_data" table, browse to and remove the "syndication_rss2.xml" lines (one line for each style you applied this Mod to).

1 is in the Administration panel.
2 Is in MySQL.
yakafaucon
Registered User
Posts: 7
Joined: Sun Sep 07, 2008 10:30 pm

Re: [BETA] simple syndication

Post by yakafaucon »

thanks.

I refreshed only the template in the ACP/styles menus and didn't see this in the main ACP menu.
Artack
Registered User
Posts: 312
Joined: Thu Feb 07, 2008 11:26 pm

Re: [BETA] simple syndication

Post by Artack »

Same situation

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
line 6, column 99: Self reference doesn't match document location [help]

No any changes in code
Purge cache many times
No lines in "phpbb_styles_template_data" table, nothing to be removed there
Any Ideas?

Best Regards
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication

Post by wouterv »

Same answer:

Download and install the modified "syndication_rss2.xml" template found here:
http://www.phpbb.com/community/viewtopi ... 5#p6870075
Refresh the cache as follows:
1) In the ACP: General>Purge the cache
2) Open in MySQL the "phpbb_styles_template_data" table, browse to and remove each "syndication_rss2.xml" line (one line for each style you applied this Mod to).
3) Refresh the webfeed page in your browser
Artack
Registered User
Posts: 312
Joined: Thu Feb 07, 2008 11:26 pm

Re: [BETA] simple syndication

Post by Artack »

wouterv wrote:2) Open in MySQL the "phpbb_styles_template_data" table, browse to and remove each "syndication_rss2.xml" line (one line for each style you applied this Mod to).
Artack wrote:No lines in "phpbb_styles_template_data" table, nothing to be removed there
database sreen
Image

Regards
Artack
Registered User
Posts: 312
Joined: Thu Feb 07, 2008 11:26 pm

Re: [BETA] simple syndication

Post by Artack »

You can make addon for viewonline

open language/en/common.php
FIND

Code: Select all

	'RETURN_TO'
AFTER ADD

Code: Select all

	'RSS'						=> 'Viewing RSS Feed',
open viewonline.php
FIND

Code: Select all

		case 'report':
			$location = $user->lang['REPORTING_POST'];
			$location_url = append_sid("{$phpbb_root_path}index.$phpEx");
		break;
AFTER ADD

Code: Select all

		case 'syndication':
			$location = $user->lang['RSS'];
			$location_url = append_sid("{$phpbb_root_path}syndication.$phpEx");
		break;
Please, test it
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication 1.1.2a

Post by wouterv »

Here is another update of this MOD.
It no longer requires the separate template files, thus no bothering with refresh after updates and no need to update multiple or new styles if any.
It is based on the 1.1.1i version and seems to produce equal code, with proper validation.

I have called it the 1.1.2a version due to the major difference with previous versions.
[EDIT] 13-09-2008: little update for post links in ATOM format.
[EDIT] 19-09-2008: some cleanup of the code (no program changes)
[EDIT] 20-09-2008: too much cleanup...back to the previous code

Valid parameters:
chars=[number] - number of characters per post, HTML and BBCode tags get stripped: syndication.php?chars=200
count=[number] - number of most recent posts: syndication.php?count=3
fid=[number1,numberX] - forum id, multiple id's separated by a comma: syndication.php?fid=32,50
t=1 - first post of topics only: syndication.php?t=1
type=atom - Atom format: syndication.php?type=atom
type=rss - RSS format: syndication.php?type=rss

You can also combine parameters: syndication.php?type=atom&count=3
The default without parameters results in: RSS format and all contents of the 20 most recent posts of all forums.

syndication.php 1.1.2a:

Code: Select all

<?php
/*
*
* @package phpBB3
* @version $Id: syndication.php,v 1.0 2006/11/27 22:29:16 angelside Exp $
* Modified by CK for holographyforum.org
* @copyright (c) Canver Software
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* Updated by several people: 2008-09-13 - Version 1.1.2a
*
*/

/**
*/
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Begin configuration
$CFG['exclude_forums'] = '';
$CFG['max_topics'] = '20';
// End configuration

// Requests
$fid = request_var('fid', '');
$count = request_var('count', 0);
$chars = request_var('chars', 0);
$type = request_var('type', '');
$topics_only = request_var('t', '');

// If not set, set the output count to max_topics
$count = ($count == 0) ? $CFG['max_topics'] : $count;

// Maximum text char limit
if ($chars <0 || $chars > 500)
	$chars = 500; //Maximum

// Generate url
$board_url = generate_board_url();
$index_url = $board_url . '/index.' . $phpEx;
$viewtopic_url = $board_url . '/viewtopic.' . $phpEx;

// ==========================================================================================================================

function codebox($preg)
{
	return $preg[2];
}

// ==========================================================================================================================

function parse_message($row, $bbcode_options, $bbcode_uid, $bbcode_bitfield)
{
	global $board_url, $type;

	$row = generate_text_for_display($row, $bbcode_uid, $bbcode_bitfield, $bbcode_options);
	$row = preg_replace_callback("/\<dt\>(.*?)\<\/dt\>\<dd\>\<code\>(.*?)\<\/code\>\<\/dd\>/si", "codebox", $row);
	$row = str_replace('<img src="./', '<img src="' . $board_url . '/', $row);

	if ($type == 'atom')
	{
		$row = str_replace("&nbsp;", " ", $row);
	}
	else
	{
		$row = str_replace("\n", "\n<br />\n", $row); // Do NOT user nl2br
		$row = htmlspecialchars($row);
	}

	return $row;
}

// ==========================================================================================================================

// Create a date according to correct RFC standard
function format_date($timestamp)
{
   global $type;

	if ($type == 'atom')
		return date('Y-m-d\TH:i:s\Z', $timestamp); // RFC 3339 for ATOM
	else
		return date('D, d M Y H:i:s O', $timestamp); // RFC 822 for RSS2
}

// ==========================================================================================================================

// Compile the feed link
$feed_link = (generate_board_url(TRUE) . $_SERVER['SCRIPT_NAME'] . "?" . htmlspecialchars($_SERVER['QUERY_STRING']));

// Get time, use current time
$last_build_date = mktime();

// Common feed header part
$rdf = '';
$rdf .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

if ($type == 'atom')
{
	// ATOM feed header part
	$rdf .= "
	<feed xmlns=\"http://www.w3.org/2005/Atom\">
	<title>".strip_tags($config['sitename'])."</title>
	<subtitle>".strip_tags($config['site_desc'])."</subtitle>
	<link href=\"$board_url\" />
	<updated>".format_date($last_build_date)."</updated>
	<id>$board_url</id>
	<link rel=\"self\" href=\"$feed_link\" />";
}
else
{
	// RSS feed header part
	$rdf .= "<rss version=\"2.0\"
	xmlns:atom=\"http://www.w3.org/2005/Atom\"
	xmlns:dc=\"http://purl.org/dc/elements/1.1/\">
		<channel>
			<atom:link href=\"$feed_link\" rel=\"self\" type=\"application/rss+xml\" />
			<title>".strip_tags($config['sitename'])."</title>
			<description>".strip_tags($config['site_desc'])."</description>
			<link>$board_url</link>
			<lastBuildDate>".format_date($last_build_date)."</lastBuildDate>";
}

$sql_where = '';

// Only topic first post
if ($topics_only == 1)
{
	$sql_where = 'AND p.post_id = t.topic_first_post_id';
	$sql_from = 'FROM ' . POSTS_TABLE . ' as p, ' . FORUMS_TABLE . ' as f, ' . USERS_TABLE . ' as u, ' . TOPICS_TABLE . ' as t';
}
else
{
	$sql_from = 'FROM ' . POSTS_TABLE . ' as p, ' . FORUMS_TABLE . ' as f, ' . USERS_TABLE . ' as u';
}

// Exclude forums
if ($CFG['exclude_forums'])
{
	$exclude_forums = explode(',', $CFG['exclude_forums']);
	foreach ($exclude_forums as $i => $id)
	{
		if ($id > 0)
		{
			 $sql_where .= ' AND p.forum_id != ' . trim($id);
		}
	}
}

if ($fid != '')
{
	$select_forums = explode(',', $fid);
	$sql_where .= ( sizeof($select_forums)>0 ) ? ' AND f.forum_id IN (' . $fid . ')' : '';
}

// SQL posts table
$sql = 'SELECT p.post_id, p.poster_id, p.post_subject, p.post_text, p.bbcode_uid, p.bbcode_bitfield, p.topic_id, p.forum_id, p.post_time, f.forum_name, f.forum_desc_options, u.username
	' . $sql_from . '
	WHERE (u.user_id = p.poster_id)
	AND p.post_approved = 1
	AND (f.forum_id = p.forum_id)
	' . $sql_where . '
	ORDER BY post_time DESC';
$result = $db->sql_query_limit($sql, $count);

while( ($row = $db->sql_fetchrow($result)) )
{

	if (!$auth->acl_get('f_list', $row['forum_id']))
	{
		// if the user does not have permissions to list this forum, skip everything until next branch
		continue;
	}

	if (empty($row['post_subject']))
	{
		$subj_sql = 'SELECT p.post_subject
		FROM ' . POSTS_TABLE . ' as p, ' . TOPICS_TABLE . ' as t
		WHERE (p.topic_id = '.$row['topic_id'] .')
		AND p.post_id = t.topic_first_post_id';

		$subj_result = $db->sql_query($subj_sql);
		$subj_row = $db->sql_fetchrow($subj_result);
		$row['post_subject'] = $subj_row['post_subject'];
	}

	if($chars > 0)
	{
		if ($chars <3)
			$chars = 3;
		strip_tags($row['post_text']);
		strip_bbcode($row['post_text']);
		$row['post_text'] = ( strlen($row['post_text']) > $chars ) ? substr($row['post_text'], 0, ($chars - 3)) . '&#8230;' : $row['post_text'];
	}

	// Define feed items
	$AUTHOR = $row['username'];
	$TIME = format_date($row['post_time']);
	$LINK = "$board_url/viewtopic.$phpEx" ."?". 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']."&p=".$row['post_id']."#p".$row['post_id'];
	$IDENTIFIER = "$board_url/viewtopic.$phpEx" ."?". 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']."&p=".$row['post_id']."#p".$row['post_id'];
	$TITLE = $row['post_subject'];
	$TEXT = parse_message($row['post_text'], $row['forum_desc_options'], $row['bbcode_uid'], $row['bbcode_bitfield']);

	if ($type == 'atom')
	{
		// ATOM feed items
		$rdf .= "
		<entry>
			<title>$TITLE</title>
			<link href=\"$LINK\"/>
			<id>$IDENTIFIER</id>
			<author>
				<name>$AUTHOR</name>
			</author>
			<published>$TIME</published>
			<updated>$TIME</updated>
			<summary type=\"xhtml\">
				<div xmlns=\"http://www.w3.org/1999/xhtml\">$TEXT</div>
			</summary>
		</entry>";
	}
	else
	{
		// RSS feed items
		$rdf .= "
			<item>
				<dc:creator>$AUTHOR</dc:creator>
				<pubDate>$TIME</pubDate>
				<guid>$IDENTIFIER</guid>
				<link>$LINK</link>
				<title>$TITLE</title>
				<description>$TEXT</description>
			</item>";
	}

}

// Gzip compression
if ($config['gzip_compress'])
{
	if (@extension_loaded('zlib') && !headers_sent())
	{
		ob_start('ob_gzhandler');
	}
}

if ($type == 'atom')
{
	// ATOM feed footer
	$rdf .= "
	</feed>";

	$content_type = 'application/atom+xml';
}
else
{
	// RSS feed footer
	$rdf .= "
		</channel>
	</rss>";

	$content_type = 'application/rss+xml';
}

header ('Content-Type: ' . $content_type . '; charset=UTF-8');

// Output the feed
echo($rdf);
?>
The original file name is "syndication.php". You can name it anything you like (with extension .php) without changes in the code, e.g. to be compatible with previous syndicators.

When copy/paste the code, remove the additional spaces that may be added at the start of the file.

Again: the "syndication_atom.xml" and "syndication_rss2.xml" tempate files are no longer required, just this file in your phpBB root.

Mod History:

2006-12-03 - Version 1.0.0a
first release

2007-01-01 - Version 1.0.1b
re-integrate exclude forums via variable in the header of the file rewrite the sql query hopefully forumspermission will work now add optional parameter to the script count and fid

2007-05-22 - Version 1.0.2b
phpBB3 RC1 test and changes
clean codes

2007-06-08 - Version 1.1.0b
rename mod to "simple syndication" from "simple RSS"
complate rewrite code/function
add rss/atom output
add rss/atom template

2007-06-20 - Version 1.1.1b
fix minor error
add new parameter for show topic only first post

2008-01-15 - Version 1.1.1c
Many fixes by different authors
Validation problems solved, need updated template: syndication_rss2.xml

2008-01-16 - Version 1.1.1d
Corrections to rss or atom type settings

2008-01-17 - Version 1.1.1e
Multiple parameter problem solved

2008-01-17 - Version 1.1.1f
Post without title problem fixed

2008-02-14 - Version 1.1.1g
Smilies fixed again

2008-06-29 - Version 1.1.1h
Suggested fix for showing inline attachments, a bug in this version with sid's is reported 14-07-2008

2008-09-01 - Version 1.1.1i
Truncate posts fixed with chars parameter, build on 1.1.1g

2008-09-13 - Version 1.1.2a
syndication_atom.xml and syndication_rss2.xml template files combined with the main file (templates no longer required)
Last edited by wouterv on Tue Sep 23, 2008 4:00 pm, edited 15 times in total.
Artack
Registered User
Posts: 312
Joined: Thu Feb 07, 2008 11:26 pm

Re: [BETA] simple syndication

Post by Artack »

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

line 5, column 108: Self reference doesn't match document location [help]

... rel="self" type="application/rss+xml" /> ^
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication

Post by wouterv »

Artack, things are mixing up now...

1)Validation problem
Which version of syndication.php are you using?
What feed type (RSS or ATOM) and does validation fail for both?
With the feed (even with the error message) called, right click and select "view source" (or what ever it is called in IE or FF), look at what code is generated at the indicated line and column.
What is the link to your webfeed, so others can have a look and try to help?

2)What is your intention with the "viewonline" suggestion, what is it supposed to do?
Artack
Registered User
Posts: 312
Joined: Thu Feb 07, 2008 11:26 pm

Re: [BETA] simple syndication

Post by Artack »

version 1.1.2a
url of my board send PM
2)What is your intention with the "viewonline" suggestion, what is it supposed to do?
it's showing users viewing RSS, when you click WHO IS ONLINE )
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication

Post by wouterv »

Artack:

If the root of your phpBB is really the root of your domain, try to hardcode the location in your syndication.php:

Find:

Code: Select all

$feed_link = (generate_board_url(TRUE) . $_SERVER['SCRIPT_NAME'] . "?" . htmlspecialchars($_SERVER['QUERY_STRING']));

Replace with:

Code: Select all

$feed_link = ("http://yourdomain.xx/syndication.php" . "?" . htmlspecialchars($_SERVER['QUERY_STRING']));
I still believe your phpBB files are not stored directly in the root of your domain, it looks like they are stored here: .../cgi-bin/php5
Locked

Return to “[3.0.x] MODs in Development”