Table of Contents

Parser Integration

Examples of SimpliePie integration into the different projects.

Textpattern

Integrate SimplePie into your Textpattern templates and posts with this plug-in.

Plugin Instructions

SimplePie Plugin for Textpattern adds one tag to your Textpattern installation:

<txp:feed>http://example.com/feed.xml</txp:feed>

Attributes

Plugin Usage

This is how the plugin is being used on Textpattern Planet:

Sample tag

<txp:feed items="5" showdate="l &#183; F j, Y &#183; h:i:s A" shortdesc="210" alttitle="Developer Weblog" >
http://textpattern.com/rss/?section=weblog
</txp:feed>

Plugin Code

Version 1.2 of the plugin code, slightly modified

global $txpcfg;
if (!class_exists('SimplePie')) require($txpcfg['txpath'].'/lib/simplepie.inc');
 
function feed($atts, $thing='') {
	global $txpcfg;
	$BLOGROOT = explode('/index.php', $_SERVER["PHP_SELF"]);
	$BLOGROOT = $BLOGROOT[0];
	$TXPROOT = $BLOGROOT . '/textpattern';
 
	$input = $thing;
	$argv = $atts;
 
	$feed = new SimplePie();
	$feed->feed_url($input);
        $feed->cache_max_minutes(30);
	$feed->cache_location($txpcfg['txpath'] . '/tmp');
	$feed->bypass_image_hotlink();
	$feed->bypass_image_hotlink_page($TXPROOT . '/lib/simplepie_image_handler.php');
	$success = $feed->init();
 
	if ($success && $feed->data) {
		$flink = $feed->get_feed_link();
		$ftitle = $feed->get_feed_title();
 
		$output='';
		$output .= '<div class="simplepie">';
		if (!isset($argv['showtitle']) || empty($argv['showtitle']) || $argv['showtitle'] == "true") {
			if (isset($argv['alttitle']) && !empty($argv['alttitle'])) {
				if ($ftitle != '' && $flink != '') $output .= "<h3><a href=\"$flink\">" . $argv['alttitle'] . "</a></h3>";
				else if ($ftitle != '') $output .= "<h3>" . $argv['alttitle'] . "</h3>";
			}
			else {
				if ($ftitle != '' && $flink != '') $output .= "<h3><a href=\"$flink\">$ftitle</a></h3>";
				else if ($ftitle != '') $output .= "<h3>$ftitle</h3>";
			}
		}
		$output .= '<ul>';
 
		$max = $feed->get_item_quantity();
		if (isset($argv['items']) && !empty($argv['items'])) $max = $feed->get_item_quantity($argv['items']);
 
		for($x=0; $x<$max; $x++) {
			$item = $feed->get_item($x);
			$link = $item->get_permalink();
			$title = StupefyEntities($item->get_title());
			$full_desc = StupefyEntities($item->get_description());
			$desc = $full_desc;
 
			if (isset($argv['shortdesc']) && !empty($argv['shortdesc'])) {
				$suffix = '...';
				$short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($item->get_description())))));
				$desc = substr($short_desc, 0, $argv['shortdesc']);
				$lastchar = substr($desc, -1, 1);
				if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
				$desc .= $suffix;
			}
 
			if (isset($argv['showdesc']) && !empty($argv['showdesc']) && $argv['showdesc']==='false') {
				if (isset($argv['showdate']) && !empty($argv['showdate'])) {
					$output .= "<li><strong><a href=\"$link\">$title</a> </strong> <br /> <em> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span> </em> </li>";
				} else {
					$output .= "<li><a href=\"$link\">$title</a></li>";
				}
			} else {
				if (isset($argv['showdate']) && !empty($argv['showdate'])) {
					$output .= "<li><strong><a href=\"$link\">$title</a> </strong> <br /> <em> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span> </em> <br />$desc</li>";
				} else {
					$output .= "<li><strong><a href=\"$link\">$title</a></strong><br />$desc</li>";
				}
			}
		}
 
		$output .= '</ul>';
		$output .= '</div>';
	}
	else {
		if (isset($argv['error']) && !empty($argv['error'])) $output = $argv['error'];
		else if (isset($feed->error)) $output = $feed->error;
	}
 
	return $output;
}
 
// SmartyPants 1.5.1 changes rolled in May 2004 by Alex Rosenberg, http://monauraljerk.org/smartypants-php/
function StupefyEntities($s = '') {
	$inputs = array('&#8211;', '&#8212;', '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8230;', '&#91;', '&#93;');
	$outputs = array('-', '--', "'", "'", '"', '"', '...', '[', ']');
	$s = str_replace($inputs, $outputs, $s);
	return $s;
}

DokuWiki

DokuWiki includes the SimplePie parser as of release 2006-11-06.

Syntax Example

{{rss>http://forum.dokuwiki.org/forum.php?req=rss}}

Output