XoopsFormCodemirror3::render()   F
last analyzed

Complexity

Conditions 62
Paths 12960

Size

Total Lines 263
Code Lines 212

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 62
eloc 212
c 1
b 0
f 0
nc 12960
nop 1
dl 0
loc 263
rs 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A codemirror_filesList() 0 8 5

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
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 *  CodeMirror3 adapter for XOOPS
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @package         class
18
 * @subpackage      editor
19
 * @since           2.5.7
20
 * @author          Rota Lucio <[email protected]>
21
 * @version         $Id$
22
 */
23
24
xoops_load('XoopsEditor');
25
26
class XoopsFormCodemirror3 extends XoopsEditor
27
{
28
    public $rootpath;
29
    public $config   = [];
30
    public $setting  = [];
31
    public $language = _LANGCODE;
32
    public $width    = '100%';
33
    public $height   = '300px';
34
    public $syntax   = 'txt'; // default
35
    public $mode     = null; // default
36
37
    /**
38
     * Constructor
39
     *
40
     * @param array $configs Editor Options
41
     */
42
    public function __construct($configs, $mode)
43
    {
44
        $this->rootPath = '/class/xoopseditor/codemirror3';
45
        parent::__construct($configs);
46
        $this->width  = isset($this->configs['width']) ? $this->configs['width'] : $this->width;
47
        $this->height = isset($this->configs['height']) ? $this->configs['height'] : $this->height;
48
        $this->syntax = isset($this->configs['syntax']) ? $this->configs['syntax'] : $this->syntax;
49
        $this->mode   = $mode;
50
    }
51
52
    public function setConfig($config)
53
    {
54
        foreach ($config as $key => $val) {
55
            $this->config[$key] = $val;
56
        }
57
    }
58
59
    public function getName()
60
    {
61
        return $this->name;
62
    }
63
64
    public function setName($value)
65
    {
66
        $this->name = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
67
    }
68
69
    /**
70
     * get textarea width
71
     *
72
     * @return  string
73
     */
74
    public function getWidth()
75
    {
76
        return $this->width;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->width also could return the type mixed which is incompatible with the documented return type string.
Loading history...
77
    }
78
79
    /**
80
     * get textarea height
81
     *
82
     * @return  string
83
     */
84
    public function getHeight()
85
    {
86
        return $this->height;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->height also could return the type mixed which is incompatible with the documented return type string.
Loading history...
87
    }
88
89
    /**
90
     * Renders the Javascript function needed for client-side for validation
91
     *
92
     * @return    string
93
     */
94
    public function renderValidationJS()
95
    {
96
        if ($this->isRequired() && $eltname = $this->getName()) {
97
            //$eltname = $this->getName();
98
            $eltcaption = $this->getCaption();
99
            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
100
            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
101
            $ret        = "\n";
102
            $ret        .= "if ( window.codemirror3_editor['{$eltname}'].getValue() == \"\" || window.codemirror3_editor['{$eltname}'].getValue() == null) ";
103
            $ret        .= "{ window.alert(\"{$eltmsg}\"); window.codemirror3_editor['{$eltname}'].focus(); return false; }";
104
            return $ret;
105
        }
106
        return '';
107
    }
108
109
    /**
110
     * Renders the Javascript function needed for client-side for get content
111
     *
112
     * @return    string
113
     */
114
    public function renderGetContentJS()
115
    {
116
        if ($eltname = $this->getName()) {
117
            $ret = "window.codemirror3_editor['{$eltname}'].getValue()";
118
            return $ret;
119
        }
120
        return '';
121
    }
122
123
    /**
124
     * get language
125
     *
126
     * @return    string
127
     */
128
    public function getLanguage()
129
    {
130
        if ($this->language) {
131
            return $this->language;
132
        }
133
        if (defined('_XOOPS_EDITOR_CODEMIRROR3_LANGUAGE')) {
134
            $this->language = strtolower(constant('_XOOPS_EDITOR_CODEMIRROR3_LANGUAGE'));
135
        } else {
136
            $this->language = str_replace('_', '-', strtolower(_LANGCODE));
137
        }
138
139
        return $this->language;
140
    }
141
142
    /**
143
     * Get initial content
144
     *
145
     * @param bool $encode To sanitizer the text? Default value should be "true"; however we have to set "false" for backward compat
146
     * @return        string
147
     */
148
    public function getValue()
149
    {
150
        //return strtr(htmlspecialchars_decode($this->_value) , array("\n" => '<br />', "\r\n" =>'<br />'));
151
        return $this->_value;
152
    }
153
154
    /**
155
     * prepare HTML for output
156
     *
157
     * @param bool    decode content?
0 ignored issues
show
Bug introduced by
The type decode was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
158
     * @return  sting HTML
0 ignored issues
show
Bug introduced by
The type sting was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
159
     */
160
    public function render($decode = true)
161
    {
162
        static $isCodemirror3JsLoaded;
163
164
        $ret = '';
165
        if (is_object($GLOBALS['xoopsModule'])) {
166
            $dirname = $GLOBALS['xoopsModule']->getVar('dirname');
0 ignored issues
show
Unused Code introduced by
The assignment to $dirname is dead and can be removed.
Loading history...
167
        } else {
168
            $dirname = 'system';
169
        }
170
171
        // Load common stuff only once
172
        if (!$isCodemirror3JsLoaded) {
173
            // CodeMirror custom css
174
            $css = ".CodeMirror {border: none;}\n";
175
            $css .= ".CodeMirror {height: 100%;}\n";
176
            $css .= ".CodeMirror {width: 100%;}\n";
177
            $css .= ".CodeMirror-gutters {background-color: #F0F0EE;}\n";
178
            $css .= ".CodeMirror-scroll {overflow-y: hidden; overflow-x: auto;}\n";
179
            $css .= ".CodeMirror-activeline-background {background: #e8f2ff !important;}\n"; // Highlighting the current line
180
            $css .= ".cm-tab {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAYAAAAkuj5RAAAAAXNSR0IArs4c6QAAAGFJREFUSMft1LsRQFAQheHPowAKoACx3IgEKtaEHujDjORSgWTH/ZOdnZOcM/sgk/kFFWY0qV8foQwS4MKBCS3qR6ixBJvElOobYAtivseIE120FaowJPN75GMu8j/LfMwNjh4HUpwg4LUAAAAASUVORK5CYII=); background-position: right; background-repeat: no-repeat;}\n"; // Visible tabs
181
            $css .= ".CodeMirror-foldmarker {color: blue; text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px; font-family: arial;}\n";
182
            // Get available codemirror themes
183
            function codemirror_filesList($d, $x)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
184
            {
185
                foreach (array_diff(scandir($d), ['.', '..']) as $f) {
186
                    if (is_file($d . '/' . $f) && (($x) ? preg_match('/' . $x . '$/', $f) : 1)) {
187
                        $l[] = $f;
188
                    }
189
                }
190
                return $l;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $l does not seem to be defined for all execution paths leading up to this point.
Loading history...
191
            }
192
193
            $themes = codemirror_filesList(XOOPS_ROOT_PATH . '/class/xoopseditor/codemirror3/codemirror/theme', '.css');
194
            // Generate no common html/javascript/stylesheet
195
            if (is_object($GLOBALS['xoTheme'])) {
196
                // uses $GLOBALS['xoTheme']
197
                // CodeMirror stuff
198
                $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/lib/codemirror.css');
199
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/lib/codemirror.js');
200
                $GLOBALS['xoTheme']->addStylesheet(null, null, $css);
201
                // CodeMirror addons
202
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/selection/active-line.js');
203
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/fold/foldcode.js');
204
                $GLOBALS['xoTheme']->addScript(null, null, 'var foldFunc = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder);');
205
                $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/display/fullscreen.css');
206
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/display/fullscreen.js');
207
                // Automatic xml tag closing
208
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/edit/closetag.js');
209
                // Automatic match brakets
210
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/addon/edit/matchbrackets.js');
211
                // CodeMirror themes
212
                foreach ($themes as $theme) {
213
                    $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/theme/' . $theme);
214
                }
215
                // CodeMirror modes
216
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/xml/xml.js');
217
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/javascript/javascript.js');
218
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/css/css.js');
219
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/less/less.js');
220
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/vbscript/vbscript.js');
221
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/htmlmixed/htmlmixed.js');
222
                $GLOBALS['xoTheme']->addScript(
223
                    null,
224
                    null,
225
                    "var mixedMode = {name: 'htmlmixed', scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: 'vbscript'}]};"
226
                ); // Define an extended mixed-mode that understands vbscript and leaves mustache/handlebars embedded templates in html mode
227
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/smarty/smarty.js');
228
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/smartymixed/smartymixed.js');
229
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/clike/clike.js');
230
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/plsql/plsql.js');
231
                $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/mode/php/php.js');
232
                // Initialize arrays for multiple CodeMirror istances
233
                $GLOBALS['xoTheme']->addScript(null, null, 'var codemirror3_editor = new Array();');
234
                $GLOBALS['xoTheme']->addScript(null, null, 'var codemirror3_textarea = new Array();');
235
                $GLOBALS['xoTheme']->addScript(null, null, 'var codemirror3_uiOptions = new Array();');
236
                $GLOBALS['xoTheme']->addScript(null, null, 'var codemirror3_codeMirrorOptions = new Array();');
237
            } else {
238
                // does not use $GLOBALS['xoTheme']
239
                // CodeMirror stuff
240
                $ret .= "<style type='text/css'>@import url(" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/lib/codemirror.css);</style>\n";
241
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/lib/codemirror.js' type='text/javascript'></script>\n";
242
                $ret .= "<style type='text/css'>\n" . $css . "</style>\n";
243
                // CodeMirror addons
244
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/selection/active-line.js' type='text/javascript'></script>\n";
245
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/fold/foldcode.js' type='text/javascript'></script>\n";
246
                $ret .= "<script type='text/javascript'>var foldFunc = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder);</script>\n";
247
                $ret .= "<style type='text/css'>@import url(" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/display/fullscreen.css);</style>\n";
248
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/display/fullscreen.js' type='text/javascript'></script>\n";
249
                // Automatic xml tag closing
250
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/edit/closetag.js' type='text/javascript'></script>\n";
251
                // Automatic match brakets
252
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/addon/edit/matchbrackets.js' type='text/javascript'></script>\n";
253
                // CodeMirror themes
254
                foreach ($themes as $theme) {
255
                    $ret .= "<style type='text/css'>@import url(" . XOOPS_URL . '/class/xoopseditor/codemirror3/codemirror/theme/' . $theme . ");</style>\n";
256
                }
257
                // CodeMirror modes
258
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/xml/xml.js' type='text/javascript'></script>\n";
259
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/javascript/javascript.js' type='text/javascript'></script>\n";
260
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/css/css.js' type='text/javascript'></script>\n";
261
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/less/less.js' type='text/javascript'></script>\n";
262
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/vbscript/vbscript.js' type='text/javascript'></script>\n";
263
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/htmlmixed/htmlmixed.js' type='text/javascript'></script>\n";
264
                $ret .= "<script type='text/javascript'>var mixedMode = {name: 'htmlmixed', scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: 'vbscript'}]};</script>\n"; // Define an extended mixed-mode that understands vbscript and leaves mustache/handlebars embedded templates in html mode
265
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/smarty/smarty.js' type='text/javascript'></script>\n";
266
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/smartymixed/smartymixed.js' type='text/javascript'></script>\n";
267
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/clike/clike.js' type='text/javascript'></script>\n";
268
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/plsql/plsql.js' type='text/javascript'></script>\n";
269
                $ret .= "<script src='" . XOOPS_URL . "/class/xoopseditor/codemirror3/codemirror/mode/php/php.js' type='text/javascript'></script>\n";
270
                // Initialize arrays for multiple CodeMirror istances
271
                $ret .= "<script type='text/javascript'>\n";
272
                $ret .= "var codemirror3_editor = new Array();\n";
273
                $ret .= "var codemirror3_textarea = new Array();\n";
274
                $ret .= "var codemirror3_uiOptions = new Array();\n";
275
                $ret .= "var codemirror3_codeMirrorOptions = new Array();\n";
276
                $ret .= "</script>\n";
277
            }
278
            $isCodemirror3JsLoaded = true;
279
        }
280
281
        // Set no common settings
282
        if ($decode) {
283
            $ts    = MyTextSanitizer::getInstance();
284
            $value = $ts->undoHtmlSpecialChars($this->getValue());
0 ignored issues
show
Unused Code introduced by
The assignment to $value is dead and can be removed.
Loading history...
285
        } else {
286
            $value = $this->getValue();
287
        }
288
        $mode = (isset($this->mode) ? $this->mode : $this->syntax);
289
        switch ($mode) {
290
            case 'txt' :
291
            case 'text/plain' :
292
                $this->setting['mode'] = 'text/plain';
293
                break;
294
            case 'htm' :
295
            case 'html' :
296
            case 'htmlmixed' :
297
            case 'text/html' :
298
            case 'xhtml' :
299
            case 'application/xhtml+xml' :
300
                $this->setting['mode'] = 'text/html';
301
                break;
302
            case 'php' :
303
            case 'text/php' :
304
            case 'text/x-php' :
305
            case 'application/php' :
306
            case 'application/x-php' :
307
            case 'application/x-httpd-php' :
308
            case 'application/x-httpd-php-source' :
309
                $this->setting['mode'] = 'php';
310
                break;
311
            case 'css' :
312
            case 'text/css' :
313
                $this->setting['mode'] = 'css';
314
                break;
315
            case 'less' :
316
            case 'text/less' :
317
                $this->setting['mode'] = 'less';
318
                break;
319
            case 'js' :
320
            case 'javascript' :
321
            case 'text/javascript' :
322
            case 'text/ecmascript' :
323
            case 'application/javascript' :
324
            case 'application/ecmascript' :
325
            case 'application/x-javascript' :
326
            case 'application/json' :
327
            case 'text/typescript' :
328
            case 'application/typescript' :
329
                $this->setting['mode'] = 'javascript';
330
                break;
331
            case 'json' :
332
            case 'application/json' :
333
                $this->setting['mode'] = 'application/json';
334
                break;
335
            case 'smarty' :
336
            case 'smartymixed' :
337
            case 'text/x-smarty' :
338
                $this->setting['mode']           = 'smartymixed';//'smarty';
339
                $this->setting['smartyVersion']  = (int)3;
340
                $this->setting['leftDelimiter']  = '<{';
341
                $this->setting['rightDelimiter'] = '}>';
342
                break;
343
            case 'mysql' :
344
            case 'text/x-mysql' :
345
            case 'text/x-mariadb' :
346
            case 'sql' :
347
            case 'text/x-plsql' :
348
                $this->setting['mode'] = $mode;
349
                break;
350
            case 'xml' :
351
            case 'text/xml' :
352
            case 'application/xml' :
353
                $this->setting['mode'] = '{name: "xml", alignCDATA: true}';
354
                break;
355
            case 'csv' :
356
            case 'text/csv' :
357
                $this->setting['mode'] = 'text/plain';
358
                break;
359
            default :
360
                break;
361
        }
362
        $this->setting['theme']           = 'eclipse';//'default';
363
        $this->setting['lineNumbers']     = true;
364
        $this->setting['firstLineNumber'] = (int)1;
365
        $this->setting['lineNumbers']     = true;
366
        $this->setting['lineWrapping']    = true;
367
        $this->setting['matchBrackets']   = true;
368
        // ??? $this->setting['autoMatchParens'] = true;
369
        $this->setting['indentUnit']     = (int)4;
370
        $this->setting['indentWithTabs'] = false;
371
        $this->setting['enterMode']      = 'keep';// ???
372
        $this->setting['tabMode']        = 'indent';//'shift'; ???
373
        $this->setting['readOnly']       = isset($this->configs['readonly']) ? $this->configs['readonly'] : false;
374
        // Visible tabs
375
        $this->setting['tabSize']        = (int)4;
376
        $this->setting['indentUnit']     = (int)4;
377
        $this->setting['indentWithTabs'] = true;
378
        // Highlighting the current line
379
        $this->setting['styleActiveLine'] = true;
380
        // Automatic xml tag closing
381
        $this->setting['autoCloseTags'] = true;
382
        // Extrakeys
383
        $this->setting['extraKeys'] = [
384
            '"Ctrl-Q": function(cm){foldFunc(cm, cm.getCursor().line);}',
385
            '"F11": function(cm) {cm.setOption("fullScreen", !cm.getOption("fullScreen"));}',
386
            '"Esc": function(cm) {if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);}'
387
        ];
388
389
        // Generate no common editor html/javascript
390
        $ret .= "<div style='height:{$this->getHeight()};width:{$this->getWidth()};border:1px solid #CCCCCC;'>";
391
        $ret .= "<textarea name='" . $this->getName() . "' id='" . $this->getName() . "' rows='" . $this->getRows() . "' cols='" . $this->getCols() . "' " . $this->getExtra() . " style='width:" . $this->getWidth() . ';height:' . $this->getHeight() . ";'>" . $this->getValue() . "</textarea>\n";
392
        $ret .= '</div>';
393
        $ret .= '<small>' . _XOOPS_EDITOR_CODEMIRROR3_MODE . ' ' . $this->setting['mode'] . '</small>';
394
        $ret .= '<br />';
395
        $ret .= '<small>' . _XOOPS_EDITOR_CODEMIRROR3_FULLSCREEN . '</small>';
396
        $ret .= "<script type='text/javascript'>\n";
397
        $ret .= "window.codemirror3_editor['" . $this->getName() . "'] = CodeMirror.fromTextArea(document.getElementById('" . $this->getName() . "'), {";
398
        $ret .= "\n";
399
        foreach ($this->setting as $key => $val) {
400
            $ret .= $key . ': ';
401
            if (true === $val) {
402
                $ret .= 'true,';
403
            } elseif (false === $val) {
404
                $ret .= 'false,';
405
            } elseif (is_array($val)) {
406
                $ret .= '{';
407
                foreach ($val as $valkey => $valval) {
408
                    $val[$valkey] = '' . $valval . '';
409
                }
410
                $ret .= implode(',', $val);
411
                $ret .= '},';
412
            } elseif (is_int($val)) {
413
                $ret .= "{$val},";
414
            } else {
415
                $ret .= "'{$val}',";
416
            }
417
            $ret .= "\n";
418
        }
419
        $ret .= "});\n";
420
        $ret .= "codemirror3_editor['" . $this->getName() . "'].on('gutterClick', foldFunc);\n";
421
        $ret .= "</script>\n";
422
        return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type string which is incompatible with the documented return type sting.
Loading history...
423
    }
424
}
425