Passed
Branch master (f2d2e3)
by Michael
18:45
created

XoopsFormCodemirror3::render()   F

Complexity

Conditions 62
Paths 12960

Size

Total Lines 247
Code Lines 206

Duplication

Lines 0
Ratio 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A codemirror_filesList() 0 3 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
    var $rootpath;
29
    var $config = array();
30
    var $setting = array();
31
    var $language = _LANGCODE;
32
    var $width = '100%';
33
    var $height = '300px';
34
    var $syntax = 'txt'; // default
35
    var $mode = null; // default
36
    
37
    /**
38
     * Constructor
39
     *
40
     * @param    array   $configs  Editor Options
41
     */
42
    function __construct($configs, $mode)
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...
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
    function setConfig( $config )
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...
53
    {
54
        foreach ($config as $key => $val) {
55
            $this->config[$key] = $val;
56
        }
57
    }
58
59
    function getName()
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...
60
    {
61
        return $this->name;
62
    }
63
64
    function setName($value)
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...
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
    function getWidth()
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...
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
    function getHeight()
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...
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
    function renderValidationJS()
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...
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
    function renderGetContentJS()
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...
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
    function getLanguage()
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...
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
    function getValue() {
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...
149
        //return strtr(htmlspecialchars_decode($this->_value) , array("\n" => '<br />', "\r\n" =>'<br />'));
150
        return $this->_value;
151
    }
152
153
    /**
154
     * prepare HTML for output
155
     *
156
     * @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...
157
     * @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...
158
     */
159
    function render($decode = true) {
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...
160
        static $isCodemirror3JsLoaded;
161
        
162
        $ret = '';
163
        if ( is_object($GLOBALS['xoopsModule']) )
164
            $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...
165
        else
166
            $dirname = 'system';
167
            
168
        // Load common stuff only once
169
        if ( !$isCodemirror3JsLoaded ) {
170
            // CodeMirror custom css
171
            $css = ".CodeMirror {border: none;}\n";
172
            $css.= ".CodeMirror {height: 100%;}\n";
173
            $css.= ".CodeMirror {width: 100%;}\n";
174
            $css.= ".CodeMirror-gutters {background-color: #F0F0EE;}\n";
175
            $css.= ".CodeMirror-scroll {overflow-y: hidden; overflow-x: auto;}\n";
176
            $css.= ".CodeMirror-activeline-background {background: #e8f2ff !important;}\n"; // Highlighting the current line
177
            $css.= ".cm-tab {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAYAAAAkuj5RAAAAAXNSR0IArs4c6QAAAGFJREFUSMft1LsRQFAQheHPowAKoACx3IgEKtaEHujDjORSgWTH/ZOdnZOcM/sgk/kFFWY0qV8foQwS4MKBCS3qR6ixBJvElOobYAtivseIE120FaowJPN75GMu8j/LfMwNjh4HUpwg4LUAAAAASUVORK5CYII=); background-position: right; background-repeat: no-repeat;}\n"; // Visible tabs
178
            $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";
179
            // Get available codemirror themes
180
            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...
181
                foreach(array_diff(scandir($d), array('.', '..')) as $f) if (is_file($d . '/' . $f) && (($x) ? preg_match('/' . $x . '$/' , $f) : 1)) $l[] = $f;
0 ignored issues
show
Bug introduced by
It seems like scandir($d) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

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