Conditions | 6 |
Paths | 384 |
Total Lines | 142 |
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 | print $this->locale_xhtml('intro'); |
||
82 | |||
83 | ptln('<div id="config__manager">'); |
||
84 | |||
85 | if($this->configuration->isLocked()) { |
||
86 | ptln('<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 | ptln('<form action="' . script() . '" method="post">'); |
||
93 | ptln('<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 | ptln(' </table>'); |
||
107 | ptln(' </div>'); |
||
108 | ptln(' </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 | ptln(' <fieldset id="' . $setting->getKey() . '">'); |
||
121 | ptln(' <legend>' . $setting->prompt($this) . '</legend>'); |
||
122 | ptln(' <div class="table">'); |
||
123 | ptln(' <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 | ptln(' <tr' . $class . '>'); |
||
140 | ptln(' <td class="label">'); |
||
141 | ptln(' <span class="outkey">' . $setting->getPrettyKey() . '</span>'); |
||
142 | ptln(' ' . $icon . $label); |
||
143 | ptln(' </td>'); |
||
144 | ptln(' <td' . $error . '>' . $input . '</td>'); |
||
145 | ptln(' </tr>'); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | ptln(' </table>'); |
||
150 | ptln(' </div>'); |
||
151 | if($in_fieldset) { |
||
152 | ptln(' </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 | ptln('<fieldset>'); |
||
172 | ptln('<div class="table">'); |
||
173 | ptln('<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 | ptln(' <tr>'); |
||
188 | ptln( |
||
189 | ' <td class="label"><span title="$meta[\'' . $undefined_setting_key . '\']">$' . |
||
190 | 'conf' . '[\'' . $setting->getArrayKey() . '\']</span></td>' |
||
191 | ); |
||
192 | ptln(' <td>' . $this->getLang('_msg_' . get_class($setting)) . '</td>'); |
||
193 | ptln(' </tr>'); |
||
194 | } |
||
195 | ptln('</table>'); |
||
196 | ptln('</div>'); |
||
197 | ptln('</fieldset>'); |
||
198 | } |
||
199 | |||
200 | // finish up form |
||
201 | ptln('<p>'); |
||
202 | ptln(' <input type="hidden" name="do" value="admin" />'); |
||
203 | ptln(' <input type="hidden" name="page" value="config" />'); |
||
204 | |||
205 | if(!$this->configuration->isLocked()) { |
||
206 | ptln(' <input type="hidden" name="save" value="1" />'); |
||
207 | ptln(' <button type="submit" name="submit" accesskey="s">' . $lang['btn_save'] . '</button>'); |
||
208 | ptln(' <button type="reset">' . $lang['btn_reset'] . '</button>'); |
||
209 | } |
||
210 | |||
211 | ptln('</p>'); |
||
212 | |||
213 | ptln('</form>'); |
||
214 | ptln('</div>'); |
||
215 | } |
||
216 | |||
300 |