AKSW / xodx

An implementation of Semantic Pingback and PuSH for a DSSN
http://aksw.org/Projects/Xodx
GNU General Public License v2.0
5 stars 6 forks source link

Loading a feed generated with feed.phtml template #3

Closed splattater closed 11 years ago

splattater commented 11 years ago

Doing this with method newFromUrl($url) of DSSN_Activity_Feed_Factory of lib-dssn-php causes a warning:

Warning: DOMDocument::load() [domdocument.load]: Extra content at the end of the document in http://xodx.local/?c=feed&a=getFeed&uri=http%3A%2F%2Fxodx.local%2F%3Fc%3Dresource%26id%3D72645a1c9a388a3dbc9f98ebf156d666, line: 2 in /var/www/xodx/libraries/lib-dssn-php/DSSN/Activity/Feed/Factory.php on line 28

The DOMDocument object doesn't get the needed information. The warning disappears by removing the line with link node (rel="hub") in feed.phtml.

Update: The warning doesn't dissapear by removing mentioned line.

splattater commented 11 years ago

Seems to be a problem with redirecting.

white-gecko commented 11 years ago

Please try this patch:

diff --git a/DSSN/Activity/Feed/Factory.php b/DSSN/Activity/Feed/Factory.php
index 15cd589..895fda9 100644
--- a/DSSN/Activity/Feed/Factory.php
+++ b/DSSN/Activity/Feed/Factory.php
@@ -18,20 +18,28 @@ class DSSN_Activity_Feed_Factory
             throw new DSSN_Exception($message);
         }

-        // since DOMDocument::loadXML thows Warnings instead of Exceptions
-        // hack the error handler (see $this->handleXmlError)
-        $handler= array('DSSN_Activity_Feed_Factory', 'HandleXmlError');
-        set_error_handler($handler);
+        $curlHandler = curl_init();

-        // try to parse the document and restore standard handler after that
-        $dom = DOMDocument::load($url);
-        restore_error_handler();
+        // set the url
+        curl_setopt($curlHandler, CURLOPT_URL, $url);
+        curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);
+        curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
+
+        $result = curl_exec($curlHandler);
+        $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
+
+        curl_close($curlHandler);
+
+        if ($httpCode-($httpCode%100) != 200) {
+            $message = 'The request to the given feed url: "' . $url;
+            $message.= '" returned the http code: "' . $httpCode . '"';
+            throw new DSSN_Exception($message);
+        }

         // route to newFromDomDocument
-        return DSSN_Activity_Feed_Factory::newFromDomDocument($dom);
+        return DSSN_Activity_Feed_Factory::newFromXml($result);
     }

-
     /*
      * creates a DSSN_Feed object from a feed xml string
      */

Save it in a file e.g. follow-redirect.patch and apply it with patch -p1 < follow-redirect.patch from the lib-dssn-php base directory.