]> git.mjollnir.org Git - s9y.git/commitdiff
Commit for dkg: Make Onyx utilize PEAR function for fetching a file. This does no...
authorgarvinhicking <garvinhicking>
Fri, 26 Aug 2005 12:51:47 +0000 (12:51 +0000)
committergarvinhicking <garvinhicking>
Fri, 26 Aug 2005 12:51:47 +0000 (12:51 +0000)
bundled-libs/Onyx/RSS.php
docs/NEWS

index 9601c4108a47dbd47cacb386326ff077705df0f2..aa8d782c0992357f2843b2fb6b5fe57b7c9d8cd7 100644 (file)
@@ -124,26 +124,29 @@ class ONYX_RSS
            ($file && file_exists($file) && $time <= $this->rss['cache_age'] && $mod >= (time() - ($this->rss['cache_age'] * 60))))
       {
          clearstatcache();
-         if (!($fp = @fopen($uri, 'r')))
+         
+         require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
+         $req = &new HTTP_Request($uri);
+         $res = $req->sendRequest();
+        
+         if (PEAR::isError($res) || $req->getResponseCode() != '200')
          {
             $this->raiseError((__LINE__-2), ONYX_ERR_INVALID_URI);
             return false;
          }
-         $firstchunk_read = false;
-         while ($chunk = fread($fp, 4096))
+
+         $fContent = $req->getResponseBody();
+         if (@preg_match('@<?xml[^>]*encoding="([^"]+)"@i', $fContent, $xml_encoding)) {
+            $this->rss['encoding'] = strtolower($xml_encoding[1]);
+         }
+
+         $parsedOkay = xml_parse($this->parser, $fContent, true);
+         if (!$parsedOkay && xml_get_error_code($this->parser) != XML_ERROR_NONE)
          {
-            if (!$firstchunk_read && @preg_match('@<?xml[^>]*encoding="([^"]+)"@i', $chunk, $xml_encoding)) {
-                $this->rss['encoding'] = strtolower($xml_encoding[1]);
-            }
-            $parsedOkay = xml_parse($this->parser, $chunk, feof($fp));
-            if (!$parsedOkay && xml_get_error_code($this->parser) != XML_ERROR_NONE)
-            {
-               $this->raiseError((__LINE__-3), 'File has an XML error (<em>'.xml_error_string(xml_get_error_code($this->parser)).'</em> at line <em>'.xml_get_current_line_number($this->parser).'</em>).');
-               return false;
-            }
-            $firstchunk_read = true;
+            $this->raiseError((__LINE__-3), 'File has an XML error (<em>'.xml_error_string(xml_get_error_code($this->parser)).'</em> at line <em>'.xml_get_current_line_number($this->parser).'</em>).');
+            return false;
          }
-         fclose($fp);
+
          clearstatcache();
          if ($file)
          {
@@ -338,17 +341,16 @@ class ONYX_RSS
    {
       if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') >= 0)
       {
-         if (!($fp = @fopen($uri, 'r')))
+         require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
+         $req = &new HTTP_Request($uri);
+
+         if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200')
             return false;
 
-         $meta = stream_get_meta_data($fp);
-         for ($j = 0; isset($meta['wrapper_data'][$j]); $j++)
-            if (strpos(strtolower($meta['wrapper_data'][$j]), 'last-modified') !== false)
-            {
-               $modtime = substr($meta['wrapper_data'][$j], 15);
-               break;
-            }
-         fclose($fp);
+         $fHeader = $req->getResponseHeader();
+         if (isset($fHeader['last-modified'])) {
+            $modtime = $fHeader['last-modified'];
+        }
       }
       else
       {
index 26138b7aba12be22b4dd51eafcee60896e3cd3ed..6d84446551e41f346265a8286b9a6cbd3511fae3 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,11 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Onyx RSS parser now uses PEAR::HTTP_Request instead of fopen wrappers
+      to work on allow_url_fopen disabled hosts. Plugins like remoterss and
+      aggregator can now properly fetch RSS feeds on those hosts.
+      (garvinhicking)
+
     * Fix putting sticky entry on the last page in postgreSQL setups.
       Thanks to Nate Johnston for working this out! (garvinhicking)