private function _getUrl($page = null) { if ($page != null) { $this->_params[$this->_paginator_param] = $page; } else { unset($this->_params[$this->_paginator_param]); } if ($page == 1 && $this->_first_page_url != '') { return $this->_first_page_url; } $url = $this->_custom_url; if ($this->_custom_url == null) { $module = strtolower($this->_request->getModule()) == 'default' ? '' : '/' . $this->_request->getModule(); $url = $module . '/' . $this->_request->getController() . '/' . $this->_request->getAction(); if ($this->_is_default_link === TRUE) { $i = 0; foreach ($this->_params as $key => $val) { $i++; if ($i == 1) { $url .= '/?' . $key . '=' . urlencode($val); } else { $url .= '&' . $key . '=' . urlencode($val); } } } else { foreach ($this->_params as $key => $val) { $url .= '/' . $key . '/' . urlencode($val); } } } else { $url = str_replace('{page}', $page, $url); } return $url; }
/** * 转发控制器 * @param XF_Controller_Request_Abstract $request * @param bool $runRouter 重新运行路由解析 默认为true * @throws XF_Controller_Exception */ private function _dispatch(XF_Controller_Request_Abstract $request = null, $runRouter = true) { $this->_dispath_count++; if ($request != null) { $this->_request = $request; } if ($this->_dispath_count == 1) { $this->_plugin_manage->routeStartup($this->_request); $this->_router->run(); $this->_plugin_manage->routeShutdown($this->_request); } elseif ($this->_dispath_count >= 5) { XF_Functions::writeErrLog('URI:' . $this->_request->getRequestUrl() . ' - loop forever dispatch controller'); throw new XF_Exception('loop forever dispatch controller'); } else { if ($runRouter == true) { $this->_router->run(); } } //没有找到正确的模块 if ($this->_request->getModule() == 'unknown') { throw new XF_Exception('404 Not found!', 404); } //加载控制器 $this->getModuleDir(); $controllerName = NULL; if (strtolower($this->_request->getModule()) != 'default') { $controllerName = ucfirst($this->_request->getModule()) . '_'; } $this->_controller_dir = $this->_module_dir . '/controllers'; $controllerFile = $this->_controller_dir . '/' . ucfirst($this->_request->getController()) . 'Controller.php'; if (is_file($controllerFile)) { require_once $controllerFile; $controllerName .= ucfirst($this->_request->getController()) . 'Controller'; if (class_exists($controllerName, FALSE)) { $this->_plugin_manage->preDispatch($this->_request); $this->_controller_instance = new $controllerName(); $this->_plugin_manage->postDispatch($this->_request); } } if ($this->_controller_instance == null) { throw new XF_Exception('404 Not found!', 404); } elseif ($this->_controller_instance instanceof XF_Controller_Interface) { $this->_controller_instance->doAction(); } else { throw new XF_Exception('404 Not found!', 404); } }
public function routeShutdown(XF_Controller_Request_Abstract $request) { //检测访问权限 $m = $request->getModule(); $c = $request->getController(); if ($m == 'user' && $c != 'front') { $auth = new XF_Auth_Storage_Session(); if ($auth->isEmpty()) { XF_Functions::go('/login/?redirect_url=' . urlencode($request->getRequestUrl())); } } //如果存在强制清除缓存命令 $auth = new XF_Auth_Storage_Session(); if ($auth->isEmpty() == false && $auth->read()->role_id != '0') { if ($request->getParam('clear') == 'cache') { XF_DataPool::getInstance()->add('clearCache', TRUE); } if ($request->getParam('clear') == 'action') { XF_DataPool::getInstance()->add('clearActionCache', TRUE); } } }