<?php
/*
* KindEditor 4.1.10
*/
namespace Think\Template\TagLib;
use Think\Template\TagLib;
class Kind extends TagLib {
protected $tags = array(
'editor' => array(
'attr' => 'id,name,width,height,urlType,resizeType,uploadJson,cssPath',
'close' => 1
) ,
);
/*
* html调用格式:<editor id=""(必填) 其他attr></editor>
* @access public
* @param array $tag 标签属性
* @return string|void
*/
public function _editor($tag, $content = '') {
empty($tag['id']) ? exit('editor标签"id"属性必填!') : $id = $tag['id'];
$name = !empty($tag['name']) ? $tag['name'] : 'content';
$resizeType = !empty($tag['resizeType']) ? $tag['resizeType'] : 0;
$urlType = !empty($tag['urlType']) ? $tag['urlType'] : 'relative';
$uploadJson = !empty($tag['uploadJson']) ? $tag['uploadJson'] : '{:U("' .CONTROLLER_NAME. '/upload")}';
$width = !empty($tag['width']) ? $tag['width'] : '80%';
$height = !empty($tag['height']) ? $tag['height'] : '500px';
$cssPath = !empty($tag['cssPath']) ? $tag['cssPath'] : '__PUBLIC__/KindEditor/plugins/code/prettify.css';
$parseStr = <<<editor
<link rel="stylesheet" href="__PUBLIC__/KindEditor/themes/default/default.css">
<script src="__PUBLIC__/KindEditor/kindeditor.js"></script>
<script src="__PUBLIC__/KindEditor/plugins/code/code.js"></script>
<script src="__PUBLIC__/KindEditor/plugins/code/prettify.js"></script>
<textarea id="$id" name="$name">$content</textarea>
<script>
KindEditor.ready(function(K) {
editor = K.create("#$id", {
cssPath : "$cssPath",
width: "$width",
height: "$height",
resizeType: "$resizeType",
urlType: "$urlType",
uploadJson: "$uploadJson",
afterBlur: function() {
this.sync();
},
});
prettyPrint();
});
</script>
editor;
return $parseStr;
}
}
/*
附KindEditor编辑器图片上传整合方法,也就是uploadJson指向的路径方法
核心文件Think/Upload.class.php207行左右,部分版本以下代码缺$info['path']信息,可按以下补齐
if (!!$path=$this->uploader->save($file,$this->replace)) {
unset($file['error'], $file['tmp_name']);
$info[$key] = $file;
$info['path'] = $path;
}
上传路径配置:
'UPLOADS'=>array('rootPath' =>'./Public/','savePath'=>'Uploads/',......),
public function upload() {
$upload = new \Think\Upload(C('UPLOADS'));
$info = $upload->upload();
if (!$info) {
$arr = array('error' => 1, "message" => $upload->getError());
$this->ajaxReturn($arr);
}else {
$path = __ROOT__ .substr($info['path'], 1);
$arr = array('error' => 0, 'url' => $path);
$this->ajaxReturn($arr);
}
exit();
}
*/ 最佳答案