Passed
Push — 1.10.x ( 7d175d...78dc19 )
by Julito
106:22 queued 54:57
created

Basic::__construct()   F

Complexity

Conditions 13
Paths 1536

Size

Total Lines 61
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 31
nc 1536
nop 3
dl 0
loc 61
rs 2.9617
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
5
6
use Chamilo\CoreBundle\Component\Editor\Toolbar;
7
8
/**
9
 * Class Basic
10
 * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
11
 */
12
class Basic extends Toolbar
13
{
14
    /**
15
     * Default plugins that will be use in all toolbars
16
     * In order to add a new plugin you have to load it in default/layout/head.tpl
17
     * @var array
18
     */
19
    public $defaultPlugins = array(
20
        'adobeair',
21
        'ajax',
22
        'audio',
23
        'bidi',
24
        'colorbutton',
25
        'colordialog',
26
        'dialogui',
27
        'dialogadvtab',
28
        'div',
29
        //if you activate this plugin the html, head tags will not be saved
30
        //'divarea',
31
        'docprops',
32
        'find',
33
        'flash',
34
        'font',
35
        'iframe',
36
        'iframedialog',
37
        'indentblock',
38
        'justify',
39
        'language',
40
        'lineutils',
41
        'liststyle',
42
        'newpage',
43
        'oembed',
44
        'pagebreak',
45
        'preview',
46
        'print',
47
        'save',
48
        'selectall',
49
        'sharedspace',
50
        'showblocks',
51
        'smiley',
52
        'sourcedialog',
53
        'stylesheetparser',
54
        'tableresize',
55
        'templates',
56
        'uicolor',
57
        'video',
58
        'widget',
59
        'wikilink',
60
        'wordcount',
61
        'xml',
62
    );
63
64
    /**
65
     * Plugins this toolbar
66
     * @var array
67
     */
68
    public $plugins = array();
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function __construct(
74
        $toolbar = null,
75
        $config = array(),
76
        $prefix = null
77
    ) {
78
        // Adding plugins depending of platform conditions
79
        $plugins = array();
80
81
        if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
82
            $plugins[] = 'glossary';
83
        }
84
85
        if (api_get_setting('youtube_for_students') == 'true') {
86
            $plugins[] = 'youtube';
87
        } else {
88
            if (api_is_allowed_to_edit() || api_is_platform_admin()) {
89
                $plugins[] = 'youtube';
90
            }
91
        }
92
93
        if (api_get_setting('enabled_googlemaps') == 'true') {
94
            $plugins[] = 'leaflet';
95
        }
96
97
        if (api_get_setting('math_asciimathML') == 'true') {
98
            $plugins[] = 'asciimath';
99
        }
100
101
        if (api_get_setting('enabled_mathjax') == 'true') {
102
            $plugins[] = 'mathjax';
103
            $config['mathJaxLib'] = api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML';
104
        }
105
106
        if (api_get_setting('enabled_asciisvg') == 'true') {
107
            $plugins[] = 'asciisvg';
108
        }
109
110
        if (api_get_setting('enabled_wiris') == 'true') {
111
            // Commercial plugin
112
            $plugins[] = 'ckeditor_wiris';
113
        }
114
115
        if (api_get_setting('enabled_imgmap') == 'true') {
116
            $plugins[] = 'mapping';
117
        }
118
119
        /*if (api_get_setting('block_copy_paste_for_students') == 'true') {
120
            // Missing
121
        }*/
122
123
        if (api_get_setting('more_buttons_maximized_mode') == 'true') {
124
            $plugins[] = 'toolbarswitch';
125
        }
126
127
        if (api_get_setting('allow_spellcheck') == 'true') {
128
            $plugins[] = 'scayt';
129
        }
130
131
        $this->defaultPlugins = array_merge($this->defaultPlugins, $plugins);
132
        parent::__construct($toolbar, $config, $prefix);
133
    }
134
135
    /**
136
     * Get the toolbar config
137
     * @return array
138
     */
139
    public function getConfig()
140
    {
141
        $config = array();
142
        if (api_get_setting('more_buttons_maximized_mode') === 'true') {
143
            $config['toolbar_minToolbar'] = $this->getMinimizedToolbar();
144
145
            $config['toolbar_maxToolbar'] = $this->getMaximizedToolbar();
146
        }
147
148
        $config['customConfig'] = api_get_path(WEB_LIBRARY_PATH).'javascript/ckeditor/config_js.php';
149
        $config['flash_flvPlayer'] = api_get_path(REL_PATH).'web/assets/ckeditor/plugins/flash/swf/player.swf';
150
151
        /*filebrowserFlashBrowseUrl
152
        filebrowserFlashUploadUrl
153
        filebrowserImageBrowseLinkUrl
154
        filebrowserImageBrowseUrl
155
        filebrowserImageUploadUrl
156
        filebrowserUploadUrl*/
157
158
        $config['extraPlugins'] = $this->getPluginsToString();
159
160
        //$config['oembed_maxWidth'] = '560';
161
        //$config['oembed_maxHeight'] = '315';
162
163
        /*$config['wordcount'] = array(
164
            // Whether or not you want to show the Word Count
165
            'showWordCount' => true,
166
            // Whether or not you want to show the Char Count
167
            'showCharCount' => true,
168
            // Option to limit the characters in the Editor
169
            'charLimit' => 'unlimited',
170
            // Option to limit the words in the Editor
171
            'wordLimit' => 'unlimited'
172
        );*/
173
174
        //$config['skins'] = 'moono';
175
176 View Code Duplication
        if (isset($this->config)) {
177
            $this->config = array_merge($config, $this->config);
178
        } else {
179
            $this->config = $config;
180
        }
181
182
        //$config['width'] = '100';
183
        //$config['height'] = '200';
184
        return $this->config;
185
    }
186
187
    /**
188
     * Get the default toolbar configuration when the setting more_buttons_maximized_mode is false
189
     * @return array
190
     */
191
    protected function getNormalToolbar()
192
    {
193
        return null;
194
    }
195
196
    /**
197
     * Get the toolbar configuration when CKEditor is minimized
198
     * @return array
199
     */
200
    protected function getMinimizedToolbar()
201
    {
202
        return [
203
            ['Save', 'NewPage', 'Templates', '-', 'PasteFromWord'],
204
            ['Undo', 'Redo'],
205
            ['Link', 'Image', 'Video', 'Flash', 'Youtube', 'Audio', 'Table', 'Asciimath', 'Asciisvg'],
206
            ['BulletedList', 'NumberedList', 'HorizontalRule'],
207
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
208
            ['Format', 'Font', 'FontSize', 'Bold', 'Italic', 'Underline', 'TextColor', 'BGColor', 'Source'],
209
            api_get_setting('enabled_wiris') == 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
210
            ['Toolbarswitch']
211
        ];
212
    }
213
214
    /**
215
     * Get the toolbar configuration when CKEditor is maximized
216
     * @return array
217
     */
218 View Code Duplication
    protected function getMaximizedToolbar()
219
    {
220
        return [
221
            ['Save', 'NewPage', 'Templates', '-', 'Preview', 'Print'],
222
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
223
            ['Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'],
224
            ['Link', 'Unlink', 'Anchor', 'Glossary'],
225
            [
226
                'Image',
227
                'Mapping',
228
                'Video',
229
                'Oembed',
230
                'Flash',
231
                'Youtube',
232
                'Audio',
233
                'leaflet',
234
                'Smiley',
235
                'SpecialChar',
236
                'Asciimath',
237
                'Asciisvg'
238
            ],
239
            '/',
240
            ['Table', '-', 'CreateDiv'],
241
            ['BulletedList', 'NumberedList', 'HorizontalRule', '-', 'Outdent', 'Indent', 'Blockquote'],
242
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
243
            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'TextColor', 'BGColor'],
244
            [api_get_setting('allow_spellcheck') == 'true' ? 'Scayt' : ''],
245
            ['Styles', 'Format', 'Font', 'FontSize'],
246
            ['PageBreak', 'ShowBlocks', 'Source'],
247
            api_get_setting('enabled_wiris') == 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
248
            ['Toolbarswitch'],
249
        ];
250
    }
251
252
}
253