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