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