Example #1
0
 public function getColorizedImage($image_id, $color)
 {
     $color = str_replace('#', '', $color);
     $id = md5(implode('+', array($image_id, $color)));
     $url = '';
     $image = new Media_Model_Library_Image();
     if (is_numeric($image_id)) {
         $image->find($image_id);
         if (!$image->getId()) {
             return $url;
         }
         if (!$image->getCanBeColorized()) {
             $color = null;
         }
         $path = $image->getLink();
         $path = Media_Model_Library_Image::getBaseImagePathTo($path);
     } else {
         if (!Zend_Uri::check($image_id) and stripos($image_id, Core_Model_Directory::getBasePathTo()) === false) {
             $path = Core_Model_Directory::getBasePathTo($image_id);
         } else {
             $path = $image_id;
         }
     }
     try {
         $image = new Core_Model_Lib_Image();
         $image->setId($id)->setPath($path)->setColor($color)->colorize();
         $url = $image->getUrl();
     } catch (Exception $e) {
         $url = '';
     }
     return $url;
 }
 /**
  * Handles campaign redirects on
  * controller_action_layout_generate_blocks_after
  *
  * @param Varien_Object $observer
  */
 public function handleCampaignsRedirect($observer)
 {
     if (!Mage::helper('factfinder')->isEnabled('campaigns') || Mage::registry('current_product') && !Mage::helper('factfinder_campaigns')->canShowCampaignsOnProduct()) {
         return;
     }
     if ((!Mage::registry('current_layer') || !Mage::helper('factfinder')->isEnabled('catalog_navigation')) && !Mage::registry('current_product')) {
         return;
     }
     if (Mage::registry('current_product')) {
         $product = Mage::registry('current_product');
         $ids = array($product->getData(Mage::helper('factfinder_campaigns')->getIdFieldName()));
         $handler = Mage::getModel('factfinder_campaigns/handler_product', $ids);
     } else {
         $handler = Mage::getSingleton('factfinder_campaigns/handler_search');
     }
     $redirect = $handler->getRedirect();
     if ($redirect) {
         // handle relative urls
         if (!Zend_Uri::check($redirect)) {
             $redirect = Mage::getBaseUrl() . $redirect;
         }
         $response = Mage::app()->getResponse();
         $response->setRedirect($redirect);
         $response->sendResponse();
         exit;
     }
 }
Example #3
0
 /**
  * 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 savedomainAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (!empty($datas['domain'])) {
                 $datas['domain'] = trim(str_replace(array('https', 'http', '://'), '', $datas['domain']));
                 $parts = explode('/', $datas['domain']);
                 $datas['domain'] = !empty($parts[0]) ? $parts[0] : null;
                 $url = 'http://' . $datas['domain'];
                 if (!Zend_Uri::check($url)) {
                     throw new Exception($this->_('Please enter a valid address'));
                 } else {
                     if (addslashes($this->getRequest()->getBaseUrl()) == addslashes($url)) {
                         throw new Exception($this->_('Please enter a valid address'));
                     }
                 }
             } else {
                 $datas['domain'] = null;
             }
             $this->getApplication()->setDomain($datas['domain'])->save();
             $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0, 'domain' => $this->getApplication()->getDomain(), 'application_url' => $this->getApplication()->getUrl());
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Example #5
0
    /**
     * 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;
    }
Example #6
0
 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;
 }
Example #7
0
 public static function watermark(array &$optionValues, XenForo_DataWriter $optionDw, $optionId)
 {
     if ($optionId !== 'sonnbXG_watermark') {
         return true;
     }
     if (!empty($optionValues['enabled'])) {
         switch ($optionValues['overlay']) {
             case 'image':
                 if (!Zend_Uri::check($optionValues['url']) && !is_file($optionValues['url'])) {
                     $optionDw->error(new XenForo_Phrase('sonnb_xengallery_watermark_image_not_valid'), $optionId);
                     return false;
                 }
                 break;
             case 'text':
                 if (!self::isTextColorValid($optionValues['textColor'])) {
                     $optionDw->error(new XenForo_Phrase('sonnb_xengallery_watermark_text_color_not_valid'), $optionId);
                     return false;
                 }
                 if (!self::isBgColorValid($optionValues['bgColor'])) {
                     $optionDw->error(new XenForo_Phrase('sonnb_xengallery_watermark_bg_color_not_valid'), $optionId);
                     return false;
                 }
                 if (!empty($optionValues['font']) && !is_file($optionValues['font'])) {
                     $optionDw->error(new XenForo_Phrase('sonnb_xengallery_watermark_font_path_not_valid'), $optionId);
                     return false;
                 }
                 break;
         }
     }
     return true;
 }
Example #8
0
 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(), '/');
 }
Example #9
0
 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;
     }
 }
 /**
  * Verifies config to make sure the Updater should run.
  * 1. It has not been configured yet
  * 2. Or it has been enabled at some point
  *
  * @param XenForo_Dependencies_Abstract $dependencies
  * @param string $apiUrl
  * @param string|null $addOnId
  * @throws XenForo_Exception
  */
 public static function onInitDependencies(XenForo_Dependencies_Abstract $dependencies, $apiUrl, $addOnId = null)
 {
     if (get_class($dependencies) !== 'XenForo_Dependencies_Admin') {
         // do nothing unless user are in AdminCP
         return;
     }
     if (XenForo_Application::$versionId < 1020000) {
         // only run if XenForo is at least 1.2.0
         return;
     }
     if (!Zend_Uri::check($apiUrl)) {
         throw new XenForo_Exception(sprintf('$apiUrl is invalid: %s', $apiUrl));
     }
     $addOnId = self::_getAddOnId($addOnId);
     $config = self::_getConfig($addOnId, $apiUrl);
     if (!empty($config['configured']) && empty($config['enabled'])) {
         // admin has turned it off, bye bye
         return;
     }
     if (!isset($GLOBALS[self::KEY])) {
         $GLOBALS[self::KEY] = array('version' => array(), 'onPreRoute' => array(), 'setupMethod' => array());
     }
     $GLOBALS[self::KEY]['version'][$apiUrl][self::$_version] = __CLASS__;
     if (!isset($GLOBALS[self::KEY]['onPreRoute'][$apiUrl])) {
         $GLOBALS[self::KEY]['onPreRoute'][$apiUrl] = create_function('$fc', __CLASS__ . '::onPreRoute($fc, ' . var_export($config, true) . ');');
         XenForo_CodeEvent::addListener('front_controller_pre_route', $GLOBALS[self::KEY]['onPreRoute'][$apiUrl]);
     }
 }
Example #11
0
 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());
     }
 }
Example #12
0
 /**
  * Définition de l'Uri
  *
  * @param string $uri
  * @throws Zend_Service_Exception si l'uri est invalide
  */
 public function setUri($uri)
 {
     if (!Zend_Uri::check($uri)) {
         throw new Zend_Service_Exception('URL invalide');
     }
     $this->uri = $uri;
 }
Example #13
0
 /** Check that the URL is valid
  * @access private
  * @param string $url to validate
  * @return string $url
  */
 private function checkUrl($url)
 {
     if (!Zend_Uri::check($url)) {
         throw new Pas_Exception_Url(self::INVALIDURL);
     }
     return $url;
 }
 /** 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;
 }
Example #15
0
 /**
  * @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));
 }
Example #16
0
 /**
  * Callback to check extra-parameters.
  *
  * @internal The availability will be ckecked just before import.
  *
  * @param string $value The value to check.
  * @return boolean
  */
 public static function validateUri($uri)
 {
     if (empty($uri)) {
         return false;
     }
     $scheme = parse_url($uri, PHP_URL_SCHEME);
     // The check is done via the server for external urls.
     if (in_array($scheme, array('http', 'https', 'ftp', 'sftp'))) {
         return Zend_Uri::check($uri);
     }
     // Unknown or unmanaged scheme.
     if ($scheme != 'file' && $uri[0] != '/') {
         return false;
     }
     // Check the security setting.
     $settings = Zend_Registry::get('archive_folder');
     if ($settings->local_folders->allow != '1') {
         return false;
     }
     // Check the base path.
     $basepath = $settings->local_folders->base_path;
     $realpath = realpath($basepath);
     if ($basepath !== $realpath || strlen($realpath) <= 2) {
         return false;
     }
     // Check the uri.
     if ($settings->local_folders->check_realpath == '1') {
         if (strpos(realpath($uri), $realpath) !== 0 || !in_array(substr($uri, strlen($realpath), 1), array('', '/'))) {
             return false;
         }
     }
     // The uri is allowed.
     return true;
 }
 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;
 }
Example #18
0
 /**
  * Validates if a string is valid as a sitemap location
  *
  * @link http://www.sitemaps.org/protocol.php#locdef <loc>
  *
  * @param  string  $value  value to validate
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_setValue($value);
     if (!is_string($value)) {
         return false;
     }
     return Zend_Uri::check($value);
 }
Example #19
0
 /**
  * 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;
 }
 /**
  * Checks whether URL to be shortened is valid
  *
  * @param string $url
  * @throws Zend_Service_ShortUrl_Exception When URL is not valid
  */
 protected function _validateUri($url)
 {
     require_once 'Zend/Uri.php';
     if (!Zend_Uri::check($url)) {
         require_once 'Zend/Service/ShortUrl/Exception.php';
         throw new Zend_Service_ShortUrl_Exception(sprintf('The url "%s" is not valid and cannot be shortened', $url));
     }
 }
Example #21
0
 /**
  * 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();
 }
Example #22
0
 /**
  * @param string $uri
  * @return $this
  */
 public function setUri($uri)
 {
     if (!Zend_Uri::factory($uri)) {
         Mage::throwException('Invalid API uri.');
     }
     $this->_apiUri = $uri;
     return $this;
 }
Example #23
0
 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;
 }
Example #24
0
 /**
  * Verifies that the provided string is a valid URL
  *
  * @param string $url
  *
  * @return boolean
  */
 public static function verifyUri(&$uri, XenForo_DataWriter $dw, $fieldName = false)
 {
     if (Zend_Uri::check($uri)) {
         return true;
     }
     $dw->error(new XenForo_Phrase('please_enter_valid_url'), $fieldName);
     return false;
 }
Example #25
0
 public function isValid($value)
 {
     if (!Zend_Uri::check($value)) {
         $this->_error(self::INVALID_URL);
         return false;
     }
     return true;
 }
Example #26
0
 public function __construct($linkString, $canPrependFull = true)
 {
     if ($canPrependFull) {
         // we have to verify this because caller may not know that all relative urls are forced to absolute by us
         $canPrependFull = !Zend_Uri::check($linkString);
     }
     parent::__construct($linkString, $canPrependFull);
 }
Example #27
0
 /**
  * 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;
 }
Example #28
0
 /**
  * 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);
     }
 }
Example #29
0
 protected function _verifyRedirectUri(&$redirectUri)
 {
     if (!Zend_Uri::check($redirectUri)) {
         $this->error(new XenForo_Phrase('bdapi_redirect_uri_must_be_valid'), 'redirect_uri');
         return false;
     }
     return true;
 }
Example #30
0
 /**
  * Set the callback URL to be used by Publishers or Subscribers when
  * communication with the Hub Server
  *
  * @param string $url
  */
 public function setCallbackUrl($url)
 {
     if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) {
         require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
         throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' . ' of "' . $url . '" must be a non-empty string and a valid' . 'URL');
     }
     $this->_callbackUrl = $url;
 }