Beispiel #1
0
 /**
  * Cast to HTTP query string
  * 
  * @param  mixed $url 
  * @param  Zend\OAuth\Config $config 
  * @param  null|array $params 
  * @return string
  */
 public function toQueryString($url, Config $config, array $params = null)
 {
     $uri = new Uri\Url($url);
     if (!$uri->isValid() || !in_array($uri->getScheme(), array('http', 'https'))) {
         throw new OAuth\Exception('\'' . $url . '\' is not a valid URI');
     }
     $params = $this->_httpUtility->assembleParams($url, $config, $params);
     return $this->_httpUtility->toEncodedQueryString($params);
 }
Beispiel #2
0
 /**
  *  Attempt to turn a relative URI into an absolute URI
  */
 protected function _absolutiseUri($link, $uri = null)
 {
     if (!Uri\Url::validate($link)) {
         if ($uri !== null) {
             $uri = new Uri\Url($uri);
             if ($link[0] !== '/') {
                 $link = $uri->getPath() . '/' . $link;
             }
             $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link);
             if (!URI\URL::validate($link)) {
                 $link = null;
             }
         }
     }
     return $link;
 }
    public function setUp()
    {
        if (defined('TESTS_Zend_Feed_PubSubHubbub_BASEURI') &&
            \Zend\Uri\Url::check(TESTS_Zend_Feed_PubSubHubbub_BASEURI)) {
            $this->_baseuri = TESTS_Zend_Feed_PubSubHubbub_BASEURI;
            if (substr($this->_baseuri, -1) != '/') $this->_baseuri .= '/';
            $name = $this->getName();
            if (($pos = strpos($name, ' ')) !== false) {
                $name = substr($name, 0, $pos);
            }
            $uri = $this->_baseuri . $name . '.php';
            $this->_adapter = new $this->_config['adapter'];
            $this->_client = new \Zend\Http\Client($uri, $this->_config);
            $this->_client->setAdapter($this->_adapter);
            \Zend\Feed\PubSubHubbub\PubSubHubbub::setHttpClient($this->_client);
            $this->_subscriber = new \Zend\Feed\PubSubHubbub\Subscriber\Subscriber;
            
            
            $this->_storage = $this->_getCleanMock('Zend_Feed_PubSubHubbub_Entity_TopicSubscription');
            $this->_subscriber->setStorage($this->_storage);

        } else {
            // Skip tests
            $this->markTestSkipped("Zend_Feed_PubSubHubbub_Subscriber dynamic tests'
            . ' are not enabled in TestConfiguration.php");
        }
    }
Beispiel #4
0
 /**
  * Checks validity of the request simply by making a quick pass and
  * confirming the presence of all REQUIRED parameters.
  *
  * @param  array $httpGetData
  * @return bool
  */
 public function isValidHubVerification(array $httpGetData)
 {
     /**
      * As per the specification, the hub.verify_token is OPTIONAL. This
      * implementation of Pubsubhubbub considers it REQUIRED and will
      * always send a hub.verify_token parameter to be echoed back
      * by the Hub Server. Therefore, its absence is considered invalid.
      */
     if (strtolower($_SERVER['REQUEST_METHOD']) !== 'get') {
         return false;
     }
     $required = array('hub_mode', 'hub_topic', 'hub_challenge', 'hub_verify_token');
     foreach ($required as $key) {
         if (!array_key_exists($key, $httpGetData)) {
             return false;
         }
     }
     if ($httpGetData['hub_mode'] !== 'subscribe' && $httpGetData['hub_mode'] !== 'unsubscribe') {
         return false;
     }
     if ($httpGetData['hub_mode'] == 'subscribe' && !array_key_exists('hub_lease_seconds', $httpGetData)) {
         return false;
     }
     if (!\Zend\Uri\Url::validate($httpGetData['hub_topic'])) {
         return false;
     }
     /**
      * Attempt to retrieve any Verification Token Key attached to Callback
      * URL's path by our Subscriber implementation
      */
     if (!$this->_hasValidVerifyToken($httpGetData)) {
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Generate a new Cookie object from a cookie string
  * (for example the value of the Set-Cookie HTTP header)
  *
  * @param string $cookieStr
  * @param \Zend\Uri\Url|string $refUri Reference URI for default values (domain, path)
  * @param boolean $encodeValue Weither or not the cookie's value should be
  *                             passed through urlencode/urldecode
  * @return \Zend\Http\Cookie A new \Zend\Http\Cookie object or false on failure.
  */
 public static function fromString($cookieStr, $refUri = null, $encodeValue = true)
 {
     // Set default values
     if (is_string($refUri)) {
         $refUri = new Uri\Url($refUri);
     }
     $name = '';
     $value = '';
     $domain = '';
     $path = '';
     $expires = null;
     $secure = false;
     $parts = explode(';', $cookieStr);
     // If first part does not include '=', fail
     if (strpos($parts[0], '=') === false) {
         return false;
     }
     // Get the name and value of the cookie
     list($name, $value) = explode('=', trim(array_shift($parts)), 2);
     $name = trim($name);
     if ($encodeValue) {
         $value = urldecode(trim($value));
     }
     // Set default domain and path
     if ($refUri instanceof Uri\Url) {
         $domain = $refUri->getHost();
         $path = $refUri->getPath();
         $path = substr($path, 0, strrpos($path, '/'));
     }
     // Set other cookie parameters
     foreach ($parts as $part) {
         $part = trim($part);
         if (strtolower($part) == 'secure') {
             $secure = true;
             continue;
         }
         $keyValue = explode('=', $part, 2);
         if (count($keyValue) == 2) {
             list($k, $v) = $keyValue;
             switch (strtolower($k)) {
                 case 'expires':
                     if (($expires = strtotime($v)) === false) {
                         /**
                          * The expiration is past Tue, 19 Jan 2038 03:14:07 UTC
                          * the maximum for 32-bit signed integer. Zend_Date
                          * can get around that limit.
                          */
                         $expireDate = new \Zend\Date\Date($v);
                         $expires = $expireDate->getTimestamp();
                     }
                     break;
                 case 'path':
                     $path = $v;
                     break;
                 case 'domain':
                     $domain = $v;
                     break;
                 default:
                     break;
             }
         }
     }
     if ($name !== '') {
         $ret = new self($name, $value, $domain, $expires, $path, $secure);
         $ret->encodeValue = $encodeValue ? true : false;
         return $ret;
     } else {
         return false;
     }
 }
Beispiel #6
0
    /**
     * Send request to the remote server
     *
     * @param string        $method
     * @param \Zend\Uri\Url $uri
     * @param string        $http_ver
     * @param array         $headers
     * @param string        $body
     * @return string Request as string
     */
    public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
    {
        $host = $uri->getHost();
            $host = (strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host);

        // Build request headers
        $path = $uri->getPath();
        if (empty($path)) {
            $path = '/';
        }
        if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
        $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
        foreach ($headers as $k => $v) {
            if (is_string($k)) $v = ucfirst($k) . ": $v";
            $request .= "$v\r\n";
        }

        // Add the request body
        $request .= "\r\n" . $body;

        // Do nothing - just return the request as string

        return $request;
    }
Beispiel #7
0
 /**
  * Send request to the remote server
  *
  * @param string        $method
  * @param \Zend\Uri\Url $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Exception('Trying to write but we are not connected');
     }
     $host = $uri->getHost();
     $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
         throw new Exception('Trying to write but we are connected to the wrong host');
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $path = $uri->getPath();
     if ($uri->getQuery()) {
         $path .= '?' . $uri->getQuery();
     }
     $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     if (is_resource($body)) {
         $request .= "\r\n";
     } else {
         // Add the request body
         $request .= "\r\n" . $body;
     }
     // Send the request
     if (!@fwrite($this->socket, $request)) {
         throw new Exception('Error writing request to server');
     }
     if (is_resource($body)) {
         if (stream_copy_to_stream($body, $this->socket) == 0) {
             throw new Exception('Error writing request to server');
         }
     }
     return $request;
 }
Beispiel #8
0
 /**
  * Prepare the request headers
  *
  * @return array
  */
 protected function _prepareHeaders()
 {
     $headers = array();
     // Set the host header
     if (!isset($this->headers['host'])) {
         $host = $this->uri->getHost();
         // If the port is not default, add it
         if (!($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80 || $this->uri->getScheme() == 'https' && $this->uri->getPort() == 443)) {
             $host .= ':' . $this->uri->getPort();
         }
         $headers[] = "Host: {$host}";
     }
     // Set the connection header
     if (!isset($this->headers['connection'])) {
         if (!$this->config['keepalive']) {
             $headers[] = "Connection: close";
         }
     }
     // Set the Accept-encoding header if not set - depending on whether
     // zlib is available or not.
     if (!isset($this->headers['accept-encoding'])) {
         if (function_exists('gzinflate')) {
             $headers[] = 'Accept-encoding: gzip, deflate';
         } else {
             $headers[] = 'Accept-encoding: identity';
         }
     }
     // Set the Content-Type header
     if ($this->method == self::POST && (!isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
         $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
     }
     // Set the user agent header
     if (!isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
         $headers[] = "User-Agent: {$this->config['useragent']}";
     }
     // Set HTTP authentication if needed
     if (is_array($this->auth)) {
         $auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
         $headers[] = "Authorization: {$auth}";
     }
     // Load cookies from cookie jar
     if (isset($this->cookiejar)) {
         $cookstr = $this->cookiejar->getMatchingCookies($this->uri, true, CookieJar::COOKIE_STRING_CONCAT);
         if ($cookstr) {
             $headers[] = "Cookie: {$cookstr}";
         }
     }
     // Add all other user defined headers
     foreach ($this->headers as $header) {
         list($name, $value) = $header;
         if (is_array($value)) {
             $value = implode(', ', $value);
         }
         $headers[] = "{$name}: {$value}";
     }
     return $headers;
 }
Beispiel #9
0
 /**
  * @group ZF-1480
  */
 public function testRemoveQueryParametersModifiesQueryAndReturnsOldQuery()
 {
     $url = new Url('http://example.com/foo/?a=1&b=2&c=3&d=4');
     $url->removeQueryParameters(array('b', 'd', 'e'));
     $this->assertEquals(array('a' => 1, 'c' => 3), $url->getQueryAsArray());
     $this->assertEquals('a=1&c=3', $url->getQuery());
 }
Beispiel #10
0
 /**
  * Set feed channel image
  * 
  * @param \DOMDocument $dom 
  * @param \DOMElement $root 
  * @return void
  */
 protected function _setImage(\DOMDocument $dom, \DOMElement $root)
 {
     $image = $this->getDataContainer()->getImage();
     if (!$image) {
         return;
     }
     if (!isset($image['title']) || empty($image['title']) || !is_string($image['title'])) {
         $message = 'RSS 2.0 feed images must include a title';
         $exception = new Writer\Exception($message);
         if (!$this->_ignoreExceptions) {
             throw $exception;
         } else {
             $this->_exceptions[] = $exception;
             return;
         }
     }
     if (empty($image['link']) || !is_string($image['link']) || !Uri\Url::validate($image['link'])) {
         $message = 'Invalid parameter: parameter \'link\'' . ' must be a non-empty string and valid URI/IRI';
         $exception = new Writer\Exception($message);
         if (!$this->_ignoreExceptions) {
             throw $exception;
         } else {
             $this->_exceptions[] = $exception;
             return;
         }
     }
     $img = $dom->createElement('image');
     $root->appendChild($img);
     $url = $dom->createElement('url');
     $text = $dom->createTextNode($image['uri']);
     $url->appendChild($text);
     $title = $dom->createElement('title');
     $text = $dom->createTextNode($image['title']);
     $title->appendChild($text);
     $link = $dom->createElement('link');
     $text = $dom->createTextNode($image['link']);
     $link->appendChild($text);
     $img->appendChild($url);
     $img->appendChild($title);
     $img->appendChild($link);
     if (isset($image['height'])) {
         if (!ctype_digit((string) $image['height']) || $image['height'] > 400) {
             $message = 'Invalid parameter: parameter \'height\'' . ' must be an integer not exceeding 400';
             $exception = new Writer\Exception($message);
             if (!$this->_ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->_exceptions[] = $exception;
                 return;
             }
         }
         $height = $dom->createElement('height');
         $text = $dom->createTextNode($image['height']);
         $height->appendChild($text);
         $img->appendChild($height);
     }
     if (isset($image['width'])) {
         if (!ctype_digit((string) $image['width']) || $image['width'] > 144) {
             $message = 'Invalid parameter: parameter \'width\'' . ' must be an integer not exceeding 144';
             $exception = new Writer\Exception($message);
             if (!$this->_ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->_exceptions[] = $exception;
                 return;
             }
         }
         $width = $dom->createElement('width');
         $text = $dom->createTextNode($image['width']);
         $width->appendChild($text);
         $img->appendChild($width);
     }
     if (isset($image['description'])) {
         if (empty($image['description']) || !is_string($image['description'])) {
             $message = 'Invalid parameter: parameter \'description\'' . ' must be a non-empty string';
             $exception = new Writer\Exception($message);
             if (!$this->_ignoreExceptions) {
                 throw $exception;
             } else {
                 $this->_exceptions[] = $exception;
                 return;
             }
         }
         $desc = $dom->createElement('description');
         $text = $dom->createTextNode($image['description']);
         $desc->appendChild($text);
         $img->appendChild($desc);
     }
 }
Beispiel #11
0
 /**
  * Add a Hub Server URL supported by Publisher
  *
  * @param  string $url
  * @return \Zend\Feed\PubSubHubbub\Subscriber\Subscriber
  */
 public function addHubUrl($url)
 {
     if (empty($url) || !is_string($url) || !\Zend\Uri\Url::validate($url)) {
         throw new Exception('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . ' URL');
     }
     $this->_hubUrls[] = $url;
     return $this;
 }
Beispiel #12
0
 /**
  * Notifies a single Hub Server URL of changes
  *
  * @param  string $url The Hub Server's URL
  * @return void
  * @throws \Zend\Feed\PubSubHubbub\Exception Thrown on failure
  */
 public function notifyHub($url)
 {
     if (empty($url) || !is_string($url) || !Uri\Url::validate($url)) {
         throw new Exception('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . 'URL');
     }
     $client = $this->_getHttpClient();
     $client->setUri($url);
     $response = $client->request();
     if ($response->getStatus() !== 204) {
         throw new Exception('Notification to Hub Server ' . 'at "' . $url . '" appears to have failed with a status code of "' . $response->getStatus() . '" and message "' . $response->getMessage() . '"');
     }
 }
Beispiel #13
0
 /**
  * Set new feed URL
  * 
  * @param  string $value 
  * @return Zend_Feed_Writer_Extension_ITunes_Feed
  */
 public function setItunesNewFeedUrl($value)
 {
     if (!Uri\Url::validate($value)) {
         throw new Writer\Exception('invalid parameter: "newFeedUrl" may only' . ' be a valid URI/IRI');
     }
     $this->_data['newFeedUrl'] = $value;
     return $this;
 }
Beispiel #14
0
 /**
  * Constructor
  *
  * If a $uri is passed, the object will attempt to populate itself using
  * that information.
  *
  * @param string|\Zend\Uri\Uri $uri
  * @return void
  * @throws \Zend\Controller\Request\Exception when invalid URI passed
  */
 public function __construct($uri = null)
 {
     if (null !== $uri) {
         if (!$uri instanceof Uri\Url) {
             $uri = new Uri\Url($uri);
         }
         if ($uri->isValid()) {
             $path = $uri->getPath();
             $query = $uri->getQuery();
             if (!empty($query)) {
                 $path .= '?' . $query;
             }
             $this->setRequestUri($path);
         } else {
             throw new Exception('Invalid URI provided to constructor');
         }
     } else {
         $this->setRequestUri();
     }
 }
Beispiel #15
0
    /**
     * Set blog URL
     *
     * @param string $blogUrl
     * @return Zend_Service_Akismet
     * @throws Zend\Service\Exception if invalid URL provided
     */
    public function setBlogUrl($blogUrl)
    {
        if (!Uri\Url::validate($blogUrl)) {
            throw new Exception\InvalidArgumentException('Invalid url provided for blog');
        }

        $this->_blogUrl = $blogUrl;
        return $this;
    }
Beispiel #16
0
 /**
  *  Attempt to absolutise the URI, i.e. if a relative URI apply the
  *  xml:base value as a prefix to turn into an absolute URI.
  */
 protected function _absolutiseUri($link)
 {
     if (!\Zend\Uri\Url::validate($link)) {
         if (!is_null($this->getBaseUrl())) {
             $link = $this->getBaseUrl() . $link;
             if (!\Zend\Uri\Url::validate($link)) {
                 $link = null;
             }
         }
     }
     return $link;
 }
Beispiel #17
0
 /**
  * Add a feed category
  *
  * @param string $category
  */ 
 public function addCategory(array $category)
 {
     if (!isset($category['term'])) {
         throw new Exception('Each category must be an array and '
         . 'contain at least a "term" element containing the machine '
         . ' readable category name');
     }
     if (isset($category['scheme'])) {
         if (empty($category['scheme']) 
             || !is_string($category['scheme'])
             || !Uri\Url::validate($category['scheme'])
         ) {
             throw new Exception('The Atom scheme or RSS domain of'
             . ' a category must be a valid URI');
         }
     }
     if (!isset($this->_data['categories'])) {
         $this->_data['categories'] = array();
     }
     $this->_data['categories'][] = $category;
 }
Beispiel #18
0
 /**
  * Send request to the remote server
  *
  * @param  string        $method
  * @param  \Zend\Uri\Url $uri
  * @param  float         $http_ver
  * @param  array         $headers
  * @param  string        $body
  * @return string        $request
  * @throws \Zend\Http\Client\Adapter\Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
  */
 public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->_curl) {
         throw new Exception("Trying to write but we are not connected");
     }
     if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
         throw new Exception("Trying to write but we are connected to the wrong host");
     }
     // set URL
     curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
     // ensure correct curl call
     $curlValue = true;
     switch ($method) {
         case Client::GET:
             $curlMethod = CURLOPT_HTTPGET;
             break;
         case Client::POST:
             $curlMethod = CURLOPT_POST;
             break;
         case Client::PUT:
             // There are two different types of PUT request, either a Raw Data string has been set
             // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
             if (is_resource($body)) {
                 $this->_config['curloptions'][CURLOPT_INFILE] = $body;
             }
             if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
                 // Now we will probably already have Content-Length set, so that we have to delete it
                 // from $headers at this point:
                 foreach ($headers as $k => $header) {
                     if (preg_match('/Content-Length:\\s*(\\d+)/i', $header, $m)) {
                         if (is_resource($body)) {
                             $this->_config['curloptions'][CURLOPT_INFILESIZE] = (int) $m[1];
                         }
                         unset($headers[$k]);
                     }
                 }
                 if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
                     throw new Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
                 }
                 if (is_resource($body)) {
                     $body = '';
                 }
                 $curlMethod = CURLOPT_PUT;
             } else {
                 $curlMethod = CURLOPT_CUSTOMREQUEST;
                 $curlValue = "PUT";
             }
             break;
         case Client::DELETE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "DELETE";
             break;
         case Client::OPTIONS:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "OPTIONS";
             break;
         case Client::TRACE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "TRACE";
             break;
         case Client::HEAD:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "HEAD";
             break;
         default:
             // For now, through an exception for unsupported request methods
             throw new Exception("Method currently not supported");
     }
     if (is_resource($body) && $curlMethod != CURLOPT_PUT) {
         throw new Exception("Streaming requests are allowed only with PUT");
     }
     // get http version to use
     $curlHttp = $httpVersion == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     // mark as HTTP request and set HTTP method
     curl_setopt($this->_curl, $curlHttp, true);
     curl_setopt($this->_curl, $curlMethod, $curlValue);
     if ($this->out_stream) {
         // headers will be read into the response
         curl_setopt($this->_curl, CURLOPT_HEADER, false);
         curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
         // and data will be written into the file
         curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
     } else {
         // ensure headers are also returned
         curl_setopt($this->_curl, CURLOPT_HEADER, true);
         // ensure actual response is returned
         curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
     }
     // set additional headers
     $headers['Accept'] = '';
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
     /**
      * Make sure POSTFIELDS is set after $curlMethod is set:
      * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
      */
     if ($method == Client::POST) {
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     } elseif ($curlMethod == CURLOPT_PUT) {
         // this covers a PUT by file-handle:
         // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
         // to group common functionality together.
         curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
         curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
         unset($this->_config['curloptions'][CURLOPT_INFILE]);
         unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
     } elseif ($method == Client::PUT) {
         // This is a PUT by a setRawData string, not by file-handle
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     }
     // set additional curl options
     if (isset($this->_config['curloptions'])) {
         foreach ((array) $this->_config['curloptions'] as $k => $v) {
             if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
                 if (curl_setopt($this->_curl, $k, $v) == false) {
                     throw new Client\Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
                 }
             }
         }
     }
     // send the request
     $response = curl_exec($this->_curl);
     // if we used streaming, headers are already there
     if (!is_resource($this->out_stream)) {
         $this->_response = $response;
     }
     $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
     $request .= $body;
     if (empty($this->_response)) {
         throw new Client\Exception("Error in cURL request: " . curl_error($this->_curl));
     }
     // cURL automatically decodes chunked-messages, this means we have to disallow the Zend\Http\Response to do it again
     if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
         $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
     }
     // Eliminate multiple HTTP responses.
     do {
         $parts = preg_split('|(?:\\r?\\n){2}|m', $this->_response, 2);
         $again = false;
         if (isset($parts[1]) && preg_match("|^HTTP/1\\.[01](.*?)\r\n|mi", $parts[1])) {
             $this->_response = $parts[1];
             $again = true;
         }
     } while ($again);
     // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
     if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
         $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
     }
     return $request;
 }
Beispiel #19
0
 public function setBy(array $by)
 {
     $author = array();
     if (!array_key_exists('name', $by) || empty($by['name']) || !is_string($by['name'])) {
         throw new Exception('Invalid parameter: author array must include a' . ' "name" key with a non-empty string value');
     }
     $author['name'] = $by['name'];
     if (isset($by['email'])) {
         if (empty($by['email']) || !is_string($by['email'])) {
             throw new Exception('Invalid parameter: "email" array' . ' value must be a non-empty string');
         }
         $author['email'] = $by['email'];
     }
     if (isset($by['uri'])) {
         if (empty($by['uri']) || !is_string($by['uri']) || !Uri\Url::validate($by['uri'])) {
             throw new Exception('Invalid parameter: "uri" array value must' . ' be a non-empty string and valid URI/IRI');
         }
         $author['uri'] = $by['uri'];
     }
     $this->_data['by'] = $author;
 }
Beispiel #20
0
 /**
  * Determine if a given URL is valid
  * 
  * @param  string $url 
  * @return void
  * @throws Zend\OAuth\Exception
  */
 protected function _validateUrl($url)
 {
     $uri = new Uri\Url($url);
     if (!$uri->isValid()) {
         throw new OAuth\Exception(sprintf("'%s' is not a valid URI", $url));
     } elseif (!in_array($uri->getScheme(), array('http', 'https'))) {
         throw new OAuth\Exception(sprintf("'%s' is not a valid URI", $url));
     }
 }
Beispiel #21
0
    /**
     * Get a specific cookie according to a URI and name
     *
     * @param \Zend\Uri\Url|string $uri The uri (domain and path) to match
     * @param string $cookie_name The cookie's name
     * @param int $ret_as Whether to return cookies as objects of \Zend\Http\Cookie or as strings
     * @return \Zend\Http\Cookie|string
     */
    public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
    {
        if (is_string($uri)) {
            $uri = new Uri\Url($uri);
        }

        if (! $uri instanceof Uri\Url) {
            throw new Exception\InvalidArgumentException('Invalid URI specified');
        }

        $host = $uri->getHost();
        if (empty($host)) {
            throw new Exception\InvalidArgumentException('Invalid URI specified; host missing');
        }

        // Get correct cookie path
        $path = $uri->getPath();
        $path = substr($path, 0, strrpos($path, '/'));
        if (! $path) $path = '/';

        if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
            $cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];

            switch ($ret_as) {
                case self::COOKIE_OBJECT:
                    return $cookie;
                    break;

                case self::COOKIE_STRING_ARRAY:
                case self::COOKIE_STRING_CONCAT:
                    return $cookie->__toString();
                    break;

                default:
                    throw new Exception\InvalidArgumentException("Invalid value passed for \$ret_as: {$ret_as}");
                    break;
            }
        } else {
            return false;
        }
    }
Beispiel #22
0
 /**
  * Adds an enclosure to the entry. The array parameter may contain the
  * keys 'uri', 'type' and 'length'. Only 'uri' is required for Atom, though the
  * others must also be provided or RSS rendering (where they are required)
  * will throw an Exception.
  *
  * @param array $enclosures
  */
 public function setEnclosure(array $enclosure)
 {
     if (!isset($enclosure['uri'])) {
         throw new Exception('Enclosure "uri" is not set');
     }
     if (!Uri\Url::validate($enclosure['uri'])) {
         throw new Exception('Enclosure "uri" is not a valid URI/IRI');
     }
     $this->_data['enclosure'] = $enclosure;
 }