Revision [10484]
This is an old revision of NewRSSAction made by JasonHuebel on 2005-08-06 22:35:55.
New RSS Action, powered with Magpie RSS
You can see it working with the ATOM feed there :
http://samueldr.com/pages/PortalRSSFeedGoogleBlog
And with a RSS feed, there :
http://samueldr.com/pages/PortalRSSFeedTheRepublica
For this action to work, you'll have to first download Magpie RSS and put it in the ./3rdparty/plugins/magpierss/.http://samueldr.com/pages/PortalRSSFeedGoogleBlog
And with a RSS feed, there :
http://samueldr.com/pages/PortalRSSFeedTheRepublica
(Note : ./ is the wikka base directory.)
After this is done, create a ./cache/ directory and make it writable.
And now, make a backup of the current RSS action (./actions/rss.php) and replace the old by this one :
<?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))
{
define('MAGPIE_DIR', '3rdparty/plugins/magpierss/');
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 "<span class='error'><em>Error: Invalid RSS syntax. <br /> Proper usage: {{rss http://domain.com/feed.xml}} or {{rss url=\"http://domain.com/feed.xml\" maxitems=\"5\"}}</em></span>";
}
?>
// 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))
{
define('MAGPIE_DIR', '3rdparty/plugins/magpierss/');
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 "<span class='error'><em>Error: Invalid RSS syntax. <br /> Proper usage: {{rss http://domain.com/feed.xml}} or {{rss url=\"http://domain.com/feed.xml\" maxitems=\"5\"}}</em></span>";
}
?>
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 !
- Proxy Support: If your wiki is behind an HTTP proxy, you need to modify the $proxy_host and $proxy_port variables in 3rdparty/plugins/magpierss/extlib/Snoopy.class.inc. --JasonHuebel
- Thanks for figuring that out, Jason! It would be nice to have a wrapper for this so we could specify a proxy via the Wikka Configuration file so all configuration would be in one place... (It's also worth noting that the "official" RSS support via Onyx-RSS does not seem to support proxies.)-- JavaWoman
- OK, I've hacked together support for putting the proxy settings in wikka.config.php, but it will require making changes to magpierss as well. I'm going to submit those changes upstream, so maybe the magpie devs will include support in the next version. I'll have a diff of those changes shortly. --JasonHuebel