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