public function testMatch() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Can\'t test get match without sending headers'); } $request = new Magento_Test_Request(); $this->assertFalse($this->_model->match($request)); $this->_model->collectRoutes('frontend', 'standard'); $this->assertTrue($this->_model->match($request)); $request->setRequestUri('core/index/index'); $this->assertTrue($this->_model->match($request)); $request->setPathInfo('not_exists/not_exists/not_exists')->setModuleName('not_exists')->setControllerName('not_exists')->setActionName('not_exists'); $this->assertFalse($this->_model->match($request)); }
public function match(Zend_Controller_Request_Http $request) { $active = Mage::getStoreConfig("dev/offline/mwdevtoolbar"); if ($active == 1) { $storeenabled = Mage::getStoreConfig('dev/offline/enable', $request->getStoreCodeFromPath()); if ($storeenabled) { Mage::getSingleton('core/session', array('name' => 'adminhtml')); $helper = Mage::helper('developertoolbar/data'); if ($helper->checkAllowsIps() == 0) { Mage::getSingleton('core/session', array('name' => 'front')); $front = $this->getFront(); $response = $front->getResponse(); $response->setHeader('HTTP/1.1', '503 Service Temporarily Unavailable'); $response->setHeader('Status', '503 Service Temporarily Unavailable'); $response->setHeader('Retry-After', '5000'); $response->setBody(html_entity_decode(Mage::getStoreConfig('dev/offline/message', $request->getStoreCodeFromPath()), ENT_QUOTES, "utf-8")); $response->sendHeaders(); $response->outputBody(); exit; } else { $showreminder = Mage::getStoreConfig('dev/offline/reminder', $request->getStoreCodeFromPath()); if ($showreminder) { $front = $this->getFront(); $response = $front->getResponse()->clearBody(); $response = $front->getResponse()->appendBody('<div style="height:12px; background:red; color: white; position:relative; width:100%;padding:3px; z-index:100000;text-trasform:capitalize;">Offline</div>'); } } } } return parent::match($request); }
/** * 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 match(Zend_Controller_Request_Http $request) { $helper = Mage::helper('BalkeTechnologies_StoreMaintenance'); $storeCode = $request->getStoreCodeFromPath(); $enabled = $helper->getConfig('enabled', $storeCode); // module enabled? if (1 == $enabled) { $allowedIPsString = $helper->getConfig('allowedIPs', $storeCode); // remove spaces from string $allowedIPsString = preg_replace('/ /', '', $allowedIPsString); $allowedIPs = array(); if ('' !== trim($allowedIPsString)) { $allowedIPs = explode(',', $allowedIPsString); } $currentIP = $_SERVER['REMOTE_ADDR']; $allowFrontendForAdmins = $helper->getConfig('allowFrontendForAdmins', $storeCode); $adminIp = null; if (1 == $allowFrontendForAdmins) { //get the admin session Mage::getSingleton('core/session', array('name' => 'adminhtml')); //verify if the user is logged in to the backend $adminSession = Mage::getSingleton('admin/session'); if ($adminSession->isLoggedIn()) { //do stuff $adminIp = $adminSession['_session_validator_data']['remote_addr']; } } if ($currentIP === $adminIp) { // current user is logged in as admin $this->__log('Access granted for admin with IP: ' . $currentIP . ' and store ' . $storeCode, 2, $storeCode); } else { // current user allowed to access website? if (!in_array($currentIP, $allowedIPs)) { $this->__log('Access denied for IP: ' . $currentIP . ' and store ' . $storeCode, 1, $storeCode); $maintenancePage = trim($helper->getConfig('maintenancePage', $storeCode)); // if custom maintenance page is defined in backend, display this one if ('' !== $maintenancePage) { Mage::getSingleton('core/session', array('name' => 'front')); $response = $this->getFront()->getResponse(); $response->setHeader('HTTP/1.1', '503 Service Temporarily Unavailable'); $response->setHeader('Status', '503 Service Temporarily Unavailable'); $response->setHeader('Retry-After', '5000'); $response->setBody($maintenancePage); $response->sendHeaders(); $response->outputBody(); } exit; } else { $this->__log('Access granted for IP: ' . $currentIP . ' and store ' . $storeCode, 2, $storeCode); } } } return parent::match($request); }
/** * Check if the request is matched. * * @param Zend_Controller_Request_Http $request * @return bool */ public function match(Zend_Controller_Request_Http $request) { if (!$this->isAllowedToViewPage($request)) { Mage::getStoreConfigFlag('dev/offlinemaintenance/custom_message', $request->getStoreCodeFromPath()) ? $this->_sendCustomMessage($request) : $this->_send503(); } elseif (Mage::getStoreConfig('dev/offlinemaintenance/showreminder', $request->getStoreCodeFromPath())) { /** @var $front Mage_Core_Controller_Varien_Front */ $front = $this->getFront(); $offlineText = Mage::helper('ho_offlinemaintenance')->__('Offline Mode Enabled'); $front->getResponse()->appendBody('<div style="line-height:22px; background:#d92b28; color: white; position:relative; text-align: center; width:100%; padding:3px; z-index:100000; text-transform:uppercase;">' . $offlineText . '</div>'); } return parent::match($request); }
/** * Match the request * * @param Zend_Controller_Request_Http $request * @return boolean */ public function match(Zend_Controller_Request_Http $request) { if (!$this->_beforeModuleMatch()) { return false; } $front = $this->getFront(); $path = trim($request->getPathInfo(), '/'); $pathParts = explode('/', $path, 4); if (!isset($pathParts[0])) { return parent::match($request); } switch ($pathParts[0]) { case Mage::getStoreConfig('arioem/parts/shortname'): $request->setRouteName('arioem'); $request->setModuleName('Vikont_ARIOEM'); $request->setControllerModule('Vikont_ARIOEM'); $controllerName = 'parts'; // empty($pathParts[1]) ? 'index' : $pathParts[1]; $request->setControllerName($controllerName); $actionName = 'index'; // empty($pathParts[2]) ? 'index' : $pathParts[2]; $request->setActionName($actionName); $request->setDispatched(true); $brand = empty($pathParts[1]) ? false : $pathParts[1]; Mage::register('oem_brand', $brand); $request->setParam('brand', $brand); $partNumber = empty($pathParts[2]) ? false : $pathParts[2]; Mage::register('oem_part_number', $partNumber); $request->setParam('partNumber', $partNumber); $controllerClassName = $this->_validateControllerClassName('Vikont_ARIOEM', $controllerName); $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse()); $controllerInstance->dispatch('index'); return true; break; case Mage::getStoreConfig('arioem/partcenter/shortname'): $request->setRouteName('arioem'); $request->setModuleName('Vikont_ARIOEM'); $request->setControllerModule('Vikont_ARIOEM'); $controllerName = 'partcenter'; $request->setControllerName($controllerName); $actionName = empty($pathParts[1]) ? 'index' : $pathParts[1]; //'index'; $request->setActionName($actionName); $request->setDispatched(true); $controllerClassName = $this->_validateControllerClassName('Vikont_ARIOEM', $controllerName); $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse()); $controllerInstance->dispatch('index'); break; } return parent::match($request); }
/** * Match the request * * @param Zend_Controller_Request_Http $request * @return boolean */ public function match(Zend_Controller_Request_Http $request) { // Just apply the translation to routes without .html if (Mage::helper('mk_languageroutes')->isUriTranslatable($request->getPathInfo())) { /** @var $translationModel MKleine_LanguageRoutes_Model_Translation */ $translationModel = Mage::getSingleton('mk_languageroutes/translation'); $translationModel->setRequest($request); Mage::dispatchEvent('languageroute_set_path_info_before', array('translation_model' => $translationModel)); if ($internalRoute = $translationModel->getTranslatedPath()) { Mage::register('languageroute_information', new Varien_Object(array('original' => trim($request->getPathInfo(), '/'), 'internal' => trim($internalRoute, '/')))); $request->setPathInfo($internalRoute); } } return parent::match($request); }
public function match(Zend_Controller_Request_Http $request) { $helper = Mage::helper('Mdl_UnderConstruction'); $storeCode = $request->getStoreCodeFromPath(); $enabled = $helper->getConfig('enabled', $storeCode); if (1 == $enabled) { $allowedIPsString = $helper->getConfig('allowedIPs', $storeCode); $allowedIPsString = preg_replace('/ /', '', $allowedIPsString); $allowedIPs = array(); if ('' !== trim($allowedIPsString)) { $allowedIPs = explode(',', $allowedIPsString); } $currentIP = $_SERVER['REMOTE_ADDR']; $allowFrontendForAdmins = $helper->getConfig('allowFrontendForAdmins', $storeCode); $adminIp = null; if (1 == $allowFrontendForAdmins) { Mage::getSingleton('core/session', array('name' => 'adminhtml')); $adminSession = Mage::getSingleton('admin/session'); if ($adminSession->isLoggedIn()) { $adminIp = $adminSession['_session_validator_data']['remote_addr']; } } if ($currentIP === $adminIp) { $this->__log('Access granted for admin with IP: ' . $currentIP . ' and store ' . $storeCode, 2, $storeCode); } else { if (!in_array($currentIP, $allowedIPs)) { $this->__log('Access denied for IP: ' . $currentIP . ' and store ' . $storeCode, 1, $storeCode); Mage::getSingleton('core/session', array('name' => 'front')); $response = $this->getFront()->getResponse(); $response->setHeader('HTTP/1.1', '503 Service Temporarily Unavailable'); $response->setHeader('Status', '503 Service Temporarily Unavailable'); $response->setHeader('Retry-After', '5000'); $response->setBody(Mage::app()->getLayout()->createBlock('core/template')->setTemplate('underconstruction/underconstruction.phtml')->toHtml()); $response->sendHeaders(); $response->outputBody(); // } exit; } else { $this->__log('Access granted for IP: ' . $currentIP . ' and store ' . $storeCode, 2, $storeCode); } } } return parent::match($request); }
public function match(Zend_Controller_Request_Http $request) { $path = explode('/', trim($request->getPathInfo(), '/')); if ($path[0] != Mageplace_Backup_Helper_Const::NAME || !array_key_exists($path[1], self::$ALLOWED_ACTIONS) || !in_array($path[2], self::$ALLOWED_ACTIONS[$path[1]])) { return parent::match($request); } if (!$this->isOwnOriginUrl($request)) { Mage::log('MPBACKUP WRONG OWN ORIGIN URL'); return false; } Mage::setIsDeveloperMode(true); @error_reporting(E_ALL ^ E_NOTICE); require_once 'Mageplace/Backup/controllers/' . ucfirst($path[1]) . 'Controller.php'; $controllerClassName = 'Mageplace_Backup_' . ucfirst($path[1]) . 'Controller'; /** @var Mageplace_Backup_BackupController|Mageplace_Backup_ProgressController $controllerInstance */ $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $this->getFront()->getResponse()); $request->setDispatched(true); Mage::getSingleton('mpbackup/session', array('sid' => $request->getParam(Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM), 'name' => $controllerInstance->getSessionNamespace() . '_' . $path[1]))->start(); $actionMethodName = $controllerInstance->getActionMethodName($path[2]); $controllerInstance->{$actionMethodName}(); return true; }
/** * Validate and Match Cms Page and modify request * * @param Zend_Controller_Request_Http $request * @return bool */ public function match(Zend_Controller_Request_Http $request) { if (Mage::helper('core')->isModuleEnabled('ArtsOnIT_OfflineMaintenance')) { $storeenabled = Mage::getStoreConfig('offlineMaintenance/settings/enabled', $request->getStoreCodeFromPath()); if ($storeenabled) { Mage::getSingleton('core/session', array('name' => 'adminhtml')); if (!Mage::getSingleton('admin/session')->isLoggedIn()) { Mage::getSingleton('core/session', array('name' => 'front')); $front = $this->getFront(); $response = $front->getResponse(); $response->setHeader('HTTP/1.1', '503 Service Temporarily Unavailable'); $response->setHeader('Status', '503 Service Temporarily Unavailable'); $response->setHeader('Retry-After', '5000'); $response->setBody(html_entity_decode(Mage::getStoreConfig('offlineMaintenance/settings/message', $request->getStoreCodeFromPath()), ENT_QUOTES, "utf-8")); $response->sendHeaders(); $response->outputBody(); exit; } else { $showreminder = Mage::getStoreConfig('offlineMaintenance/settings/showreminder', $request->getStoreCodeFromPath()); if ($showreminder) { $front = $this->getFront(); $response = $front->getResponse()->appendBody('<div style="height:12px; background:red; color: white; position:relative; width:100%;padding:3px; z-index:100000;text-trasform:capitalize;">Offline</div>'); } } } } if (!Mage::helper('smvendors')->enableVendorSlug()) { return parent::match($request); } //checking before even try to find out that current module //should use this router if (!$this->_beforeModuleMatch()) { return false; } $this->fetchDefault(); $front = $this->getFront(); $path = trim($request->getPathInfo(), '/'); if (!$path) { return parent::match($request); } $p = explode('/', $path); if (strpos($p[0], '.html') !== false) { return parent::match($request); } $vendorCollection = Mage::getResourceModel('smvendors/vendor_collection')->addFieldToFilter('vendor_slug', $p[0]); if ($vendorCollection->count() && ($vendor = $vendorCollection->getFirstItem()) && $vendor->getId()) { Mage::register('current_vendor', $vendor, true); Mage::register('in_vendor', true, true); /** * Searching router args by module name from route using it as key */ $frontName = 'vendor'; $modules = $this->getModuleByFrontName($frontName); if ($modules === false) { continue; } /** * Going through modules to find appropriate controller */ $found = false; foreach ($modules as $realModule) { $request->setRouteName($this->getRouteByFrontName($frontName)); // get controller name if (!empty($p[1])) { $controller = $p[1]; } else { // $controller = $front->getDefault('controller'); $controller = 'products'; $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getOriginalPathInfo(), '/')); } // get action name if ($realModule == 'SM_Vendors') { $action = !empty($p[2]) ? $p[2] : 'index'; } else { $action = !empty($p[2]) ? $p[2] : $front->getDefault('action'); } //checking if this place should be secure $this->_checkShouldBeSecure($request, '/' . $frontName . '/' . $controller . '/' . $action); $controllerClassName = $this->_validateControllerClassName($realModule, $controller); if (!$controllerClassName) { continue; } // instantiate controller class $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse()); if (!$controllerInstance->hasAction($action)) { continue; } $found = true; break; } // set values only after all the checks are done $request->setModuleName($frontName); $request->setControllerName($controller); $request->setActionName($action); $request->setControllerModule($realModule); // set parameters from pathinfo for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) { $request->setParam($p[$i], isset($p[$i + 1]) ? urldecode($p[$i + 1]) : ''); } // dispatch action $request->setDispatched(true); $controllerInstance->dispatch($action); return true; } return parent::match($request); }
/** * determines the Controller / Action throw Request Object * * @param Zend_Controller_Request_Http $request * @return boolan */ public function match(Zend_Controller_Request_Http $request) { // if module is not active -> use standard Router if (!Mage::getSingleton('Flagbit_Typo3connect/Core')->isEnabled()) { return parent::match($request); } // get Params from TYPO3 $params = Mage::getSingleton('Flagbit_Typo3connect/Core')->getParams(); if ($params['route']) { $config = $params['route']; if ($params['controller']) { $config .= '/' . $params['controller']; if ($params['action']) { $config .= '/' . $params['action']; } } unset($params['route'], $params['controller'], $params['action']); $frontController = Mage::app()->getFrontController(); $urlModel = Mage::getModel('core/url')->setStore(Mage::app()->getStore()); $oldUrl = '/' . $urlModel->getUrl($config, $params, true); // Remove the query string from REQUEST_URI if ($pos = strpos($oldUrl, '?')) { $oldUrl = substr($oldUrl, 0, $pos); } $request->setPathInfo($oldUrl); $frontController->rewrite(); } if (Mage::app()->getStore()->isAdmin()) { return false; } //checkings before even try to findout that current module //should use this router if (!$this->_beforeModuleMatch()) { return false; } $this->fetchDefault(); $front = $this->getFront(); $p = explode('/', trim($request->getPathInfo(), '/')); // get module name if ($request->getModuleName()) { $module = $request->getModuleName(); } else { if (!empty($p[0])) { $module = $p[0]; } else { $module = $this->getFront()->getDefault('module'); $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ''); } } if (!$module) { if (Mage::app()->getStore()->isAdmin()) { $module = 'admin'; } else { return false; } } /** * Searching router args by module name from route using it as key */ $modules = $this->getModuleByFrontName($module); /** * If we did not found anything we searching exact this module * name in array values */ if ($modules === false) { if ($moduleFrontName = $this->getModuleByName($module, $this->_modules)) { $modules = array($module); $module = $moduleFrontName; } else { return false; } } //checkings after we foundout that this router should be used for current module if (!$this->_afterModuleMatch()) { return false; } /** * Going through modules to find appropriate controller */ $found = false; foreach ($modules as $realModule) { $request->setRouteName($this->getRouteByFrontName($module)); // get controller name if ($request->getControllerName()) { $controller = $request->getControllerName(); } else { if (!empty($p[1])) { $controller = $p[1]; } else { $controller = $front->getDefault('controller'); $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getOriginalPathInfo(), '/')); } } // get action name if (empty($action)) { if ($request->getActionName()) { $action = $request->getActionName(); } else { $action = !empty($p[2]) ? $p[2] : $front->getDefault('action'); } } //checking if this place should be secure $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action); $controllerClassName = $this->_validateControllerClassName($realModule, $controller); if (!$controllerClassName) { continue; } // instantiate own controller class $controllerInstance = new $controllerClassName($request, Mage::getSingleton('Flagbit_Typo3connect/Core')->getResponse()); if (!$controllerInstance->hasAction($action)) { continue; } $found = true; break; } /** * if we did not found any siutibul */ if (!$found) { if ($this->_noRouteShouldBeApplied()) { $controller = 'index'; $action = 'noroute'; $controllerClassName = $this->_validateControllerClassName($realModule, $controller); if (!$controllerClassName) { return false; } // instantiate own controller class $controllerInstance = new $controllerClassName($request, Mage::getSingleton('Flagbit_Typo3connect/Core')->getResponse()); if (!$controllerInstance->hasAction($action)) { return false; } } else { return false; } } // set values only after all the checks are done $request->setModuleName($module); $request->setControllerName($controller); $request->setActionName($action); // set parameters from pathinfo for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) { $request->setParam($p[$i], isset($p[$i + 1]) ? $p[$i + 1] : ''); } // dispatch action $request->setDispatched(true); $controllerInstance->dispatch($action); return true; }