From 741a011f1120b6c5bff0edd0b9483ee00a79ecf2 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 26 Aug 2005 12:51:47 +0000 Subject: [PATCH] Commit for dkg: Make Onyx utilize PEAR function for fetching a file. This does no longer require allow_url_fopen. --- bundled-libs/Onyx/RSS.php | 48 ++++++++++++++++++++------------------- docs/NEWS | 5 ++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/bundled-libs/Onyx/RSS.php b/bundled-libs/Onyx/RSS.php index 9601c41..aa8d782 100644 --- a/bundled-libs/Onyx/RSS.php +++ b/bundled-libs/Onyx/RSS.php @@ -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('@]*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('@]*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 ('.xml_error_string(xml_get_error_code($this->parser)).' at line '.xml_get_current_line_number($this->parser).').'); - return false; - } - $firstchunk_read = true; + $this->raiseError((__LINE__-3), 'File has an XML error ('.xml_error_string(xml_get_error_code($this->parser)).' at line '.xml_get_current_line_number($this->parser).').'); + 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 { diff --git a/docs/NEWS b/docs/NEWS index 26138b7..6d84446 100644 --- 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) -- 2.39.5