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 {
|
|
|
|
public $etag;
|
|
|
|
public $last_modified;
|
|
|
|
public $ERROR;
|
|
|
|
public $xml;
|
|
|
|
public $items;
|
|
|
|
|
|
|
|
function __construct( $resp ) {
|
|
|
|
$this->xml = new DOMDocument;
|
2010-10-20 11:25:10 +00:00
|
|
|
$this->xml->loadXML( $resp->getContent() );
|
|
|
|
$h = $resp->getResponseHeader( 'ETag' );
|
2010-10-19 21:54:53 +00:00
|
|
|
$this->etag = $h;
|
2010-10-20 11:25:10 +00:00
|
|
|
$h = $resp->getResponseHeader( 'Last-Modified' );
|
2010-10-19 21:54:53 +00:00
|
|
|
$this->last_modified = $h;
|
|
|
|
|
2010-10-20 11:25:10 +00:00
|
|
|
$xpath = new DOMXPath( $this->xml );
|
|
|
|
$items = $xpath->evaluate( '/rss/channel/item' );
|
2010-10-19 21:54:53 +00:00
|
|
|
|
2010-10-20 18:28:47 +00:00
|
|
|
foreach ( $items as $item ) {
|
2010-10-19 21:54:53 +00:00
|
|
|
$bit = array();
|
2010-10-20 18:28:47 +00:00
|
|
|
foreach ( $item->childNodes as $n ) {
|
2010-10-20 11:25:10 +00:00
|
|
|
$name = $this->rssTokenToName( $n->nodeName );
|
2010-10-20 18:28:47 +00:00
|
|
|
if ( $name != null ) {
|
2010-10-19 21:54:53 +00:00
|
|
|
$bit[$name] = $n->nodeValue;
|
2010-10-20 11:25:10 +00:00
|
|
|
}
|
2010-10-19 21:54:53 +00:00
|
|
|
}
|
|
|
|
$this->items[] = $bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-20 11:25:10 +00:00
|
|
|
function rssTokenToName( $n ) {
|
|
|
|
switch( $n ) {
|
|
|
|
case 'dc:date':
|
|
|
|
return 'date';
|
2010-10-19 21:54:53 +00:00
|
|
|
# parse "2010-10-18T18:07:00Z"
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'pubDate':
|
|
|
|
return 'date';
|
2010-10-19 21:54:53 +00:00
|
|
|
# parse RFC date
|
2010-10-20 11:25:10 +00:00
|
|
|
case 'dc:creator':
|
|
|
|
return 'author';
|
|
|
|
case 'title':
|
|
|
|
return 'title';
|
|
|
|
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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return $n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|