Conditions | 22 |
Paths | 3457 |
Total Lines | 226 |
Code Lines | 177 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
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 | |||
65 | $adminObject = Admin::getInstance(); |
||
66 | $adminObject->displayNavigation(basename(__FILE__)); |
||
67 | |||
68 | xoops_loadLanguage('admin', 'system'); |
||
69 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
70 | xoops_loadLanguage('admin/groups', 'system'); |
||
71 | |||
72 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
73 | $moduleHandler = xoops_getHandler('module'); |
||
74 | /** @var \XoopsMemberHandler $memberHandler */ |
||
75 | $memberHandler = xoops_getHandler('member'); |
||
76 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
77 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
78 | $groups = $memberHandler->getGroups(); |
||
79 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
80 | $criteria->add(new \Criteria('isactive', 1)); |
||
81 | $moduleList = $moduleHandler->getList($criteria); |
||
82 | $moduleList[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE; |
||
83 | $moduleList[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; |
||
84 | ksort($moduleList); |
||
85 | echo " |
||
86 | <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
87 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
88 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
89 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
90 | <tr valign='middle'><th align='center'>" |
||
91 | . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') |
||
92 | . "</th><th align='center' nowrap='nowrap'>" |
||
93 | . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') |
||
94 | . '<br>' |
||
95 | . _LEFT |
||
96 | . '-' |
||
97 | . _CENTER |
||
98 | . '-' |
||
99 | . _RIGHT |
||
100 | . "</th><th align='center'>" |
||
101 | . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT') |
||
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 | $blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
|
|||
115 | $blockCount = count($blockArray); |
||
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 ($blockArray as $i) { |
||
131 | $groupsPerms = $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 | $cachetimeOptions = ''; |
||
140 | foreach ($cachetimes as $cachetime => $cachetimeName) { |
||
141 | if ($i->getVar('bcachetime') == $cachetime) { |
||
142 | $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n"; |
||
143 | } else { |
||
144 | $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</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 ($moduleList as $k => $v) { |
||
244 | echo "<option value='$k'" . (in_array($k, $modules) ? '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'), $groupsPerms) ? '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">' . $cachetimeOptions . '</select> |
||
256 | </td>'; |
||
257 | |||
258 | // Actions |
||
259 | |||
260 | 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 . "'> |
||
261 | </a> <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'> |
||
262 | </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 . "'> |
||
265 | </a>"; |
||
266 | } |
||
267 | echo " |
||
268 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
269 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
270 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
271 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
272 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
273 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
274 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
275 | </td></tr> |
||
276 | "; |
||
277 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
278 | } |
||
279 | echo "<tr><td class='foot' align='center' colspan='8'> |
||
280 | <input type='hidden' name='op' value='order'> |
||
281 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
||
282 | <input type='submit' name='submit' value='" . _SUBMIT . "'> |
||
283 | </td></tr></table> |
||
614 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.