Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-02-23 13:14:14

claywso
Member
From: Durham, NC USA
Registered: 2004-12-20
Posts: 57
Website

[SimplePie] using txp:feed within link form

I’m trying to use the links list within textpattern to build a link list to to automatically generate content.

essentially, on the page, I’d use something like this:

<txp:linklist category="news" form="noted" limit="5" sort="linksort asc" />

the form (‘noted’) that it references would look like this:

<txp:feed><txp:link_url /></txp:feed>

Depending on the number of links in the ‘news’ category, i’d expect the output to look something like this:

<h3>Title of RSS Feed (from link #1)</h1>
<ul><li>post 1</li> through <li>post 5</li></ul>
<h3>Title of RSS Feed (from link #2)</h1>
<ul><li>post 1</li> through <li>post 5</li></ul>

instead, i get this error:

cURL error 6: Couldn’t resolve host ‘link_url%20%2F%3E’cURL error 6: Couldn’t resolve host ‘link_url%20%2F%3E’

any help would be greatly appreciated.

clay

Added code block formatting (bc.) -Gocom

Last edited by Gocom (2010-02-23 15:11:15)

Offline

#2 2010-02-23 15:08:47

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [SimplePie] using txp:feed within link form

claywso wrote:

any help would be greatly appreciated.

Tags that need to be parsed, need to be parsed (that didn’t sound right). Anyways, to the code to work you need to edit the feed() function (which ever plugin that might be) so that it parses the contained statement ($thing paramerter) with parse().

Currently the function, (<txp:feed /> tag) is feeding the <txp:link_url /> to simplepie as is.

Offline

#3 2010-02-23 18:12:32

claywso
Member
From: Durham, NC USA
Registered: 2004-12-20
Posts: 57
Website

Re: [SimplePie] using txp:feed within link form

thanks for the quick response.

i’m really unsure of what to edit, though, and have posted the plugin here. Any advice on what to edit?

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->set_feed_url($input);
	$feed->set_cache_location($txpcfg['txpath'] . '/lib/simplepie_cache');
	$feed->set_cache_duration(999999999); 
        $feed->set_timeout(-1);
        $success = $feed->init();

	## define some optional defaults
	if (!isset($argv['listtype']) || empty($argv['listtype'])) {
			$argv['listtype']="ul";
	} 
	if (!isset($argv['h']) || empty($argv['h'])) {
			$argv['h']="h3";
	} 
	##
	if ($success && $feed->data) {
		$flink = $feed->get_permalink();
		$ftitle = $feed->get_title();

		$output='';
		$output .= '<div class="simplepie">';
		if (!isset($argv['showtitle']) || empty($argv['showtitle']) || $argv['showtitle'] == "true") {
			if($argv['alttitle'] == -1) {
				## no title
			} elseif (isset($argv['alttitle']) && !empty($argv['alttitle'])) {
				if ($ftitle != '' && $flink != '') {
					$output .= "<{$argv['h']}><a href=\"$flink\">" . $argv['alttitle'] . "</a></{$argv['h']}>";
				} elseif ($ftitle != '') {
					$output .= "<{$argv['h']}>" . $argv['alttitle'] . "</{$argv['h']}>";
				}
			} else {
				if ($ftitle != '' && $flink != '') $output .= "<h3><a href=\"$flink\">$ftitle</a></h3>";
				else if ($ftitle != '') $output .= "<h3>$ftitle</h3>";
			}
		}
		if (!isset($argv['listtype']) || empty($argv['listtype'])) {
			$argv['listtype']="ul";
		} 
		$output .= "<".$argv['listtype'].">";

		$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><a href=\"$link\">$title</a> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></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> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></strong><br />$desc</li>";
				} else {
					$output .= "<li><strong><a href=\"$link\">$title</a></strong><br />$desc</li>";
				}
			}
		}

		$output .= "</".$argv['listtype'].">";;
		$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;
}

Offline

#4 2010-02-23 18:34:30

claywso
Member
From: Durham, NC USA
Registered: 2004-12-20
Posts: 57
Website

Re: [SimplePie] using txp:feed within link form

Nevermind! I got over my codephobia and did a bit of research and simply changed

$input = $thing;

to

$input = parse($thing);

and it worked! thanks for the pointer!

Offline

Board footer

Powered by FluxBB