저자: Chuck Hagenbuch (chuck@horde.org)
예제 #1
0
 public function testGetBodyAfter404()
 {
     $this->_skipMissingConfig();
     $client = new Horde_Http_Client(array('request' => new self::$_requestClass()));
     $response = $client->get('http://' . $this->_server . '/doesntexist');
     $content = $response->getBody();
     $this->assertGreaterThan(0, strlen($content));
 }
예제 #2
0
 public function testGetBodyAfter404()
 {
     $this->_skipMissingConfig();
     $client = new Horde_Http_Client(array('request' => new Horde_Http_Request_Curl()));
     $response = $client->get('http://' . $this->_server . '/doesntexist');
     $content = $response->getBody();
     $this->assertTrue(!empty($content));
 }
예제 #3
0
 public function testBug12991()
 {
     $this->_skipMissingConfig();
     $client = new Horde_Http_Client(array('request' => new Horde_Http_Request_Fopen()));
     $response = $client->get($this->_server . '/doesntexist');
     $body = $response->getBody();
     $this->assertTrue(strlen($body) > 0);
 }
예제 #4
0
 public function testAddArrayResponses()
 {
     $mock = new Horde_Http_Request_Mock();
     $mock->addResponses(array(array('body' => 'A'), array('code' => 404), array('uri' => 'http://example.org'), array('headers' => 'test: TEST')));
     $client = new Horde_Http_Client(array('request' => $mock));
     $this->assertEquals('A', $client->get()->getBody());
     $this->assertEquals(404, $client->get()->code);
     $this->assertEquals('http://example.org', $client->get()->uri);
     $this->assertEquals('TEST', $client->get()->getHeader('test'));
 }
예제 #5
0
파일: Blogger.php 프로젝트: raz0rsdge/horde
 /**
  * Push content to the recipient.
  *
  * @param Horde_Push $content The content element.
  * @param array      $options Additional options.
  *
  * @return NULL
  */
 public function push(Horde_Push $content, $options = array())
 {
     $entry = new Horde_Feed_Entry_Atom(null, $this->_client);
     $types = $content->getMimeTypes();
     if (isset($types['text/html'])) {
         $body = $content->getStringContent($types['text/html'][0]);
     } else {
         if (isset($types['text/plain'])) {
             $body = $content->getStringContent($types['text/plain'][0]);
         } else {
             $body = '';
         }
     }
     /* Give the entry its initial values. */
     $entry->{'atom:title'} = $content->getSummary();
     $entry->{'atom:title'}['type'] = 'text';
     $entry->{'atom:content'} = $body;
     $entry->{'atom:content'}['type'] = 'text';
     if (!empty($options['pretend'])) {
         return sprintf("Would push \n\n%s\n\n to %s.", (string) $entry, $this->_params['url']);
     }
     /* Authenticate. */
     $response = $this->_client->post('https://www.google.com/accounts/ClientLogin', 'accountType=GOOGLE&service=blogger&source=horde-push&Email=' . $this->_params['username'] . '&Passwd=' . $this->_params['password'], array('Content-type', 'application/x-www-form-urlencoded'));
     if ($response->code !== 200) {
         throw new Horde_Push_Exception('Expected response code 200, got ' . $response->code);
     }
     $auth = null;
     foreach (explode("\n", $response->getBody()) as $line) {
         $param = explode('=', $line);
         if ($param[0] == 'Auth') {
             $auth = $param[1];
         }
     }
     if (empty($auth)) {
         throw new Horde_Push_Exception('Missing authentication token in the response!');
     }
     /* Do the initial post. */
     try {
         $entry->save($this->_params['url'], array('Authorization' => 'GoogleLogin auth=' . $auth));
         $reference = $entry->link('alternate');
         if (!empty($reference)) {
             $content->addReference($reference);
         }
     } catch (Horde_Exception $e) {
         throw new Horde_Push_Exception($e);
     }
     return sprintf('Pushed blog entry to %s.', $this->_params['url']);
 }
예제 #6
0
파일: Remote.php 프로젝트: jubinpatel/horde
 /**
  * Place the component source archive at the specified location.
  *
  * @param string $destination The path to write the archive to.
  * @param array  $options     Options for the operation.
  *
  * @return array An array with at least [0] the path to the resulting
  *               archive, optionally [1] an array of error strings, and [2]
  *               PEAR output.
  */
 public function placeArchive($destination, $options = array())
 {
     $this->createDestination($destination);
     $this->_client->{'request.timeout'} = 60;
     file_put_contents($destination . '/' . basename($this->_getDownloadUri()), $this->_client->get($this->_getDownloadUri())->getStream());
     return array($destination . '/' . basename($this->_getDownloadUri()));
 }
예제 #7
0
파일: DocsOrigin.php 프로젝트: horde/horde
 /**
  * Fetch the given remote document into a local target path.
  *
  * @param string            $remote  The remote URI.
  * @param string            $local   The local target path.
  * @param Components_Output $output  The output handler.
  *
  *
  * @return NULL
  */
 public function _fetchDocument($remote, $local, Components_Output $output)
 {
     $this->_client->{'request.timeout'} = 60;
     $content = stream_get_contents($this->_client->get($remote)->getStream());
     $content = preg_replace('#^(\\.\\. _`([^`]*)`: )((?!http://).*)#m', '\\1\\2', $content);
     file_put_contents($this->_docs_origin[1] . '/' . $local, $content);
     $output->ok(sprintf('Fetched remote %s into %s!', $remote, $this->_docs_origin[1] . '/' . $local));
 }
예제 #8
0
 /**
  * Returns the first matching key ID for an email address from a public
  * keyserver.
  *
  * @param string $address  The email address of the PGP key.
  *
  * @return string  The PGP key ID.
  * @throws Horde_Crypt_Exception
  */
 public function getKeyId($address)
 {
     $pubkey = null;
     /* Connect to the public keyserver. */
     $url = $this->_createUrl('/pks/lookup', array('op' => 'index', 'options' => 'mr', 'search' => $address));
     try {
         $output = $this->_http->get($url)->getBody();
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Crypt_Exception($e);
     }
     if (strpos($output, '-----BEGIN PGP PUBLIC KEY BLOCK') !== false) {
         $pubkey = $output;
     } elseif (strpos($output, 'pub:') !== false) {
         $output = explode("\n", $output);
         $keyids = $keyuids = array();
         $curid = null;
         foreach ($output as $line) {
             if (substr($line, 0, 4) == 'pub:') {
                 $line = explode(':', $line);
                 /* Ignore invalid lines and expired keys. */
                 if (count($line) != 7 || !empty($line[5]) && $line[5] <= time()) {
                     continue;
                 }
                 $curid = $line[4];
                 $keyids[$curid] = $line[1];
             } elseif (!is_null($curid) && substr($line, 0, 4) == 'uid:') {
                 preg_match("/<([^>]+)>/", $line, $matches);
                 $keyuids[$curid][] = $matches[1];
             }
         }
         /* Remove keys without a matching UID. */
         foreach ($keyuids as $id => $uids) {
             $match = false;
             foreach ($uids as $uid) {
                 if ($uid == $address) {
                     $match = true;
                     break;
                 }
             }
             if (!$match) {
                 unset($keyids[$id]);
             }
         }
         /* Sort by timestamp to use the newest key. */
         if (count($keyids)) {
             ksort($keyids);
             $pubkey = $this->get(array_pop($keyids));
         }
     }
     if ($pubkey) {
         $sig = $this->_pgp->pgpPacketSignature($pubkey, $address);
         if (!empty($sig['keyid']) && (empty($sig['public_key']['expires']) || $sig['public_key']['expires'] > time())) {
             return substr($this->_pgp->getKeyIDString($sig['keyid']), 2);
         }
     }
     throw new Horde_Crypt_Exception(Horde_Crypt_Translation::t("Could not obtain public key from the keyserver."));
 }
예제 #9
0
 /**
  * Process a Thunderbird autoconfig entry.
  *
  * @param string $domain                    Domain name.
  * @param string $tag                       XML tag to parse.
  * @param array $types                      List of $tag types to process.
  * @param Horde_Mail_Rfc822_Address $email  Username.
  */
 protected function _process($domain, $tag, $types, $email)
 {
     $out = array();
     $urls = array('http://' . urlencode($domain) . '/.well-known/autoconfig/mail/config-v1.1.xml', $this->ispdb . urlencode($domain));
     if (!is_null($email)) {
         array_unshift($urls, 'http://autoconfig.' . urlencode($domain) . '/mail/config-v1.1.xml?emailaddress=' . urlencode($email->bare_address));
     }
     if (is_null($this->http)) {
         $this->http = new Horde_Http_Client();
     }
     foreach ($urls as $url) {
         try {
             $get = $this->http->get($url);
             if ($get->code == 404) {
                 continue;
             }
             try {
                 $xml = new SimpleXMLElement($get->getBody());
             } catch (Exception $e) {
                 // No valid XML; ignore
                 continue;
             }
             $label = strval($xml->emailProvider->displayName);
             foreach ($xml->emailProvider->{$tag} as $val) {
                 if (in_array($val['type'], $types)) {
                     switch ($val['type']) {
                         case 'imap':
                             $ob = new Horde_Mail_Autoconfig_Server_Imap();
                             break;
                         case 'pop3':
                             $ob = new Horde_Mail_Autoconfig_Server_Pop3();
                             break;
                         case 'smtp':
                             $ob = new Horde_Mail_Autoconfig_Server_Msa();
                             break;
                     }
                     $ob->host = strval($val->hostname);
                     $ob->port = intval(strval($val->port));
                     $ob->label = $label;
                     if (strcasecmp($val->socketType, 'SSL') === 0) {
                         $ob->tls = 'tls';
                     }
                     if (!is_null($email) && $email->valid && strlen($val->username)) {
                         $ob->username = str_replace(array('%EMAILADDRESS%', '%EMAILLOCALPART%'), array($email->bare_address, $email->mailbox), $val->username);
                     }
                     $out[] = $ob;
                 }
             }
             if (count($out)) {
                 return $out;
             }
         } catch (Horde_Http_Exception $e) {
             // Not found; ignore.
         }
     }
     return false;
 }
예제 #10
0
파일: Rest.php 프로젝트: raz0rsdge/horde
 /**
  * Fetch the provided URL as string.
  *
  * @param string $url The URL.
  *
  * @return string The response as string.
  */
 private function _read($url)
 {
     $response = $this->_client->get($url);
     if ($response->code === 200) {
         return $response->getBody();
     } else {
         return false;
     }
 }
예제 #11
0
파일: PassThrough.php 프로젝트: horde/horde
 /**
  * Fetch remote data.
  *
  * @param Horde_Controller_Response  $response The response handler.
  *
  * @return NULL
  */
 public function _passThrough(Horde_Controller_Response $response)
 {
     $url = $this->getUrlWithCredentials($this->_user->getPrimaryId(), $this->_user->getPassword());
     $origin = $this->_client->get($url);
     if ($origin->code !== 200) {
         $url = $this->getUrlWithCredentials($this->_user, 'XXX');
         throw new Horde_Kolab_FreeBusy_Exception_Unauthorized(sprintf('Unable to read free/busy information from %s', $url));
     }
     $response->setHeader('X-Redirect-To', $url);
     $response->setBody($origin->getStream());
 }
예제 #12
0
파일: Base.php 프로젝트: horde/horde
 /**
  * Sends a request and parses the response.
  *
  * @param string $method      A HTTP request method (uppercase).
  * @param string $namespace   An API namespace.
  * @param array $params       URL parameters.
  * @param array|string $data  Request data.
  *
  * @return array  The decoded result data or null if no data has been
  *                returned but the request was still successful.
  * @throws Horde_OpenXchange_Exception.
  */
 protected function _request($method, $namespace, $params, $data = array())
 {
     $uri = new Horde_Url($this->_uri . '/' . $namespace, true);
     try {
         $headers = array();
         if (isset($this->_cookies)) {
             $headers['Cookie'] = implode('; ', $this->_cookies);
         }
         if ($method == 'GET') {
             $params = array_merge($params, $data);
             $data = null;
         }
         $response = $this->_client->request($method, (string) $uri->add($params), $data, $headers);
         if ($cookies = $response->getHeader('set-cookie')) {
             if (!is_array($cookies)) {
                 $cookies = array($cookies);
             }
             foreach ($cookies as $cookie) {
                 $cookie = preg_split('/;\\s*/', $cookie);
                 for ($i = 1, $c = count($cookie); $i < $c; $i++) {
                     list($key, $value) = explode('=', $cookie[$i]);
                     if ($key == 'Expires') {
                         $expire = new Horde_Date($value);
                         if ($expire->before(time())) {
                             continue 2;
                         }
                         break;
                     }
                 }
                 $this->_cookies[] = $cookie[0];
             }
         }
         $body = $response->getBody();
         $data = json_decode($body, true);
         if (!$data) {
             if ($response->code == 200) {
                 return;
             }
             throw new Horde_OpenXchange_Exception($body);
         }
         if (isset($data['error'])) {
             $e = new Horde_OpenXchange_Exception($data['error']);
             $e->details = $data;
             throw $e;
         }
         return $data;
     } catch (Horde_Http_Exception $e) {
         throw new Horde_OpenXchange_Exception($e);
     }
 }
예제 #13
0
파일: Base.php 프로젝트: horde/horde
 /**
  * Imports a URL.
  *
  * @since 2.1.0
  */
 public function importUrl($url, $header = false)
 {
     if (!isset($this->_http)) {
         throw new LogicException('Missing http parameter.');
     }
     try {
         $response = $this->_http->get($url);
         if ($response->code != 200) {
             throw new Horde_Data_Exception(sprintf(Horde_Data_Translation::t("URL %s not found"), $url));
         }
         $data = $response->getBody();
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Data_Exception($e);
     }
     return $this->importData($data, $header);
 }
예제 #14
0
파일: Owa.php 프로젝트: horde/horde
 /**
  * Lists all events in the given time range.
  *
  * @param Horde_Date $startDate Start of range date object.
  * @param Horde_Date $endDate   End of range data object.
  *
  * @return array Events in the given time range.
  *
  * @throws Horde_Kolab_FreeBusy_Exception If retrieving the events failed.
  */
 public function listEvents(Horde_Date $startDate, Horde_Date $endDate)
 {
     $url = $this->_params['url'] . '/public/?cmd=freebusy' . '&start=' . $startDate->format('c') . '&end=' . $endDate->format('c') . '&interval=' . $this->_params['interval'] . '&u=SMTP:' . $this->_owner->getOwner();
     $response = $this->_client->get($url, array('User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)'));
     if ($response->code !== 200) {
         throw new Horde_Kolab_FreeBusy_Exception_NotFound(sprintf('Unable to fetch free/busy information from %s', $url));
     }
     $owa = new Horde_Kolab_FreeBusy_Freebusy_Helper_Owa($response->getStream());
     $result = $owa->convert($startDate, $endDate, $this->_params['interval']);
     if (!isset($result[$this->_owner->getOwner()])) {
         return array();
     }
     $events = array();
     foreach ($result[$this->_owner->getOwner()] as $item) {
         $events[] = new Horde_Kolab_FreeBusy_Object_Event($item);
     }
     return $events;
 }
예제 #15
0
파일: Keyserver.php 프로젝트: horde/horde
 /**
  * Returns the first matching key for an email address from a public
  * keyserver.
  *
  * @param string $address  The email address to search for.
  *
  * @return Horde_Pgp_Element_PublicKey  The PGP public key.
  * @throws Horde_Pgp_Exception
  */
 public function getKeyByEmail($address)
 {
     $output = null;
     /* Connect to the public keyserver. */
     $url = $this->_createUrl('/pks/lookup', array('op' => 'index', 'options' => 'mr', 'search' => $address));
     // Some keyservers are broken, third time's a charm.
     for ($i = 0; $i < 3; $i++) {
         try {
             $response = $this->_http->get($url);
             // Some keyservers return HTML, try again.
             if (strpos($response->getHeader('Content-Type'), 'text/plain') !== 0) {
                 continue;
             }
             $output = ltrim($response->getBody());
         } catch (Horde_Http_Exception $e) {
             throw new Horde_Pgp_Exception($e);
         }
     }
     if (!$output) {
         throw new Horde_Pgp_Exception(Horde_Pgp_Translation::t("Could not obtain public key from the keyserver."));
     }
     if (strpos($output, '-----BEGIN PGP PUBLIC KEY BLOCK') !== false) {
         return Horde_Pgp_Element_PublicKey::create($output);
     } elseif (strpos($output, 'pub:') !== false) {
         $output = explode("\n", $output);
         $keyids = $keyuids = array();
         $curid = null;
         foreach ($output as $line) {
             if (substr($line, 0, 4) == 'pub:') {
                 $line = explode(':', $line);
                 /* Ignore invalid lines and expired keys. */
                 if (count($line) != 7 || !empty($line[5]) && $line[5] <= time()) {
                     continue;
                 }
                 $curid = $line[4];
                 $keyids[$curid] = $line[1];
             } elseif (!is_null($curid) && substr($line, 0, 4) == 'uid:') {
                 preg_match("/<([^>]+)>/", $line, $matches);
                 $keyuids[$curid][] = $matches[1];
             }
         }
         /* Remove keys without a matching UID. */
         foreach ($keyuids as $id => $uids) {
             $match = false;
             foreach ($uids as $uid) {
                 if ($uid == $address) {
                     $match = true;
                     break;
                 }
             }
             if (!$match) {
                 unset($keyids[$id]);
             }
         }
         /* Sort by timestamp to use the newest key. */
         if (count($keyids)) {
             ksort($keyids);
             return $this->get(array_pop($keyids));
         }
     }
     throw new Horde_Pgp_Exception(Horde_Pgp_Translation::t("Could not obtain public key from the keyserver."));
 }
예제 #16
0
 /**
  * Obtain an access token from a request token
  *
  * @param Horde_Oauth_Token $token Open auth token containing the oauth_token
  *                                 returned from provider after authorization
  *                                 and the token secret returned with the
  *                                 original request token.
  * @param array $params           Any additional parameters for this request
  *
  * @return unknown_type
  */
 public function getAccessToken($token, $params = array())
 {
     $params['oauth_consumer_key'] = $this->key;
     $params['oauth_token'] = $token->key;
     $request = new Horde_Oauth_Request($this->accessTokenUrl, $params);
     $request->sign($this->signatureMethod, $this, $token);
     $client = new Horde_Http_Client();
     try {
         $response = $client->post($this->accessTokenUrl, $request->buildHttpQuery());
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Oauth_Exception($e->getMessage());
     }
     return Horde_Oauth_Token::fromString($response->getBody());
 }
예제 #17
0
파일: Client.php 프로젝트: jubinpatel/horde
 /**
  * Performs an actual HTTP request, and returns the result.
  *
  * If the specified url is relative, it will be expanded based on the base
  * url.
  *
  * The returned array contains 3 keys:
  *   * body - the response body
  *   * httpCode - a HTTP code (200, 404, etc)
  *   * headers - a list of response http headers. The header names have
  *     been lowercased.
  *
  * @param string $method
  * @param string $url
  * @param string $body
  * @param array $headers
  *
  * @return array
  * @throws Horde_Dav_Exception
  */
 public function request($method, $url = '', $body = null, $headers = array())
 {
     $url = $this->getAbsoluteUrl($url);
     $this->_http->{'request.redirects'} = 5;
     $this->_http->{'request.verifyPeer'} = $this->verifyPeer;
     if ($this->proxy) {
         $this->_http->{'request.proxyServer'} = $this->proxy;
     }
     if ($this->userName && $this->authType) {
         if ($this->authType & self::AUTH_BASIC) {
             $this->_http->{'request.authenticationScheme'} = Horde_Http::AUTH_BASIC;
         }
         if ($this->authType & self::AUTH_DIGEST) {
             $this->_http->{'request.authenticationScheme'} = Horde_Http::AUTH_DIGEST;
         }
         $this->_http->{'request.username'} = $this->userName;
         $this->_http->{'request.password'} = $this->password;
     }
     // Not supported by Horde_Http_Client yet:
     // $this->trustedCertificates;
     if ($method == 'HEAD') {
         $body = null;
     }
     try {
         $result = $this->_http->request($method, $url, $body, $headers);
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Dav_Exception($e);
     }
     if (isset($result->headers['dav']) && is_array($result->headers['dav'])) {
         $result->headers['dav'] = implode(', ', $result->headers['dav']);
     }
     $response = array('body' => $result->getBody(), 'statusCode' => $result->code, 'headers' => $result->headers, 'url' => $result->uri);
     if ($response['statusCode'] >= 400) {
         switch ($response['statusCode']) {
             case 400:
                 throw new Horde_Dav_Exception('Bad request', $response['statusCode']);
             case 401:
                 throw new Horde_Dav_Exception('Not authenticated', $response['statusCode']);
             case 402:
                 throw new Horde_Dav_Exception('Payment required', $response['statusCode']);
             case 403:
                 throw new Horde_Dav_Exception('Forbidden', $response['statusCode']);
             case 404:
                 throw new Horde_Dav_Exception('Resource not found.', $response['statusCode']);
             case 405:
                 throw new Horde_Dav_Exception('Method not allowed', $response['statusCode']);
             case 409:
                 throw new Horde_Dav_Exception('Conflict', $response['statusCode']);
             case 412:
                 throw new Horde_Dav_Exception('Precondition failed', $response['statusCode']);
             case 416:
                 throw new Horde_Dav_Exception('Requested Range Not Satisfiable', $response['statusCode']);
             case 500:
                 throw new Horde_Dav_Exception('Internal server error', $response['statusCode']);
             case 501:
                 throw new Horde_Dav_Exception('Not Implemented', $response['statusCode']);
             case 507:
                 throw new Horde_Dav_Exception('Insufficient storage', $response['statusCode']);
             default:
                 throw new Horde_Dav_Exception('HTTP error response. (errorcode ' . $response['statusCode'] . ')', $response['statusCode']);
         }
     }
     return $response;
 }
예제 #18
0
파일: Feed.php 프로젝트: horde/horde
 /**
  * Read a feed located at $uri
  *
  * @param string $uri The URI to fetch the feed from.
  * @param Horde_Http_Client $httpclient The HTTP client to use.
  *
  * @throws Horde_Feed_Exception
  *
  * @return Horde_Feed_Base
  */
 public static function readUri($uri, Horde_Http_Client $httpclient = null)
 {
     if (is_null($httpclient)) {
         $httpclient = new Horde_Http_Client();
     }
     try {
         $response = $httpclient->get($uri);
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Feed_Exception('Error reading feed: ' . $e->getMessage());
     }
     if ($response->code != 200) {
         throw new Horde_Feed_Exception('Unable to read feed, got response code ' . $response->code);
     }
     $feed = $response->getBody();
     return self::read($feed, $uri);
 }
예제 #19
0
 /**
  * Builds an JSON-RPC request and sends it to the server.
  *
  * This statically called method is actually the JSON-RPC client.
  *
  * @param string|Horde_Url $url  The path to the JSON-RPC server on the
  *                               called host.
  * @param string $method         The method to call.
  * @param Horde_Http_Client $client
  * @param array $params          A hash containing any necessary parameters
  *                               for the method call.
  *
  * @return mixed  The returned result from the method.
  * @throws Horde_Rpc_Exception
  */
 public static function request($url, $method, $client, $params = null)
 {
     $headers = array('User-Agent' => 'Horde RPC client', 'Accept' => 'application/json', 'Content-Type' => 'application/json');
     $data = array('version' => '1.1', 'method' => $method);
     if (!empty($params)) {
         $data['params'] = $params;
     }
     $data = Horde_Serialize::serialize($data, Horde_Serialize::JSON);
     try {
         $result = $client->post($url, $data, $headers);
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Rpc_Exception($e->getMessage());
     }
     if ($result->code == 500) {
         $response = Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON);
         if (is_a($response, 'stdClass') && isset($response->error) && is_a($response->error, 'stdClass') && isset($response->error->name) && $response->error->name == 'JSONRPCError') {
             throw new Horde_Rpc_Exception($response->error->message);
             /* @todo: Include more information if we have an Exception that can handle this.
                return PEAR::raiseError($response->error->message,
                                        $response->error->code,
                                        null, null,
                                        isset($response->error->error) ? $response->error->error : null);
                */
         }
         throw new Horde_Rpc_Exception($http->getResponseBody());
     } elseif ($result->code != 200) {
         throw new Horde_Rpc_Exception('Request couldn\'t be answered. Returned errorcode: "' . $result->code);
     }
     return Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON);
 }
예제 #20
0
 /**
  * Downloads a timezone database.
  *
  * @throws Horde_Timezone_Exception if downloading fails.
  */
 protected function _download()
 {
     $url = @parse_url($this->_params['location']);
     if (!isset($url['scheme'])) {
         throw new Horde_Timezone_Exception('"location" parameter is missing an URL scheme.');
     }
     if (!in_array($url['scheme'], array('http', 'ftp', 'file'))) {
         throw new Horde_Timezone_Exception(sprintf('Unsupported URL scheme "%s"', $url['scheme']));
     }
     if ($url['scheme'] == 'http') {
         if (isset($this->_params['client'])) {
             $client = $this->_params['client'];
         } else {
             $client = new Horde_Http_Client();
         }
         $response = $client->get($this->_params['location']);
         $this->_tmpfile = Horde_Util::getTempFile('', true, isset($this->_params['temp']) ? $this->_params['temp'] : '');
         stream_copy_to_stream($response->getStream(), fopen($this->_tmpfile, 'w'));
         return;
     }
     if ($url['scheme'] == 'ftp') {
         try {
             $vfs = new Horde_Vfs_Ftp(array('hostspec' => $url['host'], 'username' => 'anonymous', 'password' => 'anonymous', 'pasv' => true));
             $this->_tmpfile = $vfs->readFile(dirname($url['path']), basename($url['path']));
         } catch (Horde_Vfs_Exception $e) {
             throw new Horde_Timezone_Exception($e);
         }
     } else {
         $this->_tmpfile = $this->_params['location'];
         if (!is_readable($this->_tmpfile)) {
             $e = new Horde_Timezone_Exception(sprintf('Unable to open file %s.', $this->_params['location']));
             if (isset($php_errormsg)) {
                 $e->details = $php_errormsg;
             }
             throw $e;
         }
     }
 }
예제 #21
0
 /**
  * Fetch the avatar image.
  *
  * @param string $mail  The mail address.
  * @param mixed $opts   Additional options. See getAvatarUrl().
  *
  * @return resource  The image as stream resource, or null if the server
  *                   returned an error.
  */
 public function fetchAvatar($mail, $opts = array())
 {
     $get = $this->_client->get($this->getAvatarUrl($mail, $opts));
     return $get->code == 404 ? null : $get->getStream();
 }
예제 #22
0
<?php

/**
 * Basic example for fetching a page with Horde_Http_Client
 *
 * Copyright 2007-2015 Horde LLC (http://www.horde.org/)
 *
 * @author   Chuck Hagenbuch <*****@*****.**>
 * @license  http://www.horde.org/licenses/bsd BSD
 * @category Horde
 * @package  Http
 */
require 'Horde/Autoloader/Default.php';
$client = new Horde_Http_Client();
$response = $client->get('http://www.example.com/');
var_dump($response);
echo $response->getBody();
예제 #23
0
파일: Xmlrpc.php 프로젝트: jubinpatel/horde
 /**
  * Builds an XMLRPC request and sends it to the XMLRPC server.
  *
  * This statically called method is actually the XMLRPC client.
  *
  * @param string|Horde_Url $url      The path to the XMLRPC server on the
  *                                   called host.
  * @param string $method             The method to call.
  * @param Horde_Http_Client $client  The transport client
  * @param array $params              A hash containing any necessary
  *                                   parameters for the method call.
  *
  * @return mixed  The returned result from the method.
  * @throws Horde_Rpc_Exception
  */
 public static function request($url, $method, $client, $params = null)
 {
     $headers = array('User-Agent' => 'Horde RPC client', 'Content-Type' => 'text/xml');
     try {
         $result = $client->post($url, xmlrpc_encode_request($method, $params), $headers);
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Rpc_Exception($e);
     }
     if ($result->code != 200) {
         throw new Horde_Rpc_Exception('Request couldn\'t be answered. Returned errorcode: "' . $result->code);
     } elseif (strpos($result->getBody(), '<?xml') === false) {
         throw new Horde_Rpc_Exception("No valid XML data returned:\n" . $result->getBody());
     } else {
         $response = @xmlrpc_decode(substr($result->getBody(), strpos($result->getBody(), '<?xml')));
         if (is_array($response) && isset($response['faultString'])) {
             throw new Horde_Rpc_Exception($response['faultString']);
         } elseif (is_array($response) && isset($response[0]) && is_array($response[0]) && isset($response[0]['faultString'])) {
             throw new Horde_Rpc_Exception($response[0]['faultString']);
         }
         return $response;
     }
 }
예제 #24
0
파일: Base.php 프로젝트: jubinpatel/horde
 /**
  * Check if the library has a CI job.
  *
  * @return boolean True if a CI job is defined.
  */
 protected function _hasCi()
 {
     if ($this->getChannel() != 'pear.horde.org') {
         return false;
     }
     $client = new Horde_Http_Client(array('request.timeout' => 15));
     try {
         $response = $client->get('http://ci.horde.org/job/' . str_replace('Horde_', '', $this->getName() . '/api/json'));
     } catch (Horde_Http_Exception $e) {
         return false;
     }
     return $response->code != 404;
 }
예제 #25
0
<?php

/**
 * Example of posting a new Atom entry with Horde_Feed.
 *
 * @package Feed
 */
/* Parameters */
$blogUri = 'http://www.blogger.com/feeds/YOURBLOGID/posts/default';
$username = '******';
$password = '******';
/* Get a Horde framework include_path set up. */
require 'Horde/Autoloader/Default.php';
$httpClient = new Horde_Http_Client();
/* Authenticate. */
try {
    $response = $httpClient->post('https://www.google.com/accounts/ClientLogin', 'accountType=GOOGLE&service=blogger&source=horde-feed-blogger-example-1&Email=' . $username . '&Passwd=' . $password, array('Content-type', 'application/x-www-form-urlencoded'));
    if ($response->code !== 200) {
        throw new Horde_Feed_Exception('Expected response code 200, got ' . $response->code);
    }
} catch (Horde_Feed_Exception $e) {
    die('An error occurred authenticating: ' . $e->getMessage() . "\n");
}
$auth = null;
foreach (explode("\n", $response->getBody()) as $line) {
    $param = explode('=', $line);
    if ($param[0] == 'Auth') {
        $auth = $param[1];
    }
}
if (empty($auth)) {