Просмотр исходного кода

Added Zend_Feed_Reader support for fetching an array of Pubsubhubbub Hub endpoints using getHubs() method.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18514 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 лет назад
Родитель
Сommit
0806eefcf9

+ 10 - 0
documentation/manual/en/module_specs/Zend_Feed_Reader.xml

@@ -592,6 +592,16 @@ foreach ($links as $link) {
                             Returns any copyright notice associated with the feed
                         </entry>
                     </row>
+
+                    <row>
+                        <entry><methodname>getHubs()</methodname></entry>
+
+                        <entry>
+                            Returns an array of all Hub Server <acronym>URI</acronym> endpoints which
+                            are advertised by the feed for using with the Pubsubhubbub
+                            Protocol, allowing subscriptions to the feed for real-time updates.
+                        </entry>
+                    </row>
         </tbody>
       </tgroup>
     </table>

+ 27 - 0
library/Zend/Feed/Reader/Extension/Atom/Feed.php

@@ -339,6 +339,33 @@ class Zend_Feed_Reader_Extension_Atom_Feed
     }
 
     /**
+     * Get an array of any supported Pusubhubbub endpoints
+     *
+     * @return array|null
+     */
+    public function getHubs()
+    {
+        if (array_key_exists('hubs', $this->_data)) {
+            return $this->_data['hubs'];
+        }
+        $hubs = array();
+        $list = $this->_xpath->query($this->getXpathPrefix()
+            . '//atom:link[@rel="hub"]/@href');
+
+        if ($list->length) {
+            foreach ($list as $uri) {
+                $hubs[] = $uri->nodeValue;
+            }
+        } else {
+            $hubs = null;
+        }
+
+        $this->_data['hubs'] = $hubs;
+
+        return $this->_data['hubs'];
+    }
+
+    /**
      * Get the feed title
      *
      * @return string|null

+ 18 - 0
library/Zend/Feed/Reader/Feed/Atom.php

@@ -295,6 +295,24 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract
     }
 
     /**
+     * Get an array of any supported Pusubhubbub endpoints
+     *
+     * @return array|null
+     */
+    public function getHubs()
+    {
+        if (array_key_exists('hubs', $this->_data)) {
+            return $this->_data['hubs'];
+        }
+
+        $hubs = $this->getExtension('Atom')->getHubs();
+
+        $this->_data['hubs'] = $hubs;
+
+        return $this->_data['hubs'];
+    }
+
+    /**
      * Read all entries to the internal entries array
      *
      */

+ 24 - 0
library/Zend/Feed/Reader/Feed/Rss.php

@@ -494,6 +494,30 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
     }
 
     /**
+     * Get an array of any supported Pusubhubbub endpoints
+     *
+     * @return array|null
+     */
+    public function getHubs()
+    {
+        if (array_key_exists('hubs', $this->_data)) {
+            return $this->_data['hubs'];
+        }
+
+        $hubs = $this->getExtension('Atom')->getHubs();
+
+        if (empty($hubs)) {
+            $hubs = null;
+        } else {
+            $hubs = array_unique($hubs);
+        }
+
+        $this->_data['hubs'] = $hubs;
+
+        return $this->_data['hubs'];
+    }
+
+    /**
      * Read all entries to the internal entries array
      *
      */

+ 26 - 0
tests/Zend/Feed/Reader/Feed/AtomTest.php

@@ -303,6 +303,32 @@ class Zend_Feed_Reader_Feed_AtomTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * Get Pubsubhubbub Hubs
+     */
+    public function testGetsHubsFromAtom03()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom03.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromAtom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+
+    /**
      * Implements Countable
      */
 

+ 140 - 0
tests/Zend/Feed/Reader/Feed/RssTest.php

@@ -2198,5 +2198,145 @@ class Zend_Feed_Reader_Feed_RssTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(null, $feed->getDateModified());
     }
 
+    //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
+
+    /**
+     * Get Hubs (Unencoded Text)
+     */
+    public function testGetsHubsFromRss20()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss20.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss094()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss094.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss093()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss093.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss092()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss092.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss091()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss091.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss10.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss090()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/atom10/rss090.xml')
+        );
+        $this->assertEquals(array(
+            'http://www.example.com/hub1',
+            'http://www.example.com/hub2'
+        ), $feed->getHubs());
+    }
+
+    // Missing Hubs
+
+    public function testGetsHubsFromRss20_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss20.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss094_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss094.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss093_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss093.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss092_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss092.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss091_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss091.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss10_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss10.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
+    public function testGetsHubsFromRss090_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/hubs/plain/none/rss090.xml')
+        );
+        $this->assertEquals(null, $feed->getHubs());
+    }
+
 
 }

+ 5 - 0
tests/Zend/Feed/Reader/Feed/_files/Atom/hubs/plain/atom03.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<feed version="0.3" xmlns="http://purl.org/atom/ns#">
+    <link rel="hub" href="http://www.example.com/hub1"/>
+    <link rel="hub" href="http://www.example.com/hub2"/>
+</feed>

+ 5 - 0
tests/Zend/Feed/Reader/Feed/_files/Atom/hubs/plain/atom10.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+    <link rel="hub" href="http://www.example.com/hub1"/>
+    <link rel="hub" href="http://www.example.com/hub2"/>
+</feed>