Conditions | 29 |
Paths | > 20000 |
Total Lines | 232 |
Code Lines | 164 |
Lines | 16 |
Ratio | 6.9 % |
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 |
||
134 | function modAd($lid) |
||
135 | { |
||
136 | global $xoopsDB, $xoopsModule, $xoopsConfig, $xoopsTheme, $myts, $xoopsLogger, $moduleDirName, $main_lang; |
||
137 | $contactselect = ''; |
||
138 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
139 | require_once XOOPS_ROOT_PATH . '/modules/adslight/class/utility.php'; |
||
140 | echo "<script language=\"javascript\">\nfunction CLA(CLA) { var MainWindow = window.open (CLA, \"_blank\",\"width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no\");}\n</script>"; |
||
141 | |||
142 | require_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php'; |
||
143 | $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
144 | |||
145 | $result = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, usid, town, country, contactby, premium, valid FROM ' |
||
146 | . $xoopsDB->prefix('adslight_listing') |
||
147 | . ' WHERE lid=' |
||
148 | . $xoopsDB->escape($lid)); |
||
149 | list($lid, $cide, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid) = $xoopsDB->fetchRow($result); |
||
150 | |||
151 | $categories = AdslightUtility::getMyItemIds('adslight_submit'); |
||
152 | View Code Duplication | if (is_array($categories) && count($categories) > 0) { |
|
153 | if (!in_array($cide, $categories)) { |
||
154 | redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM); |
||
155 | } |
||
156 | } else { // User can't see any category |
||
157 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||
158 | } |
||
159 | |||
160 | if ($GLOBALS['xoopsUser']) { |
||
161 | $calusern = $GLOBALS['xoopsUser']->uid(); |
||
162 | if ($usid == $calusern) { |
||
163 | echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _ADSLIGHT_MODIFANN . '</legend><br><br>'; |
||
164 | $title = $myts->htmlSpecialChars($title); |
||
165 | $status = $myts->htmlSpecialChars($status); |
||
166 | $expire = $myts->htmlSpecialChars($expire); |
||
167 | $type = $myts->htmlSpecialChars($type); |
||
168 | $desctext = $myts->displayTarea($desctext, 1); |
||
169 | $tel = $myts->htmlSpecialChars($tel); |
||
170 | |||
171 | // $price = number_format($price, 2, ',', ' '); |
||
172 | |||
173 | xoops_load('XoopsLocal'); |
||
174 | $tempXoopsLocal = new XoopsLocal; |
||
175 | // For US currency with 2 numbers after the decimal comment out if you dont want 2 numbers after decimal |
||
176 | $price = $tempXoopsLocal->number_format($price, 2, ',', ' '); |
||
177 | // For other countries uncomment the below line and comment out the above line |
||
178 | // $price = $tempXoopsLocal->number_format($price); |
||
179 | |||
180 | $typeprice = $myts->htmlSpecialChars($typeprice); |
||
181 | $typeusure = $myts->htmlSpecialChars($typeusure); |
||
182 | $submitter = $myts->htmlSpecialChars($submitter); |
||
183 | $town = $myts->htmlSpecialChars($town); |
||
184 | $country = $myts->htmlSpecialChars($country); |
||
185 | $contactby = $myts->htmlSpecialChars($contactby); |
||
186 | $premium = $myts->htmlSpecialChars($premium); |
||
187 | $useroffset = ''; |
||
188 | View Code Duplication | if ($GLOBALS['xoopsUser']) { |
|
189 | $timezone = $GLOBALS['xoopsUser']->timezone(); |
||
190 | $useroffset = (!empty($timezone)) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ']; |
||
191 | } |
||
192 | $dates = ($useroffset * 3600) + $date; |
||
193 | $dates = formatTimestamp($date, 's'); |
||
194 | |||
195 | echo "<form action=\"modify.php\" method=post enctype=\"multipart/form-data\">"; |
||
196 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
197 | echo "<table><tr class=\"head\" border=\"2\"> |
||
198 | <td class=\"head\">" . _ADSLIGHT_NUMANNN . " </td><td class=\"head\" border=\"1\">$lid " . _ADSLIGHT_DU . " $dates</td> |
||
199 | </tr><tr>"; |
||
200 | |||
201 | if ($GLOBALS['xoopsModuleConfig']['adslight_diff_name'] == '1') { |
||
202 | echo "<td class=\"head\">" . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"text\" name=\"submitter\" size=\"50\" value=\"$submitter\" ></td>"; |
||
203 | } else { |
||
204 | echo "<td class=\"head\">" . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"hidden\" name=\"submitter\" value=\"$submitter\">$submitter</td>"; |
||
205 | } |
||
206 | echo '</tr><tr>'; |
||
207 | |||
208 | if (1 == $contactby) { |
||
209 | $contactselect = _ADSLIGHT_CONTACT_BY_EMAIL; |
||
210 | } |
||
211 | if (2 == $contactby) { |
||
212 | $contactselect = _ADSLIGHT_CONTACT_BY_PM; |
||
213 | } |
||
214 | if (3 == $contactby) { |
||
215 | $contactselect = _ADSLIGHT_CONTACT_BY_BOTH; |
||
216 | } |
||
217 | if (4 == $contactby) { |
||
218 | $contactselect = _ADSLIGHT_CONTACT_BY_PHONE; |
||
219 | } |
||
220 | |||
221 | echo " <td class='head'>" . _ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\"> |
||
222 | <option value=\"" . $contactby . "\">" . $contactselect . "</option> |
||
223 | <option value=\"1\">" . _ADSLIGHT_CONTACT_BY_EMAIL . "</option> |
||
224 | <option value=\"2\">" . _ADSLIGHT_CONTACT_BY_PM . "</option> |
||
225 | <option value=\"3\">" . _ADSLIGHT_CONTACT_BY_BOTH . "</option> |
||
226 | <option value=\"4\">" . _ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>'; |
||
227 | |||
228 | if ($GLOBALS['xoopsModuleConfig']['adslight_diff_email'] == '1') { |
||
229 | echo "<tr><td class=\"head\">" . _ADSLIGHT_EMAIL . " </td><td class=\"head\"><input type=\"text\" name=\"email\" size=\"50\" value=\"$email\" ></td>"; |
||
230 | } else { |
||
231 | echo "<tr><td class=\"head\">" . _ADSLIGHT_EMAIL . " </td><td class=\"head\">$email<input type=\"hidden\" name=\"email\" value=\"$email\" ></td>"; |
||
232 | } |
||
233 | echo "</tr><tr> |
||
234 | <td class=\"head\">" . _ADSLIGHT_TEL . " </td><td class=\"head\"><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\" ></td> |
||
235 | </tr>"; |
||
236 | echo "<tr> |
||
237 | <td class=\"head\">" . _ADSLIGHT_TOWN . " </td><td class=\"head\"><input type=\"text\" name=\"town\" size=\"50\" value=\"$town\" ></td> |
||
238 | </tr>"; |
||
239 | if ($GLOBALS['xoopsModuleConfig']['adslight_use_country'] == '1') { |
||
240 | echo "<tr> |
||
241 | <td class=\"head\">" . _ADSLIGHT_COUNTRY . " </td><td class=\"head\"><input type=\"text\" name=\"country\" size=\"50\" value=\"$country\" ></td> |
||
242 | </tr>"; |
||
243 | } else { |
||
244 | echo "<input type=\"hidden\" name=\"country\" value=\"\">"; |
||
245 | } |
||
246 | |||
247 | echo "<tr><td class='head'>" . _ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\""; |
||
248 | if ('0' == $status) { |
||
249 | echo 'checked'; |
||
250 | } |
||
251 | echo '>' . _ADSLIGHT_ACTIVE . " <input type=\"radio\" name=\"status\" value=\"1\""; |
||
252 | if ('1' == $status) { |
||
253 | echo 'checked'; |
||
254 | } |
||
255 | echo '>' . _ADSLIGHT_INACTIVE . " <input type=\"radio\" name=\"status\" value=\"2\""; |
||
256 | if ('2' == $status) { |
||
257 | echo 'checked'; |
||
258 | } |
||
259 | echo '>' . _ADSLIGHT_SOLD . '</td></tr>'; |
||
260 | echo "<tr> |
||
261 | <td class=\"head\">" . _ADSLIGHT_TITLE2 . " </td><td class=\"head\"><input type=\"text\" name=\"title\" size=\"50\" value=\"$title\" ></td> |
||
262 | </tr>"; |
||
263 | echo "<tr><td class=\"head\">" |
||
264 | . _ADSLIGHT_PRICE2 |
||
265 | . " </td><td class=\"head\"><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\" > " |
||
266 | . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol']; |
||
267 | |||
268 | $result3 = $xoopsDB->query('SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price'); |
||
269 | echo " <select name=\"typeprice\">"; |
||
270 | while (list($nom_price, $id_price) = $xoopsDB->fetchRow($result3)) { |
||
271 | $sel = ''; |
||
272 | if ($id_price == $typeprice) { |
||
273 | $sel = 'selected'; |
||
274 | } |
||
275 | echo "<option value=\"$id_price\" $sel>$nom_price</option>"; |
||
276 | } |
||
277 | echo '</select></td></tr>'; |
||
278 | $module_id = $xoopsModule->getVar('mid'); |
||
279 | $groups = ($GLOBALS['xoopsUser'] instanceof XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
280 | |||
281 | /** @var XoopsGroupPermHandler $gpermHandler */ |
||
282 | $gpermHandler = xoops_getHandler('groupperm'); |
||
283 | $perm_itemid = Request::getInt('item_id', 0, 'GET'); |
||
284 | |||
285 | //If no access |
||
286 | if (!$gpermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) { |
||
287 | echo "<tr> |
||
288 | <td width='30%' class='head'>" . _ADSLIGHT_WILL_LAST . " </td><td class='head'>$expire " . _ADSLIGHT_DAY . '</td> |
||
289 | </tr>'; |
||
290 | echo "<input type=\"hidden\" name=\"expire\" value=\"$expire\" >"; |
||
291 | } else { |
||
292 | echo "<tr> |
||
293 | <td width='30%' class='head'>" . _ADSLIGHT_HOW_LONG . " </td><td class='head'><input type=\"text\" name=\"expire\" size=\"3\" maxlength=\"3\" value=\"$expire\" > " . _ADSLIGHT_DAY . '</td> |
||
294 | </tr>'; |
||
295 | } |
||
296 | |||
297 | /// Type d'annonce |
||
298 | echo "<tr> |
||
299 | <td class=\"head\">" . _ADSLIGHT_TYPE . " </td><td class=\"head\"><select name=\"type\">"; |
||
300 | |||
301 | $result5 = $xoopsDB->query('SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type'); |
||
302 | while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) { |
||
303 | $sel = ''; |
||
304 | if ($id_type == $type) { |
||
305 | $sel = 'selected'; |
||
306 | } |
||
307 | echo "<option value=\"$id_type\" $sel>$nom_type</option>"; |
||
308 | } |
||
309 | echo '</select></td></tr>'; |
||
310 | |||
311 | /// Etat de l'objet |
||
312 | echo "<tr> |
||
313 | <td class=\"head\">" . _ADSLIGHT_TYPE_USURE . " </td><td class=\"head\"><select name=\"typeusure\">"; |
||
314 | |||
315 | $result6 = $xoopsDB->query('SELECT nom_usure, id_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure'); |
||
316 | while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) { |
||
317 | $sel = ''; |
||
318 | if ($id_usure == $typeusure) { |
||
319 | $sel = 'selected'; |
||
320 | } |
||
321 | echo "<option value=\"$id_usure\" $sel>$nom_usure</option>"; |
||
322 | } |
||
323 | echo '</select></td></tr>'; |
||
324 | |||
325 | echo "<tr> |
||
326 | <td class=\"head\">" . _ADSLIGHT_CAT . " </td><td class=\"head\">"; |
||
327 | $mytree->makeMySelBox('title', 'title', $cide, '', 'cid'); |
||
328 | echo "</td> |
||
329 | </tr><tr> |
||
330 | <td class=\"head\">" . _ADSLIGHT_DESC . " </td><td class=\"head\">"; |
||
331 | $wysiwyg_text_area = AdslightUtility::getEditor(_ADSLIGHT_DESC, 'desctext', $desctext, '100%', '200px'); |
||
332 | echo $wysiwyg_text_area->render(); |
||
333 | echo "</td></tr> |
||
334 | <td colspan=2><br><input type=\"submit\" value=\"" . _ADSLIGHT_MODIFANN . "\" ></td> |
||
335 | </tr></table>"; |
||
336 | echo "<input type=\"hidden\" name=\"op\" value=\"ModAdS\" >"; |
||
337 | |||
338 | $module_id = $xoopsModule->getVar('mid'); |
||
339 | View Code Duplication | if (is_object($GLOBALS['xoopsUser'])) { |
|
340 | $groups =& $GLOBALS['xoopsUser']->getGroups(); |
||
341 | } else { |
||
342 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
343 | } |
||
344 | /** @var XoopsGroupPermHandler $gpermHandler */ |
||
345 | $gpermHandler = xoops_getHandler('groupperm'); |
||
346 | $perm_itemid = Request::getInt('item_id', 0, 'POST'); |
||
347 | //If no access |
||
348 | if (!$gpermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) { |
||
349 | if ($GLOBALS['xoopsModuleConfig']['adslight_moderated'] == '1') { |
||
350 | echo "<input type=\"hidden\" name=\"valid\" value=\"No\" >"; |
||
351 | echo '<br>' . _ADSLIGHT_MODIFBEFORE . '<br>'; |
||
352 | } else { |
||
353 | echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\" >"; |
||
354 | } |
||
355 | } else { |
||
356 | echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\" >"; |
||
357 | } |
||
358 | echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\" >"; |
||
359 | echo "<input type=\"hidden\" name=\"premium\" value=\"$premium\" >"; |
||
360 | echo "<input type=\"hidden\" name=\"date\" value=\"$date\" > |
||
361 | " .$GLOBALS['xoopsSecurity']->getTokenHTML('token') . ''; |
||
362 | echo '</form><br></fieldset><br>'; |
||
363 | } |
||
364 | } |
||
365 | } |
||
366 | |||
460 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.