public function handle(array $params = null)
 {
     $turbo = Loader::library('Turbolink');
     if ($turbo->isPjax()) {
         $response = Response::getInstance();
         if (is_a($response, 'Foundation\\Http\\Response')) {
             $content = (string) $response->getOutput();
             $body = $turbo->extract($content);
             $response->setOutput($body);
         }
     }
 }
Example #2
0
 /**
  * 解析一个静态资源的内容
  *
  */
 public static function parseResourceFile()
 {
     $pathinfo = Route::getPathInfo();
     array_shift($pathinfo);
     $resource = implode('/', $pathinfo);
     if ($GLOBALS['debug'] && IS_MULTI_MODULES) {
         $pos = strpos($resource, '/');
         $file = APP_MODULES_PATH . DIRECTORY_SEPARATOR . substr($resource, 0, $pos) . DIRECTORY_SEPARATOR . Config::get('modules_static_path_name') . substr($resource, $pos);
         if (is_file($file)) {
             Response::sendContentTypeBySubFix(substr($resource, strrpos($resource, '.') + 1));
             exit(file_get_contents($file));
         } else {
             Response::sendHttpStatus(404);
         }
     }
 }
Example #3
0
 /**
  * 运行对应的控制器
  *
  * @return void
  */
 public final function runAppController()
 {
     //检测csrf跨站攻击
     Secure::checkCsrf(Config::get('check_csrf'));
     // 关闭GPC过滤 防止数据的正确性受到影响 在db层防注入
     if (get_magic_quotes_gpc()) {
         Secure::stripslashes($_GET);
         Secure::stripslashes($_POST);
         Secure::stripslashes($_COOKIE);
         Secure::stripslashes($_REQUEST);
         //在程序中对get post cookie的改变不影响 request的值
     }
     //session保存方式自定义
     if (Config::get('session_user')) {
         Session::init();
     } else {
         ini_get('session.auto_start') || session_start();
         //自动开启session
     }
     header('Cache-control: ' . Config::get('http_cache_control'));
     // 页面缓存控制
     //如果有子类中有init()方法 执行Init() eg:做权限控制
     if (method_exists($this, "init")) {
         $this->init();
     }
     //根据动作去找对应的方法
     $method = Route::$urlParams['action'];
     if (method_exists($this, $method)) {
         $this->{$method}();
     } elseif ($GLOBALS['debug']) {
         Alpha::montFor404Page();
         throwException(Lang::get('_ACTION_NOT_FOUND_', Route::$urlParams['action']));
     } else {
         Alpha::montFor404Page();
         Response::show404Page();
     }
 }
Example #4
0
 /**
  * 防止csrf跨站攻击
  *
  * @param int $type 检测类型   0不检查,1、只检查post,2、post get都检查
  */
 public static function checkCsrf($type = 1)
 {
     if ($type !== 0 && isset($_SERVER['HTTP_REFERER']) && !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) {
         if ($type == 1) {
             if (!empty($_POST)) {
                 Response::sendHttpStatus(403);
                 throwException(Lang::get('_ILLEGAL_REQUEST_'));
             }
         } else {
             Response::sendHttpStatus(403);
             throwException(Lang::get('_ILLEGAL_REQUEST_'));
         }
     }
 }
Example #5
0
 /**
  * 启动框架
  *
  */
 public static function runApp()
 {
     //系统初始化
     self::init();
     //控制器所在路径
     $actionController = APP_CONTROLLER_PATH . Route::$urlParams['controller'] . 'Controller.php';
     $GLOBALS['debug'] && Debug::addTipInfo(Lang::get('_ACTION_CONTROLLER_', $actionController));
     Plugin::hook('alpha.before_run_controller');
     if (is_file($actionController)) {
         $className = Route::$urlParams['controller'] . 'Controller';
         $className = (IS_MULTI_MODULES ? '' : '\\Controller') . Route::$urlParams['path'] . (IS_MULTI_MODULES ? 'Controller' . DIRECTORY_SEPARATOR : '') . "{$className}";
         $className = str_replace('/', '\\', $className);
         $controller = new $className();
         call_user_func(array($controller, "runAppController"));
         //运行
     } else {
         self::montFor404Page();
         if ($GLOBALS['debug']) {
             throwException(Lang::get('_CONTROLLER_NOT_FOUND_', APP_CONTROLLER_PATH, Route::$urlParams['controller'], str_replace('/', '\\', Route::$urlParams['path']) . Route::$urlParams['controller']));
         } else {
             Response::show404Page();
         }
     }
     //输出Debug模式的信息
     self::Stop();
 }