123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\common\widget;
- use yii\base\Widget;
- use app\assets\CoreAsset;
- use app\assets\PluginsAsset;
- use Yii;
- //编辑器
- class UeditorWidget extends Widget
- {
- public $id;//容器ID
- public $name;//变量名
- public $toolBar='full';//全能型 full , 标准型 basic, 前台发布 publish, 简约:simple
- public $width='100%';
- public $height='200';
- public $defaultValue='';//初始值
- public $lang;//语言
- public $allowPageBreak=1; //允许使用分页符 1:允许 0:不允许
- public $saveRemoteImage=1; //保存远程图片,默认开启保存
- public $allowUploadAttachment=0;//允许上传附件 1:允许 0:不允许
- public $allowInsertCode=0;//允许插入源代码
- public $map;//是否开启百度地图
- public $theme = "gray";//皮肤
- private $pageBreakTag;//分页符
- private $imageUrl;//图片上传提交地址
- private $imgPath;//图片修正地址
- private $imageManagerUrl;//在线管理图片url
- private $imageManagerPath;//图片修正地址
- private $scrawlUrl;//涂鸦上传地址
- private $scrawlPath;//图片修正地址
- private $wordImageUrl;//word转存提交地址
- private $wordImagePath;
- private $fileUrl;//附件上传提交地址
- private $filePath;
- private $saveRemotImageUrl;//处理远程图片抓取的程序地址
- private $saveRemotImagePath;//保存远程图片的路径
- private $getMovieUrl; //视频数据获取程序处理地址
- public function init()
- {
- //id 和 name
- if(empty($this->id))
- {
- echo '缺少ID';
- exit;
- }
- if(empty($this->name))$this->name = $this->id;
- //语言设定
- $this->lang = 'zh-cn';
- //分页符号
- $this->pageBreakTag=Yii::$app->params['ueditor']['pageBreakTag'];
- }
- public function run()
- {
- $assetsUrl = $this->registerClientScript();
- echo "<script src='".$assetsUrl['pluginUrl']."/ueditor1_4_3/ueditor.all.min.js?v=12'></script>";
- echo "<script src='".$assetsUrl['pluginUrl']."/ueditor1_4_3/lang/".$this->lang."/".$this->lang.".js'></script>";
- echo "<script type='text/plain' id='".$this->id."' name='".$this->name."' style='width:100%' class='kiivoeditor'>".htmlspecialchars_decode($this->defaultValue)."</script>";
- echo "<script type=\"text/javascript\">
- window.UEDITOR_HOME_URL = '".$assetsUrl['pluginUrl']."/ueditor1_4_3/';";
- echo "var URL = window.UEDITOR_HOME_URL || getUEBasePath();";
- echo "UE.getEditor('".$this->id."',{theme:'".$this->theme."',lang:'".$this->lang."',";
- echo "UEDITOR_HOME_URL : URL,";
- echo "listiconpath:'".$assetsUrl['pluginUrl']."/ueditor1_4_3/themes/".$this->theme."/ueditor-list/',";
- echo "initialStyle:'ol.custom_cn li,ol.custom_cn1 li,ol.custom_cn2 li,ol.custom_num li,ol.custom_num1 li,ol.custom_num2 li{list-style:none;}',";
- echo "serverUrl:URL + 'php/controller.php?base_path=".sys_auth(BASE_PATH)."&app_path=".sys_auth(APP_PATH)."&upload_path=".sys_auth(UPLOAD_PATH)."&auth_key=".AUTH_KEY."',";
- //echo "serverUrl: 'https://www.zhitiku.cn/assets/39418df8/ueditor1_4_3/php/controller.php?base_path=".urlencode(BASE_PATH)."&app_path=".urlencode(APP_PATH)."&upload_path=".urlencode(UPLOAD_PATH)."',";
- /*
- echo "imageUrl:'".$this->imageUrl."',"; //图片上传提交地址
- echo "imagePath:'".$this->imgPath."',";
- echo "wordImageUrl:'".$this->wordImageUrl."',"; //work转存上传提交地址
- echo "wordImagePath:'".$this->wordImagePath."',";
- echo "imageManagerUrl:'".$this->imageManagerUrl."',"; //图片管理提交地址
- echo "imageManagerPath:'".$this->imageManagerPath."',";
- echo "scrawlUrl:'".$this->scrawlUrl."',"; //涂鸦图片提交地址
- echo "scrawlPath:'".$this->scrawlPath."',";
- echo "fileUrl:'".$this->fileUrl."',"; //附件上传提交地址
- echo "filePath:'".$this->filePath."',";
- echo "catcherUrl:'".$this->saveRemotImageUrl."',"; //抓取远程图片地址
- echo "catcherPath:'".$this->saveRemotImagePath."',";
- echo "getMovieUrl:'".$this->getMovieUrl."',";
- */
- //宽度
- if(!empty($this->width))echo "initialFrameWidth:'".$this->width."',";
- //高度
- if(!empty($this->height))echo "initialFrameHeight:'".$this->height."',";
- //后台时支持源码查看
- $strSource = defined('IN_ADMIN')?'"source",':'';
- //判断是否支持附件上传和图片上传
- $strAttachment = $this->allowUploadAttachment?'"simpleupload", "insertimage","attachment",':'';
- //判断是否支持分页
- $strPage = $this->allowPageBreak?'"pagebreak",':'';
- //判断是否支持百度地图
- $strMap = $this->map?'"map",':'';
- //判断是否支持插入代码
- $strInsertCode = $this->allowInsertCode?'"insertcode",':'';
- if($this->toolBar=='publish')
- {
- $this->toolBar = '"fullscreen","undo","redo", "removeformat","|","bold","italic","underline","strikethrough","|","insertunorderedlist","insertorderedlist","justifyleft","justifycenter","justifyright","justifyjustify","|","customstyle","fontsize","fontfamily","forecolor","backcolor","|","unlink", "link","blockquote",'.$strInsertCode.'"inserttable","|",'.$strAttachment.'"pasteplain"';
- }
- else if($this->toolBar=='simple')
- {
- $this->toolBar = '"undo","redo", "removeformat","|","bold","italic","underline","strikethrough","|","insertunorderedlist","insertorderedlist","justifyleft","justifycenter","justifyright","justifyjustify","|","unlink", "link","blockquote","|","simpleupload"';
- }
- else if($this->toolBar=='mobile')
- {
- $this->toolBar = '"undo","redo", "removeformat","|","bold","italic","underline","strikethrough","|","insertunorderedlist","insertorderedlist","justifyleft","justifycenter","justifyright","justifyjustify","|","simpleupload"';
- }
- else if($this->toolBar=='basic')
- {
- $this->toolBar = '"fullscreen",'.$strSource.'"undo","redo", "removeformat","cleardoc","|","bold","italic","underline","strikethrough","|","insertunorderedlist","insertorderedlist","justifyleft","justifycenter","justifyright","justifyjustify","|","rowspacingtop", "rowspacingbottom", "lineheight", "|","indent","customstyle","fontsize","fontfamily","forecolor","backcolor","|","unlink", "link","blockquote",'.$strInsertCode.'"inserttable", "|", "horizontal",'.$strPage.$strAttachment.$strMap.'"pasteplain"';
- }
- else if($this->toolBar=='full')
- {
- $this->toolBar = ' "fullscreen", '.$strSource.', "|", "undo", "redo", "|",
- "bold", "italic", "underline", "fontborder", "strikethrough", "superscript", "subscript", "removeformat", "formatmatch", "autotypeset", "blockquote", "pasteplain", "|", "forecolor", "backcolor", "insertorderedlist", "insertunorderedlist", "selectall", "cleardoc", "|",
- "rowspacingtop", "rowspacingbottom", "lineheight", "|",
- "customstyle", "paragraph", "fontfamily", "fontsize", "|",
- "directionalityltr", "directionalityrtl", "indent", "|",
- "justifyleft", "justifycenter", "justifyright", "justifyjustify", "|", "touppercase", "tolowercase", "|",
- "link", "unlink", "anchor", "|", "imagenone", "imageleft", "imageright", "imagecenter", "|",
- '.$strAttachment.' "emotion", "scrawl", "insertvideo", "music", '.$strMap.' "insertframe", "insertcode", "webapp", '.$strPage.' "template", "background", "|",
- "horizontal", "date", "time", "spechars", "snapscreen", "wordimage", "|",
- "inserttable", "deletetable", "insertparagraphbeforetable", "insertrow", "deleterow", "insertcol", "deletecol", "mergecells", "mergeright", "mergedown", "splittocells", "splittorows", "splittocols", "charts", "|",
- "print", "preview", "searchreplace", "drafts" ,"help"';
- }
- //判断是否保存远程图片
- if(!$this->saveRemoteImage)
- {
- echo "catchRemoteImageEnable:false,";
- }
- else
- {
- echo "catchRemoteImageEnable:true,";
- }
- //禁止高度自适应
- echo "autoHeightEnabled:false,";
- echo "zIndex:9999,";
- echo "toolbars:[[".$this->toolBar."]],";
- echo "pageBreakTag:'".$this->pageBreakTag."',";
- if(defined('IN_ADMIN'))
- {
- echo "
- //focus时自动清空初始化时的内容
- autoClearinitialContent:false,
- //关字数统计
- wordCount:true,
- //关闭elementPath
- elementPathEnabled:false
- //更多其他参数,请参考editor_config.js中的配置项
- });
- </script>";
- }
- else
- {
- echo "
- //focus时自动清空初始化时的内容
- autoClearinitialContent:false,
- //关闭字数统计
- wordCount:false,
- //关闭elementPath
- elementPathEnabled:false
- //更多其他参数,请参考editor_config.js中的配置项
- });
- </script>";
- }
- }
-
- protected function registerClientScript()
- {
- $view = $this->getView();
- $coreAsset = CoreAsset::register($view);
- $coreAssetsUrl = $coreAsset->baseUrl;
- $assetPlugin = PluginsAsset::register($view);
- $pluginUrl = $assetPlugin->baseUrl;
- return array('coreAssetsUrl'=>$coreAssetsUrl,'pluginUrl'=>$pluginUrl);
- }
- }
|