public function testSetGetActionName()
 {
     $this->_request->setActionName('foo');
     $this->assertEquals('foo', $this->_request->getActionName());
     $this->_request->setActionName('bar');
     $this->assertEquals('bar', $this->_request->getActionName());
 }
 public function hasHtmlOutput()
 {
     // Only show toggle for individual answer display
     if ($this->request->getActionName() !== 'answer') {
         return false;
     }
     return true;
 }
Exemple #3
0
 public function testShouldAllowAccessForCorrectRole()
 {
     $request = $this->request->setModuleName('admin')->setControllerName('index')->setActionName('index');
     $this->acl->addResource('admin_index');
     $this->acl->allow(Acl::ROLE_GUEST, 'admin_index');
     $plugin = new Acl($this->acl);
     $plugin->setRequest($this->request);
     $plugin->preDispatch();
     $this->assertEquals('admin', $this->request->getModuleName());
     $this->assertEquals('index', $this->request->getControllerName());
     $this->assertEquals('index', $this->request->getActionName());
 }
Exemple #4
0
 /**
  * Checks if site is active for the current request
  * 
  * @param bool $checkSubs  [optional] whether site should be considered
  *                         active if a subsite is active, default is false
  * @return bool
  */
 public function isActive($checkSubs = false)
 {
     if (isset($this->uri)) {
         // when uri is set, it is considered to be off-site
         return false;
     }
     
     if (null == self::$_request) {
         self::$_request = Zend_Controller_Front::getInstance()->getRequest();
     }
     
     $reqModule = self::$_request->getModuleName();
     $reqController = self::$_request->getControllerName();
     $reqAction = self::$_request->getActionName();
     
     if ($this->module == $reqModule &&
         $this->controller == $reqController &&
         $this->action == $reqAction) {
             return true;
     }
     
     if ($checkSubs && $this->hasSubSites()) {
         foreach ($this->_subSites as $id => $subSite) {
             if ($subSite->isActive(true)) {
                 return true;
             }
         }
     }
     
     return false;
 }
Exemple #5
0
 public function testPostDispatchWithoutException()
 {
     $this->request->setModuleName('foo')->setControllerName('bar')->setActionName('baz');
     $this->plugin->postDispatch($this->request);
     $this->assertEquals('baz', $this->request->getActionName());
     $this->assertEquals('bar', $this->request->getControllerName());
     $this->assertEquals('foo', $this->request->getModuleName());
 }
Exemple #6
0
 public function testPreDispatchNonWhitelistedActionWithAuthenticatedSession()
 {
     $this->request->setModuleName('default')->setControllerName('foo')->setActionName('home');
     Zend_Auth::getInstance()->getStorage()->write(true);
     $this->plugin->preDispatch($this->request);
     $this->assertEquals('default', $this->request->getModuleName());
     $this->assertEquals('foo', $this->request->getControllerName());
     $this->assertEquals('home', $this->request->getActionName());
 }
 protected function dispatchRequest(Zend_Controller_Request_Http $request, X_Page_ItemList_PItem $items, Zend_Controller_Action $controller)
 {
     /* @var $view Zend_Controller_Action_Helper_ViewRenderer */
     $view = $controller->getHelper('viewRenderer');
     /* @var $layout Zend_Layout_Controller_Action_Helper_Layout */
     $layout = $controller->getHelper('layout');
     try {
         $view->setNoRender(true);
         $layout->disableLayout();
     } catch (Exception $e) {
         X_Debug::e("Layout or View not enabled: " . $e->getMessage());
     }
     $result = array();
     $actionName = $request->getActionName();
     $controllerName = $request->getControllerName();
     $result['controller'] = $controllerName;
     $result['action'] = $actionName;
     $result['success'] = true;
     $result['items'] = array();
     /* @var $urlHelper Zend_Controller_Action_Helper_Url */
     $urlHelper = $controller->getHelper('url');
     $skipMethod = array('getCustom', 'getLinkParam', 'getLinkAction', 'getLinkController');
     foreach ($items->getItems() as $itemId => $item) {
         /* @var $item X_Page_Item_PItem */
         $aItem = array();
         $methods = get_class_methods(get_class($item));
         foreach ($methods as $method) {
             if (array_search($method, $skipMethod) !== false) {
                 continue;
             }
             if ($method == "getIcon") {
                 $aItem['icon'] = $request->getBaseUrl() . $item->getIcon();
             } elseif (X_Env::startWith($method, 'get')) {
                 $aItem[lcfirst(substr($method, 3))] = $item->{$method}();
             } elseif (X_Env::startWith($method, 'is')) {
                 $aItem[lcfirst(substr($method, 2))] = $item->{$method}();
             }
         }
         $result['items'][] = $aItem;
     }
     /* @var $jsonHelper Zend_Controller_Action_Helper_Json */
     $jsonHelper = $controller->getHelper('Json');
     $jsonHelper->direct($result, true, false);
 }
Exemple #8
0
 public function match(Zend_Controller_Request_Http $request)
 {
     $this->fetchDefault();
     $front = $this->getFront();
     $p = explode('/', trim($request->getPathInfo(), '/'));
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     } else {
         $p = explode('/', trim($request->getPathInfo(), '/'));
         $module = !empty($p[0]) ? $p[0] : $this->getFront()->getDefault('module');
     }
     if (!$module) {
         return false;
     }
     $realModule = $this->getModuleByFrontName($module);
     if (!$realModule) {
         if ($moduleFrontName = array_search($module, $this->_modules)) {
             $realModule = $module;
             $module = $moduleFrontName;
         } else {
             return false;
         }
     }
     if (!Mage::app()->isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     if (Mage::app()->isInstalled() && !$request->isPost()) {
         $shouldBeSecure = substr(Mage::getStoreConfig('web/unsecure/base_url'), 0, 5) === 'https' || Mage::getStoreConfigFlag('web/secure/use_in_adminhtml') && substr(Mage::getStoreConfig('web/secure/base_url'), 0, 5) === 'https';
         if ($shouldBeSecure && !Mage::app()->getStore()->isCurrentlySecure()) {
             $url = Mage::getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
             Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
             exit;
         }
     }
     // get controller name
     if ($request->getControllerName()) {
         $controller = $request->getControllerName();
     } else {
         $controller = !empty($p[1]) ? $p[1] : $front->getDefault('controller');
     }
     $controllerFileName = $this->getControllerFileName($realModule, $controller);
     if (!$controllerFileName || !is_readable($controllerFileName)) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     $controllerClassName = $this->getControllerClassName($realModule, $controller);
     if (!$controllerClassName) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     // get action name
     if (empty($action)) {
         if ($request->getActionName()) {
             $action = $request->getActionName();
         } else {
             $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
         }
     }
     // include controller file if needed
     if (!class_exists($controllerClassName, false)) {
         include $controllerFileName;
         if (!class_exists($controllerClassName)) {
             throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist'));
         }
     }
     // instantiate controller class
     $controllerInstance = new $controllerClassName($request, $front->getResponse());
     if (!$controllerInstance->hasAction($action)) {
         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;
     #$request->isDispatched();
 }
 /**
  * Log a message showing a reroute.
  * 
  * @param  Zend_Controller_Request_Http  $request
  * @param  Zend_Config|array  $rerouteTo   where to reroute the request to
  * @return void
  */
 public static function logReroute(Zend_Controller_Request_Http $request, $rerouteTo, $reason)
 {
     if ($rerouteTo instanceof Zend_Config) {
         $reroute = $rerouteTo->toArray();
     } else {
         $reroute = $rerouteTo;
     }
     self::log('Reroute from URI: ' . $request->getRequestUri() . ' (' . $request->getModuleName() . '/' . $request->getControllerName() . '/' . $request->getActionName() . '/' . ') to: ' . $reroute['moduleName'] . '/' . $reroute['controllerName'] . '/' . $reroute['actionName'] . " Reason: {$reason}");
 }
Exemple #10
0
 public function match(Zend_Controller_Request_Http $request)
 {
     //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('rewrite_request_path', '');
         }
     }
     if (!$module) {
         if (App_Main::isAdmin()) {
             $module = 'admin';
         }
     }
     if (empty($module)) {
         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;
         }
     }
     if (empty($modules)) {
         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('rewrite_request_path', 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 controller class
         $controllerInstance = new $controllerClassName($request, $front->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 controller class
             $controllerInstance = new $controllerClassName($request, $front->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);
     $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]) ? $p[$i + 1] : '');
     }
     // dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
 }
 /**
  * 根据Zend_Controller_Request_Http对象生成资源字符串
  * 
  * @param Zend_Controller_Request_Http $request
  * @return string
  */
 public static function parseHttpRequest(Zend_Controller_Request_Http $request)
 {
     return self::parsePageMvc($request->getActionName(), $request->getControllerName(), $request->getModuleName());
 }
Exemple #12
0
 /**
  * Match controller name
  *
  * @param Zend_Controller_Request_Http $request
  * @param string $param
  * @return string
  */
 protected function _matchActionName(Zend_Controller_Request_Http $request, $param)
 {
     if (empty($action)) {
         if ($request->getActionName()) {
             $action = $request->getActionName();
         } else {
             $action = !empty($param) ? $param : $this->getFront()->getDefault('action');
         }
     } else {
         $action = $param;
     }
     return $action;
 }
Exemple #13
0
 /**
  * Get specific request processor based on request parameters.
  *
  * @param Zend_Controller_Request_Http $request
  * @return Enterprise_PageCache_Model_Processor_Default
  */
 public function getRequestProcessor(Zend_Controller_Request_Http $request)
 {
     $processor = false;
     $configuration = Mage::getConfig()->getNode(self::XML_NODE_ALLOWED_CACHE);
     if ($configuration) {
         $configuration = $configuration->asArray();
     }
     $module = $request->getModuleName();
     if (isset($configuration[$module])) {
         $model = $configuration[$module];
         $controller = $request->getControllerName();
         if (is_array($configuration[$module]) && isset($configuration[$module][$controller])) {
             $model = $configuration[$module][$controller];
             $action = $request->getActionName();
             if (is_array($configuration[$module][$controller]) && isset($configuration[$module][$controller][$action])) {
                 $model = $configuration[$module][$controller][$action];
             }
         }
         if (is_string($model)) {
             $processor = Mage::getModel($model);
         }
     }
     return $processor;
 }
 public function match(Zend_Controller_Request_Http $request)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         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) {
         return false;
     }
     $realModule = $this->getModuleByFrontName($module);
     if (!$realModule) {
         if ($moduleFrontName = array_search($module, $this->_modules)) {
             $realModule = $module;
             $module = $moduleFrontName;
         } else {
             return false;
         }
     }
     $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(), '/'));
         }
     }
     $controllerFileName = $this->getControllerFileName($realModule, $controller);
     if (!$this->validateControllerFileName($controllerFileName)) {
         return false;
     }
     $controllerClassName = $this->getControllerClassName($realModule, $controller);
     if (!$controllerClassName) {
         return false;
     }
     // get action name
     if (empty($action)) {
         if ($request->getActionName()) {
             $action = $request->getActionName();
         } else {
             $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
         }
     }
     $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action);
     // include controller file if needed
     if (!class_exists($controllerClassName, false)) {
         if (!file_exists($controllerFileName)) {
             return false;
         }
         include $controllerFileName;
         if (!class_exists($controllerClassName, false)) {
             throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist'));
         }
     }
     // instantiate controller class
     $controllerInstance = new $controllerClassName($request, $front->getResponse());
     if (!$controllerInstance->hasAction($action)) {
         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;
     #$request->isDispatched();
 }
Exemple #15
0
 /**
  * Get specific request processor based on request parameters.
  *
  * @param Zend_Controller_Request_Http $request
  * @return Enterprise_PageCache_Model_Processor_Default|false
  */
 public function getRequestProcessor(Zend_Controller_Request_Http $request)
 {
     if ($this->_requestProcessor === null) {
         $this->_requestProcessor = false;
         $configuration = Mage::getConfig()->getNode(self::XML_NODE_ALLOWED_CACHE);
         if ($configuration) {
             $configuration = $configuration->asArray();
         }
         $module = $request->getModuleName();
         $action = $request->getActionName();
         if (strtolower($action) == self::NOT_FOUND_ACTION && isset($configuration['_no_route'])) {
             $model = $configuration['_no_route'];
         } elseif (isset($configuration[$module])) {
             $model = $configuration[$module];
             $controller = $request->getControllerName();
             if (is_array($configuration[$module]) && isset($configuration[$module][$controller])) {
                 $model = $configuration[$module][$controller];
                 if (is_array($configuration[$module][$controller]) && isset($configuration[$module][$controller][$action])) {
                     $model = $configuration[$module][$controller][$action];
                 }
             }
         }
         if (isset($model) && is_string($model)) {
             $this->_requestProcessor = Mage::getModel($model);
         }
     }
     return $this->_requestProcessor;
 }
Exemple #16
0
 /**
  * Do basic validation for request to be cached
  *
  * @param Zend_Controller_Request_Http $request request
  *
  * @return bool
  */
 public function canProcessRequest(Zend_Controller_Request_Http $request)
 {
     $res = $this->isAllowed();
     $res = $res && $this->isEnabled();
     $fullActionName = $request->getModuleName() . '_' . $request->getControllerName() . '_' . $request->getActionName();
     if (!in_array($fullActionName, $this->_getAllowedActions())) {
         $res = false;
     }
     if ($request->getParam('no_cache')) {
         $res = false;
     }
     return $res;
 }
Exemple #17
0
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to be dispatched.
  * To abort the dispatch, return FALSE.
  *
  * @param  Zend_Controller_Request_Http $action
  * @return Zend_Controller_Dispatcher_Token|boolean
  */
 public function preDispatch($action)
 {
     $module = $action->getModuleName();
     $definition = null;
     if (isset($this->config[$module])) {
         $definition = $this->config[$module];
     } else {
         if (isset($this->config['master_layout'])) {
             $definition = $this->config['master_layout'];
         }
     }
     if ($definition != null && !$action->getParam('__ignorelayout')) {
         $view = null;
         $layoutName = $this->getViewNameFrom($definition, strtolower($action->getControllerName()), strtolower($action->getActionName()));
         if ($layoutName) {
             $view = new MasterView($layoutName, $this->config['layout_path']);
         }
         if ($view != null) {
             Zend_Registry::set('MasterView', $view);
             $baseView = Zend_Registry::get(NovemberApplication::$ZEND_VIEW);
             $baseView->setMaster('MasterView');
         }
     }
     return $action;
 }
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to be dispatched.
  * To abort the dispatch, return FALSE.
  *
  * @param  Zend_Controller_Request_Http $action
  * @return Zend_Controller_Request_Http
  */
 public function preDispatch($action)
 {
     /*@var $action Zend_Controller_Request_Http */
     $controllerName = strtolower($action->getControllerName());
     $actionName = strtolower($action->getActionName());
     $moduleName = strtolower($action->getModuleName());
     // Check for authorization.
     $app = NovemberApplication::getInstance();
     $currentUser = $app->getUser();
     if ($currentUser->getRole() == User::ROLE_LOCKED) {
         $action->setControllerName(ifset($this->config, 'login_controller', 'user'));
         $action->setActionName(ifset($this->config, 'login_action', 'login'));
         return $action;
     }
     // Get the restrictions for the current request (if any)
     $conf = ifset($this->config, $moduleName);
     $roles = '';
     if (is_string($conf)) {
         $roles = $conf;
     } else {
         if (is_array($conf)) {
             // check for a default
             $roles = ifset($conf, 'default_roles', '');
             // If there's something in the controllername entry...
             $controllerConf = ifset($conf, $controllerName, $roles);
             if (is_array($controllerConf)) {
                 $roles = ifset($controllerConf, $actionName, $roles);
             } else {
                 $roles = $controllerConf;
             }
         }
     }
     // Are there required roles to authenticate?
     $loginRequired = false;
     za()->log(__CLASS__ . ':' . __LINE__ . " - Authorizing " . $currentUser->getUsername() . " for roles {$roles}");
     if ($roles != '') {
         $loginRequired = true;
         $roles = explode(',', $roles);
         // If the user has any of the roles, let them in
         foreach ($roles as $role) {
             if ($currentUser->hasRole($role)) {
                 return $action;
             }
         }
     }
     // If we've got this far, then we should ask the DB if the current user has
     // access to the current module and controller
     // We're expecting user_access =>
     // user_role
     // OR array (controller => user_role)
     $userAccess = ifset($conf, 'user_access');
     if ($userAccess != null) {
         $loginRequired = true;
         // if it's a string, just get the access for the module
         $accessService = za()->getService('AccessService');
         // See if they have access to this module
         $access = $accessService->getAccessList($currentUser->getUsername(), $moduleName);
         if (count($access)) {
             // okay, they have access, so we're all cool
             return $action;
         }
     }
     if ($loginRequired) {
         $url = build_url($controllerName, $actionName, $action->getUserParams(), false, $moduleName);
         $_SESSION[NovemberController::RETURN_URL] = $url;
         // $action->setModuleName(ifset($this->config, 'login_module', 'default'));
         $action->setControllerName($this->config['login_controller']);
         $action->setActionName($this->config['login_action']);
     }
     return $action;
 }
 private function _getParent(Zend_Controller_Request_Http $request)
 {
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     if ($controller == 'index' && $action == 'collections') {
         // we don't need to know anything: we are in the root
         return '0';
     }
     if ($controller == 'browse') {
         // we are in mode selection
         // parent is the same, but action = share
         if ($action == 'mode') {
             // rebuild the query, keep only location and provider
             $parent = array('controller' => 'browse', 'action' => 'share', 'p' => $request->getParam('p'), 'l' => $request->getParam('l'));
             return X_Env::encode(http_build_query($parent));
             //$request->getParams();
         }
         //
         if ($action == 'share') {
             // we need the providerObj to know the parent :(
             $location = $request->getParam('l', false);
             if ($location === false) {
                 // NICE, parent is the ROOT
                 return '0';
             }
             $providerId = $request->getParam('p');
             $providerObj = X_VlcShares_Plugins::broker()->getPlugins($providerId);
             if ($providerObj instanceof X_VlcShares_Plugins_ResolverInterface) {
                 // easy: provider will give us the parent
                 $location = X_Env::decode($location);
                 return X_Env::encode($providerObj->getParentLocation($location));
             }
             // so providerObj is not Resolver.... f**k
             // rude way?
             return '0';
         }
         if ($action == 'selection') {
             // same as 'controls' Q_Q
             return '0';
         }
     }
     if ($controller == 'controls') {
         // f**k: how can i manage this?
         return '0';
     }
     $data = array('controller' => $controller, 'action' => $action);
     $data = array_merge($data, $request->getParams());
     return X_Env::encode(http_build_query($data));
 }
Exemple #20
0
 /**
  * Validate and Match shop view and modify request
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     $front = $this->getFront();
     if (!Mage::isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     $routerConfig = Mage::getStoreConfig('shopbybrand/general/router');
     $_end = Mage::getStoreConfig(Magestore_Shopbybrand_Helper_Data::XML_FRONTEND_LINK);
     $_path = urldecode(trim($request->getPathInfo(), '/'));
     if (strpos($_path, $_end)) {
         $_link_params = explode('/', str_replace($_end, '/', $_path), -1);
     } else {
         $_link_params = explode('/', $_path . '/', -1);
     }
     $_count_params = count($_link_params);
     $found = false;
     if (isset($_link_params[0])) {
         $router = $_link_params[0];
         if ($router == $routerConfig) {
             $request->setRouteName('shopbybrand')->setControllerModule('Magestore_Shopbybrand')->setModuleName('brand');
             $module = 'shopbybrand';
             if (isset($_link_params[1]) && $_link_params[1]) {
                 $request->setControllerName($_link_params[1]);
             }
             if (isset($_link_params[2]) && $_link_params[2]) {
                 $request->setActionName($_link_params[2]);
             }
             // get controller name
             if ($request->getControllerName()) {
                 $controller = $request->getControllerName();
             } else {
                 if (!empty($_link_params[1])) {
                     $controller = $_link_params[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($_link_params[2]) ? $_link_params[2] : $front->getDefault('action');
                 }
             }
             //checking if this place should be secure
             $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action);
             $controllerClassName = $this->_validateControllerClassName('Magestore_Shopbybrand', $controller);
             if (!$controllerClassName) {
                 return false;
             }
             $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
             if (!$controllerInstance->hasAction($action)) {
                 return false;
             }
             $found = true;
         }
     }
     if (!$found) {
         if ($this->_noRouteShouldBeApplied()) {
             $controller = 'index';
             $action = 'noroute';
             $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
             if (!$controllerClassName) {
                 return false;
             }
             // instantiate controller class
             $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
             if (!$controllerInstance->hasAction($action)) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
 /**
  * Match the request
  *
  * @param Zend_Controller_Request_Http $request
  * @return boolean
  */
 public function match(Zend_Controller_Request_Http $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) {
         $p = explode('/', $path);
     } else {
         $p = explode('/', $this->_getDefaultPath());
     }
     // 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 ($modules === false) {
         return false;
     }
     // checks after we found out 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 controller class
         $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
         if (!$controllerInstance->hasAction($action)) {
             continue;
         }
         $found = true;
         break;
     }
     /**
      * if we did not found any suitable
      */
     if (!$found) {
         if ($this->_noRouteShouldBeApplied()) {
             $controller = 'index';
             $action = 'noroute';
             $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
             if (!$controllerClassName) {
                 return false;
             }
             // instantiate controller class
             $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->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);
     $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;
 }
Exemple #22
0
 /**
  * Initialize
  *
  * @access public
  * @return void
  */
 public function init()
 {
     $this->_request = $this->getRequest();
     $this->_module = $this->_request->getModuleName();
     $this->_controller = $this->_request->getControllerName();
     $this->_action = $this->_request->getActionName();
     $frontController = $this->getFrontController();
     $this->_plugins = $frontController->getPlugins();
     $this->_configs = $this->getInvokeArg('config');
     // Initialize view
     $this->_initView();
 }