Add binder for Horde_Http_Client
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 28 Jun 2010 20:09:40 +0000 (14:09 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 28 Jun 2010 20:20:18 +0000 (14:20 -0600)
framework/Core/lib/Horde/Core/Binder/HttpClient.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
horde/lib/Block/feed/reader.php
imp/lib/Compose.php
jonah/lib/Jonah.php

diff --git a/framework/Core/lib/Horde/Core/Binder/HttpClient.php b/framework/Core/lib/Horde/Core/Binder/HttpClient.php
new file mode 100644 (file)
index 0000000..235ceb7
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/**
+ * @category Horde
+ * @package  Core
+ */
+class Horde_Core_Binder_HttpClient implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        global $conf;
+
+        $client_opts = array();
+
+        if (!empty($conf['http']['proxy']['proxy_host'])) {
+            $client_opts['request.proxyServer'] = $conf['http']['proxy']['proxy_host'];
+            $client_opts['request.proxyPort'] = $conf['http']['proxy']['proxy_port'];
+            if (!empty($conf['http']['proxy']['proxy_user'])) {
+                $client_opts['request.proxyUsername'] = $conf['http']['proxy']['proxy_user'];
+                if (!empty($conf['http']['proxy']['proxy_pass'])) {
+                    $client_opts['request.proxyPassword'] = $conf['http']['proxy']['proxy_pass'];
+                }
+            }
+        }
+
+        return new Horde_Http_Client($client_opts);
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
index e1adf8d..7cce25e 100644 (file)
@@ -240,6 +240,7 @@ class Horde_Registry
             'Horde_Db_Pear' => new Horde_Core_Binder_DbPear(),
             'Horde_Editor' => new Horde_Core_Binder_Editor(),
             'Horde_History' => new Horde_Core_Binder_History(),
+            'Horde_Http_Client' => new Horde_Core_Binder_HttpClient(),
             'Horde_Ldap' => new Horde_Core_Binder_Ldap(),
             'Horde_Lock' => new Horde_Core_Binder_Lock(),
             'Horde_Log_Logger' => new Horde_Core_Binder_Logger(),
index e171c25..5630b9f 100644 (file)
@@ -94,6 +94,7 @@ Application Framework.
        <file name="Dns.php" role="php" />
        <file name="Editor.php" role="php" />
        <file name="History.php" role="php" />
+       <file name="HttpClient.php" role="php" />
        <file name="Identity.php" role="php" />
        <file name="Ldap.php" role="php" />
        <file name="Lock.php" role="php" />
@@ -251,6 +252,10 @@ Application Framework.
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>Http</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Kolab_Server</name>
     <channel>pear.horde.org</channel>
    </package>
@@ -291,6 +296,7 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Dns.php" as="Horde/Core/Binder/Dns.php" />
    <install name="lib/Horde/Core/Binder/Editor.php" as="Horde/Core/Binder/Editor.php" />
    <install name="lib/Horde/Core/Binder/History.php" as="Horde/Core/Binder/History.php" />
+   <install name="lib/Horde/Core/Binder/HttpClient.php" as="Horde/Core/Binder/HttpClient.php" />
    <install name="lib/Horde/Core/Binder/Identity.php" as="Horde/Core/Binder/Identity.php" />
    <install name="lib/Horde/Core/Binder/Ldap.php" as="Horde/Core/Binder/Ldap.php" />
    <install name="lib/Horde/Core/Binder/Lock.php" as="Horde/Core/Binder/Lock.php" />
index b6d6736..d2b9e8d 100644 (file)
@@ -22,13 +22,7 @@ class Horde_Block_Horde_feed_reader {
 
         try {
             if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
-                $client = new Horde_Http_Client;
-                $client->proxyServer = $GLOBALS['conf']['http']['proxy']['proxy_host'] . ':' . $GLOBALS['conf']['http']['proxy']['proxy_port'];
-                if (!empty($GLOBALS['conf']['http']['proxy']['proxy_user'])) {
-                    $client->proxyUser = $GLOBALS['conf']['http']['proxy']['proxy_user'];
-                    $client->proxyPass = empty($GLOBALS['conf']['http']['proxy']['proxy_pass']) ? $GLOBALS['conf']['http']['proxy']['proxy_pass'] : '';
-                }
-                Horde_Feed::setHttpClient($client);
+                Horde_Feed::setHttpClient($GLOBALS['injector']->getInstance('Horde_Http_Client'));
             }
 
             $feed = Horde_Feed::readUri($uri);
index 98f29bc..997628a 100644 (file)
@@ -1081,8 +1081,6 @@ class IMP_Compose
             $textpart->setHeaderCharset($charset);
 
             if (empty($options['nofinal'])) {
-                /* Any image links will be downloaded and appended to the
-                 * message body. */
                 $textpart->addPart($this->_convertToMultipartRelated($htmlBody));
             } else {
                 $textpart->addPart($htmlBody);
@@ -2267,19 +2265,11 @@ class IMP_Compose
             return $mime_part;
         }
 
-        $client_opts = $img_data = $img_parts = array();
+        $client = $GLOBALS['injector']->getInstance('Horde_Http_Client');
+        $img_data = $img_parts = array();
 
         /* Go through list of results, download the image, and create
          * Horde_Mime_Part objects with the data. */
-        if (!empty($conf['http']['proxy']['proxy_host'])) {
-            $client_opts['proxyServer'] = $conf['http']['proxy']['proxy_host'] . ':' . $conf['http']['proxy']['proxy_port'];
-            if (!empty($conf['http']['proxy']['proxy_user'])) {
-                $client_opts['proxyUser'] = $conf['http']['proxy']['proxy_user'];
-                $client_opts['proxyPass'] = empty($conf['http']['proxy']['proxy_pass']) ? $conf['http']['proxy']['proxy_pass'] : '';
-            }
-        }
-        $client = new Horde_Http_Client($client_opts);
-
         foreach ($results[1] as $url) {
             /* Attempt to download the image data. */
             $response = $client->get(str_replace('&amp;', '&', trim($url, '"\'')));
index 715e4c9..3610fcc 100644 (file)
@@ -44,16 +44,8 @@ class Jonah
     {
         global $conf;
 
-        $factory = new Horde_Http_Request_Factory();
-        $request = $factory->create();
-        if (!empty($conf['http']['proxy']['proxy_host'])) {
-            $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 = $GLOBALS['injector']->getInstance('Horde_Http_Client');
 
-        $http = new Horde_Http_Client(array('request' => $request));
         try {
             $response = $http->get($url);
         } catch (Horde_Http_Exception $e) {