Total Complexity | 77 |
Total Lines | 707 |
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 |
||
24 | class Blocksadmin |
||
25 | { |
||
26 | /** |
||
27 | * @var \XoopsMySQLDatabase|null |
||
28 | */ |
||
29 | public $db; |
||
30 | public $modHelper; |
||
31 | public $moduleDirName; |
||
32 | public $moduleDirNameUpper; |
||
33 | |||
34 | /** |
||
35 | * @param $db |
||
36 | * @param $modHelper |
||
37 | */ |
||
38 | public function __construct($db, $modHelper) |
||
39 | { |
||
40 | if (null === $db){ |
||
41 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
42 | } |
||
43 | $this->db = $db; |
||
44 | $this->modHelper = $modHelper; |
||
45 | $this->moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
46 | $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName); |
||
47 | \xoops_loadLanguage('admin', 'system'); |
||
48 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
49 | \xoops_loadLanguage('admin/groups', 'system'); |
||
50 | \xoops_loadLanguage('common', $this->moduleDirName); |
||
51 | \xoops_loadLanguage('blocksadmin', $this->moduleDirName); |
||
52 | } |
||
53 | |||
54 | public function listBlocks(): void |
||
55 | { |
||
56 | global $xoopsModule, $pathIcon16; |
||
57 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
58 | // xoops_loadLanguage('admin', 'system'); |
||
59 | // xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
60 | // xoops_loadLanguage('admin/groups', 'system'); |
||
61 | // xoops_loadLanguage('common', $moduleDirName); |
||
62 | // xoops_loadLanguage('blocks', $moduleDirName); |
||
63 | |||
64 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
65 | $moduleHandler = \xoops_getHandler('module'); |
||
66 | /** @var \XoopsMemberHandler $memberHandler */ |
||
67 | $memberHandler = \xoops_getHandler('member'); |
||
68 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
69 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
70 | $groups = $memberHandler->getGroups(); |
||
71 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
72 | $criteria->add(new \Criteria('isactive', 1)); |
||
73 | $moduleList = $moduleHandler->getList($criteria); |
||
74 | $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
||
75 | $moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
||
76 | \ksort($moduleList); |
||
77 | echo " |
||
78 | <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
79 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
80 | $moduleHandler = \xoops_getHandler('module'); |
||
|
|||
81 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
82 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
83 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
84 | <tr valign='middle'><th align='center'>" |
||
85 | . \_AM_SYSTEM_BLOCKS_TITLE |
||
86 | . "</th><th align='center' nowrap='nowrap'>" |
||
87 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE') |
||
88 | . '<br>' |
||
89 | . _LEFT |
||
90 | . '-' |
||
91 | . _CENTER |
||
92 | . '-' |
||
93 | . _RIGHT |
||
94 | . "</th><th align='center'>" |
||
95 | . \constant( |
||
96 | 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT' |
||
97 | ) |
||
98 | . "</th><th align='center'>" |
||
99 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') |
||
100 | . "</th><th align='center'>" |
||
101 | . \_AM_SYSTEM_BLOCKS_VISIBLEIN |
||
102 | . "</th><th align='center'>" |
||
103 | . \_AM_SYSTEM_ADGS |
||
104 | . "</th><th align='center'>" |
||
105 | . \_AM_SYSTEM_BLOCKS_BCACHETIME |
||
106 | . "</th><th align='center'>" |
||
107 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') |
||
108 | . '</th></tr> |
||
109 | '; |
||
110 | $blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
111 | $blockCount = \count($blockArray); |
||
112 | $class = 'even'; |
||
113 | $cachetimes = [ |
||
114 | 0 => _NOCACHE, |
||
115 | 30 => \sprintf(_SECONDS, 30), |
||
116 | 60 => _MINUTE, |
||
117 | 300 => \sprintf(_MINUTES, 5), |
||
118 | 1800 => \sprintf(_MINUTES, 30), |
||
119 | 3600 => _HOUR, |
||
120 | 18000 => \sprintf(_HOURS, 5), |
||
121 | 86400 => _DAY, |
||
122 | 259200 => \sprintf(_DAYS, 3), |
||
123 | 604800 => _WEEK, |
||
124 | 2592000 => _MONTH, |
||
125 | ]; |
||
126 | foreach ($blockArray as $i) { |
||
127 | $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||
128 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||
129 | $result = $this->db->query($sql); |
||
130 | $modules = []; |
||
131 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
132 | $modules[] = (int)$row['module_id']; |
||
133 | } |
||
134 | |||
135 | $cachetimeOptions = ''; |
||
136 | foreach ($cachetimes as $cachetime => $cachetimeName) { |
||
137 | if ($i->getVar('bcachetime') == $cachetime) { |
||
138 | $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n"; |
||
139 | } else { |
||
140 | $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n"; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; |
||
145 | if (1 === $i->getVar('visible')) { |
||
146 | $sel1 = ' checked'; |
||
147 | } else { |
||
148 | $sel0 = ' checked'; |
||
149 | } |
||
150 | if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
||
151 | $ssel0 = ' checked'; |
||
152 | } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
||
153 | $ssel1 = ' checked'; |
||
154 | } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
||
155 | $ssel2 = ' checked'; |
||
156 | } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
||
157 | $ssel4 = ' checked'; |
||
158 | } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
||
159 | $ssel3 = ' checked'; |
||
160 | } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
||
161 | $ssel5 = ' checked'; |
||
162 | } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
||
163 | $ssel6 = ' checked'; |
||
164 | } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
||
165 | $ssel7 = ' checked'; |
||
166 | } |
||
167 | if ('' === $i->getVar('title')) { |
||
168 | $title = ' '; |
||
169 | } else { |
||
170 | $title = $i->getVar('title'); |
||
171 | } |
||
172 | $name = $i->getVar('name'); |
||
173 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" |
||
174 | . $i->getVar('bid') |
||
175 | . "]' value='" |
||
176 | . $title |
||
177 | . "'></td><td class='$class' align='center' nowrap='nowrap'> |
||
178 | <div align='center' > |
||
179 | <input type='radio' name='side[" |
||
180 | . $i->getVar('bid') |
||
181 | . "]' value='" |
||
182 | . \XOOPS_CENTERBLOCK_LEFT |
||
183 | . "'$ssel2> |
||
184 | <input type='radio' name='side[" |
||
185 | . $i->getVar('bid') |
||
186 | . "]' value='" |
||
187 | . \XOOPS_CENTERBLOCK_CENTER |
||
188 | . "'$ssel3> |
||
189 | <input type='radio' name='side[" |
||
190 | . $i->getVar('bid') |
||
191 | . "]' value='" |
||
192 | . \XOOPS_CENTERBLOCK_RIGHT |
||
193 | . "'$ssel4> |
||
194 | </div> |
||
195 | <div> |
||
196 | <span style='float:right;'><input type='radio' name='side[" |
||
197 | . $i->getVar('bid') |
||
198 | . "]' value='" |
||
199 | . \XOOPS_SIDEBLOCK_RIGHT |
||
200 | . "'$ssel1></span> |
||
201 | <div align='left'><input type='radio' name='side[" |
||
202 | . $i->getVar('bid') |
||
203 | . "]' value='" |
||
204 | . \XOOPS_SIDEBLOCK_LEFT |
||
205 | . "'$ssel0></div> |
||
206 | </div> |
||
207 | <div align='center'> |
||
208 | <input type='radio' name='side[" |
||
209 | . $i->getVar('bid') |
||
210 | . "]' value='" |
||
211 | . \XOOPS_CENTERBLOCK_BOTTOMLEFT |
||
212 | . "'$ssel5> |
||
213 | <input type='radio' name='side[" |
||
214 | . $i->getVar('bid') |
||
215 | . "]' value='" |
||
216 | . \XOOPS_CENTERBLOCK_BOTTOM |
||
217 | . "'$ssel7> |
||
218 | <input type='radio' name='side[" |
||
219 | . $i->getVar('bid') |
||
220 | . "]' value='" |
||
221 | . \XOOPS_CENTERBLOCK_BOTTOMRIGHT |
||
222 | . "'$ssel6> |
||
223 | </div> |
||
224 | </td><td class='$class' align='center'><input type='text' name='weight[" |
||
225 | . $i->getVar('bid') |
||
226 | . "]' value='" |
||
227 | . $i->getVar('weight') |
||
228 | . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible[" |
||
229 | . $i->getVar('bid') |
||
230 | . "]' value='1'$sel1>" |
||
231 | . _YES |
||
232 | . " <input type='radio' name='visible[" |
||
233 | . $i->getVar('bid') |
||
234 | . "]' value='0'$sel0>" |
||
235 | . _NO |
||
236 | . '</td>'; |
||
237 | |||
238 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
239 | foreach ($moduleList as $k => $v) { |
||
240 | echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||
241 | } |
||
242 | echo '</select></td>'; |
||
243 | |||
244 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
245 | foreach ($groups as $grp) { |
||
246 | echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||
247 | } |
||
248 | echo '</select></td>'; |
||
249 | |||
250 | // Cache lifetime |
||
251 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select> |
||
252 | </td>'; |
||
253 | |||
254 | // Actions |
||
255 | |||
256 | 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 . "'> |
||
257 | </a> <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'> |
||
258 | </a>"; |
||
259 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
260 | // 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 . "'> |
||
261 | // </a>"; |
||
262 | // } |
||
263 | |||
264 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
265 | if (!\in_array($i->getVar('block_type'), ['M', 'S'])) { |
||
266 | echo " |
||
267 | <a href='blocksadmin.php?op=delete&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
268 | </a>"; |
||
269 | } |
||
270 | echo " |
||
271 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
272 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
273 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
274 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
275 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
276 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
277 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
278 | </td></tr> |
||
279 | "; |
||
280 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
281 | } |
||
282 | echo "<tr><td class='foot' align='center' colspan='8'> |
||
283 | <input type='hidden' name='op' value='order'> |
||
284 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
||
285 | <input type='submit' name='submit' value='" . _SUBMIT . "'> |
||
286 | </td></tr></table> |
||
287 | </form> |
||
288 | <br><br>"; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @param int $bid |
||
293 | */ |
||
294 | public function deleteBlock($bid) |
||
295 | { |
||
296 | // \xoops_cp_header(); |
||
297 | |||
298 | \xoops_loadLanguage('admin', 'system'); |
||
299 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
300 | \xoops_loadLanguage('admin/groups', 'system'); |
||
301 | |||
302 | $myblock = new \XoopsBlock($bid); |
||
303 | |||
304 | $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid); |
||
305 | if (!$result = $this->db->queryF($sql)) { |
||
306 | return false; |
||
307 | } |
||
308 | $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
||
309 | $this->db->queryF($sql); |
||
310 | |||
311 | $this->modHelper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * @param int $bid |
||
316 | */ |
||
317 | public function cloneBlock($bid): void |
||
318 | { |
||
319 | //require __DIR__ . '/admin_header.php'; |
||
320 | // \xoops_cp_header(); |
||
321 | |||
322 | \xoops_loadLanguage('admin', 'system'); |
||
323 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
324 | \xoops_loadLanguage('admin/groups', 'system'); |
||
325 | |||
326 | $myblock = new \XoopsBlock($bid); |
||
327 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; |
||
328 | $result = $this->db->query($sql); |
||
329 | $modules = []; |
||
330 | if ($result instanceof \mysqli_result) { |
||
331 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
332 | $modules[] = (int)$row['module_id']; |
||
333 | } |
||
334 | } |
||
335 | $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
||
336 | $block = [ |
||
337 | 'title' => $myblock->getVar('title') . ' Clone', |
||
338 | 'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'), |
||
339 | 'name' => $myblock->getVar('name'), |
||
340 | 'side' => $myblock->getVar('side'), |
||
341 | 'weight' => $myblock->getVar('weight'), |
||
342 | 'visible' => $myblock->getVar('visible'), |
||
343 | 'content' => $myblock->getVar('content', 'N'), |
||
344 | 'modules' => $modules, |
||
345 | 'is_custom' => $isCustom, |
||
346 | 'ctype' => $myblock->getVar('c_type'), |
||
347 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||
348 | 'op' => 'clone_ok', |
||
349 | 'bid' => $myblock->getVar('bid'), |
||
350 | 'edit_form' => $myblock->getOptions(), |
||
351 | 'template' => $myblock->getVar('template'), |
||
352 | 'options' => $myblock->getVar('options'), |
||
353 | ]; |
||
354 | echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>'; |
||
355 | // $form = new Blockform(); |
||
356 | // $form->render(); |
||
357 | |||
358 | echo $this->render($block); |
||
359 | // xoops_cp_footer(); |
||
360 | // require_once __DIR__ . '/admin_footer.php'; |
||
361 | // exit(); |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * @param int $bid |
||
366 | * @param string $bside |
||
367 | * @param string $bweight |
||
368 | * @param string $bvisible |
||
369 | * @param string $bcachetime |
||
370 | * @param array $bmodule |
||
371 | * @param null|array|string $options |
||
372 | */ |
||
373 | public function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups): void |
||
374 | { |
||
375 | \xoops_loadLanguage('admin', 'system'); |
||
376 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
377 | \xoops_loadLanguage('admin/groups', 'system'); |
||
378 | |||
379 | $block = new \XoopsBlock($bid); |
||
380 | $clone = $block->xoopsClone(); |
||
381 | if (empty($bmodule)) { |
||
382 | // \xoops_cp_header(); |
||
383 | \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||
384 | \xoops_cp_footer(); |
||
385 | exit(); |
||
386 | } |
||
387 | $clone->setVar('side', $bside); |
||
388 | $clone->setVar('weight', $bweight); |
||
389 | $clone->setVar('visible', $bvisible); |
||
390 | //$clone->setVar('content', $_POST['bcontent']); |
||
391 | $clone->setVar('title', Request::getString('btitle', '', 'POST')); |
||
392 | $clone->setVar('bcachetime', $bcachetime); |
||
393 | if (isset($options) && (\count($options) > 0)) { |
||
394 | $options = \implode('|', $options); |
||
395 | $clone->setVar('options', $options); |
||
396 | } |
||
397 | $clone->setVar('bid', 0); |
||
398 | if (\in_array($block->getVar('block_type'), ['C', 'E'])) { |
||
399 | $clone->setVar('block_type', 'E'); |
||
400 | } else { |
||
401 | $clone->setVar('block_type', 'D'); |
||
402 | } |
||
403 | $newid = $clone->store(); |
||
404 | if (!$newid) { |
||
405 | // \xoops_cp_header(); |
||
406 | $clone->getHtmlErrors(); |
||
407 | \xoops_cp_footer(); |
||
408 | exit(); |
||
409 | } |
||
410 | if ('' !== $clone->getVar('template')) { |
||
411 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
412 | $tplfileHandler = \xoops_getHandler('tplfile'); |
||
413 | $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
||
414 | if (\count($btemplate) > 0) { |
||
415 | $tplclone = $btemplate[0]->xoopsClone(); |
||
416 | $tplclone->setVar('tpl_id', 0); |
||
417 | $tplclone->setVar('tpl_refid', $newid); |
||
418 | $tplfileHandler->insert($tplclone); |
||
419 | } |
||
420 | } |
||
421 | |||
422 | foreach ($bmodule as $bmid) { |
||
423 | $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
||
424 | $this->db->query($sql); |
||
425 | } |
||
426 | //$groups = &$GLOBALS['xoopsUser']->getGroups(); |
||
427 | foreach ($groups as $iValue) { |
||
428 | $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')"; |
||
429 | $this->db->query($sql); |
||
430 | } |
||
431 | $this->modHelper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * @param int $bid |
||
436 | * @param string $title |
||
437 | * @param int $weight |
||
438 | * @param bool $visible |
||
439 | * @param string $side |
||
440 | * @param int $bcachetime |
||
441 | */ |
||
442 | public function setOrder($bid, $title, $weight, $visible, $side, $bcachetime, $bmodule): void |
||
443 | { |
||
444 | $myblock = new \XoopsBlock($bid); |
||
445 | $myblock->setVar('title', $title); |
||
446 | $myblock->setVar('weight', $weight); |
||
447 | $myblock->setVar('visible', $visible); |
||
448 | $myblock->setVar('side', $side); |
||
449 | $myblock->setVar('bcachetime', $bcachetime); |
||
450 | $myblock->store(); |
||
451 | // /** @var \XoopsBlockHandler $blockHandler */ |
||
452 | // $blockHandler = \xoops_getHandler('block'); |
||
453 | // return $blockHandler->insert($myblock); |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * @param int $bid |
||
458 | */ |
||
459 | public function editBlock($bid): void |
||
502 | } |
||
503 | |||
504 | /** |
||
505 | * @param int $bid |
||
506 | * @param string $btitle |
||
507 | * @param string $bside |
||
508 | * @param string $bweight |
||
509 | * @param string $bvisible |
||
510 | * @param string $bcachetime |
||
511 | * @param array $bmodule |
||
512 | * @param null|array|string $options |
||
513 | * @param null|array $groups |
||
514 | */ |
||
515 | public function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups): void |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * @param array $bid |
||
568 | */ |
||
569 | public function orderBlock( |
||
570 | $bid, |
||
571 | $oldtitle, |
||
572 | $oldside, |
||
573 | $oldweight, |
||
574 | $oldvisible, |
||
575 | $oldgroups, |
||
576 | $oldbcachetime, |
||
577 | $title, |
||
578 | $weight, |
||
579 | $visible, |
||
580 | $side, |
||
581 | $bcachetime, |
||
582 | $groups, |
||
583 | $bmodule = null |
||
584 | ): void { |
||
585 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
586 | \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
587 | } |
||
588 | foreach (\array_keys($bid) as $i) { |
||
589 | if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i] |
||
590 | || $oldside[$i] !== $side[$i] |
||
591 | || $oldbcachetime[$i] !== $bcachetime[$i]) { |
||
592 | $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); |
||
593 | } |
||
594 | if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) { |
||
595 | $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]); |
||
596 | $this->db->query($sql); |
||
597 | if (\in_array(0, $bmodule[$i], true)) { |
||
598 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0); |
||
599 | $this->db->query($sql); |
||
600 | } else { |
||
601 | foreach ($bmodule[$i] as $bmid) { |
||
602 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid); |
||
603 | $this->db->query($sql); |
||
604 | } |
||
605 | } |
||
606 | } |
||
607 | $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]); |
||
608 | $this->db->query($sql); |
||
609 | if (!empty($groups[$i])) { |
||
610 | foreach ($groups[$i] as $grp) { |
||
611 | $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]); |
||
612 | $this->db->query($sql); |
||
613 | } |
||
614 | } |
||
615 | } |
||
616 | |||
617 | $this->modHelper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * @param null|\array $block |
||
622 | */ |
||
623 | public function render($block = null) |
||
731 | } |
||
732 | } |
||
733 | |||
734 | |||
735 |