Difference between revisions of "Extension:SimpleRSS.php"

From Organic Design wiki
(updated code for testing)
(No difference)

Revision as of 20:32, 18 October 2007

<?php

  1. Extension:RobsRSS
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - 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');

  1. NOTE: because different sites seem to use keys for different things we may want
  2. to 'squash' keys in some reasonable manner to provide consistent keys to the
  3. template for output - needs testing to determine this.
  1. arrays of keys we're interested in

$channel_keys = array('title', 'link', 'pubdate', 'tagline');

  1. $item_keys = array(


  1. 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 }

  1. Expand an <rss> tag

function wfRssTagHook($text,$argv,&$parser) { global $wgRSSUseAjax; $args = ;

foreach ($argv as $k => $v) $args .= "

  • $k: $v
  • \n";

    if ($wgRSSUseAjax) { # Render a container which does ajax requests for content

    $html = "

    an ajax thingie

    ";

    } 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], "*");

    }

    1. $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; }

    1. Render a portion of RSS data (which is in the useful format returned by wfReadRSS)

    function wfRenderRSS($data,$timestamp = false) { return $html; }

    1. 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);
     }
    


    ?>