1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSCKEditor Bundle. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 - present Friends of Symfony |
7
|
|
|
* (c) 2009 - 2017 Eric GELOEN <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please read the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace FOS\CKEditorBundle\Config; |
14
|
|
|
|
15
|
|
|
use FOS\CKEditorBundle\Exception\ConfigException; |
16
|
|
|
|
17
|
|
|
final class CKEditorConfiguration |
18
|
|
|
{ |
19
|
|
|
private $toolbarItems = [ |
20
|
|
|
'basic.about' => ['About'], |
21
|
|
|
'basic.basic_styles' => ['Bold', 'Italic'], |
22
|
|
|
'basic.links' => ['Link', 'Unlink'], |
23
|
|
|
'basic.paragraph' => ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'], |
24
|
|
|
'standard.about' => ['Styles', 'Format', 'About'], |
25
|
|
|
'standard.basic_styles' => ['Bold', 'Italic', 'Strike', '-', 'RemoveFormat'], |
26
|
|
|
'standard.clipboard' => ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'], |
27
|
|
|
'standard.document' => ['Source'], |
28
|
|
|
'standard.editing' => ['Scayt'], |
29
|
|
|
'standard.links' => ['Link', 'Unlink', 'Anchor'], |
30
|
|
|
'standard.insert' => ['Image', 'Table', 'HorizontalRule', 'SpecialChar'], |
31
|
|
|
'standard.paragraph' => ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote'], |
32
|
|
|
'standard.tools' => ['Maximize'], |
33
|
|
|
'full.about' => ['About'], |
34
|
|
|
'full.basic_styles' => [ |
35
|
|
|
'Bold', |
36
|
|
|
'Italic', |
37
|
|
|
'Underline', |
38
|
|
|
'Strike', |
39
|
|
|
'Subscript', |
40
|
|
|
'Superscript', |
41
|
|
|
'-', |
42
|
|
|
'RemoveFormat', |
43
|
|
|
], |
44
|
|
|
'full.clipboard' => ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'], |
45
|
|
|
'full.colors' => ['TextColor', 'BGColor'], |
46
|
|
|
'full.document' => ['Source', '-', 'NewPage', 'Preview', 'Print', '-', 'Templates'], |
47
|
|
|
'full.editing' => ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt'], |
48
|
|
|
'full.forms' => [ |
49
|
|
|
'Form', |
50
|
|
|
'Checkbox', |
51
|
|
|
'Radio', |
52
|
|
|
'TextField', |
53
|
|
|
'Textarea', |
54
|
|
|
'SelectField', |
55
|
|
|
'Button', |
56
|
|
|
'ImageButton', |
57
|
|
|
'HiddenField', |
58
|
|
|
], |
59
|
|
|
'full.insert' => ['Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar', 'Smiley', 'PageBreak', 'Iframe'], |
60
|
|
|
'full.links' => ['Link', 'Unlink', 'Anchor'], |
61
|
|
|
'full.paragraph' => [ |
62
|
|
|
'NumberedList', |
63
|
|
|
'BulletedList', |
64
|
|
|
'-', |
65
|
|
|
'Outdent', |
66
|
|
|
'Indent', |
67
|
|
|
'-', |
68
|
|
|
'Blockquote', |
69
|
|
|
'CreateDiv', |
70
|
|
|
'-', |
71
|
|
|
'JustifyLeft', |
72
|
|
|
'JustifyCenter', |
73
|
|
|
'JustifyRight', |
74
|
|
|
'JustifyBlock', |
75
|
|
|
'-', |
76
|
|
|
'BidiLtr', |
77
|
|
|
'BidiRtl', |
78
|
|
|
], |
79
|
|
|
'full.styles' => ['Styles', 'Format', 'Font', 'FontSize', 'TextColor', 'BGColor'], |
80
|
|
|
'full.tools' => ['Maximize', 'ShowBlocks'], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
private $toolbarConfigs = [ |
84
|
|
|
'basic' => [ |
85
|
|
|
'@basic.basic_styles', |
86
|
|
|
'@basic.paragraph', |
87
|
|
|
'@basic.links', |
88
|
|
|
'@basic.about', |
89
|
|
|
], |
90
|
|
|
'standard' => [ |
91
|
|
|
'@standard.clipboard', |
92
|
|
|
'@standard.editing', |
93
|
|
|
'@standard.links', |
94
|
|
|
'@standard.insert', |
95
|
|
|
'@standard.tools', |
96
|
|
|
'@standard.document', |
97
|
|
|
'/', |
98
|
|
|
'@standard.basic_styles', |
99
|
|
|
'@standard.paragraph', |
100
|
|
|
'@standard.about', |
101
|
|
|
], |
102
|
|
|
'full' => [ |
103
|
|
|
'@full.document', |
104
|
|
|
'@full.clipboard', |
105
|
|
|
'@full.editing', |
106
|
|
|
'@full.forms', |
107
|
|
|
'/', |
108
|
|
|
'@full.basic_styles', |
109
|
|
|
'@full.paragraph', |
110
|
|
|
'@full.links', |
111
|
|
|
'@full.insert', |
112
|
|
|
'/', |
113
|
|
|
'@full.styles', |
114
|
|
|
'@full.colors', |
115
|
|
|
'@full.tools', |
116
|
|
|
'@full.about', |
117
|
|
|
], |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var bool |
122
|
|
|
*/ |
123
|
|
|
private $enable; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var bool |
127
|
|
|
*/ |
128
|
|
|
private $async; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var bool |
132
|
|
|
*/ |
133
|
|
|
private $autoload; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var bool |
137
|
|
|
*/ |
138
|
|
|
private $autoInline; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var bool |
142
|
|
|
*/ |
143
|
|
|
private $inline; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var bool |
147
|
|
|
*/ |
148
|
|
|
private $jquery; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var bool |
152
|
|
|
*/ |
153
|
|
|
private $requireJs; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var bool |
157
|
|
|
*/ |
158
|
|
|
private $inputSync; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @var array |
162
|
|
|
*/ |
163
|
|
|
private $filebrowsers; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @var string |
167
|
|
|
*/ |
168
|
|
|
private $basePath; |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @var string |
172
|
|
|
*/ |
173
|
|
|
private $jsPath; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @var string |
177
|
|
|
*/ |
178
|
|
|
private $jqueryPath; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @var string|null |
182
|
|
|
*/ |
183
|
|
|
private $defaultConfig; |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @var array |
187
|
|
|
*/ |
188
|
|
|
private $configs; |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @var array |
192
|
|
|
*/ |
193
|
|
|
private $templates; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @var array |
197
|
|
|
*/ |
198
|
|
|
private $styles; |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @var array |
202
|
|
|
*/ |
203
|
|
|
private $plugins; |
204
|
|
|
|
205
|
|
|
public function __construct(array $config) |
206
|
|
|
{ |
207
|
|
|
if ($config['enable']) { |
208
|
|
|
$config = $this->resolveConfigs($config); |
209
|
|
|
$config = $this->resolveStylesSet($config); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
$this->enable = $config['enable']; |
213
|
|
|
$this->async = $config['async']; |
214
|
|
|
$this->autoload = $config['autoload']; |
215
|
|
|
$this->autoInline = $config['auto_inline']; |
216
|
|
|
$this->inline = $config['inline']; |
217
|
|
|
$this->jquery = $config['jquery']; |
218
|
|
|
$this->requireJs = $config['require_js']; |
219
|
|
|
$this->inputSync = $config['input_sync']; |
220
|
|
|
$this->filebrowsers = $config['filebrowsers']; |
221
|
|
|
$this->basePath = $config['base_path']; |
222
|
|
|
$this->jsPath = $config['js_path']; |
223
|
|
|
$this->jqueryPath = $config['jquery_path']; |
224
|
|
|
$this->defaultConfig = $config['default_config']; |
225
|
|
|
$this->plugins = $config['plugins']; |
226
|
|
|
$this->styles = $config['styles']; |
227
|
|
|
$this->templates = $config['templates']; |
228
|
|
|
$this->plugins = $config['plugins']; |
229
|
|
|
$this->configs = $config['configs']; |
230
|
|
|
$this->toolbarConfigs = array_merge($this->toolbarConfigs, $config['toolbars']['configs']); |
231
|
|
|
$this->toolbarItems = array_merge($this->toolbarItems, $config['toolbars']['items']); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @throws ConfigException |
236
|
|
|
*/ |
237
|
|
|
private function resolveConfigs(array $config): array |
238
|
|
|
{ |
239
|
|
|
if (empty($config['configs'])) { |
240
|
|
|
return $config; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
if (!isset($config['default_config']) && !empty($config['configs'])) { |
244
|
|
|
reset($config['configs']); |
245
|
|
|
$config['default_config'] = key($config['configs']); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
if (isset($config['default_config']) && !isset($config['configs'][$config['default_config']])) { |
249
|
|
|
throw ConfigException::invalidDefaultConfig($config['default_config']); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
return $config; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
private function resolveStylesSet(array $config) |
256
|
|
|
{ |
257
|
|
|
if (empty($config['styles'])) { |
258
|
|
|
return $config; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
$stylesSets = $config['styles']; |
262
|
|
|
|
263
|
|
|
foreach ($stylesSets as &$stylesSet) { |
264
|
|
|
foreach ($stylesSet as &$value) { |
265
|
|
|
$value = array_filter($value); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
return $config; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function getToolbar(string $name): array |
273
|
|
|
{ |
274
|
|
|
$items = []; |
275
|
|
|
|
276
|
|
|
foreach ($this->toolbarConfigs[$name] as $name => $item) { |
277
|
|
|
$items[] = is_string($item) && '@' === substr($item, 0, 1) |
278
|
|
|
? $this->toolbarItems[(substr($item, 1))] |
279
|
|
|
: $item; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $items; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function getStyles(): array |
286
|
|
|
{ |
287
|
|
|
return $this->styles; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function getPlugins(): array |
291
|
|
|
{ |
292
|
|
|
return $this->plugins; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
public function getTemplates(): array |
296
|
|
|
{ |
297
|
|
|
return $this->templates; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function isEnable(): bool |
301
|
|
|
{ |
302
|
|
|
return $this->enable; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function isAsync(): bool |
306
|
|
|
{ |
307
|
|
|
return $this->async; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
public function isAutoload(): bool |
311
|
|
|
{ |
312
|
|
|
return $this->autoload; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
public function isAutoInline(): bool |
316
|
|
|
{ |
317
|
|
|
return $this->autoInline; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function isInline(): bool |
321
|
|
|
{ |
322
|
|
|
return $this->inline; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
public function isJquery(): bool |
326
|
|
|
{ |
327
|
|
|
return $this->jquery; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function isRequireJs(): bool |
331
|
|
|
{ |
332
|
|
|
return $this->requireJs; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function isInputSync(): bool |
336
|
|
|
{ |
337
|
|
|
return $this->inputSync; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public function getFilebrowsers(): array |
341
|
|
|
{ |
342
|
|
|
return $this->filebrowsers; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function getBasePath(): string |
346
|
|
|
{ |
347
|
|
|
return $this->basePath; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
public function getJsPath(): string |
351
|
|
|
{ |
352
|
|
|
return $this->jsPath; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
public function getJqueryPath(): string |
356
|
|
|
{ |
357
|
|
|
return $this->jqueryPath; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
public function getDefaultConfig(): ?string |
361
|
|
|
{ |
362
|
|
|
return $this->defaultConfig; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
public function getConfigs(): array |
366
|
|
|
{ |
367
|
|
|
return $this->configs; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @throws ConfigException |
372
|
|
|
*/ |
373
|
|
|
public function getConfig(string $name): array |
374
|
|
|
{ |
375
|
|
|
if (!isset($this->configs[$name])) { |
376
|
|
|
throw ConfigException::configDoesNotExist($name); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
return $this->configs[$name]; |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|