| Conditions | 6 |
| Paths | 384 |
| Total Lines | 141 |
| Code Lines | 97 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 74 | public function html() { |
||
| 75 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
| 76 | global $lang; |
||
| 77 | global $ID; |
||
| 78 | |||
| 79 | $this->setupLocale(true); |
||
| 80 | |||
| 81 | echo $this->locale_xhtml('intro'); |
||
| 82 | |||
| 83 | echo '<div id="config__manager">'; |
||
| 84 | |||
| 85 | if($this->configuration->isLocked()) { |
||
| 86 | echo '<div class="info">' . $this->getLang('locked') . '</div>'; |
||
| 87 | } |
||
| 88 | |||
| 89 | // POST to script() instead of wl($ID) so config manager still works if |
||
| 90 | // rewrite config is broken. Add $ID as hidden field to remember |
||
| 91 | // current ID in most cases. |
||
| 92 | echo '<form action="' . script() . '" method="post">'; |
||
| 93 | echo '<div class="no"><input type="hidden" name="id" value="' . $ID . '" /></div>'; |
||
| 94 | formSecurityToken(); |
||
| 95 | $this->printH1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
| 96 | |||
| 97 | $in_fieldset = false; |
||
| 98 | $first_plugin_fieldset = true; |
||
| 99 | $first_template_fieldset = true; |
||
| 100 | foreach($this->configuration->getSettings() as $setting) { |
||
| 101 | if(is_a($setting, SettingHidden::class)) { |
||
| 102 | continue; |
||
| 103 | } else if(is_a($setting, settingFieldset::class)) { |
||
| 104 | // config setting group |
||
| 105 | if($in_fieldset) { |
||
| 106 | echo '</table>'; |
||
| 107 | echo '</div>'; |
||
| 108 | echo '</fieldset>'; |
||
| 109 | } else { |
||
| 110 | $in_fieldset = true; |
||
| 111 | } |
||
| 112 | // fixme this should probably be a function in setting: |
||
| 113 | if($first_plugin_fieldset && $setting->getType() == 'plugin') { |
||
| 114 | $this->printH1('plugin_settings', $this->getLang('_header_plugin')); |
||
| 115 | $first_plugin_fieldset = false; |
||
| 116 | } else if($first_template_fieldset && $setting->getType() == 'template') { |
||
| 117 | $this->printH1('template_settings', $this->getLang('_header_template')); |
||
| 118 | $first_template_fieldset = false; |
||
| 119 | } |
||
| 120 | echo '<fieldset id="' . $setting->getKey() . '">'; |
||
| 121 | echo '<legend>' . $setting->prompt($this) . '</legend>'; |
||
| 122 | echo '<div class="table">'; |
||
| 123 | echo '<table class="inline">'; |
||
| 124 | } else { |
||
| 125 | // config settings |
||
| 126 | list($label, $input) = $setting->html($this, $this->hasErrors); |
||
| 127 | |||
| 128 | $class = $setting->isDefault() |
||
| 129 | ? ' class="default"' |
||
| 130 | : ($setting->isProtected() ? ' class="protected"' : ''); |
||
| 131 | $error = $setting->hasError() |
||
| 132 | ? ' class="value error"' |
||
| 133 | : ' class="value"'; |
||
| 134 | $icon = $setting->caution() |
||
| 135 | ? '<img src="' . self::IMGDIR . $setting->caution() . '.png" ' . |
||
| 136 | 'alt="' . $setting->caution() . '" title="' . $this->getLang($setting->caution()) . '" />' |
||
| 137 | : ''; |
||
| 138 | |||
| 139 | echo '<tr' . $class . '>'; |
||
| 140 | echo '<td class="label">'; |
||
| 141 | echo '<span class="outkey">' . $setting->getPrettyKey() . '</span>'; |
||
| 142 | echo $icon . $label; |
||
| 143 | echo '</td>'; |
||
| 144 | echo '<td' . $error . '>' . $input . '</td>'; |
||
| 145 | echo '</tr>'; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | echo '</table>'; |
||
| 150 | echo '</div>'; |
||
| 151 | if($in_fieldset) { |
||
| 152 | echo '</fieldset>'; |
||
| 153 | } |
||
| 154 | |||
| 155 | // show undefined settings list |
||
| 156 | $undefined_settings = $this->configuration->getUndefined(); |
||
| 157 | if($allow_debug && !empty($undefined_settings)) { |
||
| 158 | /** |
||
| 159 | * Callback for sorting settings |
||
| 160 | * |
||
| 161 | * @param Setting $a |
||
| 162 | * @param Setting $b |
||
| 163 | * @return int if $a is lower/equal/higher than $b |
||
| 164 | */ |
||
| 165 | function settingNaturalComparison($a, $b) { |
||
| 166 | return strnatcmp($a->getKey(), $b->getKey()); |
||
| 167 | } |
||
| 168 | |||
| 169 | usort($undefined_settings, 'settingNaturalComparison'); |
||
| 170 | $this->printH1('undefined_settings', $this->getLang('_header_undefined')); |
||
| 171 | echo '<fieldset>'; |
||
| 172 | echo '<div class="table">'; |
||
| 173 | echo '<table class="inline">'; |
||
| 174 | $undefined_setting_match = array(); |
||
| 175 | foreach($undefined_settings as $setting) { |
||
| 176 | if( |
||
| 177 | preg_match( |
||
| 178 | '/^(?:plugin|tpl)' . Configuration::KEYMARKER . '.*?' . Configuration::KEYMARKER . '(.*)$/', |
||
| 179 | $setting->getKey(), |
||
| 180 | $undefined_setting_match |
||
| 181 | ) |
||
| 182 | ) { |
||
| 183 | $undefined_setting_key = $undefined_setting_match[1]; |
||
| 184 | } else { |
||
| 185 | $undefined_setting_key = $setting->getKey(); |
||
| 186 | } |
||
| 187 | echo '<tr>'; |
||
| 188 | echo |
||
| 189 | '<td class="label"><span title="$meta[\'' . $undefined_setting_key . '\']">$' . |
||
| 190 | 'conf' . '[\'' . $setting->getArrayKey() . '\']</span></td>'; |
||
| 191 | echo '<td>' . $this->getLang('_msg_' . get_class($setting)) . '</td>'; |
||
| 192 | echo '</tr>'; |
||
| 193 | } |
||
| 194 | echo '</table>'; |
||
| 195 | echo '</div>'; |
||
| 196 | echo '</fieldset>'; |
||
| 197 | } |
||
| 198 | |||
| 199 | // finish up form |
||
| 200 | echo '<p>'; |
||
| 201 | echo '<input type="hidden" name="do" value="admin" />'; |
||
| 202 | echo '<input type="hidden" name="page" value="config" />'; |
||
| 203 | |||
| 204 | if(!$this->configuration->isLocked()) { |
||
| 205 | echo '<input type="hidden" name="save" value="1" />'; |
||
| 206 | echo '<button type="submit" name="submit" accesskey="s">' . $lang['btn_save'] . '</button>'; |
||
| 207 | echo '<button type="reset">' . $lang['btn_reset'] . '</button>'; |
||
| 208 | } |
||
| 209 | |||
| 210 | echo '</p>'; |
||
| 211 | |||
| 212 | echo '</form>'; |
||
| 213 | echo '</div>'; |
||
| 214 | } |
||
| 215 | |||
| 300 |