Conditions | 2 |
Paths | 2 |
Total Lines | 294 |
Code Lines | 69 |
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 |
||
52 | function showExtFields($type = 'text', $ext = '') |
||
53 | { |
||
54 | global $xoopsConfig, $xoopsDB, $_POST, $myts, $eh, $xoopsUser; |
||
55 | |||
56 | //MHE - This is added code for the listings module, handling the extension manager. |
||
57 | if (!headers_sent()) { |
||
58 | header('Content-Type:text/html; charset=' . _CHARSET); |
||
59 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
||
60 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
||
61 | header('Cache-Control: no-store, no-cache, must-revalidate'); |
||
62 | header('Cache-Control: post-check=0, pre-check=0', false); |
||
63 | header('Pragma: no-cache'); |
||
64 | } |
||
65 | echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"\n'; |
||
66 | echo '"http://www.w3.org/TR/html4/strict.dtd">'; |
||
67 | echo "<html lang=\"en\" dir=\"ltr\">\n"; |
||
68 | echo "<head>\n"; |
||
69 | echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '">'; |
||
70 | echo '<meta http-equiv="content-language" content="' . _LANGCODE . '">'; |
||
71 | echo '<title>Extension Manager</title>'; |
||
72 | echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css">'; |
||
73 | echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/modules/system/style.css">'; |
||
74 | echo '<script type="text/javascript"><!--'; |
||
75 | echo ' |
||
76 | function ext_initial_adv(formName, obj, type) |
||
77 | { |
||
78 | typeid = opener.document.forms[formName].elements[type].value; |
||
79 | if (typeid == 0) { |
||
80 | alert("' . _MD_SELECT_FORMTYPE . "\"); |
||
81 | self.close(); |
||
82 | } |
||
83 | var arr_fields = new makeArray(9); |
||
84 | arr_fields[0] = 'width'; |
||
85 | arr_fields[1] = 'height'; |
||
86 | arr_fields[2] = 'rows'; |
||
87 | arr_fields[3] = 'cols'; |
||
88 | arr_fields[4] = 'size'; |
||
89 | arr_fields[5] = 'maxsize'; |
||
90 | arr_fields[6] = 'value'; |
||
91 | arr_fields[7] = 'multiple'; |
||
92 | arr_fields[8] = 'checked'; |
||
93 | length_fields = arr_fields.length; |
||
94 | bgc_type_checkbox_grp = /checked|multiple/gi; |
||
95 | bgc_type_date_grp = /value/gi; |
||
96 | bgc_type_datetime_grp = /value/gi; |
||
97 | bgc_type_radio_grp = /checked/gi; |
||
98 | bgc_type_select_grp = /value|multiple/gi; |
||
99 | bgc_type_textarea_grp = /rows|cols|value/gi; |
||
100 | bgc_type_dhtml_grp = /rows|cols|value/gi; |
||
101 | bgc_type_textbox_grp = /size|maxsize|value/gi; |
||
102 | bgc_type_yesno_grp = /value/gi; |
||
103 | x = 0; |
||
104 | reg_checkboxes = /multiple|checked/gi; |
||
105 | while (x<length_fields) { |
||
106 | if (typeid == 'checkbox') { |
||
107 | if (arr_fields[x].match(bgc_type_checkbox_grp)) { |
||
108 | var fieldname = arr_fields[x]; |
||
109 | } else { |
||
110 | var fieldname = arr_fields[x]; |
||
111 | ext_manager.elements[fieldname].disabled = true; |
||
112 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
113 | } |
||
114 | } |
||
115 | if (typeid == 'date') { |
||
116 | if (arr_fields[x].match(bgc_type_date_grp)) { |
||
117 | var fieldname = arr_fields[x]; |
||
118 | } else { |
||
119 | var fieldname = arr_fields[x]; |
||
120 | ext_manager.elements[fieldname].disabled = true; |
||
121 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
122 | } |
||
123 | } |
||
124 | if (typeid == 'datetime') { |
||
125 | if (arr_fields[x].match(bgc_type_datetime_grp)) { |
||
126 | var fieldname = arr_fields[x]; |
||
127 | } else { |
||
128 | var fieldname = arr_fields[x]; |
||
129 | ext_manager.elements[fieldname].disabled = true; |
||
130 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
131 | } |
||
132 | } |
||
133 | if (typeid == 'radio') { |
||
134 | if (arr_fields[x].match(bgc_type_radio_grp)) { |
||
135 | var fieldname = arr_fields[x]; |
||
136 | } else { |
||
137 | var fieldname = arr_fields[x]; |
||
138 | ext_manager.elements[fieldname].disabled = true; |
||
139 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
140 | } |
||
141 | } |
||
142 | if (typeid == 'select') { |
||
143 | if (arr_fields[x].match(bgc_type_select_grp)) { |
||
144 | var fieldname = arr_fields[x]; |
||
145 | } else { |
||
146 | var fieldname = arr_fields[x]; |
||
147 | ext_manager.elements[fieldname].disabled = true; |
||
148 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
149 | } |
||
150 | } |
||
151 | if (typeid == 'textarea') { |
||
152 | if (arr_fields[x].match(bgc_type_textarea_grp)) { |
||
153 | var fieldname = arr_fields[x]; |
||
154 | } else { |
||
155 | var fieldname = arr_fields[x]; |
||
156 | ext_manager.elements[fieldname].disabled = true; |
||
157 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
158 | } |
||
159 | } |
||
160 | if (typeid == 'dhtml') { |
||
161 | if (arr_fields[x].match(bgc_type_dhtml_grp)) { |
||
162 | var fieldname = arr_fields[x]; |
||
163 | } else { |
||
164 | var fieldname = arr_fields[x]; |
||
165 | ext_manager.elements[fieldname].disabled = true; |
||
166 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
167 | } |
||
168 | } |
||
169 | if (typeid == 'textbox') { |
||
170 | if (arr_fields[x].match(bgc_type_textbox_grp)) { |
||
171 | var fieldname = arr_fields[x]; |
||
172 | } else { |
||
173 | var fieldname = arr_fields[x]; |
||
174 | ext_manager.elements[fieldname].disabled = true; |
||
175 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
176 | } |
||
177 | } |
||
178 | if (typeid == 'yesno') { |
||
179 | if (arr_fields[x].match(bgc_type_yesno_grp)) { |
||
180 | var fieldname = arr_fields[x]; |
||
181 | } else { |
||
182 | var fieldname = arr_fields[x]; |
||
183 | ext_manager.elements[fieldname].disabled = true; |
||
184 | ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey'; |
||
185 | } |
||
186 | } |
||
187 | x ++; |
||
188 | } |
||
189 | var ext = opener.document.forms[formName].elements[obj].value; |
||
190 | regx = \"|\"; |
||
191 | ext_array = ext.split(regx); |
||
192 | length = ext_array.length; |
||
193 | i = 0; |
||
194 | while (i<length) { |
||
195 | item = ext_array[i]; |
||
196 | regy = \"=\"; |
||
197 | item_array = item.split(regy); |
||
198 | item_length = item_array.length; |
||
199 | reg_textboxes = /width|height|rows|cols|size|maxsize|value/gi; |
||
200 | reg_checkboxes = /multiple|checked/gi; |
||
201 | if (item_array[0].match(reg_textboxes)) { |
||
202 | var fieldname = item_array[0]; |
||
203 | var fieldvalue = item_array[1]; |
||
204 | ext_manager.elements[fieldname].value = fieldvalue; |
||
205 | } |
||
206 | if (item_array[0].match(reg_checkboxes)) { |
||
207 | var fieldname = item_array[0]; |
||
208 | var fieldvalue = item_array[1]; |
||
209 | if (fieldvalue == 1) { |
||
210 | self_check(ext_manager, fieldname, 1); |
||
211 | } else { |
||
212 | self_check(ext_manager, fieldname, 0); |
||
213 | } |
||
214 | } |
||
215 | i ++; |
||
216 | } |
||
217 | }\n"; |
||
218 | echo " |
||
219 | function makeArray(n) |
||
220 | { |
||
221 | this.length = n; |
||
222 | for (var i=1; i <=n; i++) { |
||
223 | this[i] = null; |
||
224 | } |
||
225 | |||
226 | return this; |
||
227 | }\n"; |
||
228 | echo " |
||
229 | function updatefield(formname, fieldname, fieldvalue) |
||
230 | { |
||
231 | myform.elements[fieldname].value = [fieldvalue]; |
||
232 | }\n"; |
||
233 | echo " |
||
234 | function ext_input(formName, obj) |
||
235 | { |
||
236 | reg_checkboxes = /multiple|checked/gi; |
||
237 | var arr_fields = new makeArray(9); |
||
238 | arr_fields[0] = 'width'; |
||
239 | arr_fields[1] = 'height'; |
||
240 | arr_fields[2] = 'rows'; |
||
241 | arr_fields[3] = 'cols'; |
||
242 | arr_fields[4] = 'size'; |
||
243 | arr_fields[5] = 'maxsize'; |
||
244 | arr_fields[6] = 'value'; |
||
245 | arr_fields[7] = 'multiple'; |
||
246 | arr_fields[8] = 'checked'; |
||
247 | length_fields = arr_fields.length; |
||
248 | i = 0; |
||
249 | y = 0; |
||
250 | var output = ''; |
||
251 | while (i<length_fields) { |
||
252 | var fieldname = arr_fields[i]; |
||
253 | if (fieldname.match(reg_checkboxes)) { |
||
254 | if (ext_manager.elements[fieldname].checked === true) { |
||
255 | var fieldvalue = 1; |
||
256 | } else { |
||
257 | var fieldvalue = 0; |
||
258 | } |
||
259 | } else { |
||
260 | var fieldvalue = ext_manager.elements[fieldname].value; |
||
261 | } |
||
262 | if (fieldvalue != '') { |
||
263 | if (y == 0) { |
||
264 | output += fieldname+'='+fieldvalue; |
||
265 | } else { |
||
266 | output +='|'+fieldname+'='+fieldvalue; |
||
267 | } |
||
268 | y ++; |
||
269 | } |
||
270 | i ++; |
||
271 | } |
||
272 | opener.document.forms[formName].elements[obj].value = output; |
||
273 | opener.document.forms[formName].elements[obj].disabled = false; |
||
274 | self.close(); |
||
275 | }\n"; |
||
276 | echo " |
||
277 | function ext_select(formName, obj, idx) |
||
278 | { |
||
279 | opener.document.forms[formName].elements[obj].selectedIndex = idx; |
||
280 | self.close(); |
||
281 | }\n"; |
||
282 | echo " |
||
283 | function self_checkRadio(formName, obj, choice) |
||
284 | { |
||
285 | ext_manager.elements[obj][choice].checked = true; |
||
286 | }\n"; |
||
287 | echo " |
||
288 | function ext_checkRadio(formName, obj, choice) |
||
289 | { |
||
290 | opener.document.forms[formName].elements[obj][choice].checked = true; |
||
291 | self.close(); |
||
292 | }\n"; |
||
293 | echo " |
||
294 | function self_check(formName, obj, choice) |
||
295 | { |
||
296 | ext_manager.elements[obj].checked = choice; |
||
297 | }\n"; |
||
298 | echo "//--></script>\n"; |
||
299 | echo "</head>\n"; |
||
300 | echo '<body onload="ext_initial_adv(\'submitform\', \'ext\', \'field_type\')">'; |
||
301 | echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'> |
||
302 | <tr> |
||
303 | <td bgcolor='#2F5376'><a href='http://www.xoops.org/' target='_blank'><img src='" . XOOPS_URL . "/images/logo.gif' alt='" . $GLOBALS['xoopsConfig']['sitename'] . "'></a></td> |
||
304 | <td align='right' bgcolor='#2F5376'><img src='" . XOOPS_URL . "/images/logo.gif' alt=''></td> |
||
305 | </tr><tr><td colspan='2'><div class='content'><br>"; |
||
306 | $form = new XoopsThemeForm(_MD_EXTMANAGER, 'ext_manager', 'fieldtypes.php'); |
||
307 | |||
308 | //TO DO: change type field to drop down field, based on available types. |
||
309 | $fieldtypes = array( |
||
310 | '0' => '---', |
||
311 | 'checkbox' => _MD_FIELDNAMES_CHECKBOX, |
||
312 | 'date' => _MD_FIELDNAMES_DATE, |
||
313 | 'datetime' => _MD_FIELDNAMES_DATETIME, |
||
314 | 'radio' => _MD_FIELDNAMES_RADIO, |
||
315 | 'select' => _MD_FIELDNAMES_SELECT, |
||
316 | 'select_multi' => _MD_FIELDNAMES_SELECTMULTI, |
||
317 | 'textarea' => _MD_FIELDNAMES_TEXTAREA, |
||
318 | 'dhtml' => _MD_FIELDNAMES_DHTMLTEXTAREA, |
||
319 | 'textbox' => _MD_FIELDNAMES_TEXTBOX, |
||
320 | 'yesno' => _MD_FIELDNAMES_YESNO |
||
321 | ); |
||
322 | |||
323 | $form->addElement(new XoopsFormText(_MD_WIDTH, 'width', 10, 20, '')); |
||
324 | $form->addElement(new XoopsFormText(_MD_HEIGHT, 'height', 10, 20, '')); |
||
325 | $form->addElement(new XoopsFormText(_MD_ROWS, 'rows', 10, 20, '')); |
||
326 | $form->addElement(new XoopsFormText(_MD_COLS, 'cols', 10, 20, '')); |
||
327 | $form->addElement(new XoopsFormText(_MD_SIZE, 'size', 10, 20, '')); |
||
328 | $form->addElement(new XoopsFormText(_MD_MAXSIZE, 'maxsize', 10, 20, '')); |
||
329 | $form->addElement(new XoopsFormText(_MD_DEFAULTVALUE, 'value', 50, 100, '')); |
||
330 | $form_multiple = new XoopsFormCheckBox(_MD_MULTIPLE, 'multiple', 0); |
||
331 | $form_multiple->addOption(1, _MD_YESNO); |
||
332 | $form_checked = new XoopsFormCheckBox(_MD_CHECKED, 'checked', 0); |
||
333 | $form_checked->addOption(1, _MD_YESNO); |
||
334 | $form->addElement($form_multiple); |
||
335 | $form->addElement($form_checked); |
||
336 | $ext_update = new XoopsFormLabel('', '<INPUT type="button" value="' . _MD_UPDATE . "\" onClick=\"ext_input('submitform','ext')\" value=\"Update\">"); |
||
337 | $ext_cancel = new XoopsFormLabel('', '<INPUT type="button" value="' . _MD_CANCEL . '" onClick="self.close()" value="Cancel">'); |
||
338 | $ext_tray = new XoopsFormElementTray('', ''); |
||
339 | $ext_tray->addElement($ext_update); |
||
340 | $ext_tray->addElement($ext_cancel); |
||
341 | $form->addElement($ext_tray); |
||
342 | $form->display(); |
||
343 | echo '</div>'; |
||
344 | echo '</td></tr></table>'; |
||
345 | echo '</body>'; |
||
346 | } |
||
362 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.