Total Complexity | 80 |
Total Lines | 600 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Blocksadmin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Blocksadmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class Blocksadmin |
||
28 | { |
||
29 | /** |
||
30 | * @var \XoopsMySQLDatabase|null |
||
31 | */ |
||
32 | public $db; |
||
33 | /** |
||
34 | * @var \Xmf\Module\Helper |
||
35 | */ |
||
36 | public $helper; |
||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | public $moduleDirName; |
||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | public $moduleDirNameUpper; |
||
45 | |||
46 | /** |
||
47 | * Blocksadmin constructor. |
||
48 | */ |
||
49 | public function __construct(?\XoopsDatabase $db, \Xmf\Module\Helper $helper) |
||
50 | { |
||
51 | if (null === $db) { |
||
52 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
53 | } |
||
54 | $this->db = $db; |
||
55 | $this->helper = $helper; |
||
56 | $this->moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
57 | $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName); |
||
58 | \xoops_loadLanguage('admin', 'system'); |
||
59 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
60 | \xoops_loadLanguage('admin/groups', 'system'); |
||
61 | \xoops_loadLanguage('common', $this->moduleDirName); |
||
62 | \xoops_loadLanguage('blocksadmin', $this->moduleDirName); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return void |
||
67 | */ |
||
68 | public function listBlocks(): void |
||
69 | { |
||
70 | global $xoopsModule, $pathIcon16; |
||
71 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
72 | // xoops_loadLanguage('admin', 'system'); |
||
73 | // xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
74 | // xoops_loadLanguage('admin/groups', 'system'); |
||
75 | // xoops_loadLanguage('common', $moduleDirName); |
||
76 | // xoops_loadLanguage('blocks', $moduleDirName); |
||
77 | |||
78 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
79 | $moduleHandler = \xoops_getHandler('module'); |
||
80 | /** @var \XoopsMemberHandler $memberHandler */ |
||
81 | $memberHandler = \xoops_getHandler('member'); |
||
82 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
83 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
84 | $groups = $memberHandler->getGroups(); |
||
85 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', '1')); |
||
86 | $criteria->add(new \Criteria('isactive', '1')); |
||
87 | $moduleList = $moduleHandler->getList($criteria); |
||
88 | $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
||
89 | $moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
||
90 | \ksort($moduleList); |
||
91 | echo "<h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
92 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
93 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
94 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
95 | <tr valign='middle'><th align='center'>" . \_AM_SYSTEM_BLOCKS_TITLE . "</th><th align='center' nowrap='nowrap'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE') . '<br>' . _LEFT . '-' . _CENTER . '-' . _RIGHT . "</th> |
||
96 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT') . "</th> |
||
97 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') . "</th><th align='center'>" . \_AM_SYSTEM_BLOCKS_VISIBLEIN . "</th> |
||
98 | <th align='center'>" . \_AM_SYSTEM_ADGS . "</th> |
||
99 | <th align='center'>" . \_AM_SYSTEM_BLOCKS_BCACHETIME . "</th> |
||
100 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') . '</th> |
||
101 | </tr>'; |
||
102 | $blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
|
|||
103 | $blockCount = \count($blockArray); |
||
104 | $class = 'even'; |
||
105 | $cachetimes = [ |
||
106 | 0 => _NOCACHE, |
||
107 | 30 => \sprintf(_SECONDS, 30), |
||
108 | 60 => _MINUTE, |
||
109 | 300 => \sprintf(_MINUTES, 5), |
||
110 | 1800 => \sprintf(_MINUTES, 30), |
||
111 | 3600 => _HOUR, |
||
112 | 18000 => \sprintf(_HOURS, 5), |
||
113 | 86400 => _DAY, |
||
114 | 259200 => \sprintf(_DAYS, 3), |
||
115 | 604800 => _WEEK, |
||
116 | 2592000 => _MONTH, |
||
117 | ]; |
||
118 | foreach ($blockArray as $i) { |
||
119 | $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||
120 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||
121 | $result = $this->db->query($sql); |
||
122 | $modules = []; |
||
123 | if (!$result instanceof \mysqli_result) { |
||
124 | \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
||
125 | } |
||
126 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
127 | $modules[] = (int)$row['module_id']; |
||
128 | } |
||
129 | |||
130 | $cachetimeOptions = ''; |
||
131 | foreach ($cachetimes as $cachetime => $cachetimeName) { |
||
132 | if ($i->getVar('bcachetime') == $cachetime) { |
||
133 | $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n"; |
||
134 | } else { |
||
135 | $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n"; |
||
136 | } |
||
137 | } |
||
138 | |||
139 | $ssel7 = ''; |
||
140 | $ssel6 = $ssel7; |
||
141 | $ssel5 = $ssel6; |
||
142 | $ssel4 = $ssel5; |
||
143 | $ssel3 = $ssel4; |
||
144 | $ssel2 = $ssel3; |
||
145 | $ssel1 = $ssel2; |
||
146 | $ssel0 = $ssel1; |
||
147 | $sel1 = $ssel0; |
||
148 | $sel0 = $sel1; |
||
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[" . $i->getVar('bid') . "]' value='" . $title . "'></td> |
||
178 | <td class='$class' align='center' nowrap='nowrap'><div align='center' > |
||
179 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_LEFT . "'$ssel2> |
||
180 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_CENTER . "'$ssel3> |
||
181 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_RIGHT . "'$ssel4> |
||
182 | </div> |
||
183 | <div> |
||
184 | <span style='float:right;'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_RIGHT . "'$ssel1></span> |
||
185 | <div align='left'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_LEFT . "'$ssel0></div> |
||
186 | </div> |
||
187 | <div align='center'> |
||
188 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5> |
||
189 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7> |
||
190 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6> |
||
191 | </div> |
||
192 | </td> |
||
193 | <td class='$class' align='center'><input type='text' name='weight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "' size='5' maxlength='5'></td> |
||
194 | <td class='$class' align='center' nowrap><input type='radio' name='visible[" . $i->getVar('bid') . "]' value='1'$sel1>" . _YES . " <input type='radio' name='visible[" . $i->getVar('bid') . "]' value='0'$sel0>" . _NO . '</td>'; |
||
195 | |||
196 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
197 | foreach ($moduleList as $k => $v) { |
||
198 | echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||
199 | } |
||
200 | echo '</select></td>'; |
||
201 | |||
202 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
203 | foreach ($groups as $grp) { |
||
204 | echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||
205 | } |
||
206 | echo '</select></td>'; |
||
207 | |||
208 | // Cache lifetime |
||
209 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select> |
||
210 | </td>'; |
||
211 | |||
212 | // Actions |
||
213 | |||
214 | echo "<td class='$class' align='center'> |
||
215 | <a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
||
216 | <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
||
217 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
218 | // 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 . "'> |
||
219 | // </a>"; |
||
220 | // } |
||
221 | |||
222 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
223 | if (!\in_array($i->getVar('block_type'), ['M', 'S'])) { |
||
224 | echo " |
||
225 | <a href='blocksadmin.php?op=delete&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
226 | </a>"; |
||
227 | } |
||
228 | echo " |
||
229 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
230 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
231 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
232 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
233 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
234 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
235 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
236 | </td></tr> |
||
237 | "; |
||
238 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
239 | } |
||
240 | echo "<tr><td class='foot' align='center' colspan='8'> <input type='hidden' name='op' value='order'>" . $GLOBALS['xoopsSecurity']->getTokenHTML() . "<input type='submit' name='submit' value='" . _SUBMIT . "'></td></tr></table></form><br><br>"; |
||
241 | } |
||
242 | |||
243 | public function deleteBlock(int $bid): void |
||
259 | } |
||
260 | |||
261 | public function cloneBlock(int $bid): void |
||
303 | // xoops_cp_footer(); |
||
304 | // require_once __DIR__ . '/admin_footer.php'; |
||
305 | // exit(); |
||
306 | } |
||
307 | |||
308 | public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
||
309 | { |
||
310 | \xoops_loadLanguage('admin', 'system'); |
||
311 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
312 | \xoops_loadLanguage('admin/groups', 'system'); |
||
313 | |||
314 | $block = new \XoopsBlock($bid); |
||
315 | $clone = $block->xoopsClone(); |
||
316 | if (empty($bmodule)) { |
||
317 | // \xoops_cp_header(); |
||
318 | \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||
319 | \xoops_cp_footer(); |
||
320 | exit(); |
||
321 | } |
||
322 | $clone->setVar('side', $bside); |
||
323 | $clone->setVar('weight', $bweight); |
||
324 | $clone->setVar('visible', $bvisible); |
||
325 | //$clone->setVar('content', $_POST['bcontent']); |
||
326 | $clone->setVar('title', Request::getString('btitle', '', 'POST')); |
||
327 | $clone->setVar('bcachetime', $bcachetime); |
||
328 | if (\is_array($options) && (\count($options) > 0)) { |
||
329 | $options = \implode('|', $options); |
||
330 | $clone->setVar('options', $options); |
||
331 | } |
||
332 | $clone->setVar('bid', 0); |
||
333 | if (\in_array($block->getVar('block_type'), ['C', 'E'])) { |
||
334 | $clone->setVar('block_type', 'E'); |
||
335 | } else { |
||
336 | $clone->setVar('block_type', 'D'); |
||
337 | } |
||
338 | // $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105 |
||
339 | if ($clone->store()) { |
||
340 | $newid = $clone->id(); //get the id of the cloned block |
||
341 | } |
||
342 | if (!$newid) { |
||
343 | // \xoops_cp_header(); |
||
344 | $clone->getHtmlErrors(); |
||
345 | \xoops_cp_footer(); |
||
346 | exit(); |
||
347 | } |
||
348 | if ('' !== $clone->getVar('template')) { |
||
349 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
350 | $tplfileHandler = \xoops_getHandler('tplfile'); |
||
351 | $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid); |
||
352 | if (\count($btemplate) > 0) { |
||
353 | $tplclone = $btemplate[0]->xoopsClone(); |
||
354 | $tplclone->setVar('tpl_id', 0); |
||
355 | $tplclone->setVar('tpl_refid', $newid); |
||
356 | $tplfileHandler->insert($tplclone); |
||
357 | } |
||
358 | } |
||
359 | |||
360 | foreach ($bmodule as $bmid) { |
||
361 | $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
||
362 | $this->db->query($sql); |
||
363 | } |
||
364 | //$groups = &$GLOBALS['xoopsUser']->getGroups(); |
||
365 | foreach ($groups as $iValue) { |
||
366 | $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')"; |
||
367 | $this->db->query($sql); |
||
368 | } |
||
369 | $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
||
370 | } |
||
371 | |||
372 | public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void |
||
381 | // /** @var \XoopsBlockHandler $blockHandler */ |
||
382 | // $blockHandler = \xoops_getHandler('block'); |
||
383 | // return $blockHandler->insert($myblock); |
||
384 | } |
||
385 | |||
386 | public function editBlock(int $bid): void |
||
387 | { |
||
388 | // require_once \dirname(__DIR__,2) . '/admin/admin_header.php'; |
||
389 | // \xoops_cp_header(); |
||
390 | \xoops_loadLanguage('admin', 'system'); |
||
391 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
392 | \xoops_loadLanguage('admin/groups', 'system'); |
||
393 | // mpu_adm_menu(); |
||
394 | $myblock = new \XoopsBlock($bid); |
||
395 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; |
||
396 | $result = $this->db->query($sql); |
||
397 | $modules = []; |
||
398 | if ($result instanceof \mysqli_result) { |
||
399 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
400 | $modules[] = (int)$row['module_id']; |
||
401 | } |
||
402 | } |
||
403 | $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
||
404 | $block = [ |
||
405 | 'title' => $myblock->getVar('title'), |
||
406 | 'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK, |
||
407 | // 'name' => $myblock->getVar('name'), |
||
408 | 'side' => $myblock->getVar('side'), |
||
409 | 'weight' => $myblock->getVar('weight'), |
||
410 | 'visible' => $myblock->getVar('visible'), |
||
411 | 'content' => $myblock->getVar('content', 'N'), |
||
412 | 'modules' => $modules, |
||
413 | 'is_custom' => $isCustom, |
||
414 | 'ctype' => $myblock->getVar('c_type'), |
||
415 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||
416 | 'op' => 'edit_ok', |
||
417 | 'bid' => $myblock->getVar('bid'), |
||
418 | 'edit_form' => $myblock->getOptions(), |
||
419 | 'template' => $myblock->getVar('template'), |
||
420 | 'options' => $myblock->getVar('options'), |
||
421 | ]; |
||
422 | echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>'; |
||
423 | |||
424 | echo $this->render($block); |
||
425 | } |
||
426 | |||
427 | public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
||
428 | { |
||
429 | $myblock = new \XoopsBlock($bid); |
||
430 | $myblock->setVar('title', $btitle); |
||
431 | $myblock->setVar('weight', $bweight); |
||
432 | $myblock->setVar('visible', $bvisible); |
||
433 | $myblock->setVar('side', $bside); |
||
434 | $myblock->setVar('bcachetime', $bcachetime); |
||
435 | //update block options |
||
436 | if (isset($options)) { |
||
437 | $optionsCount = \count($options); |
||
438 | if ($optionsCount > 0) { |
||
439 | //Convert array values to comma-separated |
||
440 | foreach ($options as $i => $iValue) { |
||
441 | if (\is_array($iValue)) { |
||
442 | $options[$i] = \implode(',', $iValue); |
||
443 | } |
||
444 | } |
||
445 | $options = \implode('|', $options); |
||
446 | $myblock->setVar('options', $options); |
||
447 | } |
||
448 | } |
||
449 | $myblock->store(); |
||
450 | // /** @var \XoopsBlockHandler $blockHandler */ |
||
451 | // $blockHandler = \xoops_getHandler('block'); |
||
452 | // $blockHandler->insert($myblock); |
||
453 | |||
454 | if (!empty($bmodule) && \count($bmodule) > 0) { |
||
455 | $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
||
456 | $this->db->query($sql); |
||
457 | if (\in_array(0, $bmodule)) { |
||
458 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0); |
||
459 | $this->db->query($sql); |
||
460 | } else { |
||
461 | foreach ($bmodule as $bmid) { |
||
462 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid); |
||
463 | $this->db->query($sql); |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid); |
||
468 | $this->db->query($sql); |
||
469 | if (!empty($groups)) { |
||
470 | foreach ($groups as $grp) { |
||
471 | $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid); |
||
472 | $this->db->query($sql); |
||
473 | } |
||
474 | } |
||
475 | $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||
476 | } |
||
477 | |||
478 | public function orderBlock( |
||
479 | array $bid, array $oldtitle, array $oldside, array $oldweight, array $oldvisible, array $oldgroups, array $oldbcachetime, array $oldbmodule, array $title, array $weight, array $visible, array $side, array $bcachetime, array $groups, array $bmodule |
||
480 | ): void { |
||
481 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
482 | \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
483 | } |
||
484 | foreach (\array_keys($bid) as $i) { |
||
485 | if ($oldtitle[$i] !== $title[$i] |
||
486 | || $oldweight[$i] !== $weight[$i] |
||
487 | || $oldvisible[$i] !== $visible[$i] |
||
488 | || $oldside[$i] !== $side[$i] |
||
489 | || $oldbcachetime[$i] !== $bcachetime[$i] |
||
490 | || $oldbmodule[$i] !== $bmodule[$i]) { |
||
491 | $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); |
||
492 | } |
||
493 | if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) { |
||
494 | $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]); |
||
495 | $this->db->query($sql); |
||
496 | if (\in_array(0, $bmodule[$i], true)) { |
||
497 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0); |
||
498 | $this->db->query($sql); |
||
499 | } else { |
||
500 | foreach ($bmodule[$i] as $bmid) { |
||
501 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid); |
||
502 | $this->db->query($sql); |
||
503 | } |
||
504 | } |
||
505 | } |
||
506 | $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]); |
||
507 | $this->db->query($sql); |
||
508 | if (!empty($groups[$i])) { |
||
509 | foreach ($groups[$i] as $grp) { |
||
510 | $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]); |
||
511 | $this->db->query($sql); |
||
512 | } |
||
513 | } |
||
514 | } |
||
515 | |||
516 | $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||
517 | } |
||
518 | |||
519 | public function render(?array $block = null) |
||
627 | } |
||
628 | } |
||
629 |
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.