1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the fangface/yii2-concord package |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view |
6
|
|
|
* the file LICENSE.md that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @package fangface/yii2-concord |
9
|
|
|
* @author Fangface <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2014 Fangface <[email protected]> |
11
|
|
|
* @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace fangface\widgets; |
16
|
|
|
|
17
|
|
|
use backend\assets\CKEditorAsset; |
18
|
|
|
use fangface\widgets\InputWidget; |
19
|
|
|
use fangface\helpers\Html; |
20
|
|
|
use yii\helpers\ArrayHelper; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CKEditor widget |
25
|
|
|
*/ |
26
|
|
|
class CKEditor extends InputWidget |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string the name of the jQuery plugin |
31
|
|
|
*/ |
32
|
|
|
public $pluginName = 'ckeditor'; |
33
|
|
|
/** |
34
|
|
|
* @var array default widget plugin options that user pluginOptions will be merged into |
35
|
|
|
*/ |
36
|
|
|
public $defaultPluginOptions = []; |
37
|
|
|
/** |
38
|
|
|
* @var array the HTML attributes for the input tag. |
39
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
40
|
|
|
*/ |
41
|
|
|
public $options = ['class' => 'form-control ckeditor']; |
42
|
|
|
/** |
43
|
|
|
* @var atring the default pre-prepared config option to use [full, standard, basic or minimal] |
44
|
|
|
*/ |
45
|
|
|
public $preset = 'standard'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Renders the color picker widget |
49
|
|
|
*/ |
50
|
|
|
protected function renderWidget() |
51
|
|
|
{ |
52
|
|
|
$this->prepareConfig(); |
53
|
|
|
$this->prepareInput(); |
54
|
|
|
$this->registerAssets(); |
55
|
|
|
$this->prepareTemplate(); |
56
|
|
|
echo $this->renderTemplate(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Prepare config for the editor |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
protected function prepareConfig() |
65
|
|
|
{ |
66
|
|
|
$userOptions = $this->pluginOptions; |
67
|
|
|
$localOptions = []; |
|
|
|
|
68
|
|
|
switch ($this->preset) { |
69
|
|
|
|
70
|
|
|
case 'minimal': |
71
|
|
|
$localOptions = [ |
72
|
|
|
'height' => 100, |
73
|
|
|
'toolbarGroups' => [ |
74
|
|
|
['name' => 'undo'], |
75
|
|
|
['name' => 'basicstyles', |
76
|
|
|
'groups' => ['basicstyles', 'cleanup'], //wlchere would like to add specialchar |
77
|
|
|
], |
78
|
|
|
['name' => 'clipboard'], |
79
|
|
|
], |
80
|
|
|
'removeButtons' => 'Subscript,Superscript', |
81
|
|
|
/*'removePlugins' => 'elementspath',*/ |
82
|
|
|
'resize_enabled' => false, // wlchere - not working |
83
|
|
|
]; |
84
|
|
|
break; |
85
|
|
|
|
86
|
|
|
case 'basic': |
87
|
|
|
$localOptions = [ |
88
|
|
|
'height' => 150, |
89
|
|
|
'toolbarGroups' => [ |
90
|
|
|
['name' => 'undo'], |
91
|
|
|
['name' => 'basicstyles', |
92
|
|
|
'groups' => ['basicstyles', 'cleanup'] |
93
|
|
|
], |
94
|
|
|
['name' => 'colors'], |
95
|
|
|
['name' => 'links', |
96
|
|
|
'groups' => ['links', 'insert'] |
97
|
|
|
], |
98
|
|
|
['name' => 'others', |
99
|
|
|
'groups' => ['others', 'about'] |
100
|
|
|
], |
101
|
|
|
], |
102
|
|
|
'removeButtons' => 'Subscript,Superscript,Flash,Table,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,Youtube', |
103
|
|
|
/*'removePlugins' => 'elementspath',*/ |
104
|
|
|
'resize_enabled' => false, |
105
|
|
|
'removeDialogTabs' => 'link:advanced', |
106
|
|
|
]; |
107
|
|
|
break; |
108
|
|
|
|
109
|
|
|
case 'standard': |
110
|
|
|
default: |
111
|
|
|
$localOptions = [ |
112
|
|
|
'height' => 200, |
113
|
|
|
'toolbarGroups' => [ |
114
|
|
|
['name' => 'clipboard', |
115
|
|
|
'groups' => ['mode', 'undo', 'selection', 'clipboard', 'doctools'] |
116
|
|
|
], |
117
|
|
|
['name' => 'editing', |
118
|
|
|
'groups' => ['tools', 'about'] |
119
|
|
|
], |
120
|
|
|
'/', |
121
|
|
|
['name' => 'paragraph', |
122
|
|
|
'groups' => ['templates', 'list', 'indent', 'align'] |
123
|
|
|
], |
124
|
|
|
['name' => 'insert'], |
125
|
|
|
'/', |
126
|
|
|
['name' => 'basicstyles', |
127
|
|
|
'groups' => ['basicstyles', 'cleanup'] |
128
|
|
|
], |
129
|
|
|
['name' => 'colors'], |
130
|
|
|
['name' => 'links'], |
131
|
|
|
['name' => 'others'], |
132
|
|
|
], |
133
|
|
|
'removeButtons' => 'Smiley,Iframe' |
134
|
|
|
]; |
135
|
|
|
break; |
136
|
|
|
|
137
|
|
|
case 'full': |
|
|
|
|
138
|
|
|
$localOptions = [ |
139
|
|
|
'height' => 300, |
140
|
|
|
'toolbarGroups' => [ |
141
|
|
|
['name' => 'document', |
142
|
|
|
'groups' => ['mode', 'document', 'doctools'] |
143
|
|
|
], |
144
|
|
|
['name' => 'clipboard', |
145
|
|
|
'groups' => ['clipboard', 'undo'] |
146
|
|
|
], |
147
|
|
|
['name' => 'editing', |
148
|
|
|
'groups' => ['find', 'selection', 'spellchecker'] |
149
|
|
|
], |
150
|
|
|
['name' => 'forms'], |
151
|
|
|
'/', |
152
|
|
|
['name' => 'basicstyles', |
153
|
|
|
'groups' => ['basicstyles', 'colors','cleanup'] |
154
|
|
|
], |
155
|
|
|
['name' => 'paragraph', |
156
|
|
|
'groups' => [ 'list', 'indent', 'blocks', 'align', 'bidi' ] |
157
|
|
|
], |
158
|
|
|
['name' => 'links'], |
159
|
|
|
['name' => 'insert'], |
160
|
|
|
'/', |
161
|
|
|
['name' => 'styles'], |
162
|
|
|
['name' => 'blocks'], |
163
|
|
|
['name' => 'colors'], |
164
|
|
|
['name' => 'tools'], |
165
|
|
|
['name' => 'others'], |
166
|
|
|
], |
167
|
|
|
]; |
168
|
|
|
break; |
169
|
|
|
|
170
|
|
|
case 'all': |
171
|
|
|
// default ckeditor internal config |
172
|
|
|
break; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
//wlchere |
176
|
|
|
// console.plugins = 'dialogui,dialog,a11yhelp,about,basicstyles,bidi,blockquote,clipboard,button,panelbutton,panel,floatpanel,colorbutton,colordialog,menu,contextmenu,dialogadvtab,div,elementspath,enterkey,entities,popup,filebrowser,find,fakeobjects,flash,floatingspace,listblock,richcombo,font,format,forms,horizontalrule,htmlwriter,iframe,image,indent,indentblock,indentlist,justify,menubutton,language,link,list,liststyle,magicline,maximize,newpage,pagebreak,pastefromword,pastetext,preview,print,removeformat,resize,save,scayt,selectall,showblocks,showborders,smiley,sourcearea,specialchar,stylescombo,tab,table,tabletools,templates,toolbar,undo,wsc,wysiwygarea,autogrow,xml,ajax,lineutils,widget,codesnippet,codemirror,confighelper,maxheight,onchange,quicktable,stylesheetparser-fixed,tableresize,youtube'; |
177
|
|
|
// optional maxheight plugin |
178
|
|
|
/* |
179
|
|
|
plugins : { |
180
|
|
|
'a11yhelp' : 1, |
181
|
|
|
'about' : 1, |
182
|
|
|
'ajax' : 1, |
183
|
|
|
'autogrow' : 1, |
184
|
|
|
'basicstyles' : 1, |
185
|
|
|
'bidi' : 1, |
186
|
|
|
'blockquote' : 1, |
187
|
|
|
'clipboard' : 1, |
188
|
|
|
'codemirror' : 1, |
189
|
|
|
'codesnippet' : 1, |
190
|
|
|
'colorbutton' : 1, |
191
|
|
|
'colordialog' : 1, |
192
|
|
|
'confighelper' : 1, |
193
|
|
|
'contextmenu' : 1, |
194
|
|
|
'dialogadvtab' : 1, |
195
|
|
|
'div' : 1, |
196
|
|
|
'elementspath' : 1, |
197
|
|
|
'enterkey' : 1, |
198
|
|
|
'entities' : 1, |
199
|
|
|
'filebrowser' : 1, |
200
|
|
|
'find' : 1, |
201
|
|
|
'flash' : 1, |
202
|
|
|
'floatingspace' : 1, |
203
|
|
|
'font' : 1, |
204
|
|
|
'format' : 1, |
205
|
|
|
'forms' : 1, |
206
|
|
|
'horizontalrule' : 1, |
207
|
|
|
'htmlwriter' : 1, |
208
|
|
|
'iframe' : 1, |
209
|
|
|
'image' : 1, |
210
|
|
|
'indentblock' : 1, |
211
|
|
|
'indentlist' : 1, |
212
|
|
|
'justify' : 1, |
213
|
|
|
'language' : 1, |
214
|
|
|
'link' : 1, |
215
|
|
|
'list' : 1, |
216
|
|
|
'liststyle' : 1, |
217
|
|
|
'magicline' : 1, |
218
|
|
|
'maxheight' : 1, |
219
|
|
|
'maximize' : 1, |
220
|
|
|
'newpage' : 1, |
221
|
|
|
'onchange' : 1, |
222
|
|
|
'pagebreak' : 1, |
223
|
|
|
'pastefromword' : 1, |
224
|
|
|
'pastetext' : 1, |
225
|
|
|
'preview' : 1, |
226
|
|
|
'print' : 1, |
227
|
|
|
'quicktable' : 1, |
228
|
|
|
'removeformat' : 1, |
229
|
|
|
'resize' : 1, |
230
|
|
|
'save' : 1, |
231
|
|
|
'scayt' : 1, |
232
|
|
|
'selectall' : 1, |
233
|
|
|
'showblocks' : 1, |
234
|
|
|
'showborders' : 1, |
235
|
|
|
'smiley' : 1, |
236
|
|
|
'sourcearea' : 1, |
237
|
|
|
'specialchar' : 1, |
238
|
|
|
'stylescombo' : 1, |
239
|
|
|
'stylesheetparser-fixed' : 1, |
240
|
|
|
'tab' : 1, |
241
|
|
|
'table' : 1, |
242
|
|
|
'tableresize' : 1, |
243
|
|
|
'tabletools' : 1, |
244
|
|
|
'templates' : 1, |
245
|
|
|
'toolbar' : 1, |
246
|
|
|
'undo' : 1, |
247
|
|
|
'wsc' : 1, |
248
|
|
|
'wysiwygarea' : 1, |
249
|
|
|
'youtube |
250
|
|
|
*/ |
251
|
|
|
$this->pluginOptions = ArrayHelper::merge($localOptions, $userOptions); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Prepare the input fields for the input |
256
|
|
|
* |
257
|
|
|
* @return void |
258
|
|
|
*/ |
259
|
|
|
protected function prepareInput() |
260
|
|
|
{ |
261
|
|
|
if ($this->hasModel()) { |
262
|
|
|
$this->sections['input'] = Html::activeTextarea($this->model, $this->attribute, $this->options); |
263
|
|
|
} else { |
264
|
|
|
$this->sections['input'] = Html::textarea($this->name, $this->value, $this->options); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Registers the needed client assets |
270
|
|
|
* |
271
|
|
|
* @return void |
272
|
|
|
*/ |
273
|
|
|
public function registerAssets() |
274
|
|
|
{ |
275
|
|
|
if ($this->disabled) { |
276
|
|
|
return; |
277
|
|
|
} |
278
|
|
|
$view = $this->getView(); |
279
|
|
|
CKEditorAsset::register($view); |
280
|
|
|
$element = "jQuery('#" . $this->options['id'] . "')"; |
281
|
|
|
$this->registerPlugin($this->pluginName, $element); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
} |
285
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.