| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 135 |
| Code Lines | 82 |
| 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 |
||
| 63 | public function init() |
||
| 64 | { |
||
| 65 | // list of configured options |
||
| 66 | $configured = []; |
||
| 67 | |||
| 68 | // Load default settings |
||
| 69 | if (!($this->setting = @include($GLOBALS['xoops']->path('var/configs/tinymce.php')))) { |
||
| 70 | $this->setting = include dirname(__FILE__) . '/settings.php'; |
||
| 71 | } |
||
| 72 | |||
| 73 | // get editor language (from ...) |
||
| 74 | if (is_readable(XOOPS_ROOT_PATH . $this->rootpath . '/langs/' . $this->config['language'] . '.js')) { |
||
| 75 | $this->setting['language'] = $this->config['language']; |
||
| 76 | $configured[] = 'language'; |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->setting['content_css'] = implode(',', $this->loadCss()); |
||
| 80 | $configured[] = 'content_css'; |
||
| 81 | |||
| 82 | if (!empty($this->config['theme']) && is_dir(XOOPS_ROOT_PATH . $this->rootpath . '/themes/' . $this->config['theme'])) { |
||
| 83 | $this->setting['theme'] = $this->config['theme']; |
||
| 84 | $configured[] = 'theme'; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!empty($this->config['mode'])) { |
||
| 88 | $this->setting['mode'] = $this->config['mode']; |
||
| 89 | $configured[] = 'mode'; |
||
| 90 | } |
||
| 91 | |||
| 92 | // load all plugins except the plugins in setting["exclude_plugins"] |
||
| 93 | $this->setting['plugins'] = implode(',', $this->loadPlugins()); |
||
| 94 | $configured[] = 'plugins'; |
||
| 95 | |||
| 96 | if ('simple' != $this->setting['theme']) { |
||
| 97 | if (empty($this->config['buttons'])) { |
||
| 98 | $this->config['buttons'][] = [ |
||
| 99 | 'before' => '', |
||
| 100 | 'add' => '', |
||
| 101 | ]; |
||
| 102 | $this->config['buttons'][] = [ |
||
| 103 | 'before' => '', |
||
| 104 | 'add' => '', |
||
| 105 | ]; |
||
| 106 | $this->config['buttons'][] = [ |
||
| 107 | 'before' => '', |
||
| 108 | 'add' => '', |
||
| 109 | ]; |
||
| 110 | } |
||
| 111 | $i = 0; |
||
| 112 | foreach ($this->config['buttons'] as $button) { |
||
| 113 | $i++; |
||
| 114 | if (isset($button['before'])) { |
||
| 115 | $this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}_add_before"] = $button['before']; |
||
| 116 | } |
||
| 117 | if (isset($button['add'])) { |
||
| 118 | $this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}_add"] = $button['add']; |
||
| 119 | } |
||
| 120 | if (isset($button[''])) { |
||
| 121 | $this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}"] = $button['']; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | $configured[] = 'buttons'; |
||
| 125 | |||
| 126 | if (isset($this->config['toolbar_location'])) { |
||
| 127 | $this->setting['theme_' . $this->setting['theme'] . '_toolbar_location'] = $this->config['toolbar_location']; |
||
| 128 | $configured[] = 'toolbar_location'; |
||
| 129 | } else { |
||
| 130 | $this->setting['theme_' . $this->setting['theme'] . '_toolbar_location'] = 'top'; |
||
| 131 | } |
||
| 132 | |||
| 133 | if (isset($this->config['toolbar_align'])) { |
||
| 134 | $this->setting['theme_' . $this->setting['theme'] . '_toolbar_align'] = $this->config['toolbar_align']; |
||
| 135 | $configured[] = 'toolbar_align'; |
||
| 136 | } else { |
||
| 137 | $this->setting['theme_' . $this->setting['theme'] . '_toolbar_align'] = 'left'; |
||
| 138 | } |
||
| 139 | |||
| 140 | if (isset($this->config['statusbar_location'])) { |
||
| 141 | $this->setting['theme_' . $this->setting['theme'] . '_statusbar_location'] = $this->config['statusbar_location']; |
||
| 142 | $configured[] = 'statusbar_location'; |
||
| 143 | } |
||
| 144 | |||
| 145 | if (isset($this->config['path_location'])) { |
||
| 146 | $this->setting['theme_' . $this->setting['theme'] . '_path_location'] = $this->config['path_location']; |
||
| 147 | $configured[] = 'path_location'; |
||
| 148 | } |
||
| 149 | |||
| 150 | if (isset($this->config['resize_horizontal'])) { |
||
| 151 | $this->setting['theme_' . $this->setting['theme'] . '_resize_horizontal'] = $this->config['resize_horizontal']; |
||
| 152 | $configured[] = 'resize_horizontal'; |
||
| 153 | } |
||
| 154 | |||
| 155 | if (isset($this->config['resizing'])) { |
||
| 156 | $this->setting['theme_' . $this->setting['theme'] . '_resizing'] = $this->config['resizing']; |
||
| 157 | $configured[] = 'resizing'; |
||
| 158 | } |
||
| 159 | |||
| 160 | if (!empty($this->config['fonts'])) { |
||
| 161 | $this->setting['theme_' . $this->setting['theme'] . '_fonts'] = $this->config['fonts']; |
||
| 162 | $configured[] = 'fonts'; |
||
| 163 | } |
||
| 164 | |||
| 165 | for ($i = 1; $i <= 4; $i++) { |
||
| 166 | $buttons = []; |
||
| 167 | if (isset($this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}"])) { |
||
| 168 | $checklist = explode(',', $this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}"]); |
||
| 169 | foreach ($checklist as $plugin) { |
||
| 170 | if (false != strpos(strtolower($plugin), 'xoops')) { |
||
| 171 | if (in_array($plugin, $this->xoopsPlugins)) { |
||
| 172 | $buttons[] = $plugin; |
||
| 173 | } |
||
| 174 | } else { |
||
| 175 | $buttons[] = $plugin; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | $this->setting['theme_' . $this->setting['theme'] . "_buttons{$i}"] = implode(',', $buttons); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | $configured = array_unique($configured); |
||
| 184 | foreach ($this->config as $key => $val) { |
||
| 185 | if (isset($this->setting[$key]) || in_array($key, $configured)) { |
||
| 186 | continue; |
||
| 187 | } |
||
| 188 | $this->setting[$key] = $val; |
||
| 189 | } |
||
| 190 | |||
| 191 | if (!is_dir(XOOPS_ROOT_PATH . $this->rootpath . '/themes/' . $this->setting['theme'] . '/docs/' . $this->setting['language'] . '/')) { |
||
| 192 | $this->setting['docs_language'] = 'en'; |
||
| 193 | } |
||
| 194 | |||
| 195 | unset($this->config, $configured); |
||
| 196 | |||
| 197 | return true; |
||
| 198 | } |
||
| 342 |