/
EditorServiceProvider.php
263 lines (243 loc) · 16.7 KB
/
EditorServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
namespace Concrete\Core\Editor;
use AssetList;
use Concrete\Core\Application\Application;
use Concrete\Core\Config\Repository\Liaison;
use Concrete\Core\Entity\Site\Site;
use Concrete\Core\Foundation\Service\Provider as ServiceProvider;
use Concrete\Core\Legacy\FilePermissions;
use Concrete\Core\Legacy\TaskPermission;
use Concrete\Core\Localization\Localization;
use Concrete\Core\Site\Service;
class EditorServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(
CkeditorEditor::class,
function (Application $app) {
$siteService = $app->make('site');
$activeSite = $siteService->getActiveSiteForEditing();
$config = $activeSite->getConfigRepository();
$styles = $config->get('editor.ckeditor4.styles', []);
// Load plugins and select the site specific ones
$pluginManager = new PluginManager();
$this->registerCkeditorPlugins($pluginManager);
$this->registerCorePlugins($pluginManager);
$pluginManager->select($this->resolveSelectedPlugins($activeSite, $config, $siteService));
$editor = new CkeditorEditor($config, $siteService, $pluginManager, $styles, $app);
$editor->setToken($app->make('token')->generate('editor'));
$filePermission = FilePermissions::getGlobal();
$taskPermission = new TaskPermission();
$editor->setAllowFileManager(
$filePermission->canAccessFileManager()
&& $config->get('editor.concrete.enable_filemanager')
);
$editor->setAllowSitemap(
$taskPermission->canAccessSitemap()
&& $config->get('editor.concrete.enable_sitemap')
);
return $editor;
}
);
$this->app->alias(CkeditorEditor::class, EditorInterface::class);
$this->app->alias(CkeditorEditor::class, 'editor');
}
protected function registerCkeditorPlugins(PluginManager $pluginManager)
{
$loc = Localization::getInstance();
$loc->pushActiveContext(Localization::CONTEXT_UI);
try {
$pluginList = [
// https://ckeditor.com/cke4/addon/about
'about' => [t('About'), t('This plugin displays the editor version, online documentation links, and licensing information.')],
// https://ckeditor.com/cke4/addon/autogrow
'autogrow' => [t('Auto Grow'), t('The editor will automatically expand and shrink vertically depending on its content.')],
// https://ckeditor.com/cke4/addon/autolink
'autolink' => [t('Auto Link'), t('This plugin turns pasted URL text into links. The URL text must include the protocol type such as HTTP and HTTPS.')],
// https://ckeditor.com/cke4/addon/a11yhelp
'a11yhelp' => [t('Accessibility Help'), t('This plugin displays information about the keyboard usage using the ALT+0 combination.')],
// https://ckeditor.com/cke4/addon/basicstyles
'basicstyles' => [t('Basic Styles'), t('This plugin adds the basic formatting buttons: bold, italic, underline, strikethrough, subscript, superscript.')],
// https://ckeditor.com/cke4/addon/bidi
'bidi' => [t('BiDi (Text Direction)'), t('This plugin adds buttons to change the text direction.')],
// https://ckeditor.com/cke4/addon/blockquote
'blockquote' => [t('Blockquote'), t('This plugin adds a button to insert quotations (HTML <blockquote> tag).')],
// https://ckeditor.com/cke4/addon/clipboard
'clipboard' => [t('Clipboard'), t('This plugin handles the Cut/Copy/Paste operations.')],
// https://ckeditor.com/cke4/addon/colorbutton
'colorbutton' => [t('Color Button'), t('This plugin adds buttons to manage the text & background colors.')],
// https://ckeditor.com/cke4/addon/colordialog
'colordialog' => [t('Color Dialog'), t('This plugin improves the Color Button feature by providing an advanced color selection window.')],
// https://ckeditor.com/cke4/addon/contextmenu
'contextmenu' => [t('Context Menu'), t('The plugin replaces the browser\'s native menu with the editor\'s one.')],
// https://ckeditor.com/cke4/addon/dialogadvtab
'dialogadvtab' => [t('Advanced Tab for Dialogs'), t('This plugin provides the Advanced tab to extend some dialog windows.')],
// https://ckeditor.com/cke4/addon/div
'div' => [t('Div Container Manager'), t('This plugin adds a command that allows grouping content blocks under a container <div> element, with styles and attributes support.')],
// https://ckeditor.com/cke4/addon/divarea
'divarea' => [t('Div Editing Area'), t('This plugin uses a <div> element (instead of the <iframe> element) as the editable area. Much similar to inline editing, it allows the content to inherit styles from host page.')],
// https://ckeditor.com/cke4/addon/elementspath
'elementspath' => [t('Elements Path'), t('This plugin displays the list of HTML elements at the current cursor position.')],
// https://ckeditor.com/cke4/addon/emoji
'emoji' => [t('Emoji'), t('This plugin adds autocomplete for inserting Unicode emoji characters. Typing a colon ( : ) followed by at least two additional characters will list available emojis.')],
// https://ckeditor.com/cke4/addon/enterkey
'enterkey' => [t('Enter Key'), t('This plugin defines the Enter key (line breaking) behavior.')],
// https://ckeditor.com/cke4/addon/entities
'entities' => [t('Escape HTML Entities'), t('This plugin escapes entities in the generated HTML.')],
// https://ckeditor.com/cke4/addon/find
'find' => [t('Find / Replace'), t('This plugin adds the Find and Replace dialog.')],
// https://ckeditor.com/cke4/addon/flash
'flash' => [t('Flash Dialog'), t('This plugin adds features to manage embedded Flash files.')],
// https://ckeditor.com/cke4/addon/floatingspace
'floatingspace' => [t('Floating Space'), t('This plugin places the editor toolbar in the best position.')],
// https://ckeditor.com/cke4/addon/font
'font' => [t('Font Size and Family'), t('This plugin adds the Font Size and Font Family dropdowns.')],
// https://ckeditor.com/cke4/addon/format
'format' => [t('Format'), t('This plugin adds the Format dropdown.')],
// https://ckeditor.com/cke4/addon/horizontalrule
'horizontalrule' => [t('Horizontal Rule'), t('This plugin adds a button to insert Horizontal Rules (<hr>).')],
// https://ckeditor.com/cke4/addon/htmlwriter
'htmlwriter' => [t('HTML Output Writer'), t('This plugin provides flexible HTML output formatting.')],
// https://ckeditor.com/cke4/addon/image
'image' => [t('Image'), t('This plugin adds the image-related features.')],
// https://ckeditor.com/cke4/addon/image2
'image2' => [t('Enhanced Image'), t('This is an enhanced version of the Image plugin that introduces the image widget.')],
// https://ckeditor.com/cke4/addon/indentblock
'indentblock' => [t('Indent Block'), t('This plugin adds buttons to manage the text indentation.')],
// https://ckeditor.com/cke4/addon/indentlist
'indentlist' => [t('Indent List'), t('This plugin adds buttons to manage the lists (<ul> and <ol> elements) indentation.')],
// https://ckeditor.com/cke4/addon/justify
'justify' => [t('Justify'), t('This plugin adds text justification buttons.')],
// https://ckeditor.com/cke4/addon/language
'language' => [t('Language'), t('This plugin adds the Language button.')],
// https://ckeditor.com/cke4/addon/list
'list' => [t('List'), t('This plugin adds buttons to add/remove numbered and bulleted lists.')],
// https://ckeditor.com/cke4/addon/liststyle
'liststyle' => [t('List Style'), t('This plugin adds numbered list and ordered list properties dialogs (available in context menu).')],
// https://ckeditor.com/cke4/addon/magicline
'magicline' => [t('Magic Line'), t('This plugin makes it easier to place cursor and add content near some problematic document elements.')],
// https://ckeditor.com/cke4/addon/maximize
'maximize' => [t('Maximize'), t('This plugin adds a button to maximize the editor.')],
// https://ckeditor.com/cke4/addon/newpage
'newpage' => [t('New Page'), t('This plugin adds a button to clears the editor content.')],
// https://ckeditor.com/cke4/addon/pagebreak
'pagebreak' => [t('Page Break'), t('This plugin adds a button which inserts horizontal page breaks (useful for document printing).')],
// https://ckeditor.com/cke4/addon/pastetext
'pastetext' => [t('Paste As Plain Text'), t('This adds a button to paste clipboard contents as plain text.')],
// https://ckeditor.com/cke4/addon/pastefromword
'pastefromword' => [t('Paste from Word'), t('This adds a button to paste content from Microsoft Word and maintain original formatting.')],
// https://ckeditor.com/cke4/addon/placeholder
'placeholder' => [t('Placeholder'), t('This plugin lets you create and edit placeholders (non-editable text fragments).')],
// https://ckeditor.com/cke4/addon/preview
'preview' => [t('Preview'), t('This plugin adds a button which shows a preview of the document as it will be displayed to end users or printed.')],
// https://ckeditor.com/cke4/addon/removeformat
'removeformat' => [t('Remove Format'), t('This plugin adds the Remove Format button to remove all styles from the selected part of the document.')],
// https://ckeditor.com/cke4/addon/resize
'resize' => [t('Editor Resize'), t('This plugin adds a handle that allows resizing the classic editor instances.')],
// https://ckeditor.com/cke4/addon/scayt
'scayt' => [t('SpellCheckAsYouType (SCAYT)'), t('This plugin brings Spell Check As You Type (SCAYT) functionality.')],
// https://ckeditor.com/cke4/addon/selectall
'selectall' => [t('Select All'), t('This plugin adds a Select all button.')],
// https://ckeditor.com/cke4/addon/showblocks
'showblocks' => [t('Show Blocks'), t('This plugin adds a button to outline all block-level elements.')],
// https://ckeditor.com/cke4/addon/showborders
'showborders' => [t('Show Table Borders'), t('This plugin displays visible outlines around all table elements.')],
// https://ckeditor.com/cke4/addon/smiley
'smiley' => [t('Insert Smiley'), t('This plugin adds a button to insert emoticons.')],
// https://ckeditor.com/cke4/addon/sourcearea
'sourcearea' => [t('Source Editing Area'), t('This plugin adds a button to switch to the HTML source editing mode.')],
// https://ckeditor.com/cke4/addon/sourcedialog
'sourcedialog' => [t('Source Dialog'), t('This plugin adds a button to edit the HTML source in a dialog window.')],
// https://ckeditor.com/cke4/addon/specialchar
'specialchar' => [t('Special Characters'), t('This plugin adds a button to insert characters.')],
// https://ckeditor.com/cke4/addon/stylescombo
'stylescombo' => [t('Styles Combo'), t('This plugin adds the Styles dropdown.')],
// https://ckeditor.com/cke4/addon/tab
'tab' => [t('Tab Key Handling'), t('This plugin provides basic TAB/SHIFT-TAB key handling (move to next/previous table cell, move to next editor instance in page).')],
// https://ckeditor.com/cke4/addon/table
'table' => [t('Table'), t('This plugin adds the Table Properties dialog window to create and edit tables.')],
// https://ckeditor.com/cke4/addon/tableresize
'tableresize' => [t('Table Resize'), t('This plugin adds support for table column resizing with the mouse.')],
// https://ckeditor.com/cke4/addon/tableselection
'tableselection' => [t('Table Selection'), t('This plugin allows selecting arbitrary rectangular table fragments, applying formatting or adding links to all selected cells, cut/copy/paste entire rows or columns.')],
// https://ckeditor.com/cke4/addon/tabletools
'tabletools' => [t('Table Tools'), t('This plugin adds a more advanced context menu for table items and the Cell Properties dialog window.')],
// https://ckeditor.com/cke4/addon/toolbar
'toolbar' => [t('Editor Toolbar'), t('This plugin provides the classical experience to access editor commands, including items like buttons and drop-down lists.')],
// https://ckeditor.com/cke4/addon/undo
'undo' => [t('Undo'), t('This plugin provides the undo and redo features.')],
// https://ckeditor.com/cke4/addon/wysiwygarea
'wysiwygarea' => [t('IFrame Editing Area'), t('This plugin represents an editing area that stores the editor content inside of an embedded iframe.')],
];
} finally {
$loc->popActiveContext();
}
foreach ($pluginList as $key => list($name, $description)) {
$editorPlugin = new Plugin();
$editorPlugin->setKey($key);
$editorPlugin->setName($name);
$editorPlugin->setDescription($description);
$pluginManager->register($editorPlugin);
}
}
private function registerCorePlugins(PluginManager $pluginManager)
{
$plugin = new Plugin();
$plugin->setKey('concreteinline');
$plugin->setName(t('Concrete Inline'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
$plugin = new Plugin();
$plugin->setKey('concretefilemanager');
$plugin->setName(t('Concrete File Browser'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
$plugin = new Plugin();
$plugin->setKey('concreteuploadimage');
$plugin->setName(t('Concrete Upload Image'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
$plugin = new Plugin();
$plugin->setKey('concretelink');
$plugin->setName(t('Concrete Link'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
$plugin = new Plugin();
$plugin->setKey('normalizeonchange');
$plugin->setName(t('Normalize On Change'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
$plugin = new Plugin();
$plugin->setKey('concretestyles');
$plugin->setName(t('Concrete Styles'));
$plugin->requireAsset('ckeditor');
$pluginManager->register($plugin);
}
/**
* Find the selected ckeditor plugins
*
* @param \Concrete\Core\Entity\Site\Site $activeSite
* @param \Concrete\Core\Config\Repository\Liaison $config
* @param \Concrete\Core\Site\Service $siteService
*
* @return array
*/
protected function resolveSelectedPlugins(Site $activeSite, Liaison $config, Service $siteService)
{
// Load the selected plugins from the current site
$selectedPlugins = $config->get('editor.ckeditor4.plugins.selected');
if (!is_array($selectedPlugins)) {
// Resolve the default config to use
if ($activeSite->getSiteHandle() === 'default') {
$defaultConfig = $config;
} else {
$defaultConfig = $siteService->getDefault()->getConfigRepository();
}
// Load in default selected plugins and hidden selected plugins
$selectedPlugins = (array) $defaultConfig->get('editor.ckeditor4.plugins.selected_default', []);
$selectedPlugins = array_merge($selectedPlugins, (array) $defaultConfig->get('editor.ckeditor4.plugins.selected_hidden', []));
}
return $selectedPlugins;
}
}