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