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