1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\CleanerTinyMCEConfig\Api; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Director; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Core\Config\Configurable; |
8
|
|
|
use SilverStripe\Core\Injector\Injectable; |
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
10
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader; |
11
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig; |
12
|
|
|
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig; |
13
|
|
|
use SilverStripe\View\Parsers\ShortcodeParser; |
14
|
|
|
use Sunnysideup\CleanerTinyMCEConfig\Config\HTMLEditorConfigOptions; |
15
|
|
|
|
16
|
|
|
class ApplyTinyMceConfigs |
17
|
|
|
{ |
18
|
|
|
use Injectable; |
19
|
|
|
|
20
|
|
|
use Configurable; |
21
|
|
|
|
22
|
|
|
public function applyAll() |
23
|
|
|
{ |
24
|
|
|
$editorConfigs = Injector::inst()->get(HTMLEditorConfigOptions::class)->getEditors(); |
25
|
|
|
$remove = Config::inst()->get(HTMLEditorConfigOptions::class, 'remove_options'); |
26
|
|
|
|
27
|
|
|
$adminModule = ModuleLoader::inst()->getManifest()->getModule('silverstripe/admin'); |
28
|
|
|
$assetsAdminModule = ModuleLoader::inst()->getManifest()->getModule('silverstripe/asset-admin'); |
29
|
|
|
$cmsModule = ModuleLoader::inst()->getManifest()->getModule('silverstripe/cms'); |
30
|
|
|
|
31
|
|
|
foreach ($editorConfigs as $editorConfigName => $editorConfigSettings) { |
32
|
|
|
if (! in_array($editorConfigName, $remove, true)) { |
33
|
|
|
$editor = TinyMCEConfig::get($editorConfigName); |
34
|
|
|
// Register the default internal shortcodes. |
35
|
|
|
ShortcodeParser::get('default')->register( |
36
|
|
|
'sitetree_link', |
37
|
|
|
function (array $arguments, ?string $content = null, ?ShortcodeParser $parser = null): string { |
38
|
|
|
return (string) \SilverStripe\CMS\Model\SiteTree::link_shortcode_handler($arguments, $content, $parser); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
); |
41
|
|
|
$editor->enablePlugins('charmap', 'fullscreen'); |
42
|
|
|
$editor |
43
|
|
|
->enablePlugins([ |
44
|
|
|
'contextmenu' => null, |
45
|
|
|
'image' => null, |
46
|
|
|
'anchor' => null, |
47
|
|
|
'sslink' => $adminModule->getResource('client/dist/js/TinyMCE_sslink.js'), |
48
|
|
|
'sslinkinternal' => $cmsModule->getResource('client/dist/js/TinyMCE_sslink-internal.js'), |
49
|
|
|
'sslinkanchor' => $cmsModule->getResource('client/dist/js/TinyMCE_sslink-anchor.js'), |
50
|
|
|
'sslinkfile' => $assetsAdminModule->getResource('client/dist/js/TinyMCE_sslink-file.js'), |
51
|
|
|
'sslinkexternal' => $adminModule->getResource('client/dist/js/TinyMCE_sslink-external.js'), |
52
|
|
|
'sslinkemail' => $adminModule->getResource('client/dist/js/TinyMCE_sslink-email.js'), |
53
|
|
|
//media ... |
54
|
|
|
'ssmedia' => $assetsAdminModule->getResource('client/dist/js/TinyMCE_ssmedia.js'), |
55
|
|
|
'ssembed' => $assetsAdminModule->getResource('client/dist/js/TinyMCE_ssembed.js'), |
56
|
|
|
'visualchars', |
57
|
|
|
]) |
58
|
|
|
->setOptions([ |
59
|
|
|
'friendly_name' => 'Default CMS', |
60
|
|
|
'priority' => '50', |
61
|
|
|
'skin' => 'silverstripe', |
62
|
|
|
'body_class' => 'typography', |
63
|
|
|
'contextmenu' => 'sslink anchor ssmedia ssembed inserttable | cell row column deletetable', |
64
|
|
|
'use_native_selects' => false, |
65
|
|
|
// 'valid_elements' => '@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title' |
66
|
|
|
// . '|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],' |
67
|
|
|
// . '-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*],' |
68
|
|
|
// . '-sub[class],-sup[class],-blockquote[dir|class],-cite[dir|class|id|title],' |
69
|
|
|
// . '-table[cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],' |
70
|
|
|
// . '-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],' |
71
|
|
|
// . 'tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],' |
72
|
|
|
// . '#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],' |
73
|
|
|
// . '-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],' |
74
|
|
|
// . '-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align],' |
75
|
|
|
// . '-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],' |
76
|
|
|
// . '-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],' |
77
|
|
|
// . 'dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir]', |
78
|
|
|
// 'extended_valid_elements' => 'img[class|src|alt|title|hspace|vspace|width|height|align|name' |
79
|
|
|
// . '|usemap|data*],iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],' |
80
|
|
|
// . 'object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]', |
81
|
|
|
]) |
82
|
|
|
; |
83
|
|
|
// enable ability to insert anchors |
84
|
|
|
$editor->insertButtonsAfter('sslink', 'anchor'); |
85
|
|
|
|
86
|
|
|
// disable plugins |
87
|
|
|
if (! empty($editorConfigSettings['disabled_plugins'])) { |
88
|
|
|
$editor->disablePlugins( |
89
|
|
|
$this->stringToArray($editorConfigSettings['disabled_plugins']) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// add buttons |
94
|
|
|
if (! empty($editorConfigSettings['add_buttons'])) { |
95
|
|
|
$addButtons = $this->stringToArray($editorConfigSettings['add_buttons']); |
96
|
|
|
foreach ($addButtons as $line => $buttons) { |
97
|
|
|
$editor->addButtonsToLine($line, $buttons); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// remove buttons |
102
|
|
|
if (! empty($editorConfigSettings['remove_buttons'])) { |
103
|
|
|
$removeButtons = $this->stringToArray($editorConfigSettings['remove_buttons']); |
104
|
|
|
$editor->removeButtons($removeButtons); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// $editor->removeButtons( |
108
|
|
|
// [ |
109
|
|
|
// 'outdent', |
110
|
|
|
// 'indent', |
111
|
|
|
// // 'numlist', |
112
|
|
|
// 'hr', |
113
|
|
|
// 'pastetext', |
114
|
|
|
// 'pasteword', |
115
|
|
|
// 'visualaid', |
116
|
|
|
// 'anchor', |
117
|
|
|
// 'tablecontrols', |
118
|
|
|
// 'justifyleft', |
119
|
|
|
// 'justifycenter', |
120
|
|
|
// 'justifyright', |
121
|
|
|
// 'strikethrough', |
122
|
|
|
// 'justifyfull', |
123
|
|
|
// 'underline', |
124
|
|
|
// ] |
125
|
|
|
// ); |
126
|
|
|
|
127
|
|
|
// add macrons |
128
|
|
|
if (! empty($editorConfigSettings['add_macrons'])) { |
129
|
|
|
$editor |
130
|
|
|
->addButtonsToLine(1, ['charmap']) |
131
|
|
|
->setOption( |
132
|
|
|
'charmap_append', |
133
|
|
|
[ |
134
|
|
|
['256', 'A - macron'], |
135
|
|
|
['274', 'E - macron'], |
136
|
|
|
['298', 'I - macron'], |
137
|
|
|
['332', 'O - macron'], |
138
|
|
|
['362', 'U - macron'], |
139
|
|
|
['257', 'a - macron'], |
140
|
|
|
['275', 'e - macron'], |
141
|
|
|
['299', 'i - macron'], |
142
|
|
|
['333', 'o - macron'], |
143
|
|
|
['363', 'u - macron'], |
144
|
|
|
] |
145
|
|
|
) |
146
|
|
|
; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
// lines |
150
|
|
|
if (! empty($editorConfigSettings['lines'])) { |
151
|
|
|
$lines = $editorConfigSettings['lines']; |
152
|
|
|
for ($i = 1; $i < 4; ++$i) { |
153
|
|
|
$lines[$i] = isset($lines[$i]) ? $this->stringToArray($lines[$i]) : []; |
154
|
|
|
$editor->setButtonsForLine($i, implode(', ', $lines[$i])); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
//options |
159
|
|
|
$editor->setOptions( |
160
|
|
|
[ |
161
|
|
|
'fix_list_elements' => true, |
162
|
|
|
'skin' => 'silverstripe', |
163
|
|
|
'importcss_append' => true, |
164
|
|
|
'style_formats_merge' => false, |
165
|
|
|
'style_formats' => [], |
166
|
|
|
'contextmenu' => 'sslink anchor ssmedia ssembed', |
167
|
|
|
'use_native_selects' => false, |
168
|
|
|
'paste_as_text' => true, |
169
|
|
|
'paste_text_sticky' => true, |
170
|
|
|
'paste_text_sticky_default' => true, |
171
|
|
|
'width' => '100%', |
172
|
|
|
'mode' => 'none', |
173
|
|
|
'body_class' => 'typography', |
174
|
|
|
'document_base_url' => Director::absoluteBaseURL(), |
175
|
|
|
'cleanup_callback' => 'sapphiremce_cleanup', |
176
|
|
|
'browser_spellcheck' => true, |
177
|
|
|
'statusbar' => true, |
178
|
|
|
'elementpath' => true, // https://www.tinymce.com/docs/configure/editor-appearance/#elementpath |
179
|
|
|
'relative_urls' => true, |
180
|
|
|
'remove_script_host' => true, |
181
|
|
|
'convert_urls' => false, // Prevent site-root images being rewritten to base relative |
182
|
|
|
'menubar' => false, |
183
|
|
|
'language' => 'en', |
184
|
|
|
'branding' => false, |
185
|
|
|
'upload_folder_id' => null, // Set folder ID for insert media dialog |
186
|
|
|
'valid_elements' => '@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title' |
187
|
|
|
. '|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style]' |
188
|
|
|
. ',-ol[class],' |
189
|
|
|
. '-ul[class],' |
190
|
|
|
. '-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*],' |
191
|
|
|
. '-sub[class],-sup[class],-blockquote[dir|class],' |
192
|
|
|
. '-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align],' |
193
|
|
|
. '-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],' |
194
|
|
|
. '-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],' |
195
|
|
|
. 'dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class]', |
196
|
|
|
'extended_valid_elements' => 'img[class|src|alt|title|hspace|vspace|width|height|align|name|usemap|data*],' |
197
|
|
|
. 'object[classid|codebase|width|height|data|type],' |
198
|
|
|
. 'embed[width|height|name|flashvars|src|bgcolor|align|play|loop|quality|' |
199
|
|
|
. 'allowscriptaccess|type|pluginspage|autoplay],' |
200
|
|
|
. 'param[name|value],' |
201
|
|
|
. 'map[class|name|id],' |
202
|
|
|
. 'area[shape|coords|href|target|alt],' |
203
|
|
|
. 'ins[cite|datetime],del[cite|datetime],' |
204
|
|
|
. 'menu[label|type],' |
205
|
|
|
. 'meter[form|high|low|max|min|optimum|value],' |
206
|
|
|
. 'cite,abbr,,b,article,aside,code,col,colgroup,details[open],dfn,figure,figcaption,' |
207
|
|
|
. 'footer,header,kbd,mark,,nav,pre,q[cite],small,summary,time[datetime],var,ol[start|type]', |
208
|
|
|
] |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
if (! empty($editorConfigSettings['options'])) { |
212
|
|
|
$editor->setOptions($editorConfigSettings['options']); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// block formats |
216
|
|
|
if (! empty($editorConfigSettings['blocks'])) { |
217
|
|
|
$blocks = $this->stringToArray($editorConfigSettings['blocks']) ?? []; |
218
|
|
|
foreach ($editorConfigSettings['blocks'] as $tag => $name) { |
219
|
|
|
$blocks[] = $name . '=' . $tag; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$formats = implode(';', $blocks); |
223
|
|
|
$valids = implode(';', $blocks); |
|
|
|
|
224
|
|
|
$editor->setOptions( |
225
|
|
|
[ |
226
|
|
|
'block_formats' => $formats, |
227
|
|
|
'theme_advanced_blocks' => $formats, |
228
|
|
|
// 'valid_elements' => $formats, |
229
|
|
|
] |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$default = Config::inst()->get(HTMLEditorConfigOptions::class, 'main_editor'); |
236
|
|
|
if ($default) { |
237
|
|
|
HTMLEditorConfig::set_active_identifier($default); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
protected function stringToArray($mixed): array |
242
|
|
|
{ |
243
|
|
|
if (! is_array($mixed)) { |
244
|
|
|
$mixed = explode(',', $mixed); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
// $mixed = array_map('trim', $mixed); |
248
|
|
|
// $mixed = array_filter($mixed); |
249
|
|
|
return $mixed; |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths