Passed
Push — master ( 946983...891f40 )
by Julito
07:53 queued 11s
created

Basic::getMaximizedToolbar()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 28
nc 4
nop 0
dl 0
loc 32
rs 9.472
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
8
9
use Chamilo\CoreBundle\Component\Editor\Toolbar;
10
11
class Basic extends Toolbar
12
{
13
    /**
14
     * Default plugins that will be use in all toolbars
15
     * In order to add a new plugin you have to load it in default/layout/head.tpl.
16
     */
17
    public array $defaultPlugins = [
18
        //'adobeair',
19
        //'ajax',
20
        'audio',
21
        'image2_chamilo',
22
        'bidi',
23
        'colorbutton',
24
        'colordialog',
25
        'dialogui',
26
        'dialogadvtab',
27
        'div',
28
        //if you activate this plugin the html, head tags will not be saved
29
        //'divarea',
30
        //'docprops',
31
        'find',
32
        'flash',
33
        'font',
34
        'iframe',
35
        //'iframedialog',
36
        'indentblock',
37
        'justify',
38
        'language',
39
        'lineutils',
40
        'liststyle',
41
        'newpage',
42
        'oembed',
43
        'pagebreak',
44
        'preview',
45
        'print',
46
        'save',
47
        'selectall',
48
        //'sharedspace',
49
        'showblocks',
50
        'smiley',
51
        //'sourcedialog',
52
        //'stylesheetparser',
53
        //'tableresize',
54
        'templates',
55
        //'uicolor',
56
        'video',
57
        'widget',
58
        'wikilink',
59
        'wordcount',
60
        'inserthtml',
61
        //'xml',
62
        'qmarkersrolls',
63
    ];
64
65
    /**
66
     * Plugins this toolbar.
67
     */
68
    public array $plugins = [];
69
    private string $toolbarSet;
70
71
    public function __construct(
72
        $router,
73
        $toolbar = null,
74
        $config = [],
75
        $prefix = null
76
    ) {
77
        $isAllowedToEdit = api_is_allowed_to_edit();
78
        $isPlatformAdmin = api_is_platform_admin();
79
        // Adding plugins depending of platform conditions
80
        $plugins = [];
81
82
        if ('ismanual' === api_get_setting('show_glossary_in_documents')) {
83
            $plugins[] = 'glossary';
84
        }
85
86
        if ('true' === api_get_setting('youtube_for_students')) {
87
            $plugins[] = 'youtube';
88
        } else {
89
            if (api_is_allowed_to_edit() || api_is_platform_admin()) {
90
                $plugins[] = 'youtube';
91
            }
92
        }
93
94
        if ('true' === api_get_setting('enabled_googlemaps')) {
95
            $plugins[] = 'leaflet';
96
        }
97
98
        if ('true' === api_get_setting('math_asciimathML')) {
99
            $plugins[] = 'asciimath';
100
        }
101
102
        if ('true' === api_get_setting('enabled_mathjax')) {
103
            $plugins[] = 'mathjax';
104
            $config['mathJaxLib'] = api_get_path(WEB_PUBLIC_PATH).'assets/MathJax/MathJax.js?config=TeX-MML-AM_HTMLorMML';
105
        }
106
107
        if ('true' === api_get_setting('enabled_asciisvg')) {
108
            $plugins[] = 'asciisvg';
109
        }
110
111
        if ('true' === api_get_setting('enabled_wiris')) {
112
            // Commercial plugin
113
            $plugins[] = 'ckeditor_wiris';
114
        }
115
116
        if ('true' === api_get_setting('enabled_imgmap')) {
117
            $plugins[] = 'mapping';
118
        }
119
120
        /*if (api_get_setting('block_copy_paste_for_students') == 'true') {
121
            // Missing
122
        }*/
123
124
        if ('true' === api_get_setting('more_buttons_maximized_mode')) {
125
            $plugins[] = 'toolbarswitch';
126
        }
127
128
        if ('true' === api_get_setting('allow_spellcheck')) {
129
            $plugins[] = 'scayt';
130
        }
131
132
        if (api_get_configuration_sub_value('ckeditor_vimeo_embed/config') && ($isAllowedToEdit || $isPlatformAdmin)) {
133
            $plugins[] = 'ckeditor_vimeo_embed';
134
        }
135
136
        if (api_get_configuration_value('ck_editor_block_image_copy_paste')) {
137
            $plugins[] = 'blockimagepaste';
138
        }
139
        $this->defaultPlugins = array_unique(array_merge($this->defaultPlugins, $plugins));
140
        $this->toolbarSet = $toolbar;
141
        parent::__construct($router, $toolbar, $config, $prefix);
142
    }
143
144
    /**
145
     * Get the toolbar config.
146
     *
147
     * @return array
148
     */
149
    public function getConfig()
150
    {
151
        $config = [];
152
        /*if ('true' === api_get_setting('more_buttons_maximized_mode')) {
153
            $config['toolbar_minToolbar'] = $this->getMinimizedToolbar();
154
            $config['toolbar_maxToolbar'] = $this->getMaximizedToolbar();
155
        }
156
157
        $config['customConfig'] = api_get_path(WEB_PUBLIC_PATH).'editor/config?'.api_get_cidreq().'&tool=document&type=files';*/
158
        //$config['flash_flvPlayer'] = api_get_path(WEB_LIBRARY_JS_PATH).'ckeditor/plugins/flash/swf/player.swf';
159
160
        /*filebrowserFlashBrowseUrl
161
        filebrowserFlashUploadUrl
162
        filebrowserImageBrowseLinkUrl
163
        filebrowserImageBrowseUrl
164
        filebrowserImageUploadUrl
165
        filebrowserUploadUrl*/
166
167
        //$config['extraPlugins'] = $this->getPluginsToString();
168
169
        //$config['oembed_maxWidth'] = '560';
170
        //$config['oembed_maxHeight'] = '315';
171
172
        /*$config['wordcount'] = array(
173
            // Whether or not you want to show the Word Count
174
            'showWordCount' => true,
175
            // Whether or not you want to show the Char Count
176
            'showCharCount' => true,
177
            // Option to limit the characters in the Editor
178
            'charLimit' => 'unlimited',
179
            // Option to limit the words in the Editor
180
            'wordLimit' => 'unlimited'
181
        );*/
182
183
        /*$config['skin'] = 'moono-lisa';
184
        $config['image2_chamilo_alignClasses'] = [
185
            'pull-left',
186
            'text-center',
187
            'pull-right',
188
            'img-va-baseline',
189
            'img-va-top',
190
            'img-va-bottom',
191
            'img-va-middle',
192
            'img-va-super',
193
            'img-va-sub',
194
            'img-va-text-top',
195
            'img-va-text-bottom',
196
        ];
197
        $config['startupOutlineBlocks'] = true === api_get_configuration_value('ckeditor_startup_outline_blocks');*/
198
199
        $customPlugins = '';
200
        $customPluginsPath = [];
201
        if ('true' === api_get_setting('editor.translate_html')) {
202
            $customPlugins .= ' translatehtml';
203
            $customPluginsPath['translatehtml'] = api_get_path(WEB_PUBLIC_PATH).'libs/editor/tinymce_plugins/translatehtml/plugin.js';
204
205
            $languageList = api_get_languages();
206
            $rtlIsocodes = ['ps', 'ar', 'he', 'fa'];
207
            $list = [];
208
            foreach ($languageList as $isocode => $name) {
209
                // Example format language list : ['ar:Arabic:rtl', 'fr:French', 'es:Spanish'];
210
                $rtl = (in_array($isocode, $rtlIsocodes)?':rtl':'');
211
                $list[] = $isocode.':'.$name.$rtl;
212
            }
213
            $config['translatehtml_lenguage_list'] = $list;
214
        }
215
216
        $plugins = [
217
            'advlist autolink lists link image charmap print preview anchor',
218
            'searchreplace visualblocks code fullscreen',
219
            'insertdatetime media table paste wordcount'.$customPlugins,
220
        ];
221
222
        /*plugins: [
223
           'fullpage advlist autolink lists link image charmap print preview anchor',
224
           'searchreplace visualblocks code fullscreen',
225
           'insertdatetime media table paste wordcount emoticons'
226
       ],*/
227
228
        if ($this->getConfigAttribute('fullPage')) {
229
            $plugins[] = 'fullpage';
230
        }
231
232
        $config['plugins'] = implode(' ', $plugins);
233
        $config['toolbar'] = 'undo redo directionality | bold italic underline strikethrough | insertfile image media template link | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent |  numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen  preview save print | code codesample | ltr rtl'.$customPlugins;
234
235
        if (!empty($customPluginsPath)) {
236
            $config['external_plugins'] = $customPluginsPath;
237
        }
238
239
        //$config['skin'] = 'oxide';
240
        $config['skin_url'] = '/build/libs/tinymce/skins/ui/oxide';
241
        $config['content_css'] = '/build/libs/tinymce/skins/content/default/content.css';
242
        $config['branding'] = false;
243
        $config['relative_urls'] = false;
244
        $config['toolbar_mode'] = 'sliding';
245
        $config['autosave_ask_before_unload'] = true;
246
        $config['toolbar_mode'] = 'sliding';
247
248
        //file_picker_callback : browser,
249
250
        $iso = api_get_language_isocode();
251
        $url = api_get_path(WEB_PATH);
252
253
        // Language list: https://www.tiny.cloud/get-tiny/language-packages/
254
        if ('en_US' !== $iso) {
255
            $config['language'] = $iso;
256
            $config['language_url'] = "$url/libs/editor/langs/$iso.js";
257
        }
258
259
260
261
        /*if (isset($this->config)) {
262
            $this->config = array_merge($config, $this->config);
263
        } else {
264
            $this->config = $config;
265
        }*/
266
267
        $this->config = $config;
268
269
        //$config['width'] = '100';
270
        $config['height'] = '300';
271
272
        return $this->config;
273
    }
274
275
    /**
276
     * @return array
277
     */
278
    public function getNewPageBlock()
279
    {
280
        return ['NewPage', 'Templates', '-', 'PasteFromWord', 'inserthtml'];
281
    }
282
283
    /**
284
     * Get the default toolbar configuration when the setting more_buttons_maximized_mode is false.
285
     *
286
     * @return array
287
     */
288
    protected function getNormalToolbar()
289
    {
290
        return null;
291
    }
292
293
    /**
294
     * Get the toolbar configuration when CKEditor is minimized.
295
     *
296
     * @return array
297
     */
298
    protected function getMinimizedToolbar()
299
    {
300
        return [
301
            $this->getNewPageBlock(),
302
            ['Undo', 'Redo'],
303
            [
304
                'Link',
305
                'Image',
306
                'Video',
307
                'Oembed',
308
                'Flash',
309
                'Youtube',
310
                'VimeoEmbed',
311
                'Audio',
312
                'Table',
313
                'Asciimath',
314
                'Asciisvg',
315
            ],
316
            ['BulletedList', 'NumberedList', 'HorizontalRule'],
317
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
318
            ['Styles', 'Format', 'Font', 'FontSize', 'Bold', 'Italic', 'Underline', 'TextColor', 'BGColor'],
319
            'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
320
            ['Toolbarswitch', 'Source'],
321
        ];
322
    }
323
324
    /**
325
     * Get the toolbar configuration when CKEditor is maximized.
326
     *
327
     * @return array
328
     */
329
    protected function getMaximizedToolbar()
330
    {
331
        return [
332
            $this->getNewPageBlock(),
333
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'inserthtml'],
334
            ['Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'],
335
            ['Link', 'Unlink', 'Anchor', 'Glossary'],
336
            [
337
                'Image',
338
                'Mapping',
339
                'Video',
340
                'Oembed',
341
                'Flash',
342
                'Youtube',
343
                'VimeoEmbed',
344
                'Audio',
345
                'leaflet',
346
                'Smiley',
347
                'SpecialChar',
348
                'Asciimath',
349
                'Asciisvg',
350
            ],
351
            '/',
352
            ['Table', '-', 'CreateDiv'],
353
            ['BulletedList', 'NumberedList', 'HorizontalRule', '-', 'Outdent', 'Indent', 'Blockquote'],
354
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
355
            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'TextColor', 'BGColor'],
356
            ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
357
            ['Styles', 'Format', 'Font', 'FontSize'],
358
            ['PageBreak', 'ShowBlocks'],
359
            'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
360
            ['Toolbarswitch', 'Source'],
361
        ];
362
    }
363
}
364