<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST , ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace plugin\ueditor\user\controller;
use temmoku\controller;
use temmoku\db;
class setting extends controller{

	public function ueditor_config(){
		error_reporting(E_ERROR);
		$CONFIG = include APP_PATH."/plugin/ueditor/php/config.php";
		$action = $_GET['action'];
		if('uploadimage'==$action || 'uploadscrawl'==$action ){
			if(C('ueditor|UEDITOR_CONFIG.is_upphoto')==='0'){
				echo json_encode(["state" => "权限不足不允许上传图片"]);
				exit;
			}
		}elseif('uploadvideo'==$action){
			if(C('ueditor|UEDITOR_CONFIG.is_upinsertvideo')==='0'){
				echo json_encode(["state" => "权限不足不允许上传视频"]);
				exit;
			}
		}elseif('uploadfile'==$action){
			if(C('ueditor|UEDITOR_CONFIG.is_upfile')==='0'){
				echo json_encode(["state" => "权限不足不允许上传附件"]);
				exit;
			}
		}
		//exit;
		switch ($action) {
		    case 'config':
		        $result =  json_encode($CONFIG);
		        break;
		    /* 上传图片 */
		    case 'uploadimage':
		    /* 上传涂鸦 */
		    case 'uploadscrawl':
		    /* 上传视频 */
		    case 'uploadvideo':
		    /* 上传文件 */
		    case 'uploadfile':
		        $result = include(APP_PATH."/plugin/ueditor/php/action_upload.php");
		        break;
		
		    /* 列出图片 */
		    case 'listimage':
		        $result = include(APP_PATH."/plugin/ueditor/php/action_list.php");
		        break;
		    /* 列出文件 */
		    case 'listfile':
		        $result = include(APP_PATH."/plugin/ueditor/php/action_list.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;
		}
	}
	
}
?>
