]> git.wh0rd.org - tt-rss.git/commitdiff
add support for dc:subject and slash:comments
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 16:55:08 +0000 (20:55 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 16:55:08 +0000 (20:55 +0400)
classes/feeditem/atom.php
classes/feeditem/rss.php
classes/feedparser.php
include/rssfuncs.php

index 7dc4ce5c1373cea87de139898b43ba87a4ad0afd..d2193389731a3e13b766ad008dc25584c74ece8f 100644 (file)
@@ -1,9 +1,11 @@
 <?php
 class FeedItem_Atom {
        private $elem;
+       private $xpath;
 
        function __construct($elem, $doc, $xpath) {
                $this->elem = $elem;
+               $this->xpath = $xpath;
        }
 
        function get_id() {
@@ -63,9 +65,12 @@ class FeedItem_Atom {
 
        }
 
-       // todo
        function get_comments_count() {
+               $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
 
+               if ($comments) {
+                       return $comments->nodeValue;
+               }
        }
 
        function get_categories() {
@@ -77,6 +82,11 @@ class FeedItem_Atom {
                                array_push($cats, $cat->getAttribute("term"));
                }
 
+               $categories = $this->xpath->query("dc:subject", $this->elem);
+
+               foreach ($categories as $cat) {
+                       array_push($cats, $cat->nodeValue);
+               }
 
                return $cats;
        }
@@ -100,6 +110,18 @@ class FeedItem_Atom {
                        }
                }
 
+               $enclosures = $this->xpath->query("media:content", $this->elem);
+
+               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 e5e2a8e56544626c3dc98b46ef55d2b5c4cb8d09..7a3b0d342564ed0d8d89abb4e09d02b765062746 100644 (file)
@@ -63,9 +63,12 @@ class FeedItem_RSS {
 
        }
 
-       // todo
        function get_comments_count() {
+               $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
 
+               if ($comments) {
+                       return $comments->nodeValue;
+               }
        }
 
        function get_categories() {
@@ -76,6 +79,12 @@ class FeedItem_RSS {
                        array_push($cats, $cat->nodeValue);
                }
 
+               $categories = $this->xpath->query("dc:subject", $this->elem);
+
+               foreach ($categories as $cat) {
+                       array_push($cats, $cat->nodeValue);
+               }
+
                return $cats;
        }
 
@@ -96,8 +105,6 @@ class FeedItem_RSS {
 
                $enclosures = $this->xpath->query("media:content", $this->elem);
 
-               $encs = array();
-
                foreach ($enclosures as $enclosure) {
                        $enc = new FeedEnclosure();
 
index 8cb736a8b5fd8a2b795dd557b1b3a14c7c0ecff9..f61c2a0031aba86c465abb0298ca2e1a23d94477 100644 (file)
@@ -29,6 +29,9 @@ class FeedParser {
                $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
                $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/');
                $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
+               $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');
+               $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
+
                $this->xpath = $xpath;
 
                $root = $xpath->query("(//atom:feed|//channel|//rdf:rdf|//rdf:RDF)")->item(0);
index d1175a30386eceff23c2cdeb49093c4012514e56..f342bf7f11a2e7ea81e8c52fc62abf6cb902a3a8 100644 (file)
                                $entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245));
                                $entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245));
 
-                               $num_comments = $item->get_comments_count();
-
-                               if (is_array($num_comments) && is_array($num_comments[0])) {
-                                       $num_comments = (int) $num_comments[0]["data"];
-                               } else {
-                                       $num_comments = 0;
-                               }
+                               $num_comments = (int) $item->get_comments_count();
 
                                _debug("author $entry_author", $debug_enabled);
                                _debug("num_comments: $num_comments", $debug_enabled);