| Conditions | 23 |
| Paths | 3457 |
| Total Lines | 222 |
| Code Lines | 178 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 50 | function listBlocks() |
||
| 51 | { |
||
| 52 | global $xoopsModule, $pathIcon16; |
||
| 53 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
| 54 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 55 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); //$capsDirName |
||
| 56 | /** @var \XoopsMySQLDatabase $db */ |
||
| 57 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 58 | xoops_loadLanguage('admin', 'system'); |
||
| 59 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
| 60 | xoops_loadLanguage('admin/groups', 'system'); |
||
| 61 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 62 | $moduleHandler = xoops_getHandler('module'); |
||
| 63 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 64 | $memberHandler = xoops_getHandler('member'); |
||
| 65 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 66 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 67 | $groups = $memberHandler->getGroups(); |
||
| 68 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
| 69 | $criteria->add(new \Criteria('isactive', 1)); |
||
| 70 | $module_list = $moduleHandler->getList($criteria); |
||
| 71 | $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE; |
||
| 72 | $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; |
||
| 73 | ksort($module_list); |
||
| 74 | echo " |
||
| 75 | <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
| 76 | $moduleHandler = xoops_getHandler('module'); |
||
|
|
|||
| 77 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
| 78 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 79 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
| 80 | <tr valign='middle'><th align='center'>" |
||
| 81 | . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') |
||
| 82 | . "</th><th align='center' nowrap='nowrap'>" |
||
| 83 | . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') |
||
| 84 | . '<br>' |
||
| 85 | . _LEFT |
||
| 86 | . '-' |
||
| 87 | . _CENTER |
||
| 88 | . '-' |
||
| 89 | . _RIGHT |
||
| 90 | . "</th><th align='center'>" |
||
| 91 | . constant( |
||
| 92 | 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT' |
||
| 93 | ) |
||
| 94 | . "</th><th align='center'>" |
||
| 95 | . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE') |
||
| 96 | . "</th><th align='center'>" |
||
| 97 | . _AM_SYSTEM_BLOCKS_VISIBLEIN |
||
| 98 | . "</th><th align='center'>" |
||
| 99 | . _AM_SYSTEM_ADGS |
||
| 100 | . "</th><th align='center'>" |
||
| 101 | . _AM_SYSTEM_BLOCKS_BCACHETIME |
||
| 102 | . "</th><th align='center'>" |
||
| 103 | . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION') |
||
| 104 | . '</th></tr> |
||
| 105 | '; |
||
| 106 | $block_arr = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
| 107 | $block_count = count($block_arr); |
||
| 108 | $class = 'even'; |
||
| 109 | $cachetimes = [ |
||
| 110 | '0' => _NOCACHE, |
||
| 111 | '30' => sprintf(_SECONDS, 30), |
||
| 112 | '60' => _MINUTE, |
||
| 113 | '300' => sprintf(_MINUTES, 5), |
||
| 114 | '1800' => sprintf(_MINUTES, 30), |
||
| 115 | '3600' => _HOUR, |
||
| 116 | '18000' => sprintf(_HOURS, 5), |
||
| 117 | '86400' => _DAY, |
||
| 118 | '259200' => sprintf(_DAYS, 3), |
||
| 119 | '604800' => _WEEK, |
||
| 120 | '2592000' => _MONTH, |
||
| 121 | ]; |
||
| 122 | foreach ($block_arr as $i) { |
||
| 123 | /** @var \XoopsBlock $i */ |
||
| 124 | $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||
| 125 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||
| 126 | $result = $db->query($sql); |
||
| 127 | $modules = []; |
||
| 128 | if ($result instanceof \mysqli_result) { |
||
| 129 | while (false !== ($row = $db->fetchArray($result))) { |
||
| 130 | $modules[] = (int)$row['module_id']; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $cachetime_options = ''; |
||
| 134 | foreach ($cachetimes as $cachetime => $cachetime_name) { |
||
| 135 | if ($i->getVar('bcachetime') == $cachetime) { |
||
| 136 | $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n"; |
||
| 137 | } else { |
||
| 138 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; |
||
| 142 | if (1 === $i->getVar('visible')) { |
||
| 143 | $sel1 = ' checked'; |
||
| 144 | } else { |
||
| 145 | $sel0 = ' checked'; |
||
| 146 | } |
||
| 147 | if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
||
| 148 | $ssel0 = ' checked'; |
||
| 149 | } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
||
| 150 | $ssel1 = ' checked'; |
||
| 151 | } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
||
| 152 | $ssel2 = ' checked'; |
||
| 153 | } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
||
| 154 | $ssel4 = ' checked'; |
||
| 155 | } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
||
| 156 | $ssel3 = ' checked'; |
||
| 157 | } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
||
| 158 | $ssel5 = ' checked'; |
||
| 159 | } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
||
| 160 | $ssel6 = ' checked'; |
||
| 161 | } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
||
| 162 | $ssel7 = ' checked'; |
||
| 163 | } |
||
| 164 | if ('' === $i->getVar('title')) { |
||
| 165 | $title = ' '; |
||
| 166 | } else { |
||
| 167 | $title = $i->getVar('title'); |
||
| 168 | } |
||
| 169 | $name = $i->getVar('name'); |
||
| 170 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" |
||
| 171 | . $i->getVar('bid') |
||
| 172 | . "]' value='" |
||
| 173 | . $title |
||
| 174 | . "'></td><td class='$class' align='center' nowrap='nowrap'> |
||
| 175 | <div align='center' > |
||
| 176 | <input type='radio' name='side[" |
||
| 177 | . $i->getVar('bid') |
||
| 178 | . "]' value='" |
||
| 179 | . XOOPS_CENTERBLOCK_LEFT |
||
| 180 | . "'$ssel2> |
||
| 181 | <input type='radio' name='side[" |
||
| 182 | . $i->getVar('bid') |
||
| 183 | . "]' value='" |
||
| 184 | . XOOPS_CENTERBLOCK_CENTER |
||
| 185 | . "'$ssel3> |
||
| 186 | <input type='radio' name='side[" |
||
| 187 | . $i->getVar('bid') |
||
| 188 | . "]' value='" |
||
| 189 | . XOOPS_CENTERBLOCK_RIGHT |
||
| 190 | . "'$ssel4> |
||
| 191 | </div> |
||
| 192 | <div> |
||
| 193 | <span style='float:right;'><input type='radio' name='side[" |
||
| 194 | . $i->getVar('bid') |
||
| 195 | . "]' value='" |
||
| 196 | . XOOPS_SIDEBLOCK_RIGHT |
||
| 197 | . "'$ssel1></span> |
||
| 198 | <div align='left'><input type='radio' name='side[" |
||
| 199 | . $i->getVar('bid') |
||
| 200 | . "]' value='" |
||
| 201 | . XOOPS_SIDEBLOCK_LEFT |
||
| 202 | . "'$ssel0></div> |
||
| 203 | </div> |
||
| 204 | <div align='center'> |
||
| 205 | <input type='radio' name='side[" |
||
| 206 | . $i->getVar('bid') |
||
| 207 | . "]' value='" |
||
| 208 | . XOOPS_CENTERBLOCK_BOTTOMLEFT |
||
| 209 | . "'$ssel5> |
||
| 210 | <input type='radio' name='side[" |
||
| 211 | . $i->getVar('bid') |
||
| 212 | . "]' value='" |
||
| 213 | . XOOPS_CENTERBLOCK_BOTTOM |
||
| 214 | . "'$ssel7> |
||
| 215 | <input type='radio' name='side[" |
||
| 216 | . $i->getVar('bid') |
||
| 217 | . "]' value='" |
||
| 218 | . XOOPS_CENTERBLOCK_BOTTOMRIGHT |
||
| 219 | . "'$ssel6> |
||
| 220 | </div> |
||
| 221 | </td><td class='$class' align='center'><input type='text' name='weight[" |
||
| 222 | . $i->getVar('bid') |
||
| 223 | . "]' value='" |
||
| 224 | . $i->getVar('weight') |
||
| 225 | . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible[" |
||
| 226 | . $i->getVar('bid') |
||
| 227 | . "]' value='1'$sel1>" |
||
| 228 | . _YES |
||
| 229 | . " <input type='radio' name='visible[" |
||
| 230 | . $i->getVar('bid') |
||
| 231 | . "]' value='0'$sel0>" |
||
| 232 | . _NO |
||
| 233 | . '</td>'; |
||
| 234 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
| 235 | foreach ($module_list as $k => $v) { |
||
| 236 | echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||
| 237 | } |
||
| 238 | echo '</select></td>'; |
||
| 239 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
| 240 | foreach ($groups as $grp) { |
||
| 241 | /** @var \XoopsGroup $grp */ |
||
| 242 | echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||
| 243 | } |
||
| 244 | echo '</select></td>'; |
||
| 245 | // Cache lifetime |
||
| 246 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select> |
||
| 247 | </td>'; |
||
| 248 | // Actions |
||
| 249 | echo "<td class='$class' align='center'><a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'> |
||
| 250 | </a> <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'> |
||
| 251 | </a>"; |
||
| 252 | if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
| 253 | echo " <a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
| 254 | </a>"; |
||
| 255 | } |
||
| 256 | echo " |
||
| 257 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
| 258 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
| 259 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
| 260 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
| 261 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
| 262 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
| 263 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
| 264 | </td></tr> |
||
| 265 | "; |
||
| 266 | $class = 'even' === $class ? 'odd' : 'even'; |
||
| 267 | } |
||
| 268 | echo "<tr><td class='foot' align='center' colspan='7'> |
||
| 269 | <input type='hidden' name='op' value='order'> |
||
| 270 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
||
| 271 | <input type='submit' name='submit' value='" . _SUBMIT . "'> |
||
| 272 | </td></tr></table> |
||
| 577 |