Total Complexity | 80 |
Total Lines | 667 |
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 |
||
30 | class Blocksadmin |
||
31 | { |
||
32 | /** |
||
33 | * @var \XoopsMySQLDatabase|null |
||
34 | */ |
||
35 | public $db; |
||
36 | /** |
||
37 | * @var Helper |
||
38 | */ |
||
39 | public $helper; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | public $moduleDirName; |
||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | public $moduleDirNameUpper; |
||
48 | |||
49 | /** |
||
50 | * Blocksadmin constructor. |
||
51 | * @param \XoopsDatabase|null $db |
||
52 | * @param Helper|null $helper |
||
53 | */ |
||
54 | public function __construct(?\XoopsDatabase $db, Helper $helper) |
||
55 | { |
||
56 | if (null === $db) { |
||
57 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
58 | } |
||
59 | $this->db = $db; |
||
60 | $this->helper = $helper; |
||
61 | $this->moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
62 | $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName); |
||
63 | \xoops_loadLanguage('admin', 'system'); |
||
64 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
65 | \xoops_loadLanguage('admin/groups', 'system'); |
||
66 | \xoops_loadLanguage('common', $this->moduleDirName); |
||
67 | \xoops_loadLanguage('blocksadmin', $this->moduleDirName); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return void |
||
72 | */ |
||
73 | public function listBlocks(): void |
||
74 | { |
||
75 | global $xoopsModule, $pathIcon16; |
||
76 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
77 | // xoops_loadLanguage('admin', 'system'); |
||
78 | // xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
79 | // xoops_loadLanguage('admin/groups', 'system'); |
||
80 | // xoops_loadLanguage('common', $moduleDirName); |
||
81 | // xoops_loadLanguage('blocks', $moduleDirName); |
||
82 | |||
83 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
84 | $moduleHandler = \xoops_getHandler('module'); |
||
85 | /** @var \XoopsMemberHandler $memberHandler */ |
||
86 | $memberHandler = \xoops_getHandler('member'); |
||
87 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
88 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
89 | $groups = $memberHandler->getGroups(); |
||
90 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', '1')); |
||
91 | $criteria->add(new \Criteria('isactive', '1')); |
||
92 | $moduleList = $moduleHandler->getList($criteria); |
||
93 | $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
||
94 | $moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
||
95 | \ksort($moduleList); |
||
96 | echo "<h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
97 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
98 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
99 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
100 | <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> |
||
101 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT') . "</th> |
||
102 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') . "</th><th align='center'>" . \_AM_SYSTEM_BLOCKS_VISIBLEIN . "</th> |
||
103 | <th align='center'>" . \_AM_SYSTEM_ADGS . "</th> |
||
104 | <th align='center'>" . \_AM_SYSTEM_BLOCKS_BCACHETIME . "</th> |
||
105 | <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') . '</th> |
||
106 | </tr>'; |
||
107 | $blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
108 | // $blockCount = \count($blockArray); |
||
109 | $class = 'even'; |
||
110 | $cachetimes = [ |
||
111 | 0 => _NOCACHE, |
||
112 | 30 => \sprintf(_SECONDS, 30), |
||
113 | 60 => _MINUTE, |
||
114 | 300 => \sprintf(_MINUTES, 5), |
||
115 | 1800 => \sprintf(_MINUTES, 30), |
||
116 | 3600 => _HOUR, |
||
117 | 18000 => \sprintf(_HOURS, 5), |
||
118 | 86400 => _DAY, |
||
119 | 259200 => \sprintf(_DAYS, 3), |
||
120 | 604800 => _WEEK, |
||
121 | 2592000 => _MONTH, |
||
122 | ]; |
||
123 | foreach ($blockArray as $i) { |
||
124 | $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||
125 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||
|
|||
126 | $result = $this->db->query($sql); |
||
127 | if (!$this->db->isResultSet($result)) { |
||
128 | \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
||
129 | } |
||
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 | $ssel7 = ''; |
||
145 | $ssel6 = $ssel7; |
||
146 | $ssel5 = $ssel6; |
||
147 | $ssel4 = $ssel5; |
||
148 | $ssel3 = $ssel4; |
||
149 | $ssel2 = $ssel3; |
||
150 | $ssel1 = $ssel2; |
||
151 | $ssel0 = $ssel1; |
||
152 | $sel1 = $ssel0; |
||
153 | $sel0 = $sel1; |
||
154 | if (1 === $i->getVar('visible')) { |
||
155 | $sel1 = ' checked'; |
||
156 | } else { |
||
157 | $sel0 = ' checked'; |
||
158 | } |
||
159 | if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
||
160 | $ssel0 = ' checked'; |
||
161 | } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
||
162 | $ssel1 = ' checked'; |
||
163 | } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
||
164 | $ssel2 = ' checked'; |
||
165 | } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
||
166 | $ssel4 = ' checked'; |
||
167 | } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
||
168 | $ssel3 = ' checked'; |
||
169 | } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
||
170 | $ssel5 = ' checked'; |
||
171 | } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
||
172 | $ssel6 = ' checked'; |
||
173 | } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
||
174 | $ssel7 = ' checked'; |
||
175 | } |
||
176 | if ('' === $i->getVar('title')) { |
||
177 | $title = ' '; |
||
178 | } else { |
||
179 | $title = $i->getVar('title'); |
||
180 | } |
||
181 | $name = $i->getVar('name'); |
||
182 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" . $i->getVar('bid') . "]' value='" . $title . "'></td> |
||
183 | <td class='$class' align='center' nowrap='nowrap'><div align='center' > |
||
184 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_LEFT . "'$ssel2> |
||
185 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_CENTER . "'$ssel3> |
||
186 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_RIGHT . "'$ssel4> |
||
187 | </div> |
||
188 | <div> |
||
189 | <span style='float:right;'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_RIGHT . "'$ssel1></span> |
||
190 | <div align='left'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_LEFT . "'$ssel0></div> |
||
191 | </div> |
||
192 | <div align='center'> |
||
193 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5> |
||
194 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7> |
||
195 | <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6> |
||
196 | </div> |
||
197 | </td> |
||
198 | <td class='$class' align='center'><input type='text' name='weight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "' size='5' maxlength='5'></td> |
||
199 | <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>'; |
||
200 | |||
201 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
202 | foreach ($moduleList as $k => $v) { |
||
203 | echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||
204 | } |
||
205 | echo '</select></td>'; |
||
206 | |||
207 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
208 | foreach ($groups as $grp) { |
||
209 | echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||
210 | } |
||
211 | echo '</select></td>'; |
||
212 | |||
213 | // Cache lifetime |
||
214 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select> |
||
215 | </td>'; |
||
216 | |||
217 | // Actions |
||
218 | |||
219 | echo "<td class='$class' align='center'> |
||
220 | <a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
||
221 | <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
||
222 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
223 | // 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 . "'> |
||
224 | // </a>"; |
||
225 | // } |
||
226 | |||
227 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
228 | if (!\in_array($i->getVar('block_type'), ['M', 'S'])) { |
||
229 | echo " |
||
230 | <a href='blocksadmin.php?op=delete&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
231 | </a>"; |
||
232 | } |
||
233 | echo " |
||
234 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
235 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
236 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
237 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
238 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
239 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
240 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
241 | </td></tr> |
||
242 | "; |
||
243 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
244 | } |
||
245 | 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>"; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @param int $bid |
||
250 | */ |
||
251 | public function deleteBlock(int $bid): void |
||
252 | { |
||
253 | // \xoops_cp_header(); |
||
254 | |||
255 | \xoops_loadLanguage('admin', 'system'); |
||
256 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
257 | \xoops_loadLanguage('admin/groups', 'system'); |
||
258 | |||
259 | $myblock = new \XoopsBlock($bid); |
||
260 | |||
261 | $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid); |
||
262 | $this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error()); |
||
263 | $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
||
264 | $this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error()); |
||
265 | |||
266 | $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * @param int $bid |
||
271 | */ |
||
272 | public function cloneBlock(int $bid): void |
||
273 | { |
||
274 | //require __DIR__ . '/admin_header.php'; |
||
275 | // \xoops_cp_header(); |
||
276 | |||
277 | \xoops_loadLanguage('admin', 'system'); |
||
278 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
279 | \xoops_loadLanguage('admin/groups', 'system'); |
||
280 | |||
281 | $myblock = new \XoopsBlock($bid); |
||
282 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; |
||
283 | $result = $this->db->query($sql); |
||
284 | if (!$this->db->isResultSet($result)) { |
||
285 | \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
||
286 | } |
||
287 | $modules = []; |
||
288 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
289 | $modules[] = (int)$row['module_id']; |
||
290 | } |
||
291 | |||
292 | $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
||
293 | $block = [ |
||
294 | 'title' => $myblock->getVar('title') . ' Clone', |
||
295 | 'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'), |
||
296 | 'name' => $myblock->getVar('name'), |
||
297 | 'side' => $myblock->getVar('side'), |
||
298 | 'weight' => $myblock->getVar('weight'), |
||
299 | 'visible' => $myblock->getVar('visible'), |
||
300 | 'content' => $myblock->getVar('content', 'N'), |
||
301 | 'modules' => $modules, |
||
302 | 'is_custom' => $isCustom, |
||
303 | 'ctype' => $myblock->getVar('c_type'), |
||
304 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||
305 | 'op' => 'clone_ok', |
||
306 | 'bid' => $myblock->getVar('bid'), |
||
307 | 'edit_form' => $myblock->getOptions(), |
||
308 | 'template' => $myblock->getVar('template'), |
||
309 | 'options' => $myblock->getVar('options'), |
||
310 | ]; |
||
311 | echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>'; |
||
312 | // $form = new Blockform(); |
||
313 | // $form->render(); |
||
314 | |||
315 | echo $this->render($block); |
||
316 | // xoops_cp_footer(); |
||
317 | // require_once __DIR__ . '/admin_footer.php'; |
||
318 | // exit(); |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * @param int $bid |
||
323 | * @param string $bside |
||
324 | * @param string $bweight |
||
325 | * @param string $bvisible |
||
326 | * @param string $bcachetime |
||
327 | * @param array|null $bmodule |
||
328 | * @param array|null $options |
||
329 | * @param array|null $groups |
||
330 | */ |
||
331 | public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
||
332 | { |
||
333 | \xoops_loadLanguage('admin', 'system'); |
||
334 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
335 | \xoops_loadLanguage('admin/groups', 'system'); |
||
336 | |||
337 | $block = new \XoopsBlock($bid); |
||
338 | $clone = $block->xoopsClone(); |
||
339 | if (empty($bmodule)) { |
||
340 | // \xoops_cp_header(); |
||
341 | \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||
342 | \xoops_cp_footer(); |
||
343 | exit(); |
||
344 | } |
||
345 | $newid = 0; |
||
346 | $clone->setVar('side', $bside); |
||
347 | $clone->setVar('weight', $bweight); |
||
348 | $clone->setVar('visible', $bvisible); |
||
349 | //$clone->setVar('content', $_POST['bcontent']); |
||
350 | $clone->setVar('title', Request::getString('btitle', '', 'POST')); |
||
351 | $clone->setVar('bcachetime', $bcachetime); |
||
352 | if (\is_array($options) && (\count($options) > 0)) { |
||
353 | $options = \implode('|', $options); |
||
354 | $clone->setVar('options', $options); |
||
355 | } |
||
356 | $clone->setVar('bid', 0); |
||
357 | if (\in_array($block->getVar('block_type'), ['C', 'E'])) { |
||
358 | $clone->setVar('block_type', 'E'); |
||
359 | } else { |
||
360 | $clone->setVar('block_type', 'D'); |
||
361 | } |
||
362 | // $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105 |
||
363 | if ($clone->store()) { |
||
364 | $newid = $clone->id(); //get the id of the cloned block |
||
365 | } |
||
366 | if (0 !== $newid) { |
||
367 | // \xoops_cp_header(); |
||
368 | $clone->getHtmlErrors(); |
||
369 | \xoops_cp_footer(); |
||
370 | exit(); |
||
371 | } |
||
372 | if ('' !== $clone->getVar('template')) { |
||
373 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
374 | $tplfileHandler = \xoops_getHandler('tplfile'); |
||
375 | $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid); |
||
376 | if (\count($btemplate) > 0) { |
||
377 | $tplclone = $btemplate[0]->xoopsClone(); |
||
378 | $tplclone->setVar('tpl_id', 0); |
||
379 | $tplclone->setVar('tpl_refid', $newid); |
||
380 | $tplfileHandler->insert($tplclone); |
||
381 | } |
||
382 | } |
||
383 | |||
384 | foreach ($bmodule as $bmid) { |
||
385 | $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
||
386 | $this->db->query($sql); |
||
387 | } |
||
388 | //$groups = &$GLOBALS['xoopsUser']->getGroups(); |
||
389 | foreach ($groups as $iValue) { |
||
390 | $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')"; |
||
391 | $this->db->query($sql); |
||
392 | } |
||
393 | $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * @param string $bid |
||
398 | * @param string $title |
||
399 | * @param string $weight |
||
400 | * @param string $visible |
||
401 | * @param string $side |
||
402 | * @param string $bcachetime |
||
403 | * @param array|null $bmodule |
||
404 | */ |
||
405 | public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void |
||
406 | { |
||
407 | $myblock = new \XoopsBlock($bid); |
||
408 | $myblock->setVar('title', $title); |
||
409 | $myblock->setVar('weight', $weight); |
||
410 | $myblock->setVar('visible', $visible); |
||
411 | $myblock->setVar('side', $side); |
||
412 | $myblock->setVar('bcachetime', $bcachetime); |
||
413 | $myblock->store(); |
||
414 | // /** @var \XoopsBlockHandler $blockHandler */ |
||
415 | // $blockHandler = \xoops_getHandler('block'); |
||
416 | // return $blockHandler->insert($myblock); |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * @param int $bid |
||
421 | * @return void |
||
422 | */ |
||
423 | public function editBlock(int $bid): void |
||
424 | { |
||
425 | // require_once \dirname(__DIR__,2) . '/admin/admin_header.php'; |
||
426 | // \xoops_cp_header(); |
||
427 | \xoops_loadLanguage('admin', 'system'); |
||
428 | \xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
429 | \xoops_loadLanguage('admin/groups', 'system'); |
||
430 | // mpu_adm_menu(); |
||
431 | $myblock = new \XoopsBlock($bid); |
||
432 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; |
||
433 | $result = $this->db->query($sql); |
||
434 | if (!$this->db->isResultSet($result)) { |
||
435 | \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
||
436 | } |
||
437 | $modules = []; |
||
438 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
439 | $modules[] = (int)$row['module_id']; |
||
440 | } |
||
441 | |||
442 | $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
||
443 | $block = [ |
||
444 | 'title' => $myblock->getVar('title'), |
||
445 | 'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK, |
||
446 | // 'name' => $myblock->getVar('name'), |
||
447 | 'side' => $myblock->getVar('side'), |
||
448 | 'weight' => $myblock->getVar('weight'), |
||
449 | 'visible' => $myblock->getVar('visible'), |
||
450 | 'content' => $myblock->getVar('content', 'N'), |
||
451 | 'modules' => $modules, |
||
452 | 'is_custom' => $isCustom, |
||
453 | 'ctype' => $myblock->getVar('c_type'), |
||
454 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||
455 | 'op' => 'edit_ok', |
||
456 | 'bid' => $myblock->getVar('bid'), |
||
457 | 'edit_form' => $myblock->getOptions(), |
||
458 | 'template' => $myblock->getVar('template'), |
||
459 | 'options' => $myblock->getVar('options'), |
||
460 | ]; |
||
461 | echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>'; |
||
462 | |||
463 | echo $this->render($block); |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * @param int $bid |
||
468 | * @param string $btitle |
||
469 | * @param string $bside |
||
470 | * @param string $bweight |
||
471 | * @param string $bvisible |
||
472 | * @param string $bcachetime |
||
473 | * @param array|null $bmodule |
||
474 | * @param array|null $options |
||
475 | * @param array|null $groups |
||
476 | */ |
||
477 | public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
||
478 | { |
||
479 | $myblock = new \XoopsBlock($bid); |
||
480 | $myblock->setVar('title', $btitle); |
||
481 | $myblock->setVar('weight', $bweight); |
||
482 | $myblock->setVar('visible', $bvisible); |
||
483 | $myblock->setVar('side', $bside); |
||
484 | $myblock->setVar('bcachetime', $bcachetime); |
||
485 | //update block options |
||
486 | if (isset($options)) { |
||
487 | $optionsCount = \count($options); |
||
488 | if ($optionsCount > 0) { |
||
489 | //Convert array values to comma-separated |
||
490 | foreach ($options as $i => $iValue) { |
||
491 | if (\is_array($iValue)) { |
||
492 | $options[$i] = \implode(',', $iValue); |
||
493 | } |
||
494 | } |
||
495 | $options = \implode('|', $options); |
||
496 | $myblock->setVar('options', $options); |
||
497 | } |
||
498 | } |
||
499 | $myblock->store(); |
||
500 | // /** @var \XoopsBlockHandler $blockHandler */ |
||
501 | // $blockHandler = \xoops_getHandler('block'); |
||
502 | // $blockHandler->insert($myblock); |
||
503 | |||
504 | if (!empty($bmodule) && \count($bmodule) > 0) { |
||
505 | $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
||
506 | $this->db->query($sql); |
||
507 | if (\in_array(0, $bmodule)) { |
||
508 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0); |
||
509 | $this->db->query($sql); |
||
510 | } else { |
||
511 | foreach ($bmodule as $bmid) { |
||
512 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid); |
||
513 | $this->db->query($sql); |
||
514 | } |
||
515 | } |
||
516 | } |
||
517 | $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid); |
||
518 | $this->db->query($sql); |
||
519 | if (!empty($groups)) { |
||
520 | foreach ($groups as $grp) { |
||
521 | $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); |
||
522 | $this->db->query($sql); |
||
523 | } |
||
524 | } |
||
525 | $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||
526 | } |
||
527 | |||
528 | /** |
||
529 | * @param array $bid |
||
530 | * @param array $oldtitle |
||
531 | * @param array $oldside |
||
532 | * @param array $oldweight |
||
533 | * @param array $oldvisible |
||
534 | * @param array $oldgroups |
||
535 | * @param array $oldbcachetime |
||
536 | * @param array $oldbmodule |
||
537 | * @param array $title |
||
538 | * @param array $weight |
||
539 | * @param array $visible |
||
540 | * @param array $side |
||
541 | * @param array $bcachetime |
||
542 | * @param array $groups |
||
543 | * @param array $bmodule |
||
544 | */ |
||
545 | public function orderBlock( |
||
546 | 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 |
||
547 | ): void { |
||
548 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
549 | \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
550 | } |
||
551 | foreach (\array_keys($bid) as $i) { |
||
552 | if ($oldtitle[$i] !== $title[$i] |
||
553 | || $oldweight[$i] !== $weight[$i] |
||
554 | || $oldvisible[$i] !== $visible[$i] |
||
555 | || $oldside[$i] !== $side[$i] |
||
556 | || $oldbcachetime[$i] !== $bcachetime[$i] |
||
557 | || $oldbmodule[$i] !== $bmodule[$i]) { |
||
558 | $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); |
||
559 | } |
||
560 | if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) { |
||
561 | $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]); |
||
562 | $this->db->query($sql); |
||
563 | if (\in_array(0, $bmodule[$i], true)) { |
||
564 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0); |
||
565 | $this->db->query($sql); |
||
566 | } else { |
||
567 | foreach ($bmodule[$i] as $bmid) { |
||
568 | $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid); |
||
569 | $this->db->query($sql); |
||
570 | } |
||
571 | } |
||
572 | } |
||
573 | $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]); |
||
574 | $this->db->query($sql); |
||
575 | if (!empty($groups[$i])) { |
||
576 | foreach ($groups[$i] as $grp) { |
||
577 | $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]); |
||
578 | $this->db->query($sql); |
||
579 | } |
||
580 | } |
||
581 | } |
||
582 | |||
583 | $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * @param array|null $block |
||
588 | */ |
||
589 | public function render(?array $block = null) |
||
697 | } |
||
698 | } |
||
699 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.