public function getVideos($offset) { if (!$this->_videos) { $this->_videos = array(); try { $this->_setYoutubeUrl($offset); $feed = Zend_Feed_Reader::import($this->getLink()); } catch (Exception $e) { $feed = array(); } foreach ($feed as $entry) { $params = Zend_Uri::factory($entry->getLink())->getQueryAsArray(); $image = null; $link = null; if (!empty($params['v'])) { $image = "http://img.youtube.com/vi/{$params['v']}/0.jpg"; $link = "http://www.youtube.com/embed/{$params['v']}"; } else { $link = $entry->getLink(); } $video = new Core_Model_Default(array('video_id' => $params['v'], 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => $link, 'image' => $image)); $this->_videos[] = $video; } } return $this->_videos; }
/** * @dataProvider dataForTestUrlEncodeAndDecode */ public function testUrlEncodeAndDecode($str) { $encoded = Centurion_Inflector::urlEncode($str); $scheme = Zend_Uri::factory(); $scheme->setQuery($encoded); $this->assertEquals($str, Centurion_Inflector::urlDecode($encoded)); }
public function isCurrentlySecure() { $standardRule = !empty($_SERVER['HTTPS']) && 'off' != $_SERVER['HTTPS']; $offloaderHeader = trim((string) Mage::getConfig()->getNode(self::XML_PATH_OFFLOADER_HEADER, 'default')); if (!empty($offloaderHeader) && !empty($_SERVER[$offloaderHeader]) || $standardRule) { return true; } if (Mage::isInstalled()) { $secureBaseUrl = ''; if (!$this->isAdmin()) { $secureBaseUrl = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL); } else { $secureBaseUrl = (string) Mage::getConfig()->getNode(Mage_Core_Model_Url::XML_PATH_SECURE_URL, 'default'); } if (!$secureBaseUrl) { return false; } if (false !== strpos($secureBaseUrl, '{{base_url}}')) { $secureBaseUrl = Mage::getConfig()->substDistroServerVars('{{base_url}}'); } $uri = Zend_Uri::factory($secureBaseUrl); $port = $uri->getPort(); $isSecure = $uri->getScheme() == 'https' && isset($_SERVER['SERVER_PORT']) && $port == $_SERVER['SERVER_PORT']; return $isSecure; } else { $isSecure = isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']; return $isSecure; } }
/** Returns a reference to the response content. * * @return static */ public function invoke() { if (!$this->hasEncapsulatedObject()) { $this->setEncapsulatedObject(JsonApi_Response::factory(new JsonApi_Http_Response(Zend_Uri::factory($this->getBrowser()->getRequest()->getUri()), $this->getBrowser()->getResponse()->getStatusCode(), $this->getBrowser()->getResponse()->getContent()))); } return $this; }
public function startByPhotoId(\Sirprize\Flickr\Id $photoId) { if ($this->_started) { return $this; } $this->_started = true; require_once 'Zend/Uri.php'; $uri = \Zend_Uri::factory('http://api.flickr.com/services/rest/'); $args = array('api_key' => $this->_getService()->getApiKey(), 'format' => 'php_serial', 'method' => 'flickr.photos.getInfo', 'photo_id' => (string) $photoId); try { $this->_getRestClient()->getHttpClient()->resetParameters()->setUri($uri)->setParameterGet($args); $cacheId = $this->_getService()->makeCacheIdFromParts(array(__METHOD__, $photoId)); $this->_responseHandler = $this->_getService()->getResponseHandlerInstance(); $this->_getRestClient()->get($this->_responseHandler, 2, array(), $cacheId); if ($this->_responseHandler->isError()) { // service error $this->_onStartError($this->_getOnStartErrorMessage($this->_responseHandler->getMessage())); return $this; } $data = $this->_responseHandler->getPhp(); $this->_description = $data['photo']['description']['_content']; $this->_onStartSuccess($this->_getOnStartSuccessMessage($photoId)); $this->_loaded = true; return $this; } catch (Exception $e) { // connection error $this->_onStartError($this->_getOnStartErrorMessage($e->getMessage())); throw new \Sirprize\Flickr\Exception($exception->getMessage()); } }
protected function _getCallbackUri() { $uri = Zend_Uri::factory('http'); $uri->setHost($_SERVER['HTTP_HOST']); $uri->setPath($this->_helper->getHelper('Url')->simple('callback', 'twitter', 'admin')); return rtrim($uri->getUri(), '/'); }
/** * Parses, validates and returns a valid Zend_Uri object * from given $input. * * @param string|Zend_Uri_Http $input * @return null|Zend_Uri_Http * @throws Zend_Service_Technorati_Exception * @static */ public static function normalizeUriHttp($input) { // allow null as value if ($input === null) { return null; } if ($input instanceof Zend_Uri_Http) { $uri = $input; } else { try { $uri = Zend_Uri::factory((string) $input); } // wrap exception under Zend_Service_Technorati_Exception object catch (Exception $e) { throw new Zend_Service_Technorati_Exception($e->getMessage(), 0, $e); } } // allow inly Zend_Uri_Http objects or child classes if (!($uri instanceof Zend_Uri_Http)) { throw new Zend_Service_Technorati_Exception( "Invalid URL $uri, only HTTP(S) protocols can be used"); } return $uri; }
/** * Parses, validates and returns a valid Zend_Uri object * from given $input. * * @param string|Zend_Uri_Http $input * @return null|Zend_Uri_Http * @throws Zend_Service_Technorati_Exception * @static */ public static function normalizeUriHttp($input) { // allow null as value if ($input === null) { return null; } /** * @see Zend_Uri */ require_once 'Zend/Uri.php'; if ($input instanceof Zend_Uri_Http) { $uri = $input; } else { try { $uri = Zend_Uri::factory((string) $input); } catch (Exception $e) { /** * @see Zend_Service_Technorati_Exception */ require_once 'Zend/Service/Technorati/Exception.php'; throw new Zend_Service_Technorati_Exception($e->getMessage(), 0, $e); } } // allow inly Zend_Uri_Http objects or child classes if (!$uri instanceof Zend_Uri_Http) { /** * @see Zend_Service_Technorati_Exception */ require_once 'Zend/Service/Technorati/Exception.php'; throw new Zend_Service_Technorati_Exception("Invalid URL {$uri}, only HTTP(S) protocols can be used"); } return $uri; }
public function parseKey() { if ($this->_parsedKey === null) { $keyVersion = null; $pool = null; $version = null; $key = $this->getKey(); /** * MagentoConnect key version */ // http://connect20.magentocommerce.com/community/Interface_Frontend_Default_Modern if (strstr($key, 'connect20') !== false) { $keyVersion = self::KEY_V2; } elseif (strstr($key, 'magento-') !== false) { $keyVersion = self::KEY_V1; } else { throw new Exception('Key version can not be determined.'); } /** * Extension pool */ switch ($keyVersion) { case self::KEY_V2: $uri = Zend_Uri::factory($key); $path = $uri->getPath(); $pathAsArray = explode('/', $path); if (array_key_exists(1, $pathAsArray)) { $pool = $pathAsArray[1]; } break; case self::KEY_V1: $pathAsArray = explode('/', $key); $pool = reset($pathAsArray); $pool = strstr($pool, '-'); $pool = substr($pool, 1); break; } if (empty($pool)) { throw new Exception('Extension pool can not be determined.'); } /** * Extension version and name */ $extension = end($pathAsArray); if (strstr($extension, '-') !== false) { $version = substr(strstr($extension, '-'), 1); } if (strstr($extension, '-', true) !== false) { $name = strstr($extension, '-', true); } else { $name = $extension; } if (empty($name)) { throw new Exception('Extension name can not be determined.'); } $this->_parsedKey = array('key' => array('value' => $key, 'version' => $keyVersion), 'extension' => array('name' => $name, 'pool' => $pool, 'version' => $version)); } return $this->_parsedKey; }
/** * Get Feed URL * @return string * @throws Zend_Uri_Exception */ public function getFeedUrl() { $version = Mage::getConfig()->getModuleConfig('PayEx_MasterPass')->version->asArray(); $params = array('site_url' => Mage::getStoreConfig('web/unsecure/base_url'), 'installed_version' => $version, 'mage_ver' => Mage::getVersion(), 'edition' => Mage::getEdition()); $uri = Zend_Uri::factory(self::URL_NEWS); $uri->addReplaceQueryParameters($params); return $uri->getUri(); }
/** * Initializes the image * * @param DOMNode $dom * @param string $namespace * @return void */ public function __construct(DOMNode $dom, $namespace) { $xpath = new DOMXPath($dom->ownerDocument); $xpath->registerNamespace('yh', $namespace); $this->Url = Zend_Uri::factory($xpath->query('./yh:Url/text()', $dom)->item(0)->data); $this->Height = (int) $xpath->query('./yh:Height/text()', $dom)->item(0)->data; $this->Width = (int) $xpath->query('./yh:Width/text()', $dom)->item(0)->data; }
/** * @param string $uri * @return $this */ public function setUri($uri) { if (!Zend_Uri::factory($uri)) { Mage::throwException('Invalid API uri.'); } $this->_apiUri = $uri; return $this; }
/** * Constructor * * @param $uri Zend_Uri_Http|string URI for the web service */ public function __construct($uri) { if ($uri instanceof Zend_Uri_Http) { $this->_uri = $uri; } else { $this->_uri = Zend_Uri::factory($uri); } }
public function getWebAuthUrl($permissions) { require_once 'Zend/Uri.php'; $uri = \Zend_Uri::factory('http://flickr.com/services/auth/'); $args = array('api_key' => $this->getApiKey(), 'perms' => $permissions); $uri->setQuery($this->signArgs($args)); return $uri; }
/** * Assigns values to properties relevant to Image * * @param DOMElement $dom * @return void */ public function __construct(DOMElement $dom) { $xpath = new DOMXPath($dom->ownerDocument); $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05'); $this->Url = Zend_Uri::factory($xpath->query('./az:URL/text()', $dom)->item(0)->data); $this->Height = (int) $xpath->query('./az:Height/text()', $dom)->item(0)->data; $this->Width = (int) $xpath->query('./az:Width/text()', $dom)->item(0)->data; }
/** * Set the URI to use in the request * * @param string|Zend_Uri_Http $uri URI for the web service * @return Zend_Rest_Client */ public function setUri($uri) { if ($uri instanceof Zend_Uri_Http) { $this->_uri = $uri; } else { $this->_uri = Zend_Uri::factory($uri); } return $this; }
/** * Test that passing an invalid URI object throws an exception * */ public function testInvalidUriObjectException() { try { $uri = Zend_Uri::factory('mailto:nobody@example.com'); $this->client->setUri($uri); $this->fail('Excepted invalid URI object exception was not thrown'); } catch (Zend_Http_Client_Exception $e) { // We're good } }
function testRouteDisambiguationByRequirements() { $router = new Zend_Controller_YARouter(); $router->connect('y', '/:year', array('controller' => 'year', 'action' => 'index'), array('year' => '\\d{4}')); $router->connect('x', '/:x', array('controller' => 'x', 'action' => 'index')); $url = Zend_Uri::factory('http://localhost/foo'); $token = $router->route(new Mock_Zend_Controller_Dispatcher(), $url); $this->assertEquals($token->getControllerName(), 'x'); $this->assertEquals($token->getActionName(), 'index'); $this->assertEquals($token->getParams(), array('x' => 'foo')); }
/** * Set S3 endpoint to use * * @param string|Zend_Uri_Http $endpoint * @return Zend_Service_Amazon_S3 */ public function setEndpoint($endpoint) { if (!$endpoint instanceof Zend_Uri_Http) { $endpoint = Zend_Uri::factory($endpoint); } if (!$endpoint->valid()) { throw new Zend_Service_Amazon_S3_Exception('Invalid endpoint supplied'); } $this->_endpoint = $endpoint; return $this; }
protected function _getUri($action, $controller, $module) { if (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('host'); } $uri = Zend_Uri::factory('http'); $uri->setHost($host); $uri->setPath(Zend_Controller_Action_HelperBroker::getStaticHelper('Url')->simple($action, $controller, $module)); return rtrim($uri->getUri(), '/'); }
/** * Constructor. * * @param array|null $config (Default: null) * @param string $host (Default: https://email.us-east-1.amazonaws.com) * @return void * @throws Exception if accessKey is not present in the config * @throws Exception if privateKey is not present in the config */ public function __construct(array $config = array(), $host = 'https://email.us-east-1.amazonaws.com') { if (!array_key_exists('accessKey', $config)) { throw new Exception('This transport requires the Amazon access key'); } if (!array_key_exists('privateKey', $config)) { throw new Exception('This transport requires the Amazon private key'); } $this->_accessKey = $config['accessKey']; $this->_privateKey = $config['privateKey']; $this->_host = Zend_Uri::factory($host); }
/** * Create a new request object * * @param Zend_Uri_Http|string $url Target URL * @param string $method HTTP request method - default is GET */ public function __construct($uri, $method = 'GET') { if (!$uri instanceof Zend_Uri_Http) { if (!Zend_Uri_Http::check($uri)) { require_once 'Spizer/Exception.php'; throw new Spizer_Exception("'{$uri}' is not a valid HTTP URL"); } $uri = Zend_Uri::factory($uri); } $this->_uri = $uri; $this->_method = $method; }
public function testDailyCountsResultSet() { $object = new Zend_Service_Technorati_DailyCountsResultSet($this->dom); // check counts $this->assertType('integer', $object->totalResults()); $this->assertEquals(5, $object->totalResults()); $this->assertType('integer', $object->totalResultsAvailable()); $this->assertEquals(5, $object->totalResultsAvailable()); // check properties $this->assertType('Zend_Uri_Http', $object->getSearchUrl()); $this->assertEquals(Zend_Uri::factory('http://technorati.com/search/google'), $object->getSearchUrl()); }
/** * Returns true if the $uri is valid * * If $uri is not a valid URI, then this method returns false, and * getMessages() will return an array of messages that explain why the * validation failed. * * @throws Zend_Validate_Exception If validation of $value is impossible * @param string $uri URI to be validated * @return boolean */ public function isValid($uri) { $uri = (string) $uri; $this->_setValue($uri); try { Zend_Uri::factory($uri, 'iMSCP_Uri_Redirect'); } catch (Exception $e) { $this->_error(self::INVALID_URI); return false; } return true; }
public function getFormData() { $uri = Zend_Uri::factory(Mage::getBaseUrl('web')); if ($uri->getScheme() !== 'https') { $uri->setPort(null); $baseUrl = str_replace('http://', 'https://', $uri->getUri()); } else { $baseUrl = $uri->getUri(); } $data = Mage::getModel('varien/object')->setDbHost('localhost')->setDbName('magento')->setDbUser('root')->setDbPass('')->setSecureBaseUrl($baseUrl); return $data; }
/** * @param mixed $value */ public function isValid($value) { $this->_setValue($value); try { $uri = Zend_Uri::factory($value); } catch (Exception $e) { $this->_message = $e->getMessage(); $this->_error(self::NO_VALID_URI, $value); return false; } return $uri->valid(); }
/** * Set S3 endpoint to use * * @param string|Zend_Uri_Http $endpoint * @return Zend_Service_Amazon_S3 */ public function setEndpoint($endpoint) { if (!$endpoint instanceof Zend_Uri_Http) { $endpoint = Zend_Uri::factory($endpoint); } if (!$endpoint->valid()) { require_once 'Zend/Service/Amazon/S3/Exception.php'; throw new Zend_Service_Amazon_S3_Exception("Invalid endpoint supplied"); } $this->_endpoint = $endpoint; return $this; }
/** * Récupère les vidéos youtube * * @param string $search * @return array */ public function getList($search, $type = "video_id") { if (!$this->_videos) { $this->_videos = array(); try { $video_id = $search; if (Zend_Uri::check($search)) { $params = Zend_Uri::factory($search)->getQueryAsArray(); if (!empty($params['v'])) { $video_id = $params['v']; } } $this->_setYoutubeUrl($search, $type); $datas = @file_get_contents($this->getLink()); try { $datas = Zend_Json::decode($datas); } catch (Exception $e) { $datas = array(); } if ($datas and !empty($datas['pageInfo']['totalResults'])) { $feed = array(); foreach ($datas['items'] as $item) { $video_id = null; if (!empty($item["id"]["videoId"])) { $video_id = $item["id"]["videoId"]; } elseif (!empty($item["id"]) and !is_array($item["id"])) { $video_id = $item["id"]; } if (is_null($video_id)) { continue; } $feed[] = new Core_Model_Default(array('title' => !empty($item['snippet']['title']) ? $item['snippet']['title'] : null, 'content' => !empty($item['snippet']['description']) ? $item['snippet']['description'] : null, 'link' => "http://www.youtube.com/watch?v={$video_id}", 'image' => "http://img.youtube.com/vi/{$video_id}/0.jpg")); } } else { if ($type == "video_id") { return $this->getList($search, "search"); } } } catch (Exception $e) { $feed = array(); } foreach ($feed as $entry) { $params = Zend_Uri::factory($entry->getLink())->getQueryAsArray(); if (empty($params['v'])) { continue; } $video = new Core_Model_Default(array('id' => $params['v'], 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => "http://www.youtube.com/embed/{$params['v']}", 'image' => "http://img.youtube.com/vi/{$params['v']}/0.jpg")); $this->_videos[] = $video; } } return $this->_videos; }
public function testServer() { $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['HTTP_MS_ASPROTOCOLVERSION'] = '2.5'; $_SERVER['HTTP_USER_AGENT'] = 'Apple-iPhone/705.18'; $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Contacts</Class><SyncKey>1356</SyncKey><CollectionId>48ru47fhf7ghf7fgh4</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options><AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize></AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>'); $request = new Zend_Controller_Request_Http(Zend_Uri::factory('http://localhost/Microsoft-Server-ActiveSync?User=abc1234&DeviceId=Appl7R743U8YWH8&DeviceType=iPhone&Cmd=Sync')); $server = new Syncope_Server('abc1234', $request, $doc); $server->handle(); }
/** * Test that passing an invalid URI object throws an exception * */ public function testInvalidUriObjectException() { try { $uri = Zend_Uri::factory('mailto:nobody@example.com'); $this->client->setUri($uri); $this->fail('Excepted invalid URI object exception was not thrown'); } catch (Zend_Http_Client_Exception $e) { // We're good } catch (Zend_Uri_Exception $e) { // URI is currently unimplemented $this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet'); } }