Difference between revisions of "Extension:SimpleRSS.php"

From Organic Design wiki
(a few comments)
m
Line 19: Line 19:
 
);
 
);
  
 +
 +
# Called from $wgExtensionFunctions array when initialising extensions
 +
function wfSetupRobsRSS() {
 +
global $wgParser,$wgRSSUseAjax,$wgAjaxExportList;
 +
$wgParser->setHook($wgRobsRSSTag,array($this,'wfRssTagHook'));
 +
if ($wgRSSUseAjax) $wgAjaxExportList[] = 'wfRenderRSS'; # Allow Ajax Dispatcher to call wfRenderRSS
 +
}
  
 
# Expand an <rss> tag
 
# Expand an <rss> tag
Line 35: Line 42:
 
}
 
}
  
return $html;
+
return "Hello!";
 +
# return $html;
 
}
 
}
 
   
 
   
Line 67: Line 75:
 
                 ->item(0)->childNodes->item(0)->nodeValue;
 
                 ->item(0)->childNodes->item(0)->nodeValue;
 
                 # <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>
 
                 # <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>
 +
                $data .= "<p>$item_title: $item_link $item_desc $item_date";
 
                 }
 
                 }
 
             # add collected info into $data
 
             # add collected info into $data
Line 81: Line 90:
 
}
 
}
  
# Called from $wgExtensionFunctions array when initialising extensions
 
function wfSetupRobsRSS() {
 
global $wgParser,$wgRSSUseAjax,$wgAjaxExportList;
 
$wgParser->setHook($wgRobsRSSTag,array($this,'wfRssTagHook'));
 
if ($wgRSSUseAjax) $wgAjaxExportList[] = 'wfRenderRSS'; # Allow Ajax Dispatcher to call wfRenderRSS
 
}
 
 
?>
 
?>

Revision as of 05:23, 14 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 = true; $wgExtensionFunctions[] = 'wfSetupRobsRSS'; $wgExtensionCredits['taghook'][] = array( 'name' => 'RobsRSS', 'author' => 'User:Rob', 'description' => 'A dynamic aggregating RSS reader', 'url' => 'http://www.mediawiki.org/wiki/Extension:RobsRSS', 'version' => ROBSRSS_VERSION );


  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupRobsRSS() { global $wgParser,$wgRSSUseAjax,$wgAjaxExportList; $wgParser->setHook($wgRobsRSSTag,array($this,'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); }

    return "Hello!";

    1. 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) { $doc = new DOMDocument(); # do some cache stuff here $doc->load($url); # get feed details $feed=$doc->getElementsByTagName('channel')->item(0);

           $feed_title = $channel->getElementsByTagName('title')
           ->item(0)->childNodes->item(0)->nodeValue;
           $feed_link = $channel->getElementsByTagName('link')
           ->item(0)->childNodes->item(0)->nodeValue;
           $feed_desc = $channel->getElementsByTagName('description')
           ->item(0)->childNodes->item(0)->nodeValue;
    


    foreach ($dom->getElementsByTagName('item') as $item) { # what follows looks overly complicated? simplify?

               for ($i=0; $i<=2; $i++) {
                   $item_title=$dom->item($i)->getElementsByTagName('title')
                   ->item(0)->childNodes->item(0)->nodeValue;
                   $item_link=$dom->item($i)->getElementsByTagName('link')
                   ->item(0)->childNodes->item(0)->nodeValue;
                   $item_desc=$dom->item($i)->getElementsByTagName('description')
                   ->item(0)->childNodes->item(0)->nodeValue;
                   $item_date=$dom->item($i)->getElementsByTagName('pubDate')
                   ->item(0)->childNodes->item(0)->nodeValue;
                   # <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>
    

    $data .= "

    $item_title: $item_link $item_desc $item_date"; } # add collected info into $data # TODO need to grab date information so we can sort # Date is in UDF from memory } } return $data; }

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

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