<?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\admin\controller;
use temmoku\controller;
use temmoku\db;
use plugin\ueditor\public_class\cache;
class index extends controller{
	
	public function set(){
		
		if('post'===$_POST['step']){
			if($_POST['ueditor']['function']){
				$_POST['ueditor']['function']=serialize($_POST['ueditor']['function']);
			}
			foreach($_POST['ueditor'] AS $key=>$name){
				$one=db::select('*')->from(P_jab."set")->where("u_key LIKE '$key' ")->row();
				if($one){
					db::update(P_jab."set")->cols(array('u_value'))->where("u_key LIKE '$key'")->bindValue('u_value', "$name")->query();
				}else{
					db::insert(P_jab."set")->cols(array('u_key'=>"$key",'u_value'=>"$name"))->query();
				}
			}
			cache::setting_cache();
			$this->Success('修改成功');
		}
		$uedtior_config=include_once 'uedtior.config.php';
		$this->assign('uedtior_config', $uedtior_config);
		$_settingDB=db::select('*')->from(P_jab."set")->query();
    	foreach($_settingDB AS $row){
    		$settingDB[$row['u_key']]=$row['u_value'];
    	}
		$this->assign('settingDB',$settingDB);
		$this->display(tpl('set'));
	}
	
	
	public function ueditor_config(){
		error_reporting(E_ERROR);
		$CONFIG = include APP_PATH."/plugin/ueditor/php/config.php";
		$action = $_GET['action'];
		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;
		
		    /* 抓取远程文件 */
		    case 'catchimage':
		        $result = include(APP_PATH."/plugin/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;
		}
	}
}
?>
