Extension talk:SimpleFeed

Latest comment: 3 years ago by P1ayer in topic Fix to MediaWiki 1.35.1 Support

Setting char limits edit

Hi, I've modified the extension in order to set a limit of chars displayed in the description field.

<?php
/* 
* SimpleFeed MediaWiki extension
* 
* Copyright (C) 2007-2008 Jonny Lamb <jonnylamb@jonnylamb.com>
* 
* 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. See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
* 
* Last modified: Isaac Contreras - fladei
* 		4 October 2011
* Added:	Line 96 to get the limit of maximum chars
* 		Line 126 to cut the Description string to accomplish the limit of maximum chars
*/

// Check to make sure we're actually in MediaWiki.
if (!defined('MEDIAWIKI'))
{
	echo 'This file is part of MediaWiki. It is not a valid entry point.';
	exit(1);
}

// Path to simplepie.inc (including leading slash).
$simplepie_path = './extensions/SimpleFeed/';

// Path to SimplePie cache folder (excluding leader slash).
// Defaults to "./extensions/cache"
$simplepie_cache_folder = $simplepie_path . 'cache/';

if ( ! @include($simplepie_path.'simplepie.inc') )
{
	define('SIMPLEPIE_NOT_FOUND', true);
}

$wgExtensionFunctions[] = 'wfSimpleFeed';
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'SimpleFeed',
	'description' => 'Uses SimplePie to output RSS/atom feeds',
	'author' => 'Jonny Lamb',
	'url' => 'http://www.mediawiki.org/wiki/Extension:SimpleFeed'
);

function wfSimpleFeed()
{
	global $wgParser;
	$wgParser->setHook('feed', 'parseFeed');
}

//function parseFeed($input, $args, &$parser)
function parseFeed($input, $args, $parser)
{
	global $simplepie_cache_folder;

	// Disable page caching.
	$parser->disableCache();
	
	// Check to see whether SimplePie was actually included.
	if (defined('SIMPLEPIE_NOT_FOUND'))
	{
		return '<strong>Error</strong>: <code>simplepie.inc</code> was not found in the path. Please edit the path (beginning of extensions/SimpleFeed.php) or add <code>simplefeed.inc</code> to the current path.';
	}
	
	// Must have a feed URL and a template to go by outputting items.
	if (!isset($args['url']) or !isset($input))
	{
		return 0;
	}

	$feed = new SimplePie();
	$feed->set_cache_location($simplepie_cache_folder);

	$feed->set_feed_url($args['url']);

	// Get the feed information!
	$feed->init();

	$feed->handle_content_type();

	// Either use default date format (j F Y), or the $date(string) argument.
	// The date argument should conform to PHP's date function, nicely documented
	// at http://php.net/date.
	$date = (isset($args['date'])) ? $args['date'] : 'j F Y';
	
	$limit = (isset($args['limit'])) ? $args['limit'] : '100';
	
	$output = '';

	// Use the $entries(int) argument to determine how many entries to show.
	// Defaults to 5, and 0 is unlimited.
	if (isset($args['entries']))
	{
		$max = ($args['entries'] == 0) ? $feed->get_item_quantity() : $feed->get_item_quantity($args['entries']);
	}
	else
	{
		$max = $feed->get_item_quantity(5);
	}
	
	// Loop through each item.
	for ($i = 0; $i < $max; $i++)
	{
		$item = $feed->get_item($i);

		$itemwikitext = $input;

		// {PERMALINK} -> Link to the URL of the post.
		$itemwikitext = str_replace('{PERMALINK}', $item->get_permalink(), $itemwikitext);
		//echo "Link: ".$itemwikitext;
		// {DATE} -> The posting date of the post, formatted in the aforementioned way.
		$itemwikitext = str_replace('{DATE}', $item->get_date($date), $itemwikitext);

		// {DESCRIPTION} -> The actual post (or post description if there's a tear).
		$itemwikitext = str_replace('{DESCRIPTION}', substr($item->get_description(), 0, $limit).'...', $itemwikitext);
		
		// If $type="planet" is used, the author is got from the post title.
		// e.g. title = "Joe Bloggs: I love Mediawiki"
		// This will make: {AUTHOR} -> "Joe Bloggs"
		//                 {TITLE} -> "I love Mediawiki"
		// If this is not set however, the title and author are received the usual way.
		if ($args['type'] == 'planet')
		{
			$title = preg_replace('/(.*): (.*)/sU', '\\2', $item->get_title());
			preg_match('/(.+?): (.+)/sU', $item->get_title(), $matches);
			$author = $matches[1];
		}
		else
		{
			$title = $item->get_title();
			// Often the author is hard to recieve. Maybe it's not a very important
			// thing to output into RSS...?
			$itemauthor = $item->get_author();
			$author = ($itemauthor != null) ? $itemauthor->get_name() : '';
		}
		
		// {TITLE} -> Title of the post.
		$itemwikitext = str_replace('{TITLE}', $title, $itemwikitext);
		
		// {AUTHOR} -> Author of the post.
		$itemwikitext = str_replace('{AUTHOR}', $author, $itemwikitext);

		// Add to the overall output the post just done.
		$output .= $itemwikitext;
	}

	// Parse the text into HTML between the <feed>[...]</feed> tags, with arguments replaced.
	$parserObject = $parser->parse($output, $parser->mTitle, $parser->mOptions, false, false);
	
	// Output formatted text.
	return $parserObject->getText();
}

?>

The new param is limit, and you should be able to use it by entering

<feed url="http://myfeed.com" entries=3 type="planet" limit=150>
*[{PERMALINK} {TITLE}]
{DESCRIPTION}
</feed> 

Use at Wikigender(New Home) --Fladei 18:00, 06 October 2011 (UTC)Reply

Extension does not work with feeds generated by php-scripts edit

Hi, I have a problem it seems your extension does not work with feeds generated by php-scripts.
It does not show anything, only a blank page.
The URL of my RSS feed: http://galdom.portal-werner.de/e107_plugins/rss_menu/rss.php?1.2

Ditto. When I paste your BBC example into my page, I just get the same thing as the output. MatthewBurton 20:56, 7 April 2007 (UTC)Reply
This extension really does not work for me. Just crashes the page on which I try to include the <feed> tags. --128.233.100.42 23:40, 29 June 2007 (UTC)Reply
This is a big problem since there are many php generated feeds. Could this be fixed? — Preceding unsigned comment added by 68.127.150.121 (talkcontribs) 20:20, 23 July 2007
Try changing $feed->feed_url($args['url']); to $feed->set_feed_url($args['url']); — Preceding unsigned comment added by 75.197.172.18 (talkcontribs) 16:15, 8 October 2007

How to install edit

I couldn't make it work using the provided instructions either. This worked for me

  1. Save SimpleFeed.php to /extensions
  2. Save simplepie.inc to /extensions
  3. Create /extensions/cache. Set correct write permission (chmod). Webserver-user should be allowed to write.
  4. Add include("./extensions/SimpleFeed.php"); to LocalSettings.php. Last line works fine.
 Note: If you are in a corporate environment, check out any proxy servers or firewalls

SimplePie have their own extension for MediaWiki. I installed that first and the instructions are really good. However, you are not able to modify the layout as much as with SimpleFeed. — Preceding unsigned comment added by 194.19.86.146 (talkcontribs) 13:38, 16 April 2007 (UTC)Reply

Got errors when using

include("./extensions/SimpleFeed.php");

replace it with:

require_once("$IP/extensions/SimpleFeed.php");

helped. --sandb 15 Oct 2009

Right, same here, use "include" doesn't work. "require_once" does.

MediaWiki 1.10 Support edit

Anyone get this to work in MediaWiki 1.10? — Preceding unsigned comment added by 148.177.1.211 (talkcontribs) 16:10, 29 June 2007

Not Yet

I get

Fatal error: Call to undefined method SimplePie::feed_url() in /<my directory>/SimpleFeed.php on line 71

The other SimplePie extension does not work either.

Any help would be appreciated.

Mguentz 01:58, 13 August 2007 (UTC)Reply

See Extension:SimpleFeed#SimplePie_version_problem--Arcy 18:39, 7 November 2007 (UTC) That worked for me.Reply

Cache Directory edit

When installing, I had to put the cache directory in the root wiki folder, rather than extensions/. Anything else gave me an error. Seems that SimplePie looks there. Cheezerman 19:08, 11 December 2007 (UTC)Reply

No error for me, but also nothing in the cache folder. (Le Pubard)
I had to change something in simplepie.inc :
before : var $cache_location = './cache';
after : var $cache_location = 'extensions/cache';
— Preceding unsigned comment added by 82.224.189.221 (talkcontribs) 13:18, 6 January 2008

gzinflate() edit

I'm trying to use SimpleFeed with simplepie 1.1.1, php 5.1.1, and mediawiki 1.11

Whenever I load a page with <feed> it returns

Warning: gzinflate() [function.gzinflate]: data error in W:\www\wi\extensions\simplepie.inc on line 7743

Anyone had this issue before? — Preceding unsigned comment added by 202.173.151.202 (talkcontribs) 03:13, 30 March 2008

Howto use SimplePie Addons edit

Hi,

I tried to use one of the SimplePie Addons (i.e. http://simplepie.org/wiki/addons/yahoo_weather)

By adding

require_once('simplepie_yahoo_weather.inc');
[...]
$itemwikitext = str_replace('{WEATHER_CONDITION}', $weather->get_condition(), $itemwikitext);

I just get the error

Fatal error: Call to a member function get_condition() on a non-object in /is/htdocs/wp1064305_TTQI81XDD8/www/wiki/extensions/SimpleFeed.php on line 114

But isn't that definied in simplepie_yahoo_weather.inc? I'm using the file from Ryan [1] — Preceding unsigned comment added by Crazyelk (talkcontribs) 19:22, 7 April 2008

Get rid of PHP Notice errors edit

To get rid of PHP Notice errors ...

PHP Notice:  Undefined index:  type in /var/www/wiki/wk/extensions/SimpleFeed.php on line 117

... replace ...

if ($args['type'] == 'planet')

... in line 117 with ...

if (isset($args['type']) && $args['type'] == 'planet')

Ivan Pepelnjak 14:03, 6 May 2008 (UTC)Reply

Hello Jonny Lamb. I was not able to find any resource to contact you. Please include the patch from Ivan above.
Thank you --Mark Ziegler 08:28, 29 November 2010 (UTC)Reply

In reverse order edit

aug 28: I think there's a bug when displaying multiple feed-tags on one page. I made a page with feeds from various sources on a clean install and the Wiki is grinding to a halt after a few refreshes.

Hi,

This extension almost works fine but as for my Hungarian wiki, it publicate the feeds in reverse order. The latest news are below... :( What should I do? Thanks! 89.132.222.148 00:49, 22 August 2008 (UTC) (NetBandita)Reply

after some minutes....
Hmmm.... I have solved. :D In the simplepie.inc there is in the line of 515 the next 'var': var $order_by_date = false; You should change it from true to false. That's all. :)
(sorry for my grammar mistakes if...)89.132.222.148 00:56, 22 August 2008

https feeds edit

I had trouble using this extension with https-feeds. Turns out that the extension sends "ssl://$host" as the hostname in the Host header.

My ugly fix:

$ diff -u simplepie.inc simplepie.fixed.ssl.inc 
--- simplepie.inc	2008-11-17 16:20:04.000000000 +0100
+++ simplepie.fixed.ssl.inc	2008-11-17 16:20:41.000000000 +0100
@@ -7727,7 +7727,15 @@
 						$get = '/';
 					}
 					$out = "GET $get HTTP/1.0\r\n";
-					$out .= "Host: $url_parts[host]\r\n";
+					if (preg_match("/^ssl:\/\//", $url_parts[host]))
+					{
+					  $foo = preg_replace("/^ssl:\/\//", "", $url_parts[host]);
+					  $out .= "Host: $foo\r\n";
+					}
+					else
+					{
+					  $out .= "Host: $url_parts[host]\r\n";
+					}
					$out .= "User-Agent: $useragent\r\n";
					if (extension_loaded('zlib'))
					{

17 November 2008 — Preceding unsigned comment added by 193.15.99.110 (talkcontribs)

Firefox CSS issues in Mediawiki 1.14 edit

Is anyone else having issues with this extension and importing common.css, etc for Mediawiki 1.14? With my install it seems to be overriding things that should be content type of type/css and forcing type/html which ends up breaking the css import. Anyone else see this and know how to fix it? 16 April 2009 — Preceding unsigned comment added by 76.110.234.160 (talkcontribs)

Outputting HTML tags edit

I'm noticing that URLs within the {DESCRIPTION} area are being transcluded in full markup: e.g. <a href="mylink">link text</a> Can this be fixed in any way? Coldmachine 20:39, 20 May 2009 (UTC)Reply
I have the same problem. Any solution or advice,please? --Biris 10:53, 29 June 2009 (UTC)Reply

It can be fixed, or at least worked around. I added this line in SimpleFeed.php after $feed->set_feed_url($args['url']);

$feed->strip_htmltags(array_merge($feed->strip_htmltags, array('a', 'img')));

I'm sure someone else can make use of the tags instead of wiping them, but that's the best I can do. RotsiserMho 03:45, 29 January 2010 (UTC)Reply

cURL error 6: Couldn't resolve host 'http:' edit

If I attempt to paste:

<feed url="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml">
== [{PERMALINK} {TITLE}] ==
'''{DATE}, by {AUTHOR}'''
{DESCRIPTION}
</feed>

I get the error: "cURL error 6: Couldn't resolve host 'http:'"


<feed>http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml</feed> works though.

I have mediawiki 1.7.1. I installed simplepie and simplefeed in March 2008.

i would like to cusomize my feeds, how would I fix this error? Odessaukrain2 16:48, 1 July 2009 (UTC)Reply

Maybe try to update your MW. There's a new Simplepie version too, 1.2 released in July. But if other feeds work fine maybe its a defect in the feed you're trying to use. --Kenny5 03:37, 31 July 2009 (UTC)Reply

PHP 5.3 problems edit

This extension does not work on my PHP 5.3 system. Error message:

PHP Warning:  Parameter 3 to parseFeed() expected to be a reference, value given in /srv/www/htdocs/wiki/includes/parser/Parser.php on line 3243

I had to change the following line

function parseFeed($input, $args, &$parser)

to

function parseFeed($input, $args, $parser)

BTW: This error seems to be quite common for PHP applications after upgrade to PHP 5.3.

Display the feed sorted by ascending date edit

To display the feed sorted by ascending date, replace ...

// Loop through each item.
for ($i = 0; $i < $max; $i++)
{

(approximately line 104) with ...

$fOffset = 0; $fMult = 1;
if (isset($args['sort']) and $args['sort'] == 'asc') {
        $fOffset = $max - 1; $fMult = -1;
}

// Loop through each item.
for ($i = 0; $i < $max; $i++)
{
        $item = $feed->get_item($i * $fMult + $fOffset);

After the change, the feed is sorted in descending (default) order unless you add the sort="asc" attribute in the feed tag.

Ivan Pepelnjak 09:25, 15 April 2010 (UTC)Reply

Simple use - didn't work edit

The 'Simple use'-method didn't work (showed a zero (0)) SimpleFeed requires a url-argument and a 'template' ($input)

// because this is used in SimpleFeed.php
if (!isset($args['url']) or !isset($input))
{
 return 0;
}

Use the more advanced format, or customize SimpleFeed.php

simplepie is not downloadable edit

http://simplepie.org/ >>> download >>> https://github.com/rmccue/simplepie/downloads

"Sorry, there aren't any downloads for this repository. "

Okip 00:37, 6 June 2011 (UTC)Reply

better link: http://simplepie.org/downloads/ Okip 00:40, 6 June 2011 (UTC)Reply

That link from that page to the SimplePie plugin download is also broken 134.219.64.224 14:00, 22 September 2011 (UTC)Reply
Download the full zip from simplepie.org, and simply use the .inc file from that. It works for me with MW1.18.1--Teststudent 23:01, 31 January 2012 (UTC)Reply

?UNIQ4e8965ed1d93725b-feed-00000001-QINU? edit

I followed the instruction and after adding I got

<feed> http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml</feed>

Please help me .

Same problem here. I also get this strange string... --80.131.98.30 15:33, 12 January 2012 (UTC)Reply
I believe it might be caused by some RSS feeds that do not send you the date of the feed item. You can fix it by removing the [date="h:i:s d/m/y T"] and {DATE} from the feed url line. Also, as mentioned above, in SimpleFeed.php change function parseFeed($input, $args, &$parser) to function parseFeed($input, $args, $parser). One or both of those fixed the problem, I think it was the date change but the other change helps things as well. -- 24.40.138.205 03:28, 16 November 2012 (UTC)Reply

Where can I download it? edit

The Github link leads nowhere.

  • You need two files to get this extension to work, SimpleFeed.php and simplepie.inc. I've put both of them up on my SkyDrive for anyone who needs at: http://skydrive.live.com/?cid=92373444895FA451&id=92373444895FA451!147
    • Note that I'm not responsible for the content of those files. I just downloaded SimpleFeed.php from a SimpleFeed link a while back and simplepie.inc from simplepie.org. Although they are working fine for me, download and use them at your own risk.

Git with simlepie.inc edit

Hi everybody,

we at the TDF (w:en:The Document Foundation) do use the SimpleFeed extension. I'm cleaning up the extension. It uses many deprecated functions and because of the problematic situation to get simplepie.inc, I provide our changes at Github with our modifications. Feel free to help us to expand the extension and start pull requests. You can find the repository at https://github.com/dennisroczek/simplefeed .

Regards

Dennisroczek (talk) 09:03, 6 October 2015 (UTC)Reply

MediaWiki 1.34.0 Support edit

  1. Create directory extensions/SimpleFeed
  2. Download SimpleFeed 1.0.23 from https://github.com/jonnylamb/simplefeed , and decompression to extensions/SimpleFeed
  3. Delete file simplepie.inc
  4. Download simplepie 1.5.4 from https://github.com/simplepie/simplepie , and decompression
  5. Copy autoloader.php and library to extensions/SimpleFeed
  6. Rename autoloader.php to simplepie.inc
  7. Create directory extensions/SimpleFeed/cache , Permissions are usually 755, 775 or 777.
  8. Edit file LocalSettings.php
require_once("$IP/extensions/SimpleFeed/SimpleFeed.php");
-P1ayer (talk) 08:00, 4 March 2020 (UTC)Reply

Fix to MediaWiki 1.35.1 Support edit

  • File: /extensions/SimpleFeed/SimpleFeed.php
  • Line 66:
$parser->disableCache();
Fix to
$parser->getOutput()->updateCacheExpiry(0);
-P1ayer (talk) 13:54, 2 March 2021 (UTC)Reply
Return to "SimpleFeed" page.