| <?php | 
|     /** | 
|      * 用户控制器 | 
|      */ | 
|     class UserController extends System_Controller_Web{ | 
|   | 
|         public function init(){ | 
|             $this->request = $this->getRequest();     | 
|             if($this->request->action == "login"){ | 
|                 $this->setLayout(); | 
|             } | 
|             parent::init(); | 
|             $this->user_service = new Service_User(); | 
|         } | 
|          | 
|         /** | 
|          * 管理员登录 | 
|          * @return [type] [description] | 
|          */ | 
|         public function LoginAction(){ | 
|             if($this->request->isXmlHttpRequest()){ | 
|                 $username = $this->request->getPost('username'); | 
|                 $password = $this->request->getPost('password'); | 
|                 //进行管理员登录 | 
|                 if(!$this->user_service->login($username, $password)){ | 
|                     exit($this->showError($this->user_service->error, 400, true)); | 
|                 } | 
|                 else{ | 
|                     exit($this->showSuccess('登录成功', true)); | 
|                 } | 
|             } | 
|             else{ | 
|                 $session = Yaf_Session::getInstance(); | 
|                 if(isset($session['user'])){ | 
|                     $this->redirect('/admin/index/index'); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         /** | 
|          * 退出登录 | 
|          */ | 
|         public function LogoutAction(){ | 
|             $session = Yaf_Session::getInstance(); | 
|             $session->del('user'); | 
|             $this->redirect('/user_login.html'); | 
|         } | 
|   | 
|         /** | 
|          * 上传 | 
|          */ | 
|         public function UploadAction(){ | 
|             //header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问 | 
|             //header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header | 
|             date_default_timezone_set("Asia/Shanghai"); | 
|             error_reporting(E_ERROR); | 
|             header("Content-Type: text/html; charset=utf-8"); | 
|   | 
|             $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("themes/ueditor/php/config.json")), true); | 
|             $action = $this->get('action'); | 
|             switch ($action) { | 
|                 case 'config': | 
|                     $result =  json_encode($CONFIG); | 
|                     break; | 
|   | 
|                 /* 上传图片 */ | 
|                 case 'uploadimage': | 
|                 /* 上传涂鸦 */ | 
|                 case 'uploadscrawl': | 
|                 /* 上传视频 */ | 
|                 case 'uploadvideo': | 
|                 /* 上传文件 */ | 
|                 case 'uploadfile': | 
|                     $result = include("themes/ueditor/php/action_upload.php"); | 
|                     break; | 
|   | 
|                 /* 列出图片 */ | 
|                 case 'listimage': | 
|                     $result = include("themes/ueditor/php/action_list.php"); | 
|                     break; | 
|                 /* 列出文件 */ | 
|                 case 'listfile': | 
|                     $result = include("themes/ueditor/php/action_list.php"); | 
|                     break; | 
|   | 
|                 /* 抓取远程文件 */ | 
|                 case 'catchimage': | 
|                     $result = include("themes/ueditor/php/action_crawler.php"); | 
|                     break; | 
|   | 
|                 default: | 
|                     $result = json_encode(array( | 
|                         'state'=> '请求地址出错' | 
|                     )); | 
|                     break; | 
|             } | 
|   | 
|             /* 输出结果 */ | 
|             if (isset($_GET["callback"])) { | 
|                 if (preg_match("/^[\w_]+$/", $_GET["callback"])) { | 
|                     echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')'; | 
|                 } else { | 
|                     echo json_encode(array( | 
|                         'state'=> 'callback参数不合法' | 
|                     )); | 
|                 } | 
|             } else { | 
|                 echo $result; | 
|             } | 
|             die(); | 
|         } | 
|   | 
|   | 
|     } | 
|   | 
|          |