2010-10-19 21:54:53 +00:00
|
|
|
<?php
|
2010-10-20 11:25:10 +00:00
|
|
|
|
2010-10-19 21:54:53 +00:00
|
|
|
class RSSData {
|
2010-11-13 19:11:28 +00:00
|
|
|
public $error;
|
2010-10-19 21:54:53 +00:00
|
|
|
public $items;
|
|
|
|
|
2010-11-04 23:19:00 +00:00
|
|
|
/**
|
|
|
|
* Constructor, takes a DOMDocument and returns an array of parsed items.
|
2010-11-05 00:59:28 +00:00
|
|
|
* @param $xml DOMDocument: the pre-parsed XML Document
|
2012-10-07 10:11:49 +00:00
|
|
|
* @return RSSData object with a member items that is an array of parsed items,
|
2010-11-04 23:19:00 +00:00
|
|
|
*/
|
2010-11-01 16:25:04 +00:00
|
|
|
function __construct( $xml ) {
|
2010-11-13 19:11:28 +00:00
|
|
|
if ( !( $xml instanceof DOMDocument ) ) {
|
|
|
|
$this->error = "Not passed DOMDocument object.";
|
2010-11-04 23:19:00 +00:00
|
|
|
return;
|
2010-11-01 16:25:04 +00:00
|
|
|
}
|
|
|
|
$xpath = new DOMXPath( $xml );
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
$items = $xpath->query( '/rss/channel/item' );
|
2010-10-19 21:54:53 +00:00
|
|
|
|
2010-11-05 00:59:28 +00:00
|
|
|
if( $items->length !== 0 ) {
|
2010-11-04 23:19:00 +00:00
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$bit = array();
|
|
|
|
foreach ( $item->childNodes as $n ) {
|
|
|
|
$name = $this->rssTokenToName( $n->nodeName );
|
|
|
|
if ( $name != null ) {
|
2010-11-05 00:59:28 +00:00
|
|
|
/**
|
|
|
|
* Because for DOMElements the nodeValue is just
|
2010-11-04 23:19:00 +00:00
|
|
|
* the text of the containing element, without any
|
|
|
|
* tags, it makes this a safe, if unattractive,
|
|
|
|
* value to use. If you want to allow people to
|
|
|
|
* mark up their RSS, some more precautions are
|
2010-11-05 00:59:28 +00:00
|
|
|
* needed.
|
|
|
|
*/
|
2010-11-04 23:19:00 +00:00
|
|
|
$bit[$name] = $n->nodeValue;
|
|
|
|
}
|
2010-10-20 11:25:10 +00:00
|
|
|
}
|
2010-11-04 23:19:00 +00:00
|
|
|
$this->items[] = $bit;
|
2010-10-19 21:54:53 +00:00
|
|
|
}
|
2010-11-04 23:19:00 +00:00
|
|
|
} else {
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
$this->error = 'No RSS items found.';
|
2010-11-04 23:19:00 +00:00
|
|
|
return;
|
2010-10-19 21:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 23:19:00 +00:00
|
|
|
/**
|
|
|
|
* Return a string that will be used to map RSS elements that
|
|
|
|
* contain similar data (e.g. dc:date, date, and pubDate) to the
|
|
|
|
* same array key. This works on WordPress feeds as-is, but it
|
|
|
|
* probably needs a way to concert dc:date format dates to be the
|
|
|
|
* same as pubDate.
|
2010-11-05 00:59:28 +00:00
|
|
|
*
|
|
|
|
* @param $n String: name of the element we have
|
|
|
|
* @return String Name to map it to
|
2010-11-04 23:19:00 +00:00
|
|
|
*/
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
protected function rssTokenToName( $n ) {
|
|
|
|
switch( $n ) {
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'dc:date':
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
return 'date';
|
|
|
|
# parse "2010-10-18T18:07:00Z"
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'pubDate':
|
|
|
|
return 'date';
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
# parse RFC date
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'dc:creator':
|
|
|
|
return 'author';
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
case 'title':
|
|
|
|
return 'title';
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'content:encoded':
|
|
|
|
return 'encodedContent';
|
2010-10-19 21:54:53 +00:00
|
|
|
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'slash:comments':
|
|
|
|
case 'slash:department':
|
|
|
|
case 'slash:section':
|
|
|
|
case 'slash:hit_parade':
|
|
|
|
case 'feedburner:origLink':
|
|
|
|
case 'wfw:commentRss':
|
|
|
|
case 'comments':
|
|
|
|
case 'category':
|
2010-10-19 21:54:53 +00:00
|
|
|
return null;
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
|
2010-10-19 21:54:53 +00:00
|
|
|
default:
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
return $n;
|
2010-10-19 21:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-07 10:11:49 +00:00
|
|
|
}
|