Example #1
0
 /**
  * @covers Mage_Adminhtml_Block_Catalog_Product_Edit_NewCategory::getSaveCategoryUrl
  * @covers Mage_Adminhtml_Block_Catalog_Product_Edit_NewCategory::getSuggestCategoryUrl
  * @dataProvider urlMethodsDataProvider
  * @param string $expectedUrl
  * @param string $executedMethod
  */
 public function testGetUrlMethods($expectedUrl, $executedMethod)
 {
     $this->_urlModel->expects($this->once())->method('getUrl')->with($expectedUrl)->will($this->returnCallback(function ($string) {
         return strrev($string);
     }));
     $this->assertEquals(strrev($expectedUrl), call_user_func_array(array($this->_object, $executedMethod), array($expectedUrl)));
 }
Example #2
0
 /**
  * Generate url
  * @param string $value
  * @throws InvalidArgumentException
  * @return Mage_Core_Model_Abstract|boolean
  */
 public function process($value)
 {
     if (false === is_array($value) || !isset($value['path'])) {
         throw new InvalidArgumentException('Passed value has incorrect format');
     }
     $params = array_key_exists('params', $value) ? $value['params'] : null;
     return $this->_urlModel->getUrl($value['path'], $params);
 }
Example #3
0
 public function getAdminBaseUrl()
 {
     $model = new Mage_Core_Model_Url();
     $useSession = $model->getUseSession();
     $url = $model->setUseSession(0)->setStore('admin')->getUrl('adminhtml');
     $model->setUseSession($useSession);
     return $url;
 }
Example #4
0
 /**
  * Generate url
  * @param string $value
  * @throws InvalidArgumentException
  * @return Mage_Core_Model_Abstract|boolean
  */
 public function process($value)
 {
     if (false === is_array($value) || (!isset($value['path']) || !isset($value['params']))) {
         throw new InvalidArgumentException('Passed value has incorrect format');
     }
     $path = $value['path'];
     $params = $value['params'];
     return $this->_urlModel->getUrl($path, $params);
 }
Example #5
0
 public function getUrl($routePath = null, $routeParams = null)
 {
     $route = Mage::helper('blog')->getRoute();
     if (!empty($route)) {
         $isUseCategoryUrl = Mage::helper('blog')->isCategoryUrl();
         $category = Mage::getSingleton('blog/cat');
         $post = Mage::getSingleton('blog/post');
         $tag = $this->getRequest()->getParam('tag', false);
         if ($isUseCategoryUrl && $category->getCatId()) {
             $route .= '/' . Smartwave_Blog_Helper_Data::CATEGORY_URI_PARAM . '/' . $category->getIdentifier();
         }
         if ($post->getIdentifier()) {
             if ($isUseCategoryUrl && $category->getCatId()) {
                 $route .= '/' . Smartwave_Blog_Helper_Data::POST_URI_PARAM . '/' . $post->getIdentifier();
             } else {
                 $route .= '/' . $post->getIdentifier();
             }
         }
         if ($tag) {
             $route .= '/' . Smartwave_Blog_Helper_Data::TAG_URI_PARAM . '/' . $tag;
         }
         $routePath = $route;
     }
     return parent::getUrl($routePath, $routeParams);
 }
Example #6
0
 /**
  * Note: isolation flushes the URL memory cache
  * @magentoAppIsolation enabled
  */
 public function testIsOwnOriginUrl()
 {
     $_SERVER['HTTP_REFERER'] = 'http://localhost/';
     $this->assertTrue($this->_model->isOwnOriginUrl());
     $_SERVER['HTTP_REFERER'] = 'http://example.com/';
     $this->assertFalse($this->_model->isOwnOriginUrl());
 }
Example #7
0
 /**
  * Retrieve route URL
  *
  * @param string $routePath
  * @param array $routeParams
  * @return string
  */
 public function getRouteUrl($routePath = null, $routeParams = null)
 {
     $url = parent::getRouteUrl($routePath, $routeParams);
     $baseUrl = trim($this->getBaseUrl(), '/');
     $vdeBaseUrl = $baseUrl . '/' . $this->_helper->getFrontName();
     if (strpos($url, $baseUrl) === 0 && strpos($url, $vdeBaseUrl) === false) {
         $url = str_replace($baseUrl, $vdeBaseUrl, $url);
     }
     return $url;
 }
Example #8
0
 /**
  * Retrieve link on product rss feed tagged with loaded tag
  *
  * @return bool|string
  */
 public function getLinkUrl()
 {
     if ($this->_isRssEnabled && $this->_tagId) {
         /** @var $tagModel Mage_Tag_Model_Tag */
         $this->_tagModel->load($this->_tagId);
         if ($this->_tagModel && $this->_tagModel->getId()) {
             return $this->_coreUrlModel->getUrl('rss/catalog/tag', array('tagName' => urlencode($this->_tagModel->getName())));
         }
     }
     return false;
 }
Example #9
0
 public function getUrl($routePath = null, $routeParams = null)
 {
     $forceVendorUrl = !empty($routeParams['_current']);
     if ($forceVendorUrl) {
         Mage::app()->getStore()->useVendorUrl(true);
     }
     $url = parent::getUrl($routePath, $routeParams);
     if ($forceVendorUrl) {
         Mage::app()->getStore()->resetUseVendorUrl();
     }
     return $url;
 }
Example #10
0
 public function getUrl($routePath = null, $routeParams = null)
 {
     $url = parent::getUrl($routePath, $routeParams);
     if (substr($url, -1) != "/") {
         if (strpos($url, "?") !== false) {
             if (substr($url, strpos($url, "?") - 1, 1) != "/") {
                 $url = substr_replace($url, "/?", strpos($url, "?"), 1);
             }
         } else {
             $url .= "/";
         }
     }
     return $url;
 }
 public function getUrl($routePath = null, $routeParams = null)
 {
     $this->_escape = isset($routeParams['_escape']) ? $routeParams['_escape'] : isset($routeParams['_m_escape']);
     $result = $this->encodeUrl($routePath, parent::getUrl($routePath, $routeParams));
     $result = preg_replace('#\\/[-_\\w\\d]+\\/\\.#', '.', $result);
     if (strpos($result, '/.html') !== false) {
         $currentUrl = parent::getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true, '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
         Mage::log("Wrong URL {$result} on page {$currentUrl}", Zend_Log::DEBUG, 'seo_errors.log');
         try {
             throw new Exception();
         } catch (Exception $e) {
             Mage::log("{$e->getMessage()}\n{$e->getTraceAsString()}", Zend_Log::DEBUG, 'seo_errors.log');
         }
     }
     return $result;
 }
Example #12
0
 public function getUrl($routePath = null, $routeParams = null)
 {
     $url = parent::getUrl($routePath, $routeParams);
     if ($subD = Mage::registry('current_subdomain')) {
         $urlParts = parse_url($url);
         $urlHostParts = explode('.', $urlParts['host']);
         // Custom case for dev server
         if ('dev.bloomnation.com' == $urlParts['host']) {
             $urlParts['host'] = 'lapremier.dev.bloomnation.com';
         } else {
             $urlHostParts[0] = $subD;
             $urlParts['host'] = implode('.', $urlHostParts);
         }
         $url = (isset($urlParts["scheme"]) ? $urlParts["scheme"] . "://" : "") . (isset($urlParts["user"]) ? $urlParts["user"] . ":" : "") . (isset($urlParts["pass"]) ? $urlParts["pass"] . "@" : "") . (isset($urlParts["host"]) ? $urlParts["host"] : "") . (isset($urlParts["port"]) ? ":" . $urlParts["port"] : "") . (isset($urlParts["path"]) ? $urlParts["path"] : "") . (isset($urlParts["query"]) ? "?" . $urlParts["query"] : "") . (isset($urlParts["fragment"]) ? "#" . $urlParts["fragment"] : "");
     }
     return $url;
 }
Example #13
0
 /**
  * Custom logic to retrieve Urls
  *
  * @param string $routePath
  * @param array $routeParams
  * @return string
  */
 public function getUrl($routePath = null, $routeParams = null)
 {
     $result = parent::getUrl($routePath, $routeParams);
     if (!$this->useSecretKey()) {
         return $result;
     }
     $_route = $this->getRouteName() ? $this->getRouteName() : '*';
     $_controller = $this->getControllerName() ? $this->getControllerName() : $this->getDefaultControllerName();
     $_action = $this->getActionName() ? $this->getActionName() : $this->getDefaultActionName();
     $secret = array(self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($_controller, $_action));
     if (is_array($routeParams)) {
         $routeParams = array_merge($secret, $routeParams);
     } else {
         $routeParams = $secret;
     }
     if (is_array($this->getRouteParams())) {
         $routeParams = array_merge($this->getRouteParams(), $routeParams);
     }
     return parent::getUrl("{$_route}/{$_controller}/{$_action}", $routeParams);
 }
Example #14
0
 /**
  * Retrieve store URL directive
  * Support url and direct_url properties
  *
  * @param array $construction
  * @return string
  */
 public function storeDirective($construction)
 {
     $params = $this->_getIncludeParameters($construction[2]);
     if (!isset($params['_query'])) {
         $params['_query'] = array();
     }
     foreach ($params as $k => $v) {
         if (strpos($k, '_query_') === 0) {
             $params['_query'][substr($k, 7)] = $v;
             unset($params[$k]);
         }
     }
     $params['_absolute'] = $this->_useAbsoluteLinks;
     if ($this->_useSessionInUrl === false) {
         $params['_nosid'] = true;
     }
     if (isset($params['direct_url'])) {
         $path = '';
         $params['_direct'] = $params['direct_url'];
         unset($params['direct_url']);
     } else {
         $path = $params['url'];
         unset($params['url']);
     }
     if (!self::$_urlInstance) {
         self::$_urlInstance = Mage::getModel('core/url')->setStore(Mage::app()->getStore(Mage::getDesign()->getStore())->getId());
     }
     $_urlInstanceOldStore = null;
     if (!empty($path) && !Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) && !Mage::app()->isSingleStoreMode()) {
         $params['_query']['___store'] = Mage::app()->getStore(Mage::getDesign()->getStore())->getCode();
     } elseif (!empty($path) && Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) && !Mage::app()->isSingleStoreMode()) {
         $_urlInstanceOldStore = self::$_urlInstance->getStore();
         self::$_urlInstance->setStore(Mage::app()->getStore(Mage::getDesign()->getStore())->getCode());
     }
     $url = self::$_urlInstance->getUrl($path, $params);
     if (null == !$_urlInstanceOldStore) {
         self::$_urlInstance->setStore($_urlInstanceOldStore);
     }
     return $url;
 }
Example #15
0
 /**
  * Build url by requested path and parameters
  *
  * @param   string|null $routePath
  * @param   array|null $routeParams
  * @return  string
  */
 public function getUrl($routePath = null, $routeParams = null)
 {
     /*
              use https
              if url show in web browser start with https, all urls in the webpage must be start with https,
              for example: if main page is https, but ajax request send in this page is http, then ajax request will fail
                           if main page is http, but ajax request send in this page is https, then ajax request will fail also
     */
     //use https
     if (isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']) {
         //if it has set $routeParams,then add  '_secure' => true
         if (is_array($routeParams)) {
             if (!isset($routeParams['_secure'])) {
                 $routeParams['_secure'] = true;
             }
         } else {
             //set $routeParams to use https
             $routeParams = array('_secure' => true);
         }
     }
     return parent::getUrl($routePath, $routeParams);
 }
Example #16
0
 public function getRoutePath($routeParams = array())
 {
     if ($this->_pageUrlKey === null) {
         if ($this->_query) {
             $this->setData('query_params', $this->_query);
         }
         return parent::getRoutePath($routeParams);
     }
     /* @var $core Mana_Core_Helper_Data */
     $core = Mage::helper('mana_core');
     if (!$this->hasData('route_path')) {
         $query = $this->_query;
         if ($query !== null) {
             if (is_string($query)) {
                 $this->setQuery($query);
             } elseif (is_array($query)) {
                 $this->setQueryParams($query, !empty($routeParams['_current']));
             }
             if ($query === false) {
                 $this->setQueryParams(array());
             }
         }
         $queryParams = $this->getQueryParams();
         $seoParams = array();
         foreach ($this->getQueryParams() as $key => $value) {
             $path = false;
             if ($key == 'p' && $value == 1) {
                 unset($queryParams[$key]);
                 continue;
             }
             if ($value !== null) {
                 if ($url = $this->_getParameterUrl($key)) {
                     $position = $url->getPosition();
                     $attribute_id = $url->getAttributeId();
                     $category_id = null;
                     switch ($url->getType()) {
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE:
                             $path = $this->_generateAttributeParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY:
                             list($path, $category_id) = $this->_generateCategoryParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE:
                             $path = $this->_generatePriceParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_TOOLBAR:
                             $path = $this->_generateToolbarParameter($url, $value);
                             break;
                         default:
                             throw new Exception('Not implemented');
                     }
                 }
             }
             if ($path) {
                 $seoParams[$key] = compact('path', 'position', 'attribute_id', 'category_id');
                 unset($queryParams[$key]);
             }
         }
         $this->_redirectToSubcategory($seoParams);
         uasort($seoParams, array($this, '_compareSeoParams'));
         $routePath = $this->_encode($this->_pageUrlKey);
         $first = true;
         foreach ($seoParams as $path) {
             if ($first) {
                 if ($routePath) {
                     $routePath .= $this->_schema->getQuerySeparator();
                 }
                 $first = false;
             } else {
                 $routePath .= $this->_schema->getParamSeparator();
             }
             $routePath .= $path['path'];
         }
         if ($routePath) {
             $routePath .= $core->addDotToSuffix($this->_suffix);
         }
         $this->setData('query_params', $queryParams);
         $this->setData('route_path', $routePath);
     }
     return $this->_getData('route_path');
 }
Example #17
0
 /**
  * Replace URLs from cache
  *
  * @param string $html
  * @return string
  */
 protected function _afterCacheUrl($html)
 {
     if ($this->_cache->canUse(self::CACHE_GROUP)) {
         Mage::app()->setUseSessionVar(false);
         Magento_Profiler::start('CACHE_URL');
         $html = $this->_urlBuilder->sessionUrlVar($html);
         Magento_Profiler::stop('CACHE_URL');
     }
     return $html;
 }
 /**
  * Translates the action part before delivered to frontend
  *
  * @return false|mixed|null|string
  */
 public function getActionName()
 {
     if (!$this->translationEnabled()) {
         return parent::getActionName();
     }
     return $this->getTranslationModel()->translateActionToFront(parent::getActionName());
 }
Example #19
0
 /**
  * Retrieve action path.
  * Add backend area front name as a prefix to action path
  *
  * @return string
  */
 public function getActionPath()
 {
     $path = parent::getActionPath();
     if ($path) {
         if ($this->getAreaFrontName()) {
             $path = $this->getAreaFrontName() . '/' . $path;
         }
     }
     return $path;
 }
Example #20
0
 public function addSessionParam()
 {
     $session = Mage::getSingleton('core/session');
     if (!self::$_encryptedSessionId) {
         $helper = Mage::helper('core');
         if (!$helper) {
             return $this;
         }
         self::$_encryptedSessionId = $session->getEncryptedSessionId();
     }
     $this->setQueryParam(Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM, self::$_encryptedSessionId);
     return $this;
 }
Example #21
0
 /**
  * Retrieve route path
  *
  * @param array $routeParams
  * @return string
  */
 public function getRoutePath($routeParams = array())
 {
     return $this->_helper->getFrontName() . '/' . parent::getRoutePath($routeParams);
 }
Example #22
0
 /**
  * return the Route URL
  *
  * @param string $routePath
  * @param array $routeParams
  * @return string
  */
 public function getRouteUrl($routePath = null, $routeParams = null, $getOriginalData = false)
 {
     if (!Mage::getSingleton('Flagbit_Typo3connect/Core')->isEnabled() || $getOriginalData) {
         return parent::getRouteUrl($routePath, $routeParams);
     }
     $this->unsetData('route_params');
     if (!is_null($routePath)) {
         $this->setRoutePath($routePath);
     }
     if (is_array($routeParams)) {
         $this->setRouteParams($routeParams, false);
     }
     $url = $this->getRoutePath($routeParams);
     //$url = $this->getBaseUrl().$this->getRoutePath($routeParams);
     return $url;
 }
Example #23
0
 public function testSetRoutePathWhenRouteParamsExists()
 {
     $this->assertNull($this->_model->getControllerName());
     $this->assertNull($this->_model->getActionName());
     $this->_model->setRoutePath('m/c/a/p1/v1/p2/v2');
     $this->assertNotNull($this->_model->getControllerName());
     $this->assertNotNull($this->_model->getActionName());
     $this->assertNotEmpty($this->_model->getRouteParams());
     $this->assertArrayHasKey('p1', $this->_model->getRouteParams());
     $this->assertArrayHasKey('p2', $this->_model->getRouteParams());
     $this->assertEquals('v1', $this->_model->getRouteParam('p1'));
     $this->assertEquals('v2', $this->_model->getRouteParam('p2'));
 }
Example #24
0
 /**
  * Custom logic to retrieve Urls
  *
  * @param string $routePath
  * @param array $routeParams
  * @return string
  */
 public function getUrl($routePath = null, $routeParams = null)
 {
     $cacheSecretKey = false;
     // automatically persist http/https state based on current state
     // this is is overridden if the secure flag has been explicitly
     // set in the params
     if (!isset($routeParams['_secure'])) {
         $routeParams['_secure'] = $this->getSecure();
     }
     if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
         unset($routeParams['_cache_secret_key']);
         $cacheSecretKey = true;
     }
     $result = parent::getUrl($routePath, $routeParams);
     if (!$this->useSecretKey()) {
         return $result;
     }
     $_route = $this->getRouteName() ? $this->getRouteName() : '*';
     $_controller = $this->getControllerName() ? $this->getControllerName() : $this->getDefaultControllerName();
     $_action = $this->getActionName() ? $this->getActionName() : $this->getDefaultActionName();
     if ($cacheSecretKey) {
         $secret = array(self::SECRET_KEY_PARAM_NAME => "\${$_controller}/{$_action}\$");
     } else {
         $secret = array(self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($_controller, $_action));
     }
     if (is_array($routeParams)) {
         $routeParams = array_merge($secret, $routeParams);
     } else {
         $routeParams = $secret;
     }
     if (is_array($this->getRouteParams())) {
         $routeParams = array_merge($this->getRouteParams(), $routeParams);
     }
     return parent::getUrl("{$_route}/{$_controller}/{$_action}", $routeParams);
 }
Example #25
0
 /**
  * Add session param
  *
  * @return Mage_Core_Model_Url
  */
 public function addSessionParam()
 {
     $session = Mage::getSingleton('core/session');
     if (!self::$_encryptedSessionId) {
         $helper = Mage::helper('core');
         if (!$helper) {
             return $this;
         }
         self::$_encryptedSessionId = $session->getEncryptedSessionId();
     }
     $this->setQueryParam($session->getSessionIdQueryParam(), self::$_encryptedSessionId);
     return $this;
 }
Example #26
0
 protected function setOriginalUrl($routePath = null, $routeParams = null)
 {
     // Get the original URLs from the registry
     $original_urls = Mage::registry('original_urls');
     // If this value is empty, it is not yet initialized
     if (empty($original_urls)) {
         return parent::getUrl($routePath, $routeParams);
     }
     // Fetch the result from this method
     $rt = parent::getUrl($routePath, $routeParams);
     // Replace the current URL with the original URL
     $store = Mage::app()->getStore();
     if ($store->getConfig('web/secure/use_in_frontend') == 1 && isset($original_urls['web/secure/base_url'])) {
         $rt = str_replace($store->getConfig('web/secure/base_url'), $original_urls['web/secure/base_url'], $rt);
     } elseif (isset($original_urls['web/unsecure/base_url'])) {
         $rt = str_replace($store->getConfig('web/unsecure/base_url'), $original_urls['web/unsecure/base_url'], $rt);
     }
     return $rt;
 }