Exemple #1
0
 public function setPathInfo($pathInfo = null)
 {
     parent::setPathInfo($pathInfo);
     $path = $this->_pathInfo;
     $paths = explode('/', trim($path, '/'));
     $language = !empty($paths[0]) ? $paths[0] : '';
     if (in_array($language, Core_Model_Language::getLanguageCodes())) {
         $this->_language_code = $language;
         unset($paths[array_search($language, $paths)]);
         $paths = array_values($paths);
     }
     if (!$this->isInstalling()) {
         if (!empty($paths[0]) and $paths[0] == Application_Model_Application::OVERVIEW_PATH) {
             $this->_is_application = true;
             $this->_use_application_key = true;
             unset($paths[0]);
         }
         if (Application_Model_Application::getInstance()->getDomain() == $this->getHttpHost()) {
             $this->_is_application = true;
             $this->_use_application_key = false;
         }
     }
     $paths = array_diff($paths, Core_Model_Language::getLanguageCodes());
     $paths = array_values($paths);
     $this->_pathInfo = '/' . implode('/', $paths);
     return $this;
 }
 /**
  * @test
  * @loadFixture product
  * @loadFixture questions
  */
 public function rewrite()
 {
     $request = new Zend_Controller_Request_Http();
     $response = new Zend_Controller_Response_Http();
     $request->setPathInfo('productquestions/index/index/id/12/category/2/-questions.html');
     $result = $this->_data->rewrite($request, $response);
     $this->assertEquals(false, $result);
 }
Exemple #3
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testMatch()
 {
     $request = new Zend_Controller_Request_Http();
     //Open Node
     $request->setPathInfo('parent_node');
     $controller = $this->_model->match($request);
     $this->assertInstanceOf('Mage_Core_Controller_Varien_Action_Redirect', $controller);
 }
Exemple #4
0
 /**
  * Match with router
  *
  * @param Zend_Controller_Request_Http $request
  * @return boolean
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     $path = trim($request->getPathInfo(), '/');
     if (strrpos($path, '.json') === strlen($path) - 5) {
         $request->setPathInfo(substr($path, 0, strlen($path) - 5));
         Mage::getSingleton('easyAjax/core')->setEasyAjax(true);
         return parent::match($request);
     }
     return false;
 }
 public function indexAction()
 {
     if (!($guid = $this->_getParam('guid')) || !($resource = Engine_Api::_()->getItemByGuid($guid))) {
         return $this->_helper->viewRenderer()->setNoRender();
     }
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $req = new Zend_Controller_Request_Http();
     $req->setPathInfo($resource->getHref());
     $req = $router->route($req);
     $this->_forward($req->getActionName(), $req->getControllerName(), $req->getModuleName(), $req->getParams());
 }
Exemple #6
0
 protected function forwardShopby()
 {
     $reservedKey = Mage::getStoreConfig('amshopby/seo/key');
     $realModule = 'Amasty_Shopby';
     $this->request->setPathInfo($reservedKey);
     $this->request->setModuleName('amshopby');
     $this->request->setRouteName('amshopby');
     $this->request->setControllerName('index');
     $this->request->setActionName('index');
     $this->request->setControllerModule($realModule);
     $file = Mage::getModuleDir('controllers', $realModule) . DS . 'IndexController.php';
     include $file;
     //compatibility with 1.3
     $class = $realModule . '_IndexController';
     $controllerInstance = new $class($this->request, $this->getFront()->getResponse());
     $this->request->setDispatched(true);
     $controllerInstance->dispatch('index');
 }
Exemple #7
0
 /**
  * Matches a user submitted path with a previously defined route.
  * Assigns and returns an array of defaults on a successful match.
  *
  * @param  Zend_Controller_Request_Http $request Request to get the path info from
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($request, $partial = null)
 {
     $path = trim($request->getPathInfo(), self::URI_DELIMITER);
     $subPath = $path;
     $values = array();
     $numRoutes = count($this->_routes);
     foreach ($this->_routes as $key => $route) {
         if ($key > 0 && $matchedPath !== null && $subPath !== '' && $subPath !== false) {
             $separator = substr($subPath, 0, strlen($this->_separators[$key]));
             if ($separator !== $this->_separators[$key]) {
                 return false;
             }
             $subPath = substr($subPath, strlen($separator));
         }
         // TODO: Should be an interface method. Hack for 1.0 BC
         if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
             $match = $subPath;
         } else {
             $request->setPathInfo($subPath);
             $match = $request;
         }
         $res = $route->match($match, true, $key == $numRoutes - 1);
         if ($res === false) {
             return false;
         }
         $matchedPath = $route->getMatchedPath();
         if ($matchedPath !== null) {
             $subPath = substr($subPath, strlen($matchedPath));
             $separator = substr($subPath, 0, strlen($this->_separators[$key]));
         }
         $values = $res + $values;
     }
     $request->setPathInfo($path);
     if ($subPath !== '' && $subPath !== false) {
         return false;
     }
     return $values;
 }
 /**
  * Apply configuration rewrites to current url
  *
  * @return bool
  */
 protected function _rewriteConfig()
 {
     $config = $this->_config->getNode('global/rewrite');
     if (!$config) {
         return false;
     }
     foreach ($config->children() as $rewrite) {
         $from = (string) $rewrite->from;
         $to = (string) $rewrite->to;
         if (empty($from) || empty($to)) {
             continue;
         }
         $from = $this->_processRewriteUrl($from);
         $to = $this->_processRewriteUrl($to);
         $pathInfo = preg_replace($from, $to, $this->_request->getPathInfo());
         if (isset($rewrite->complete)) {
             $this->_request->setPathInfo($pathInfo);
         } else {
             $this->_request->rewritePathInfo($pathInfo);
         }
     }
     return true;
 }
Exemple #9
0
 public function setPathInfo($pathInfo = null)
 {
     parent::setPathInfo($pathInfo);
     $path = $this->_pathInfo;
     $paths = explode('/', trim($path, '/'));
     $language = !empty($paths[0]) ? $paths[0] : '';
     if (in_array($language, Core_Model_Language::getLanguageCodes())) {
         $this->_language_code = $language;
         unset($paths[0]);
         $paths = array_values($paths);
     }
     if (!$this->isInstalling()) {
         $paths = $this->_initApplication($paths);
         if (!$this->isApplication()) {
             $this->_initWhiteLabelEditor();
         }
     }
     // $paths = array_diff($paths, Core_Model_Language::getLanguageCodes());
     $paths = array_values($paths);
     $this->_pathInfo = '/' . implode('/', $paths);
     $detector = new Mobile_Detect();
     $this->_is_native = $detector->isNative();
     return $this;
 }
 public function match(Zend_Controller_Request_Http $request)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         return false;
     }
     $pageId = $request->getPathInfo();
     // remove suffix if any
     $suffix = Mage::helper('amshopby/url')->getUrlSuffix();
     if ($suffix && '/' != $suffix) {
         $pageId = str_replace($suffix, '', $pageId);
     }
     //add trailing slash
     $pageId = trim($pageId, '/') . '/';
     $reservedKey = Mage::getStoreConfig('amshopby/seo/key') . '/';
     //  canon/
     //  electronics - false
     //  electronics/shopby/canon/
     //  electronics/shopby/red/
     //  electronics/shopby/
     //  shopby/
     //  shopby/red/
     //  shopby/canon/ - false
     //  shopby/manufacturer-canon/ - false
     //  manufacturer-canon/ - true
     // starts from shopby
     $isAllProductsPage = substr($pageId, 0, strlen($reservedKey)) == $reservedKey;
     // has shopby in the middle
     $isCategoryPage = false !== strpos($pageId, '/' . $reservedKey);
     if (!Mage::getStoreConfig('amshopby/seo/urls')) {
         // If path info have something after reserved key
         if (($isAllProductsPage || $isCategoryPage) && substr($pageId, -strlen($reservedKey), strlen($reservedKey)) != $reservedKey) {
             return false;
         }
     }
     if ($isAllProductsPage) {
         // no support for old style urls
         if ($this->hasBrandIn(self::MIDDLE, $pageId)) {
             return false;
         }
     }
     if (!$isAllProductsPage && !$isCategoryPage) {
         if (!$this->hasBrandIn(self::BEGINNING, $pageId)) {
             return false;
         }
         //it is brand page and we modify the url to be in the old style
         $pageId = $reservedKey . $pageId;
     }
     // get layered navigation params as string
     list($cat, $params) = explode($reservedKey, $pageId, 2);
     $params = trim($params, '/');
     if ($params) {
         $params = explode('/', $params);
     }
     // remember for futire use in the helper
     if ($params) {
         Mage::register('amshopby_current_params', $params);
     }
     $cat = trim($cat, '/');
     if ($cat) {
         // normal category
         // if somebody has old urls in the cache.
         if (!Mage::getStoreConfig('amshopby/seo/urls')) {
             return false;
         }
         // we do not use Mage::getVersion() here as it is not defined in the old versions.
         $isVersionEE13 = 'true' == (string) Mage::getConfig()->getNode('modules/Enterprise_UrlRewrite/active');
         if ($isVersionEE13) {
             $urlRewrite = Mage::getModel('enterprise_urlrewrite/url_rewrite');
             /* @var $urlRewrite Enterprise_UrlRewrite_Model_Url_Rewrite */
             if (version_compare(Mage::getVersion(), '1.13.0.2', '>=')) {
                 $catReqPath = array('request' => $cat . $suffix, 'whole' => $cat);
             } else {
                 $catReqPath = array($cat);
             }
             $urlRewrite->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($catReqPath);
         } else {
             $urlRewrite = Mage::getModel('core/url_rewrite');
             /* @var $urlRewrite Mage_Core_Model_Url_Rewrite */
             $cat = $cat . $suffix;
             $catReqPath = $cat;
             $urlRewrite->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($catReqPath);
         }
         // todo check in ee13
         if (!$urlRewrite->getId()) {
             $store = $request->getParam('___from_store');
             $store = Mage::app()->getStore($store)->getId();
             if (!$store) {
                 return false;
             }
             $urlRewrite->setData(array())->setStoreId($store)->loadByRequestPath($catReqPath);
             if (!$urlRewrite->getId()) {
                 return false;
             }
         }
         $request->setPathInfo($cat);
         $request->setModuleName('catalog');
         $request->setControllerName('category');
         $request->setActionName('view');
         if ($isVersionEE13) {
             $categoryId = str_replace('catalog/category/view/id/', '', $urlRewrite->getTargetPath());
             $request->setParam('id', $categoryId);
         } else {
             $request->setParam('id', $urlRewrite->getCategoryId());
             $urlRewrite->rewrite($request);
         }
     } else {
         // root category
         $realModule = 'Amasty_Shopby';
         $request->setPathInfo(trim($reservedKey, '/'));
         $request->setModuleName('amshopby');
         $request->setRouteName('amshopby');
         $request->setControllerName('index');
         $request->setActionName('index');
         $request->setControllerModule($realModule);
         $file = Mage::getModuleDir('controllers', $realModule) . DS . 'IndexController.php';
         include $file;
         //compatibility with 1.3
         $class = $realModule . '_IndexController';
         $controllerInstance = new $class($request, $this->getFront()->getResponse());
         $request->setDispatched(true);
         $controllerInstance->dispatch('index');
     }
     return true;
 }
 /**
  * @group ZF-7848
  */
 public function testChainingWithConfiguredEmptyStaticRoutesMatchesCorrectly()
 {
     $routes = array('admin' => array('route' => 'admin', 'defaults' => array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), 'chains' => array('index' => array('type' => 'Zend_Controller_Router_Route_Static', 'route' => '', 'defaults' => array('module' => 'admin', 'controller' => 'index', 'action' => 'index')), 'login' => array('route' => 'login', 'defaults' => array('module' => 'admin', 'controller' => 'login', 'action' => 'index')))));
     $config = new Zend_Config($routes);
     $rewrite = new Zend_Controller_Router_Rewrite();
     $rewrite->addConfig($config);
     $routes = $rewrite->getRoutes();
     $indexRoute = $rewrite->getRoute('admin-index');
     $loginRoute = $rewrite->getRoute('admin-login');
     $request = new Zend_Controller_Request_Http();
     $request->setPathInfo('/admin');
     $values = $indexRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/');
     $values = $indexRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/login');
     $values = $loginRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'login', 'action' => 'index'), $values);
 }
 function getSEORequest($uri)
 {
     $request = new Zend_Controller_Request_Http($uri);
     $request->setPathInfo($uri);
     return $request;
 }
Exemple #13
0
 public function getOriginalRequest()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setPathInfo($this->getOriginalPathInfo());
     return $request;
 }
Exemple #14
0
 public function testSetPathInfo()
 {
     $this->_request->setPathInfo('/archives/past/4');
     $this->assertEquals('/archives/past/4', $this->_request->getPathInfo());
 }
Exemple #15
0
 /**
  * Checks if the role is allowed to access the given route.
  *
  * @param   Zend_Controller_Router_Route|string $route      A route or route name.
  * @param   array                               $data       Optional parameters to assemble the route.
  * @param   mixed                               $privilege  An optional privilege.
  *
  * @return  bool    If the role is allowed to access the given route.
  */
 public function isRouteAllowed($route, array $data = array(), $privilege = null)
 {
     $router = Zend_Controller_Front::getInstance()->getRouter();
     if (!$route instanceof Zend_Controller_Router_Route) {
         $route = $router->getRoute((string) $route);
     }
     $request = new Zend_Controller_Request_Http();
     $request->setPathInfo($route->assemble($data));
     $router->route($request);
     return $this->isRequestAllowed($request, $privilege);
 }
Exemple #16
0
 public function match(Zend_Controller_Request_Http $request)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         return false;
     }
     $pageId = $request->getPathInfo();
     // remove suffix if any
     $suffix = Mage::getStoreConfig('catalog/seo/category_url_suffix');
     if ($suffix && '/' != $suffix) {
         $pageId = str_replace($suffix, '', $pageId);
     }
     //add trailing slash
     $pageId = trim($pageId, '/') . '/';
     $reservedKey = Mage::getStoreConfig('amshopby/seo/key') . '/';
     //check if we have reserved word in the url
     if (false === strpos($pageId, '/' . $reservedKey)) {
         if (substr($pageId, 0, strlen($reservedKey)) != $reservedKey) {
             return false;
         }
     } else {
         $reservedKey = '/' . $reservedKey;
     }
     // get layered navigation params as string
     list($cat, $params) = explode($reservedKey, $pageId, 2);
     $params = trim($params, '/');
     if ($params) {
         $params = explode('/', $params);
     }
     // remember for futire use in the helper
     if ($params) {
         Mage::register('amshopby_current_params', $params);
     }
     $cat = trim($cat, '/');
     if ($cat) {
         // normal category
         // if somebody has old urls in the cache.
         if (!Mage::getStoreConfig('amshopby/seo/urls')) {
             return false;
         }
         Varien_Autoload::registerScope('catalog');
         $cat = $cat . $suffix;
         $urlRewrite = Mage::getModel('core/url_rewrite')->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($cat);
         if (!$urlRewrite->getId()) {
             $store = $request->getParam('___from_store');
             $store = Mage::app()->getStore($store)->getId();
             if (!$store) {
                 return false;
             }
             $urlRewrite = Mage::getModel('core/url_rewrite')->setStoreId($store)->loadByRequestPath($cat);
         }
         if (!$urlRewrite->getId()) {
             return false;
         }
         $request->setPathInfo($cat);
         $request->setModuleName('catalog');
         $request->setControllerName('category');
         $request->setActionName('view');
         $request->setParam('id', $urlRewrite->getCategoryId());
         $urlRewrite->rewrite($request);
     } else {
         // root category
         $realModule = 'Amasty_Shopby';
         $request->setPathInfo(trim($reservedKey, '/'));
         $request->setModuleName('amshopby');
         $request->setRouteName('amshopby');
         $request->setControllerName('index');
         $request->setActionName('index');
         $request->setControllerModule($realModule);
         $file = Mage::getModuleDir('controllers', $realModule) . DS . 'IndexController.php';
         include $file;
         //compatibility with 1.3
         $class = $realModule . '_IndexController';
         $controllerInstance = new $class($request, $this->getFront()->getResponse());
         $request->setDispatched(true);
         $controllerInstance->dispatch('index');
     }
     return true;
 }
Exemple #17
0
 /**
  * @param Zend_Controller_Request_Http $request
  * @return $this|Zend_Controller_Request_Http
  * @throws EcommerceTeam_Sln_Exception_Rewrite
  */
 protected function _oldRewrite(Zend_Controller_Request_Http $request)
 {
     /** @var $helper EcommerceTeam_Sln_Helper_Data */
     $helper = Mage::helper('ecommerceteam_sln');
     $separator = $helper->getConfigData('url_separator');
     $requestPath = trim($request->getPathInfo(), '/');
     $requestPath = Mage::helper('ecommerceteam_sln/request')->clearSuffix($requestPath);
     $path = explode('/', $requestPath);
     $filterKey = array_search($separator, $path);
     if ($filterKey !== false) {
         $filterParams = array_slice($path, $filterKey + 1);
         if (count($filterParams) % 2) {
             array_unshift($filterParams, 'attributes');
         }
         if ($filterKey) {
             $categoryUrlKey = implode('/', array_slice($path, 0, $filterKey));
         } else {
             $categoryUrlKey = implode('/', $path);
         }
         if ($filterKey && $categoryUrlKey) {
             if (Mage::getStoreConfig("catalog/seo/category_url_suffix") == "/") {
                 $categoryUrlKey = $categoryUrlKey . '/';
             } else {
                 $categoryUrlKey = trim($categoryUrlKey, '/') . $helper->getUrlSuffix();
             }
             /** @var $urlRewriteModel Mage_Core_Model_Url_Rewrite */
             $urlRewriteModel = Mage::getModel('core/url_rewrite');
             if ($helper->isMagentoEnterprise()) {
                 $urlRewriteModel = Mage::getModel('enterprise_urlrewrite/url_rewrite');
             }
             $urlRewriteModel->setData('store_id', Mage::app()->getStore()->getId());
             $targetPath = $urlRewriteModel->loadByRequestPath(array($categoryUrlKey))->getTargetPath();
             if (!$urlRewriteModel->getData('category_id')) {
                 throw new EcommerceTeam_Sln_Exception_Rewrite($this->__("Can't resolve category request path."));
             }
             $currentCategory = Mage::getModel('catalog/category')->load($urlRewriteModel->getData('category_id'));
             Mage::getSingleton('catalog/layer')->setCurrentCategory($currentCategory);
             $itemsLength = count($filterParams);
             $request->setParam('layered_navigation_base_url', Mage::getBaseUrl('web') . $urlRewriteModel->getRequestPath());
             for ($i = 0; $i < $itemsLength; $i += 2) {
                 $request->setParam($filterParams[$i], isset($filterParams[$i + 1]) ? explode(',', $filterParams[$i + 1]) : null);
             }
             if ($targetPath) {
                 $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, trim($request->getPathInfo(), '/'));
                 $request->setPathInfo($targetPath);
                 return $request;
             }
         }
     }
     return $this;
 }