<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechnoGeeks &#187; WordPress</title>
	<atom:link href="http://techno-geeks.org/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://techno-geeks.org</link>
	<description>A fusion of technology, music, and geekyness.</description>
	<lastBuildDate>Sat, 04 Sep 2010 08:17:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Selective RSS Plugin for WordPress</title>
		<link>http://techno-geeks.org/2009/06/selective-rss-plugin-for-wordpress/</link>
		<comments>http://techno-geeks.org/2009/06/selective-rss-plugin-for-wordpress/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 16:42:03 +0000</pubDate>
		<dc:creator>jesse</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://techno-geeks.org/?p=199</guid>
		<description><![CDATA[We had a client recently request that we embed an RSS feed from a different site inside their WordPress install. This would&#8217;ve been very easy considering there are 100&#8217;s of RSS feed plugins that will accomplish this task. However, they wanted to only display RSS items that had certain keywords in the title. My initial [...]]]></description>
			<content:encoded><![CDATA[<p>We had a client recently request that we embed an RSS feed from a different site inside their WordPress install. This would&#8217;ve been very easy considering there are 100&#8217;s of RSS feed plugins that will accomplish this task. However, they wanted to only display RSS items that had certain keywords in the title. My initial search found no WP plugins that currently were capable of this. I also tried one of the more popular ones, <a href="http://wordpress.org/extend/plugins/feedlist/">FeedList</a>, but it used the <a href="http://codex.wordpress.org/Function_Reference/get_rss">get_rss()</a> function in the WordPress API. For some reason, this function was not properly parsing the feed they wanted to use, most likely due to it not being a <a href="http://validator.w3.org/feed/">valid feed</a>.</p>
<p>So to make a long story short: I decided to make a quick hack up solution and write my own WP plugin. My only hurdle-like requirement is that it had to work for PHP4 as well because the client is on one of our older servers. I ended up finding a really good <a href="http://www.stemkoski.com/how-to-easily-parse-a-rss-feed-with-php-4-or-php-5/">example by Ryan Stemkoski</a>. He wrote a perfect function for me to tweak a little and expand upon. I am currently waiting to get approved on WordPress extend so I can host my plugin there. For now, I have created a <a href="http://techno-geeks.org/selective-rss/">page here where you can download</a> the plugin.</p>
<p>Note: I haven&#8217;t tested this in a more recent version of WP yet but I will be soon. Let me know if you find any bugs!</p>
<p>I also figured I would post the source code in case someone needed a quick and dirty solution with some examples.</p>
<p>rss_lib.php</p>
<pre class="brush: php;">
&lt;?php

/*
* RSS Parsing Function
*
* Original Author: Ryan Stemkoski
* http://www.stemkoski.com/how-to-easily-parse-a-rss-feed-with-php-4-or-php-5/
*
* Slight modifications by Jesse R. Adams (DualTech Services, Inc.)
*/ 

function parseRSS($url) { 

	//PARSE RSS FEED
        $feedeed = implode('', file($url));
        $parser = xml_parser_create();
        xml_parse_into_struct($parser, $feedeed, $valueals, $index);
        xml_parser_free($parser);

	//CONSTRUCT ARRAY
        foreach($valueals as $keyey =&gt; $valueal){
            if($valueal['type'] != 'cdata') {
                $item[$keyey] = $valueal;
			}
        }

        $i = 0;

        foreach($item as $key =&gt; $value){

            if($value['type'] == 'open') {

                $i++;
                $itemame[$i] = $value['tag'];

            } elseif($value['type'] == 'close') {

                $feed = $values[$i];
                $item = $itemame[$i];
                $i--;

                if(count($values[$i])&gt;1){
                    $values[$i][strtolower($item)][] = $feed;
                } else {
                    $values[$i][strtolower($item)] = $feed;
                }

            } else {
                $values[$i][strtolower($value['tag'])] = $value['value'];
            }
        }

	//RETURN ARRAY VALUES
	return $values[0];
} 

/*
* Convert Raw RSS Parse into concise list of items
*
* Optionally pass in limit (on number of items)
* and/or array list of words to grab items by.
*
*/

function extractRSSItems($xmlArray, $limit = null, $filteredWords = array()) {
	$array = array();
	$regex = null;

	if (count($filteredWords) &gt; 0) {
		$regex = implode('|', $filteredWords);
	}

	foreach($xmlArray['rss']['channel']['item'] as $item) {
		if (!$regex || ($regex &amp;&amp; preg_match(&quot;/$regex/i&quot;, $item['title']))) {
			$array[] = $item;
		}
 	}

	if($limit) {
		array_splice($array, ($limit - 1), (count($array) - $limit));
	}

	return $array;
}
?&gt;
</pre>
<p>selective_rss.php</p>
<pre class="brush: php;">
&lt;?php
/*
Plugin Name: Selective RSS
Plugin URI: http://techno-geeks.org/selective-rss
Description: Simple Plugin that allows you to embed RSS feed items into Pages or Posts. Optionally allows you to choose how many items to display and allows you to limit items to ones that contain certain words in the titles.
Version: 0.1.0b
Author: Jesse R. Adams (DualTech Services, Inc.)
Author URI: http://www.dual-tech.com/about-dualtech-services/
*/

require_once('rss_lib.php');

function filter_feeds($content) {
	$limit = null;
	$filter = array();
	$url = null;

	$inputTag = preg_match('/\[srss (.+)\]/', $content, $matches);
	$rawArgs = explode(',', $matches[1]);

	foreach($rawArgs as $input) {
                preg_match_all('/^(url|filter|limit)=(.+)$/i', $input, $matches);
                $key = $matches[1][0];
                $value = $matches[2][0]

		if ($key == 'filter') {
			$filter = explode(';', $value);
		} else {
			$$key = $value;
		}
	}

	if ($url) {
		$xml = parseRSS($url);
		$items = extractRSSItems($xml, $limit, $filter);

		$htmlToAdd = '';
		foreach ($items as $item) {
			$htmlToAdd .= '&lt;a href=&quot;' . $item['link'] . '&quot; target=&quot;new&quot;&gt;' . $item['title'] . '&lt;/a&gt;' . &quot;&lt;br/&gt;\n&quot;;
			$htmlToAdd .= $item['description'] . &quot;&lt;br/&gt;&lt;br/&gt;\n&quot;;
		}

		$content = preg_replace('/\[srss .+\]/', $htmlToAdd, $content);
	}
	return $content;
}

add_filter('the_content', 'filter_feeds');
?&gt;
</pre>
<p>Update 06/19: Fixed the way arguments are parsed to be less limiting on possibilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://techno-geeks.org/2009/06/selective-rss-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
