Wiki source for NewRSSAction


Show raw source

=====New RSS Action, powered with Magpie RSS=====

>>**See also**
~-[[RSSHandler]]
~-JwRssTest
**Demos:** --Demo off--

>>For this action to work, you'll have to first download [[http://magpierss.sourceforge.net/ | Magpie RSS]] and put it in the **./3rdparty/plugins/magpierss/**.
(Note : **./** is the wikka base directory.)

After this is done, create a **./cache/** directory and make it writable.

::c::
And now, make a backup of the current RSS action (./actions/rss.php) and replace the old by this one :
%%(php)
<?php
// Action usage:
// {{rss http://domain.com/feed.xml}} or {{rss url="http://domain.com/feed.xml" maxitems="5"}}

// As said in the magpie RSS cookbook :
# Magpie throws USER_WARNINGS only
# so you can cloak these, by only showing ERRORs
// Those warnings are triggered when Magpie can't download the remote RSS file, and there is no cached version.
// Another possible warning is when the feed is improperly parsed. The cookbook talks about illegal HTML, I handled that pretty well for atom feeds.
error_reporting(E_ERROR);
// This can create an error or warning on some shared hosting, so comment it out if it does.(user // or # in front of the line)

// This is the default cache dir.
$rss_cache_path = "./cache/"; // set this to a writable directory to store the cache files in
$caching = 1; // change this to false to disable caching || Set to 0 for false and 1 for true.

if (!$vars['maxitems']) {
$maxitems = 15; // set this to the maximum items the RSS action should display if there is no maxitems specified in the variables.

}
else {
$maxitems = $vars['maxitems'];
}


// Sticking with default Magpie RSS value : 1 hour.
#$lowest_cache_time_allowed = "5"; // set this to the lowest caching time allowed
#$rss_cache_time = (int)trim($vars['cachetime']);
#if (!$rss_cache_time) {
# $rss_cache_time = 30; // set this for default cache time
#} elseif ($rss_cache_time < $lowest_cache_time_allowed) {
# $rss_cache_time = $lowest_cache_time_allowed;
#}


//Action configuration
$rss_path = $vars['url'];
if ((!$rss_path) && $wikka_vars) $rss_path = $wikka_vars;
$rss_path = $this->cleanUrl(trim($rss_path));

if (preg_match("/^(http|https):\/\/([^\\s\"<>]+)$/i", $rss_path))
{

// Set Your Proxy Settings Here
define('MAGPIE_PROXY_HOST', '');
define('MAGPIE_PROXY_PORT', '');

// Path To MagpieRSS
define('MAGPIE_DIR', '3rdparty/plugins/magpierss/');

// Cache Settings
define('MAGPIE_CACHE_DIR', $rss_cache_path);
define('MAGPIE_CACHE_ON', $caching);

// Not sure how to use this one, so i'll stick with commenting it, default aging with Magpie is set to 1 hour.
#define('MAGPIE_CACHE_AGE', 10);

require_once(MAGPIE_DIR.'rss_fetch.inc');

$rss = fetch_rss( $rss_path );
if ($rss) {
$i = 1;
$cached_output = "<h3>".$rss->channel['title']."</h3>";
if ($rss->channel['link']) {
$cached_output .= '<div align="right"><a href="'.$rss->channel['link'].'">FEED URL : '.$rss->channel['link'].'</a></div>';
}
$cached_output .= "<ul>\n";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
if ($item['content']) {
$description = implode($item['content']);
}
else {
$description = $item['description'];
}
$cached_output .= "<li><a href=$href>$title</a><br />$description</li>";
if ($i >= $maxitems) {
break;
}
$i++;
}
$cached_output .= "</ul>\n";

echo $this->ReturnSafeHTML($cached_output);
} else {
echo "An error occured when fetching or parsing the feed.<br />Check that the feed is compliant.";
}
} else {
echo '<em class="error">Error: Invalid RSS syntax. <br /> Proper usage: {{rss http://domain.com/feed.xml}} or {{rss url="http://domain.com/feed.xml" maxitems="5"}}</em>';
}

?>
%%

You also need to patch the ##rss_fetch.inc## file included with magpierss. This patch adds proxy support. Save the file below as ##magpierss_proxy_support.patch## in the same directory as ##rss_fetch.inc## (usually ##3rdparty/plugins/magpierss##).

%%(patch)diff -u --recursive magpierss-0.71.1/rss_fetch.inc magpierss-0.71.1-proxy/rss_fetch.inc
--- magpierss-0.71.1/rss_fetch.inc 2005-02-09 13:59:01.000000000 -0600
+++ magpierss-0.71.1-proxy/rss_fetch.inc 2005-08-06 16:52:02.000000000 -0500
@@ -270,6 +270,8 @@
$client->agent = MAGPIE_USER_AGENT;
$client->read_timeout = MAGPIE_FETCH_TIME_OUT;
$client->use_gzip = MAGPIE_USE_GZIP;
+ $client->proxy_host = MAGPIE_PROXY_HOST;
+ $client->proxy_port = MAGPIE_PROXY_PORT;
if (is_array($headers) ) {
$client->rawheaders = $headers;
}
@@ -391,6 +393,14 @@
if ( !defined('MAGPIE_USE_GZIP') ) {
define('MAGPIE_USE_GZIP', true);
}
+
+ if ( !defined('MAGPIE_PROXY_HOST') ) {
+ define ('MAGPIE_PROXY_HOST', '');
+ }
+
+ if ( !defined('MAGPIE_PROXY_PORT', '') ) {
+ define ('MAGPIE_PROXY_PORT', '');
+ }
}

// NOTE: the following code should really be in Snoopy, or at least
%%

Change the the magpeirss directory. Then apply the patch by using the following command (in Linux):

%%(shell) patch -Np1 <magpierss_proxy_support.patch %%

To set a proxy, modify the MAGPIE_PROXY_HOST and MAGPIE_PROXY_PORT defines in your new rss.php file.

I think that it is **NOT** idiot proof and there may be place for optimisations.
Feel free to edit the code and tell me what you did, i'm a learner !

And, at last, please comment, so I'll know that people are seeing it. Thank you !

~& If you have any problems with the proxy support patch, please let JasonHuebel know.

----
CategoryDevelopmentSyndication
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki