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