Extension:SimpleRSS.php
<?php
- Extension:RobsRSS
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:RobCategory:Extensions created with Template:Extension
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('ROBSRSS_VERSION','0.0.0, 2007-10-14');
$wgRobsRSSTag = "rss"; $wgRSSUseAjax = false; $wgExtensionFunctions[] = 'wfSetupRobsRSS'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'RobsRSS', 'author' => 'User:Rob', 'description' => 'A dynamic aggregating RSS reader', 'url' => 'http://www.mediawiki.org/wiki/Extension:RobsRSS', 'version' => ROBSRSS_VERSION );
require('extensions/RobsRSSExtension/magpierss-0.72/rss_fetch.inc');
- NOTE: because different sites seem to use keys for different things we may want
- to 'squash' keys in some reasonable manner to provide consistent keys to the
- template for output - needs testing to determine this.
- arrays of keys we're interested in
$channel_keys = array('title', 'link', 'pubdate', 'tagline');
- $item_keys = array(
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupRobsRSS() { global $wgParser,$wgRSSUseAjax,$wgAjaxExportList,$wgRobsRSSTag; $wgParser->setHook($wgRobsRSSTag,'wfRssTagHook'); if ($wgRSSUseAjax) $wgAjaxExportList[] = 'wfRenderRSS'; # Allow Ajax Dispatcher to call wfRenderRSS }
- Expand an <rss> tag
function wfRssTagHook($text,$argv,&$parser) { global $wgRSSUseAjax; $args = ;
foreach ($argv as $k => $v) $args .= "
\n";
if ($wgRSSUseAjax) { # Render a container which does ajax requests for content
$html = "
";
} else { # Not using ajax, render the output now $html = wfRenderRSS($data,$timestamp); } # grab each url and process $data = wfReadRSS(preg_split("/[\n\r]/", $text, -1, PREG_SPLIT_NO_EMPTY));
# dump data $channel = array(); foreach ($data as $v) { $channel[$v->channel[title]][channel] = $v->channel; $channel[$v->channel[title]][items] = $v->items;
$html .= "\n
".$v->channel[title]."
\n"; $html .= "\n
Channel keys
\n";
$html .= list_array_keys($v->channel, "*");
$html .= "\n
Item keys
\n";
$html .= list_array_keys($v->items[0], "*");
}
- $html .= print_r($channel, true);
return $html;
}
function list_array_keys($array, $indent) { foreach($array as $key => $value) { $output .= "$indent $key\n"; if(is_array($value)) $output .= list_array_keys($value, $indent."*"); } return $output; }
- Render a portion of RSS data (which is in the useful format returned by wfReadRSS)
function wfRenderRSS($data,$timestamp = false) { return $html; }
- Read RSS from URL's and return as some kind of useful runtime structure
function wfReadRSS($urls) { $data = array(); foreach ($urls as $url) { $data[] = fetch_rss($url); } return $data; }
# parse raw xml to fix entities # taken from http://lastrss.oslab.net/
function unhtmlentities ($string) { // Get HTML entities table $trans_tbl = get_html_translation_table (HTML_ENTITIES, ENT_QUOTES); // Flip keys<==>values $trans_tbl = array_flip ($trans_tbl); // Add support for ' entity (missing in HTML_ENTITIES) $trans_tbl += array(''' => "'"); // Replace entities by values return strtr ($string, $trans_tbl); }
?>