]> git.wh0rd.org Git - tt-rss.git/commitdiff
pass xpath object to feeditem, support media-rss objects
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 15:40:43 +0000 (19:40 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 15:40:43 +0000 (19:40 +0400)
classes/feeditem/atom.php
classes/feeditem/rss.php
classes/feedparser.php

index 0d888c4437f61ac261eda8fc4e8b0c753b3dbdc2..7dc4ce5c1373cea87de139898b43ba87a4ad0afd 100644 (file)
@@ -2,7 +2,7 @@
 class FeedItem_Atom {
        private $elem;
 
-       function __construct($elem) {
+       function __construct($elem, $doc, $xpath) {
                $this->elem = $elem;
        }
 
index d5667102dc4d29559e33688af7381b7a86124a49..e5e2a8e56544626c3dc98b46ef55d2b5c4cb8d09 100644 (file)
@@ -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;
        }
 
index f127ba73d9596e8dbb775e02c5fdd8256fd625df..eabbb5b2863668e80d57d7c8c687c34767c6a6c6 100644 (file)
@@ -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;