| Conditions | 62 |
| Paths | 12960 |
| Total Lines | 247 |
| Code Lines | 206 |
| 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 |
||
| 159 | function render($decode = true) { |
||
| 160 | static $isCodemirror3JsLoaded; |
||
| 161 | |||
| 162 | $ret = ''; |
||
| 163 | if ( is_object($GLOBALS['xoopsModule']) ) |
||
| 164 | $dirname = $GLOBALS['xoopsModule']->getVar('dirname'); |
||
| 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){ |
||
| 181 | foreach(array_diff(scandir($d), array('.', '..')) as $f) if (is_file($d . '/' . $f) && (($x) ? preg_match('/' . $x . '$/' , $f) : 1)) $l[] = $f; |
||
| 182 | return $l; |
||
| 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() ); |
||
| 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; |
||
| 406 | } |
||
| 408 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.