summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-05-01 19:40:43 +0400
committerAndrew Dolgov <[email protected]>2013-05-01 19:40:43 +0400
commit4c00e15b5d05b0d137af9a33bf79172bfeb0df24 (patch)
treee5a6f98d49d5504b36e574431891cd786ec46be1
parentfd0daa9b55b98b18b62f1eb710d5df197254ed04 (diff)
pass xpath object to feeditem, support media-rss objects
-rw-r--r--classes/feeditem/atom.php2
-rw-r--r--classes/feeditem/rss.php18
-rw-r--r--classes/feedparser.php5
3 files changed, 21 insertions, 4 deletions
diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php
index 0d888c443..7dc4ce5c1 100644
--- a/classes/feeditem/atom.php
+++ b/classes/feeditem/atom.php
@@ -2,7 +2,7 @@
class FeedItem_Atom {
private $elem;
- function __construct($elem) {
+ function __construct($elem, $doc, $xpath) {
$this->elem = $elem;
}
diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php
index d5667102d..e5e2a8e56 100644
--- a/classes/feeditem/rss.php
+++ b/classes/feeditem/rss.php
@@ -1,9 +1,11 @@
<?php
class FeedItem_RSS {
private $elem;
+ private $xpath;
- function __construct($elem) {
+ function __construct($elem, $doc, $xpath) {
$this->elem = $elem;
+ $this->xpath = $xpath;
}
function get_id() {
@@ -92,6 +94,20 @@ class FeedItem_RSS {
array_push($encs, $enc);
}
+ $enclosures = $this->xpath->query("media:content", $this->elem);
+
+ $encs = array();
+
+ foreach ($enclosures as $enclosure) {
+ $enc = new FeedEnclosure();
+
+ $enc->type = $enclosure->getAttribute("type");
+ $enc->link = $enclosure->getAttribute("url");
+ $enc->length = $enclosure->getAttribute("length");
+
+ array_push($encs, $enc);
+ }
+
return $encs;
}
diff --git a/classes/feedparser.php b/classes/feedparser.php
index f127ba73d..eabbb5b28 100644
--- a/classes/feedparser.php
+++ b/classes/feedparser.php
@@ -27,6 +27,7 @@ class FeedParser {
$root = $this->doc->firstChild;
$xpath = new DOMXPath($this->doc);
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
+ $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/');
$this->xpath = $xpath;
$root = $xpath->query("(//atom:feed|//channel)")->item(0);
@@ -62,7 +63,7 @@ class FeedParser {
$articles = $xpath->query("//atom:entry");
foreach ($articles as $article) {
- array_push($this->items, new FeedItem_Atom($article));
+ array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath));
}
break;
@@ -83,7 +84,7 @@ class FeedParser {
$articles = $xpath->query("//channel/item");
foreach ($articles as $article) {
- array_push($this->items, new FeedItem_RSS($article));
+ array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath));
}
break;