($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)
{
{
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
{