コード例 #1
0
ファイル: Main.php プロジェクト: kevinwan/gongpingjiaPHP
 public function routeShutdown(XF_Controller_Request_Abstract $request)
 {
     //如果存在强制清除缓存命令
     $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);
         }
     }
     //自动清除缓存
     if ($request->getParam('autoclear') == 'true') {
         XF_DataPool::getInstance()->add('clearActionCache', TRUE);
     }
     //获取用户当前真实的地区id
     $data = array('id' => '1', 'name' => '北京', 'pinyin' => 'beijing');
     $ip = new Application_Model_IP();
     $ip->table()->setAssociatedAuto('city');
     $row = $ip->getByIP($request->getClientIp());
     if ($row != false) {
         $data = array('id' => $row->province_id, 'name' => $row->city_province_id->name, 'pinyin' => $row->city_province_id->pinyin);
     }
     XF_View::getInstance()->assign('trueCity', (object) $data);
 }
コード例 #2
0
ファイル: Paginator.php プロジェクト: kevinwan/xf
 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;
 }
コード例 #3
0
ファイル: Front.php プロジェクト: kevinwan/xf
 /**
  * 转发控制器
  * @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);
     }
 }
コード例 #4
0
ファイル: Front.php プロジェクト: kevinwan/gongpingjiaPHP
 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);
         }
     }
 }