| Conditions | 28 |
| Paths | 2881 |
| Total Lines | 225 |
| Code Lines | 152 |
| Lines | 12 |
| Ratio | 5.33 % |
| 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 |
||
| 86 | while (false !== ($myrow = $db->fetchArray($result))) { |
||
| 87 | $block_arr[] = new \XoopsBlock($myrow); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * |
||
| 92 | */ |
||
| 93 | function list_blocks() |
||
| 94 | { |
||
| 95 | global $query4redirect, $block_arr; |
||
| 96 | |||
| 97 | // cachetime options |
||
| 98 | $cachetimes = [ |
||
| 99 | '0' => _NOCACHE, |
||
| 100 | '30' => sprintf(_SECONDS, 30), |
||
| 101 | '60' => _MINUTE, |
||
| 102 | '300' => sprintf(_MINUTES, 5), |
||
| 103 | '1800' => sprintf(_MINUTES, 30), |
||
| 104 | '3600' => _HOUR, |
||
| 105 | '18000' => sprintf(_HOURS, 5), |
||
| 106 | '86400' => _DAY, |
||
| 107 | '259200' => sprintf(_DAYS, 3), |
||
| 108 | '604800' => _WEEK, |
||
| 109 | '2592000' => _MONTH, |
||
| 110 | ]; |
||
| 111 | |||
| 112 | // displaying TH |
||
| 113 | lx_collapsableBar('default', 'defaultIcon'); |
||
| 114 | echo "<img onclick=\"toggle('default'); toggleIcon('defaultIcon');\" id='defaultIcon' src='" . XOOPS_URL . "/modules/lexikon/assets/images/close12.gif' alt=''></a> " . _AM_BADMIN . '<br><br>'; |
||
| 115 | echo "<div id='default' style='float:left; width:100%;'>"; |
||
| 116 | echo "<form action='admin.php' name='blockadmin' method='post'> |
||
| 117 | <table width='95%' class='outer' cellpadding='4' cellspacing='1'> |
||
| 118 | <tr valign='middle'> |
||
| 119 | <th>" . _AM_TITLE . "</th> |
||
| 120 | <th align='center' nowrap='nowrap'>" . _AM_SIDE . "<div style='font-size:smaller;'>" . _LEFT . '-' . _CENTER . '-' . _RIGHT . "</div></th> |
||
| 121 | <th align='center'>" . _AM_WEIGHT . "</th> |
||
| 122 | <th align='center'>" . _AM_VISIBLEIN . "</th> |
||
| 123 | <th align='center'>" . _AM_BCACHETIME . "</th> |
||
| 124 | <th align='right'>" . _AM_ACTION . "</th> |
||
| 125 | </tr>\n"; |
||
| 126 | |||
| 127 | // blocks displaying loop |
||
| 128 | $class = 'even'; |
||
| 129 | $block_configs = get_block_configs(); |
||
| 130 | foreach (array_keys($block_arr) as $i) { |
||
| 131 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; |
||
| 132 | $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = $ssel5 = $ssel6 = $ssel7 = ''; |
||
| 133 | |||
| 134 | $weight = $block_arr[$i]->getVar('weight'); |
||
| 135 | $title = $block_arr[$i]->getVar('title'); |
||
| 136 | $name = $block_arr[$i]->getVar('name'); |
||
| 137 | $bcachetime = $block_arr[$i]->getVar('bcachetime'); |
||
| 138 | $bid = $block_arr[$i]->getVar('bid'); |
||
| 139 | |||
| 140 | // visible and side |
||
| 141 | if (1 != $block_arr[$i]->getVar('visible')) { |
||
| 142 | $sseln = ' checked'; |
||
| 143 | $scoln = '#FF9966'; |
||
| 144 | } else { |
||
| 145 | switch ($block_arr[$i]->getVar('side')) { |
||
| 146 | default: |
||
| 147 | case XOOPS_SIDEBLOCK_LEFT: |
||
| 148 | $ssel0 = ' checked'; |
||
| 149 | $scol0 = '#00FF00'; |
||
| 150 | break; |
||
| 151 | case XOOPS_SIDEBLOCK_RIGHT: |
||
| 152 | $ssel1 = ' checked'; |
||
| 153 | $scol1 = '#00FF00'; |
||
| 154 | break; |
||
| 155 | case XOOPS_CENTERBLOCK_LEFT: |
||
| 156 | $ssel2 = ' checked'; |
||
| 157 | $scol2 = '#00FF00'; |
||
| 158 | break; |
||
| 159 | case XOOPS_CENTERBLOCK_RIGHT: |
||
| 160 | $ssel4 = ' checked'; |
||
| 161 | $scol4 = '#00FF00'; |
||
| 162 | break; |
||
| 163 | case XOOPS_CENTERBLOCK_CENTER: |
||
| 164 | $ssel3 = ' checked'; |
||
| 165 | $scol3 = '#00FF00'; |
||
| 166 | break; |
||
| 167 | case XOOPS_CENTERBLOCK_BOTTOMLEFT: |
||
| 168 | $ssel5 = ' checked'; |
||
| 169 | $scol5 = '#00FF00'; |
||
| 170 | break; |
||
| 171 | case XOOPS_CENTERBLOCK_BOTTOMRIGHT: |
||
| 172 | $ssel6 = ' checked'; |
||
| 173 | $scol6 = '#00FF00'; |
||
| 174 | break; |
||
| 175 | case XOOPS_CENTERBLOCK_BOTTOM: |
||
| 176 | $ssel7 = ' checked'; |
||
| 177 | $scol7 = '#00FF00'; |
||
| 178 | break; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | // bcachetime |
||
| 183 | $cachetime_options = ''; |
||
| 184 | foreach ($cachetimes as $cachetime => $cachetime_name) { |
||
| 185 | if ($bcachetime == $cachetime) { |
||
| 186 | $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n"; |
||
| 187 | } else { |
||
| 188 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | // target modules |
||
| 193 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 194 | $result = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'"); |
||
| 195 | $selected_mids = []; |
||
| 196 | while (list($selected_mid) = $db->fetchRow($result)) { |
||
| 197 | $selected_mids[] = (int)$selected_mid; |
||
| 198 | } |
||
| 199 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 200 | $moduleHandler = xoops_getHandler('module'); |
||
| 201 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
| 202 | $criteria->add(new \Criteria('isactive', 1)); |
||
| 203 | $module_list = $moduleHandler->getList($criteria); |
||
| 204 | $module_list[-1] = _AM_TOPPAGE; |
||
| 205 | $module_list[0] = _AM_ALLPAGES; |
||
| 206 | ksort($module_list); |
||
| 207 | $module_options = ''; |
||
| 208 | foreach ($module_list as $mid => $mname) { |
||
| 209 | if (in_array($mid, $selected_mids)) { |
||
| 210 | $module_options .= "<option value='$mid' selected>$mname</option>\n"; |
||
| 211 | } else { |
||
| 212 | $module_options .= "<option value='$mid'>$mname</option>\n"; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | |||
| 216 | // delete link if it is cloned block |
||
| 217 | if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { |
||
| 218 | $delete_link = "<br><a href='admin.php?fct=blocksadmin&op=delete&bid=$bid'>" . _DELETE . '</a>'; |
||
| 219 | } else { |
||
| 220 | $delete_link = ''; |
||
| 221 | } |
||
| 222 | |||
| 223 | // clone link if it is marked as cloneable block |
||
| 224 | // $modversion['blocks'][n]['can_clone'] |
||
| 225 | if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { |
||
| 226 | $can_clone = true; |
||
| 227 | } else { |
||
| 228 | $can_clone = false; |
||
| 229 | foreach ($block_configs as $bconf) { |
||
| 230 | if ($block_arr[$i]->getVar('show_func') == $bconf['show_func'] |
||
| 231 | && $block_arr[$i]->getVar('func_file') == $bconf['file'] |
||
| 232 | && (empty($bconf['template']) |
||
| 233 | || $block_arr[$i]->getVar('template') == $bconf['template'])) { |
||
| 234 | if (!empty($bconf['can_clone'])) { |
||
| 235 | $can_clone = true; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | } |
||
| 240 | if ($can_clone) { |
||
| 241 | $clone_link = "<br><a href='admin.php?fct=blocksadmin&op=clone&bid=$bid'>" . _CLONE . '</a>'; |
||
| 242 | } else { |
||
| 243 | $clone_link = ''; |
||
| 244 | } |
||
| 245 | |||
| 246 | // displaying part |
||
| 247 | echo " |
||
| 248 | <tr valign='middle'> |
||
| 249 | <td class='$class'> |
||
| 250 | $name |
||
| 251 | <br> |
||
| 252 | <input type='text' name='title[$bid]' value='$title' size='20' > |
||
| 253 | </td> |
||
| 254 | <td class='$class' align='center' nowrap='nowrap' width='125px'> |
||
| 255 | <div align='center' > |
||
| 256 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_LEFT . "'$ssel2 > |
||
| 257 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_CENTER . "'$ssel3 > |
||
| 258 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_RIGHT . "'$ssel4 > |
||
| 259 | </div> |
||
| 260 | <div> |
||
| 261 | <span style='float:right;'><input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_RIGHT . "'$ssel1 ></span> |
||
| 262 | <div align='left'><input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_LEFT . "'$ssel0 ></div> |
||
| 263 | </div> |
||
| 264 | <div align='center'> |
||
| 265 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5 > |
||
| 266 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7 > |
||
| 267 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6 > |
||
| 268 | </div> |
||
| 269 | <br> |
||
| 270 | <div style='float:left;width:30%;'> </div> |
||
| 271 | <div style='float:left;background-color:$scoln;'> |
||
| 272 | <input type='radio' name='side[$bid]' value='-1' $sseln > |
||
| 273 | </div> |
||
| 274 | <div style='float:left;'>" . _NONE . "</div> |
||
| 275 | </td> |
||
| 276 | <td class='$class' align='center'> |
||
| 277 | <input type='text' name=weight[$bid] value='$weight' size='3' maxlength='5' style='text-align:right;' > |
||
| 278 | </td> |
||
| 279 | <td class='$class' align='center'> |
||
| 280 | <select name='bmodule[$bid][]' size='5' multiple='multiple'> |
||
| 281 | $module_options |
||
| 282 | </select> |
||
| 283 | </td> |
||
| 284 | <td class='$class' align='center'> |
||
| 285 | <select name='bcachetime[$bid]' size='1'> |
||
| 286 | $cachetime_options |
||
| 287 | </select> |
||
| 288 | </td> |
||
| 289 | <td class='$class' align='right'> |
||
| 290 | <a href='admin.php?fct=blocksadmin&op=edit&bid=$bid'>" . _EDIT . "</a>{$delete_link}{$clone_link} |
||
| 291 | <input type='hidden' name='bid[$bid]' value='$bid' > |
||
| 292 | </td> |
||
| 293 | </tr>\n"; |
||
| 294 | |||
| 295 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 296 | } |
||
| 297 | |||
| 298 | echo "<tr> |
||
| 299 | <td class='foot' align='center' colspan='6'> |
||
| 300 | <input type='hidden' name='query4redirect' value='$query4redirect' > |
||
| 301 | <input type='hidden' name='fct' value='blocksadmin' > |
||
| 302 | <input type='hidden' name='op' value='order' > |
||
| 303 | " . $GLOBALS['xoopsSecurity']->getTokenHTML('myblocksadmin') . " |
||
| 304 | <input type='submit' name='submit' value='" . _SUBMIT . "' > |
||
| 305 | </td> |
||
| 306 | </tr> |
||
| 307 | </table> |
||
| 308 | </form>\n"; |
||
| 309 | echo '</div>'; |
||
| 310 | } |
||
| 311 | |||
| 376 |