| Conditions | 6 |
| Paths | 1600 |
| Total Lines | 149 |
| Code Lines | 104 |
| 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 |
||
| 82 | public function html() { |
||
| 83 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
| 84 | global $lang; |
||
| 85 | global $ID; |
||
| 86 | |||
| 87 | if (is_null($this->_config)) { $this->_config = new Configuration(self::METADATA); } |
||
| 88 | $this->setupLocale(true); |
||
| 89 | |||
| 90 | print $this->locale_xhtml('intro'); |
||
| 91 | |||
| 92 | ptln('<div id="config__manager">'); |
||
| 93 | |||
| 94 | if ($this->_config->locked) |
||
| 95 | ptln('<div class="info">'.$this->getLang('locked').'</div>'); |
||
| 96 | elseif ($this->_error) |
||
| 97 | ptln('<div class="error">'.$this->getLang('error').'</div>'); |
||
| 98 | elseif ($this->_changed) |
||
| 99 | ptln('<div class="success">'.$this->getLang('updated').'</div>'); |
||
| 100 | |||
| 101 | // POST to script() instead of wl($ID) so config manager still works if |
||
| 102 | // rewrite config is broken. Add $ID as hidden field to remember |
||
| 103 | // current ID in most cases. |
||
| 104 | ptln('<form action="'.script().'" method="post">'); |
||
| 105 | ptln('<div class="no"><input type="hidden" name="id" value="'.$ID.'" /></div>'); |
||
| 106 | formSecurityToken(); |
||
| 107 | $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
| 108 | |||
| 109 | /** @var setting[] $undefined_settings */ |
||
| 110 | $undefined_settings = array(); |
||
| 111 | $in_fieldset = false; |
||
| 112 | $first_plugin_fieldset = true; |
||
| 113 | $first_template_fieldset = true; |
||
| 114 | foreach($this->_config->setting as $setting) { |
||
| 115 | if (is_a($setting, 'setting_hidden')) { |
||
| 116 | // skip hidden (and undefined) settings |
||
| 117 | if ($allow_debug && is_a($setting, 'setting_undefined')) { |
||
| 118 | $undefined_settings[] = $setting; |
||
| 119 | } else { |
||
| 120 | continue; |
||
| 121 | } |
||
| 122 | } else if (is_a($setting, 'setting_fieldset')) { |
||
| 123 | // config setting group |
||
| 124 | if ($in_fieldset) { |
||
| 125 | ptln(' </table>'); |
||
| 126 | ptln(' </div>'); |
||
| 127 | ptln(' </fieldset>'); |
||
| 128 | } else { |
||
| 129 | $in_fieldset = true; |
||
| 130 | } |
||
| 131 | if ($first_plugin_fieldset && substr($setting->_key, 0, 10)=='plugin'.Configuration::KEYMARKER) { |
||
|
|
|||
| 132 | $this->_print_h1('plugin_settings', $this->getLang('_header_plugin')); |
||
| 133 | $first_plugin_fieldset = false; |
||
| 134 | } else if ($first_template_fieldset && substr($setting->_key, 0, 7)=='tpl'.Configuration::KEYMARKER) { |
||
| 135 | $this->_print_h1('template_settings', $this->getLang('_header_template')); |
||
| 136 | $first_template_fieldset = false; |
||
| 137 | } |
||
| 138 | ptln(' <fieldset id="'.$setting->_key.'">'); |
||
| 139 | ptln(' <legend>'.$setting->prompt($this).'</legend>'); |
||
| 140 | ptln(' <div class="table">'); |
||
| 141 | ptln(' <table class="inline">'); |
||
| 142 | } else { |
||
| 143 | // config settings |
||
| 144 | list($label,$input) = $setting->html($this, $this->_error); |
||
| 145 | |||
| 146 | $class = $setting->is_default() |
||
| 147 | ? ' class="default"' |
||
| 148 | : ($setting->is_protected() ? ' class="protected"' : ''); |
||
| 149 | $error = $setting->error() |
||
| 150 | ? ' class="value error"' |
||
| 151 | : ' class="value"'; |
||
| 152 | $icon = $setting->caution() |
||
| 153 | ? '<img src="'.self::IMGDIR.$setting->caution().'.png" '. |
||
| 154 | 'alt="'.$setting->caution().'" title="'.$this->getLang($setting->caution()).'" />' |
||
| 155 | : ''; |
||
| 156 | |||
| 157 | ptln(' <tr'.$class.'>'); |
||
| 158 | ptln(' <td class="label">'); |
||
| 159 | ptln(' <span class="outkey">'.$setting->_out_key(true, true).'</span>'); |
||
| 160 | ptln(' '.$icon.$label); |
||
| 161 | ptln(' </td>'); |
||
| 162 | ptln(' <td'.$error.'>'.$input.'</td>'); |
||
| 163 | ptln(' </tr>'); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | ptln(' </table>'); |
||
| 168 | ptln(' </div>'); |
||
| 169 | if ($in_fieldset) { |
||
| 170 | ptln(' </fieldset>'); |
||
| 171 | } |
||
| 172 | |||
| 173 | // show undefined settings list |
||
| 174 | if ($allow_debug && !empty($undefined_settings)) { |
||
| 175 | /** |
||
| 176 | * Callback for sorting settings |
||
| 177 | * |
||
| 178 | * @param setting $a |
||
| 179 | * @param setting $b |
||
| 180 | * @return int if $a is lower/equal/higher than $b |
||
| 181 | */ |
||
| 182 | function _setting_natural_comparison($a, $b) { |
||
| 183 | return strnatcmp($a->_key, $b->_key); |
||
| 184 | } |
||
| 185 | |||
| 186 | usort($undefined_settings, '_setting_natural_comparison'); |
||
| 187 | $this->_print_h1('undefined_settings', $this->getLang('_header_undefined')); |
||
| 188 | ptln('<fieldset>'); |
||
| 189 | ptln('<div class="table">'); |
||
| 190 | ptln('<table class="inline">'); |
||
| 191 | $undefined_setting_match = array(); |
||
| 192 | foreach($undefined_settings as $setting) { |
||
| 193 | if ( |
||
| 194 | preg_match( |
||
| 195 | '/^(?:plugin|tpl)'.Configuration::KEYMARKER.'.*?'.Configuration::KEYMARKER.'(.*)$/', |
||
| 196 | $setting->_key, |
||
| 197 | $undefined_setting_match |
||
| 198 | ) |
||
| 199 | ) { |
||
| 200 | $undefined_setting_key = $undefined_setting_match[1]; |
||
| 201 | } else { |
||
| 202 | $undefined_setting_key = $setting->_key; |
||
| 203 | } |
||
| 204 | ptln(' <tr>'); |
||
| 205 | ptln(' <td class="label"><span title="$meta[\''.$undefined_setting_key.'\']">$'. |
||
| 206 | $this->_config->_name.'[\''.$setting->_out_key().'\']</span></td>'); |
||
| 207 | ptln(' <td>'.$this->getLang('_msg_'.get_class($setting)).'</td>'); |
||
| 208 | ptln(' </tr>'); |
||
| 209 | } |
||
| 210 | ptln('</table>'); |
||
| 211 | ptln('</div>'); |
||
| 212 | ptln('</fieldset>'); |
||
| 213 | } |
||
| 214 | |||
| 215 | // finish up form |
||
| 216 | ptln('<p>'); |
||
| 217 | ptln(' <input type="hidden" name="do" value="admin" />'); |
||
| 218 | ptln(' <input type="hidden" name="page" value="config" />'); |
||
| 219 | |||
| 220 | if (!$this->_config->locked) { |
||
| 221 | ptln(' <input type="hidden" name="save" value="1" />'); |
||
| 222 | ptln(' <button type="submit" name="submit" accesskey="s">'.$lang['btn_save'].'</button>'); |
||
| 223 | ptln(' <button type="reset">'.$lang['btn_reset'].'</button>'); |
||
| 224 | } |
||
| 225 | |||
| 226 | ptln('</p>'); |
||
| 227 | |||
| 228 | ptln('</form>'); |
||
| 229 | ptln('</div>'); |
||
| 230 | } |
||
| 231 | |||
| 412 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.