代码拉取完成,页面将自动刷新
<?php
namespace yiiexts\kindeditor;
use Yii;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\InputWidget;
/**
* Class Kindeditor
* @package yiiexts\kindeditor
*/
class Kindeditor extends InputWidget
{
/**
* default options.
*/
private $_options = [
'id' => 'editor',
];
/**
* default editor options.
*/
private $_editorOptions = [
'width' => '100%',
'height' => '480',
'items' => [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],
'allowImageUpload' => false,
'allowFlashUpload' => false,
'allowMediaUpload' => false,
'allowFileUpload' => false,
'allowFileManager' => false,
'filePostName' => 'file',
];
/**
* editor options
* @var array
*/
public $editorOptions = [];
/**
* renders the widget.
*/
public function run()
{
$this->options = ArrayHelper::merge($this->_options, $this->options);
echo $this->renderWidget();
$this->registerAssets();
}
private function registerAssets()
{
KindeditorAsset::register($this->getView());
$this->getView()->registerJs($this->initJs());
}
private function renderWidget()
{
if ($this->hasModel()) {
return Html::activeTextarea($this->model, $this->attribute, $this->options);
} else {
return Html::textarea($this->name, $this->value, $this->options);
}
}
/**
* @return string the editor initial javascript.
*/
private function initJs()
{
$options = $this->initEditorOptions();
$optionsJSON = json_encode($options);
return <<<EOL
KindEditor.ready(function(K) {
window.editor = K.create('#{$this->options['id']}', $optionsJSON);
});
EOL;
}
/**
* @return array
*/
private function initEditorOptions()
{
$options = ArrayHelper::merge($this->_editorOptions, $this->editorOptions);
if (Yii::$app->getRequest()->enableCsrfValidation && $this->isAllowUpload($options)) {
$options['extraFileUploadParams'] = ArrayHelper::merge(
isset($options['extraFileUploadParams']) ? $options['extraFileUploadParams'] : [],
[Yii::$app->getRequest()->csrfParam => Yii::$app->getRequest()->csrfToken]
);
}
return $options;
}
/**
* @param $options
* @return bool indicate whether allow upload.
*/
private function isAllowUpload($options)
{
$uploadOptions = ['allowImageUpload', 'allowFlashUpload', 'allowMediaUpload', 'allowFileUpload'];
foreach ($uploadOptions as $option) {
if (isset($options[$option]) && $options[$option]) {
return true;
}
}
return false;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。