From: Michael J. Rubinsky Date: Mon, 28 Jun 2010 17:40:01 +0000 (-0400) Subject: Use Horde_Http X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a969c1c42a036dc64bd8ea8917d8914254d937c4;p=horde.git Use Horde_Http --- diff --git a/jonah/lib/Exception.php b/jonah/lib/Exception.php new file mode 100644 index 000000000..628e336ab --- /dev/null +++ b/jonah/lib/Exception.php @@ -0,0 +1,12 @@ + + * @package Jonah + */ +class Jonah_Exception extends Horde_Exception_Prior +{ +} diff --git a/jonah/lib/Jonah.php b/jonah/lib/Jonah.php index 9dc14c817..715e4c939 100644 --- a/jonah/lib/Jonah.php +++ b/jonah/lib/Jonah.php @@ -36,28 +36,34 @@ class Jonah const ORDER_COMMENTS = 2; /** - * @TODO: Use Horde_Http + * Obtain the list of stories from the passed in URI. + * + * @param string $url The url to get the list of the channel's stories. */ static public function readURL($url) { global $conf; - $options['method'] = 'GET'; - $options['timeout'] = 5; - $options['allowRedirects'] = true; - + $factory = new Horde_Http_Request_Factory(); + $request = $factory->create(); if (!empty($conf['http']['proxy']['proxy_host'])) { - $options = array_merge($options, $conf['http']['proxy']); + $request->proxyServer = $conf['http']['proxy']['proxy_host']; + $request->proxyPort = $conf['http']['proxy']['proxy_port']; + $request->proxyUsername = $conf['http']['proxy']['proxy_user']; + $request->proxyPassword = $conf['http']['proxy']['proxy_pass']; } - $http = new HTTP_Request($url, $options); - @$http->sendRequest(); - if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Could not open %s."), $url)); + $http = new Horde_Http_Client(array('request' => $request)); + try { + $response = $http->get($url); + } catch (Horde_Http_Exception $e) { + throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $e->getMessage())); } - - $result = array('body' => $http->getResponseBody()); - $content_type = $http->getResponseHeader('Content-Type'); + if ($response->code <> '200') { + throw new Jonah_Exception(sprintf(_("Could not open %s: %s"), $url, $response->code)); + } + $result = array('body' => $response->getBody()); + $content_type = $response->getHeader('Content-Type'); if (preg_match('/.*;\s?charset="?([^"]*)/', $content_type, $match)) { $result['charset'] = $match[1]; } elseif (preg_match('/<\?xml[^>]+encoding=["\']?([^"\'\s?]+)[^?].*?>/i', $result['body'], $match)) { diff --git a/jonah/lib/News.php b/jonah/lib/News.php index dff9ca95f..030f93f38 100644 --- a/jonah/lib/News.php +++ b/jonah/lib/News.php @@ -730,9 +730,10 @@ class Jonah_News { */ function _fetchExternalStories($url, $timestamp) { - $xml = Jonah::readURL($url); - if (is_a($xml, 'PEAR_Error')) { - Horde::logMessage($xml, 'ERR'); + try { + $xml = Jonah::readURL($url); + } catch (Jonah_Exception $e) { + Horde::logMessage($e, 'ERR'); return array('timestamp' => $timestamp); }