[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
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 »

Ah, ok.
I briefly tried the Inline attachment thing on my board, the picture didn't show at all like it does in your board.
Disabled attachment right away again, don't want the users to spam my storage space, most board do not allow attachment, as you say.
This means I'm not able to further test your issue sofar.
cz777cooper
Registered User
Posts: 4
Joined: Sat Jul 12, 2008 1:59 pm
Location: Czech republic
Contact:

Re: [BETA] simple syndication

Post by cz777cooper »

Still have problems, can't validate. I have phpBB 3.0.2 and MOD simple syndication v 1.1.1h (from here)at http://lota.regionaliste.cz/syndication.php and feed is not valid. FeedReader can reed it, but any other no.
This feed does not validate.
line 1, column 4: XML parsing error: <unknown>:1:4: xml declaration not at start of external entity [help]

<?xml version="1.0" encoding="UTF-8"?>
^
by http://feedvalidator.org/check.cgi?url= ... cation.php. Please help? Thanks
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 »

Your whole site seems to be down.
Re-check your syndication.php, syndication_atom.xml and syndication_rss2.xml files and make sure they do NOT start with a space or blank line.
I suggest to use version 1.1.1g for now, as the 1.1.1h version seems to have some issues:
http://www.phpbb.com/community/viewtopi ... 0#p4308685
XXREEFER
Registered User
Posts: 10
Joined: Wed May 31, 2006 8:30 pm

Re: [BETA] simple syndication

Post by XXREEFER »

Got it installed and VERY happy with this mod :!:
XXREEFER
Registered User
Posts: 10
Joined: Wed May 31, 2006 8:30 pm

Re: [BETA] simple syndication

Post by XXREEFER »

Noticed today - on the BlackBerry Feedreader - that the Topic poster is missing from the output, do not know wether thats on purpose but I would like to be able to see who made a certain post ?

[Edit] The poster is only missing on the BB, looking op PC they are there in small fonts
franziski
Registered User
Posts: 2
Joined: Sat Aug 16, 2008 7:45 pm

Re: [BETA] simple syndication

Post by franziski »

I have using successfully this simple - but great!!! - mod.

I am very satisfied...only was wondering how I can truncate the post text to a number of lines - like happens for the announcements.

Thanks in advance e thanks for this great mod.
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 »

XXREEFER:
Thew way the contents of the feed are displayed depends on the feed reader program.
As you noticed, the BB seems to skip the author name, so does Firefox.
In IE7 the author is indeed displayed in lowercase gray text.
With the Firefox addon Newsfox you can select to the display the author in a separate column.

Franziski:
I have not figured out how to do that, the syndicator I used with phpBB 2.0 did have that option.
Maybe we'll find out one day.
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 »

Truncating the number of characters for the posts shown in the feed seems to be more difficult then I expected.
The original author made provisions for it by defining the $chars variable, which was not used in the syndicator, called like this: syndication.php?chars=100

The following modification to my version 1.1.1g partially works, change this:

Code: Select all

	  $row['post_subject'] = $subj_row['post_subject'];
   }

   $template->assign_block_vars('item', array(
To this:

Code: Select all

	  $row['post_subject'] = $subj_row['post_subject'];
   }

   if($chars > 0) {
      $row['post_text'] = ( strlen($row['post_text']) > $chars ) ? substr($row['post_text'], 0, ($chars - 4)) . ' ...' : $row['post_text'];
   }

   $template->assign_block_vars('item', array(
This works well for post with just text, without BBCode or smilies.
If the line contains BBCcode or smilies and gets cutoff in the middle of the code, it causes an invalid feed (it shows correct in IE7, but does not validate) :-(
Any suggestions to correct this are welcome.

[EDIT] The next post shows a 1.1.1i version that seems to make the "chars" parameter to work and validate properly.
Last edited by wouterv on Mon Sep 01, 2008 8:56 pm, edited 1 time in total.
wouterv
Registered User
Posts: 265
Joined: Wed Jan 02, 2008 10:22 am
Location: The Netherlands
Name: Wouter

Re: [BETA] simple syndication 1.1.1i

Post by wouterv »

Parameter "chars" is enabled.
[EDIT] Little update made for chars < 3

Changes as made for the 1.1.1h version(http://www.phpbb.com/community/viewtopi ... 0#p5994075) are NOT incorporated, due to the bug reported (http://www.phpbb.com/community/viewtopi ... 0#p6193915).
This 1.1.1i version is build on the 1.1.1g version (http://www.phpbb.com/community/viewtopi ... 0#p4308685).

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.

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

syndication.php 1.1.1i:

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-01 - Version 1.1.1i
*
*/

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

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


$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'];
	}

	$template->assign_block_vars('item', array(
		'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']),
		)
	);
}

$template->assign_var('FEED_LINK', generate_board_url(TRUE) . $_SERVER['SCRIPT_NAME'] . "?" . htmlspecialchars($_SERVER['QUERY_STRING']));

if ($type == 'atom')
{
	$content_type = 'application/atom+xml';
	$tpl = 'atom';
}
else
{
	$content_type = 'application/rss+xml';
	$tpl = 'rss2';
}

$template->set_filenames(array(
	'body' => 'syndication_' . $tpl . '.xml')
);

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

$template->assign_vars(array(
	'HEADER' => '<?xml version="1.0" encoding="UTF-8"?>' . "\n", // workaround for remove_php_tags() removing this line from the template
	'TITLE' => strip_tags($config['sitename']),
	'DESCRIPTION' => strip_tags($config['site_desc']),
	'LINK' => $board_url,
	'LAST_BUILD' => format_date($last_build_date)
	)
);

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

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

//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
//header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
//header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.1
//header("Pragma: no-cache"); // HTTP/1.0

$template->display('body');
exit;
?>
The modified "syndication_rss2.xml" template for proper validation:

Code: Select all

{HEADER}
<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>{TITLE}</title>
		<description>{DESCRIPTION}</description>
		<link>{LINK}</link>
		<lastBuildDate>{LAST_BUILD}</lastBuildDate>
		<!-- BEGIN item -->
		<item>
			<dc:creator>{item.AUTHOR}</dc:creator>
			<pubDate>{item.TIME}</pubDate>
			<guid>{item.IDENTIFIER}</guid>
			<link>{item.LINK}</link>
			<title>{item.TITLE}</title>
			<description>{item.TEXT}</description>
		</item>
		<!-- END item -->
	</channel>
</rss>
To refresh the Template if you replaced the original one:
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).

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
Last edited by wouterv on Wed Sep 10, 2008 5:18 am, edited 3 times in total.
cesare2008
Registered User
Posts: 22
Joined: Thu Sep 04, 2008 8:40 am

Re: [BETA] simple syndication

Post by cesare2008 »

Hi,
First of all thanks for your supreme work - I really like your mod. Unfortunately I have still one problem:

On my safari (leopard; macbook pro, built-in rss-reader) it actually duplicates the same entry multiple times (3x) after a while. Otherwise the rss reader in safari works fine.

If I read the created rss feed with the google reader or another online reader (e.g. bloglines) everything is fine.

whats the matter? do you have a clue?

P.S. This is the URL in case you want to check it out:
[url]feed://forum.naturheilpraxis-gehrig.ch/syndication.php?type=rss[/url]

and a screenshot:
http://www.naturheilpraxis-gehrig.ch/screenshot.png

cheers,
cesare
yakafaucon
Registered User
Posts: 7
Joined: Sun Sep 07, 2008 10:30 pm

Re: [BETA] simple syndication

Post by yakafaucon »

HI,
I'm writing you from France, Grenoble where I'm one of the admin of gf38.net a soccer fan forum.

I tried your syndication mod and adopted it. Great job guy !
The Easiest mod in the phbb community.

I would like to had a time filter: I don't want to display the 10 last posts but also the posts sent during the last 20 minutes for example but with a limit (ie : syndicate the 20 last posts during the 20 last minutes). Liek that, I don't have too many items in the syndication file.

Do U think it's hard to do ? Maybe this also exists ?

Thanx for your reply.

Chris.
Skywalker1970
Registered User
Posts: 7
Joined: Mon Sep 08, 2008 11:56 am

Re: [BETA] simple syndication

Post by Skywalker1970 »

Hi,

I'm from germany and my english is not so good, but I hope, you understand me.
I'm a Mac user and I use Firefox 3.0.1 and Safari 3.1.2 here.
phpBB 3.0.2 is install on my webserver.

I use Syndication 1.1.1g without problems.
Now I install Syndication 1.1.1i and I delete the cache from phpBB3.

Safari works with now with new version of Syndication, but Firefox has a problem:
When I choose the rss or atom feed on my website now, Firefox open the "Save" dialog and will save the syndication.php. Firefox does't display the RSS feed.
Syndication 1.1.1g works but Syndication 1.1.1i not.
Why not?

Greetings, Bernd
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 »

cesare2008:
You seems to use an older version syndication.php or did not update the syndication_rss2.xml" template.
Please check and install the latest 1.1.1i version.

yakafaucon:
When I have time I will look into it.

Skywalker1970:
Make sure the .php files do not start with spaces or blanks!
Skywalker1970
Registered User
Posts: 7
Joined: Mon Sep 08, 2008 11:56 am

Re: [BETA] simple syndication

Post by Skywalker1970 »

wouterv wrote: Skywalker1970:
Make sure the .php files do not start with spaces or blanks!
Hm, that's not the solution.
The problem is the same.

You can test it here:
My forum

Atom Feed works in Firefox but RSS feed doesn't work.
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 »

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.
Locked

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