Conditions | 62 |
Paths | 12960 |
Total Lines | 263 |
Code Lines | 212 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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'); |
||
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) |
||
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; |
||
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()); |
||
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; |
||
423 | } |
||
425 |