XoopsModules25x /
tdmdownloads
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * You may not change or alter any portion of this comment or credits |
||||
| 5 | * of supporting developers from this source code or any supporting source code |
||||
| 6 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||
| 7 | * |
||||
| 8 | * PHP version 5 |
||||
| 9 | * |
||||
| 10 | * @category Module |
||||
| 11 | * @author XOOPS Development Team |
||||
| 12 | * @copyright XOOPS Project |
||||
| 13 | * @link https://xoops.org |
||||
| 14 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||||
| 15 | */ |
||||
| 16 | |||||
| 17 | use Xmf\Request; |
||||
| 18 | |||||
| 19 | require __DIR__ . '/admin_header.php'; |
||||
| 20 | |||||
| 21 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 22 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName |
||||
| 23 | |||||
| 24 | if (!is_object($xoopsModule) || !is_object($GLOBALS['xoopsUser']) |
||||
| 25 | || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) { |
||||
| 26 | exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403')); |
||||
| 27 | } |
||||
| 28 | if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) { |
||||
| 29 | require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||||
| 30 | |||||
| 31 | $op = 'list'; |
||||
| 32 | |||||
| 33 | if (isset($_POST)) { |
||||
| 34 | foreach ($_POST as $k => $v) { |
||||
| 35 | ${$k} = $v; |
||||
| 36 | } |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /* |
||||
| 40 | if (Request::hasVar('op')) { |
||||
| 41 | if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone" |
||||
| 42 | || $_GET['op'] === "edit" |
||||
| 43 | ) { |
||||
| 44 | $op = $_GET['op']; |
||||
| 45 | $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0; |
||||
| 46 | } |
||||
| 47 | } |
||||
| 48 | */ |
||||
| 49 | |||||
| 50 | $op = Request::getString('op', $op); |
||||
| 51 | |||||
| 52 | if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) { |
||||
| 53 | $bid = Request::getInt('bid', 0, 'GET'); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | function listBlocks() |
||||
| 57 | { |
||||
| 58 | global $xoopsModule, $pathIcon16; |
||||
| 59 | |||||
| 60 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||||
| 61 | |||||
| 62 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 63 | |||||
| 64 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName |
||||
| 65 | |||||
| 66 | /** @var \XoopsMySQLDatabase $db */ |
||||
| 67 | |||||
| 68 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||
| 69 | |||||
| 70 | xoops_loadLanguage('admin', 'system'); |
||||
| 71 | |||||
| 72 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||||
| 73 | |||||
| 74 | xoops_loadLanguage('admin/groups', 'system'); |
||||
| 75 | |||||
| 76 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||
| 77 | |||||
| 78 | $moduleHandler = xoops_getHandler('module'); |
||||
| 79 | |||||
| 80 | /** @var \XoopsMemberHandler $memberHandler */ |
||||
| 81 | |||||
| 82 | $memberHandler = xoops_getHandler('member'); |
||||
| 83 | |||||
| 84 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
| 85 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||
| 86 | |||||
| 87 | $groups = $memberHandler->getGroups(); |
||||
| 88 | |||||
| 89 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||||
| 90 | |||||
| 91 | $criteria->add(new \Criteria('isactive', 1)); |
||||
| 92 | |||||
| 93 | $module_list = $moduleHandler->getList($criteria); |
||||
| 94 | |||||
| 95 | $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE; |
||||
| 96 | |||||
| 97 | $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; |
||||
| 98 | |||||
| 99 | ksort($module_list); |
||||
| 100 | |||||
| 101 | echo " |
||||
| 102 | <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||||
| 103 | |||||
| 104 | $moduleHandler = xoops_getHandler('module'); |
||||
| 105 | |||||
| 106 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||||
| 107 | |||||
| 108 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||||
| 109 | |||||
| 110 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||||
| 111 | <tr valign='middle'><th align='center'>" |
||||
| 112 | . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') |
||||
| 113 | . "</th><th align='center' nowrap='nowrap'>" |
||||
| 114 | . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') |
||||
| 115 | . '<br>' |
||||
| 116 | . _LEFT |
||||
| 117 | . '-' |
||||
| 118 | . _CENTER |
||||
| 119 | . '-' |
||||
| 120 | . _RIGHT |
||||
| 121 | . "</th><th align='center'>" |
||||
| 122 | . constant( |
||||
| 123 | 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT' |
||||
| 124 | ) |
||||
| 125 | . "</th><th align='center'>" |
||||
| 126 | . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE') |
||||
| 127 | . "</th><th align='center'>" |
||||
| 128 | . _AM_SYSTEM_BLOCKS_VISIBLEIN |
||||
| 129 | . "</th><th align='center'>" |
||||
| 130 | . _AM_SYSTEM_ADGS |
||||
| 131 | . "</th><th align='center'>" |
||||
| 132 | . _AM_SYSTEM_BLOCKS_BCACHETIME |
||||
| 133 | . "</th><th align='center'>" |
||||
| 134 | . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION') |
||||
| 135 | . '</th></tr> |
||||
| 136 | '; |
||||
| 137 | |||||
| 138 | $block_arr = \XoopsBlock::getByModule($xoopsModule->mid()); |
||||
|
0 ignored issues
–
show
|
|||||
| 139 | |||||
| 140 | $block_count = count($block_arr); |
||||
| 141 | |||||
| 142 | $class = 'even'; |
||||
| 143 | |||||
| 144 | $cachetimes = [ |
||||
| 145 | '0' => _NOCACHE, |
||||
| 146 | '30' => sprintf(_SECONDS, 30), |
||||
| 147 | '60' => _MINUTE, |
||||
| 148 | '300' => sprintf(_MINUTES, 5), |
||||
| 149 | '1800' => sprintf(_MINUTES, 30), |
||||
| 150 | '3600' => _HOUR, |
||||
| 151 | '18000' => sprintf(_HOURS, 5), |
||||
| 152 | '86400' => _DAY, |
||||
| 153 | '259200' => sprintf(_DAYS, 3), |
||||
| 154 | '604800' => _WEEK, |
||||
| 155 | '2592000' => _MONTH, |
||||
| 156 | ]; |
||||
| 157 | |||||
| 158 | foreach ($block_arr as $i) { |
||||
| 159 | /** @var \XoopsBlock $i */ |
||||
| 160 | |||||
| 161 | $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||||
| 162 | |||||
| 163 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||||
| 164 | |||||
| 165 | $result = $db->query($sql); |
||||
| 166 | |||||
| 167 | $modules = []; |
||||
| 168 | |||||
| 169 | while (false !== ($row = $db->fetchArray($result))) { |
||||
| 170 | $modules[] = (int)$row['module_id']; |
||||
| 171 | } |
||||
| 172 | |||||
| 173 | $cachetime_options = ''; |
||||
| 174 | |||||
| 175 | foreach ($cachetimes as $cachetime => $cachetime_name) { |
||||
| 176 | if ($i->getVar('bcachetime') == $cachetime) { |
||||
| 177 | $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n"; |
||||
| 178 | } else { |
||||
| 179 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; |
||||
| 180 | } |
||||
| 181 | } |
||||
| 182 | |||||
| 183 | $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; |
||||
| 184 | |||||
| 185 | if (1 === $i->getVar('visible')) { |
||||
| 186 | $sel1 = ' checked'; |
||||
| 187 | } else { |
||||
| 188 | $sel0 = ' checked'; |
||||
| 189 | } |
||||
| 190 | |||||
| 191 | if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
||||
| 192 | $ssel0 = ' checked'; |
||||
| 193 | } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
||||
| 194 | $ssel1 = ' checked'; |
||||
| 195 | } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
||||
| 196 | $ssel2 = ' checked'; |
||||
| 197 | } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
||||
| 198 | $ssel4 = ' checked'; |
||||
| 199 | } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
||||
| 200 | $ssel3 = ' checked'; |
||||
| 201 | } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
||||
| 202 | $ssel5 = ' checked'; |
||||
| 203 | } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
||||
| 204 | $ssel6 = ' checked'; |
||||
| 205 | } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
||||
| 206 | $ssel7 = ' checked'; |
||||
| 207 | } |
||||
| 208 | |||||
| 209 | if ('' === $i->getVar('title')) { |
||||
| 210 | $title = ' '; |
||||
| 211 | } else { |
||||
| 212 | $title = $i->getVar('title'); |
||||
| 213 | } |
||||
| 214 | |||||
| 215 | $name = $i->getVar('name'); |
||||
| 216 | |||||
| 217 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" |
||||
| 218 | . $i->getVar('bid') |
||||
| 219 | . "]' value='" |
||||
| 220 | . $title |
||||
| 221 | . "'></td><td class='$class' align='center' nowrap='nowrap'> |
||||
| 222 | <div align='center' > |
||||
| 223 | <input type='radio' name='side[" |
||||
| 224 | . $i->getVar('bid') |
||||
| 225 | . "]' value='" |
||||
| 226 | . XOOPS_CENTERBLOCK_LEFT |
||||
| 227 | . "'$ssel2> |
||||
| 228 | <input type='radio' name='side[" |
||||
| 229 | . $i->getVar('bid') |
||||
| 230 | . "]' value='" |
||||
| 231 | . XOOPS_CENTERBLOCK_CENTER |
||||
| 232 | . "'$ssel3> |
||||
| 233 | <input type='radio' name='side[" |
||||
| 234 | . $i->getVar('bid') |
||||
| 235 | . "]' value='" |
||||
| 236 | . XOOPS_CENTERBLOCK_RIGHT |
||||
| 237 | . "'$ssel4> |
||||
| 238 | </div> |
||||
| 239 | <div> |
||||
| 240 | <span style='float:right;'><input type='radio' name='side[" |
||||
| 241 | . $i->getVar('bid') |
||||
| 242 | . "]' value='" |
||||
| 243 | . XOOPS_SIDEBLOCK_RIGHT |
||||
| 244 | . "'$ssel1></span> |
||||
| 245 | <div align='left'><input type='radio' name='side[" |
||||
| 246 | . $i->getVar('bid') |
||||
| 247 | . "]' value='" |
||||
| 248 | . XOOPS_SIDEBLOCK_LEFT |
||||
| 249 | . "'$ssel0></div> |
||||
| 250 | </div> |
||||
| 251 | <div align='center'> |
||||
| 252 | <input type='radio' name='side[" |
||||
| 253 | . $i->getVar('bid') |
||||
| 254 | . "]' value='" |
||||
| 255 | . XOOPS_CENTERBLOCK_BOTTOMLEFT |
||||
| 256 | . "'$ssel5> |
||||
| 257 | <input type='radio' name='side[" |
||||
| 258 | . $i->getVar('bid') |
||||
| 259 | . "]' value='" |
||||
| 260 | . XOOPS_CENTERBLOCK_BOTTOM |
||||
| 261 | . "'$ssel7> |
||||
| 262 | <input type='radio' name='side[" |
||||
| 263 | . $i->getVar('bid') |
||||
| 264 | . "]' value='" |
||||
| 265 | . XOOPS_CENTERBLOCK_BOTTOMRIGHT |
||||
| 266 | . "'$ssel6> |
||||
| 267 | </div> |
||||
| 268 | </td><td class='$class' align='center'><input type='text' name='weight[" |
||||
| 269 | . $i->getVar('bid') |
||||
| 270 | . "]' value='" |
||||
| 271 | . $i->getVar('weight') |
||||
| 272 | . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible[" |
||||
| 273 | . $i->getVar('bid') |
||||
| 274 | . "]' value='1'$sel1>" |
||||
| 275 | . _YES |
||||
| 276 | . " <input type='radio' name='visible[" |
||||
| 277 | . $i->getVar('bid') |
||||
| 278 | . "]' value='0'$sel0>" |
||||
| 279 | . _NO |
||||
| 280 | . '</td>'; |
||||
| 281 | |||||
| 282 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||||
| 283 | |||||
| 284 | foreach ($module_list as $k => $v) { |
||||
| 285 | echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||||
| 286 | } |
||||
| 287 | |||||
| 288 | echo '</select></td>'; |
||||
| 289 | |||||
| 290 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||||
| 291 | |||||
| 292 | foreach ($groups as $grp) { |
||||
| 293 | /** @var \XoopsGroup $grp */ |
||||
| 294 | |||||
| 295 | echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||||
| 296 | } |
||||
| 297 | |||||
| 298 | echo '</select></td>'; |
||||
| 299 | |||||
| 300 | // Cache lifetime |
||||
| 301 | |||||
| 302 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select> |
||||
| 303 | </td>'; |
||||
| 304 | |||||
| 305 | // Actions |
||||
| 306 | |||||
| 307 | 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 . "'> |
||||
| 308 | </a> <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'> |
||||
| 309 | </a>"; |
||||
| 310 | |||||
| 311 | if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||||
| 312 | 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 . "'> |
||||
| 313 | </a>"; |
||||
| 314 | } |
||||
| 315 | |||||
| 316 | echo " |
||||
| 317 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||||
| 318 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||||
| 319 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||||
| 320 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||||
| 321 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||||
| 322 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||||
| 323 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||||
| 324 | </td></tr> |
||||
| 325 | "; |
||||
| 326 | |||||
| 327 | $class = 'even' === $class ? 'odd' : 'even'; |
||||
| 328 | } |
||||
| 329 | |||||
| 330 | echo "<tr><td class='foot' align='center' colspan='7'> |
||||
| 331 | <input type='hidden' name='op' value='order'> |
||||
| 332 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
||||
| 333 | <input type='submit' name='submit' value='" . _SUBMIT . "'> |
||||
| 334 | </td></tr></table> |
||||
| 335 | </form> |
||||
| 336 | <br><br>"; |
||||
| 337 | } |
||||
| 338 | |||||
| 339 | /** |
||||
| 340 | * @param int $bid |
||||
| 341 | */ |
||||
| 342 | |||||
| 343 | function cloneBlock($bid) |
||||
| 344 | { |
||||
| 345 | require_once __DIR__ . '/admin_header.php'; |
||||
| 346 | |||||
| 347 | //require_once __DIR__ . '/admin_header.php'; |
||||
| 348 | |||||
| 349 | xoops_cp_header(); |
||||
| 350 | |||||
| 351 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 352 | |||||
| 353 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName |
||||
| 354 | |||||
| 355 | xoops_loadLanguage('admin', 'system'); |
||||
| 356 | |||||
| 357 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||||
| 358 | |||||
| 359 | xoops_loadLanguage('admin/groups', 'system'); |
||||
| 360 | |||||
| 361 | // mpu_adm_menu(); |
||||
| 362 | |||||
| 363 | $myblock = new \XoopsBlock($bid); |
||||
| 364 | |||||
| 365 | /** @var \XoopsMySQLDatabase $db */ |
||||
| 366 | |||||
| 367 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||
| 368 | |||||
| 369 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; |
||||
| 370 | |||||
| 371 | $result = $db->query($sql); |
||||
| 372 | |||||
| 373 | $modules = []; |
||||
| 374 | |||||
| 375 | while (false !== ($row = $db->fetchArray($result))) { |
||||
| 376 | $modules[] = (int)$row['module_id']; |
||||
| 377 | } |
||||
| 378 | |||||
| 379 | $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); |
||||
| 380 | |||||
| 381 | $block = [ |
||||
| 382 | 'title' => $myblock->getVar('title') . ' Clone', |
||||
| 383 | 'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'), |
||||
| 384 | 'name' => $myblock->getVar('name'), |
||||
| 385 | 'side' => $myblock->getVar('side'), |
||||
| 386 | 'weight' => $myblock->getVar('weight'), |
||||
| 387 | 'visible' => $myblock->getVar('visible'), |
||||
| 388 | 'content' => $myblock->getVar('content', 'N'), |
||||
| 389 | 'modules' => $modules, |
||||
| 390 | 'is_custom' => $is_custom, |
||||
| 391 | 'ctype' => $myblock->getVar('c_type'), |
||||
| 392 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||||
| 393 | 'op' => 'clone_ok', |
||||
| 394 | 'bid' => $myblock->getVar('bid'), |
||||
| 395 | 'edit_form' => $myblock->getOptions(), |
||||
| 396 | 'template' => $myblock->getVar('template'), |
||||
| 397 | 'options' => $myblock->getVar('options'), |
||||
| 398 | ]; |
||||
| 399 | |||||
| 400 | echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>'; |
||||
| 401 | |||||
| 402 | require_once __DIR__ . '/blockform.php'; |
||||
| 403 | |||||
| 404 | /** @var \XoopsThemeForm $form */ |
||||
| 405 | |||||
| 406 | $form->display(); |
||||
| 407 | |||||
| 408 | // xoops_cp_footer(); |
||||
| 409 | |||||
| 410 | require_once __DIR__ . '/admin_footer.php'; |
||||
| 411 | |||||
| 412 | exit(); |
||||
| 413 | } |
||||
| 414 | |||||
| 415 | /** |
||||
| 416 | * @param int $bid |
||||
| 417 | * @param $bside |
||||
| 418 | * @param $bweight |
||||
| 419 | * @param $bvisible |
||||
| 420 | * @param $bcachetime |
||||
| 421 | * @param $bmodule |
||||
| 422 | * @param $options |
||||
| 423 | */ |
||||
| 424 | |||||
| 425 | function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options) |
||||
| 426 | { |
||||
| 427 | xoops_loadLanguage('admin', 'system'); |
||||
| 428 | |||||
| 429 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||||
| 430 | |||||
| 431 | xoops_loadLanguage('admin/groups', 'system'); |
||||
| 432 | |||||
| 433 | /** @var \XoopsBlock $block */ |
||||
| 434 | |||||
| 435 | $block = new \XoopsBlock($bid); |
||||
| 436 | |||||
| 437 | $clone = $block->xoopsClone(); |
||||
| 438 | |||||
| 439 | if (empty($bmodule)) { |
||||
| 440 | xoops_cp_header(); |
||||
| 441 | |||||
| 442 | xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||||
| 443 | |||||
| 444 | xoops_cp_footer(); |
||||
| 445 | |||||
| 446 | exit(); |
||||
| 447 | } |
||||
| 448 | |||||
| 449 | $clone->setVar('side', $bside); |
||||
| 450 | |||||
| 451 | $clone->setVar('weight', $bweight); |
||||
| 452 | |||||
| 453 | $clone->setVar('visible', $bvisible); |
||||
| 454 | |||||
| 455 | //$clone->setVar('content', $_POST['bcontent']); |
||||
| 456 | |||||
| 457 | $clone->setVar('title', Request::getString('btitle', '', 'POST')); |
||||
| 458 | |||||
| 459 | $clone->setVar('bcachetime', $bcachetime); |
||||
| 460 | |||||
| 461 | if (isset($options) && (count($options) > 0)) { |
||||
| 462 | $options = implode('|', $options); |
||||
| 463 | |||||
| 464 | $clone->setVar('options', $options); |
||||
| 465 | } |
||||
| 466 | |||||
| 467 | $clone->setVar('bid', 0); |
||||
| 468 | |||||
| 469 | if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) { |
||||
| 470 | $clone->setVar('block_type', 'E'); |
||||
| 471 | } else { |
||||
| 472 | $clone->setVar('block_type', 'D'); |
||||
| 473 | } |
||||
| 474 | |||||
| 475 | $newid = $clone->store(); |
||||
| 476 | |||||
| 477 | if (!$newid) { |
||||
| 478 | xoops_cp_header(); |
||||
| 479 | |||||
| 480 | $clone->getHtmlErrors(); |
||||
| 481 | |||||
| 482 | xoops_cp_footer(); |
||||
| 483 | |||||
| 484 | exit(); |
||||
| 485 | } |
||||
| 486 | |||||
| 487 | if ('' !== $clone->getVar('template')) { |
||||
| 488 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||||
| 489 | |||||
| 490 | $tplfileHandler = xoops_getHandler('tplfile'); |
||||
| 491 | |||||
| 492 | /** @var \XoopsTplfile[] $btemplate */ |
||||
| 493 | |||||
| 494 | $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
||||
| 495 | |||||
| 496 | if (count($btemplate) > 0) { |
||||
| 497 | /** @var \XoopsObject $tplclone */ |
||||
| 498 | |||||
| 499 | $tplclone = $btemplate[0]->xoopsClone(); |
||||
| 500 | |||||
| 501 | $tplclone->setVar('tpl_id', 0); |
||||
| 502 | |||||
| 503 | $tplclone->setVar('tpl_refid', $newid); |
||||
| 504 | |||||
| 505 | $tplfileHandler->insert($tplclone); |
||||
| 506 | } |
||||
| 507 | } |
||||
| 508 | |||||
| 509 | /** @var \XoopsMySQLDatabase $db */ |
||||
| 510 | |||||
| 511 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||
| 512 | |||||
| 513 | foreach ($bmodule as $bmid) { |
||||
| 514 | $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
||||
| 515 | |||||
| 516 | $db->query($sql); |
||||
| 517 | } |
||||
| 518 | |||||
| 519 | $groups = &$GLOBALS['xoopsUser']->getGroups(); |
||||
| 520 | |||||
| 521 | $count = count($groups); |
||||
| 522 | |||||
| 523 | for ($i = 0; $i < $count; ++$i) { |
||||
| 524 | $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')"; |
||||
| 525 | |||||
| 526 | $db->query($sql); |
||||
| 527 | } |
||||
| 528 | |||||
| 529 | redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED); |
||||
| 530 | } |
||||
| 531 | |||||
| 532 | /** |
||||
| 533 | * @param int $bid |
||||
| 534 | * @param string $title |
||||
| 535 | * @param int $weight |
||||
| 536 | * @param bool $visible |
||||
| 537 | * @param string $side |
||||
| 538 | * @param int $bcachetime |
||||
| 539 | */ |
||||
| 540 | |||||
| 541 | function setOrder($bid, $title, $weight, $visible, $side, $bcachetime) |
||||
| 542 | { |
||||
| 543 | $myblock = new \XoopsBlock($bid); |
||||
| 544 | |||||
| 545 | $myblock->setVar('title', $title); |
||||
| 546 | |||||
| 547 | $myblock->setVar('weight', $weight); |
||||
| 548 | |||||
| 549 | $myblock->setVar('visible', $visible); |
||||
| 550 | |||||
| 551 | $myblock->setVar('side', $side); |
||||
| 552 | |||||
| 553 | $myblock->setVar('bcachetime', $bcachetime); |
||||
| 554 | |||||
| 555 | $myblock->store(); |
||||
|
0 ignored issues
–
show
The function
XoopsBlock::store() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 556 | } |
||||
| 557 | |||||
| 558 | /** |
||||
| 559 | * @param int $bid |
||||
| 560 | */ |
||||
| 561 | |||||
| 562 | function editBlock($bid) |
||||
| 563 | { |
||||
| 564 | require_once __DIR__ . '/admin_header.php'; |
||||
| 565 | |||||
| 566 | //require_once __DIR__ . '/admin_header.php'; |
||||
| 567 | |||||
| 568 | xoops_cp_header(); |
||||
| 569 | |||||
| 570 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 571 | |||||
| 572 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName |
||||
| 573 | |||||
| 574 | xoops_loadLanguage('admin', 'system'); |
||||
| 575 | |||||
| 576 | xoops_loadLanguage('admin/blocksadmin', 'system'); |
||||
| 577 | |||||
| 578 | xoops_loadLanguage('admin/groups', 'system'); |
||||
| 579 | |||||
| 580 | // mpu_adm_menu(); |
||||
| 581 | |||||
| 582 | $myblock = new \XoopsBlock($bid); |
||||
| 583 | |||||
| 584 | /** @var \XoopsMySQLDatabase $db */ |
||||
| 585 | |||||
| 586 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||
| 587 | |||||
| 588 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; |
||||
| 589 | |||||
| 590 | $result = $db->query($sql); |
||||
| 591 | |||||
| 592 | $modules = []; |
||||
| 593 | |||||
| 594 | while (false !== ($row = $db->fetchArray($result))) { |
||||
| 595 | $modules[] = (int)$row['module_id']; |
||||
| 596 | } |
||||
| 597 | |||||
| 598 | $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); |
||||
| 599 | |||||
| 600 | $block = [ |
||||
| 601 | 'title' => $myblock->getVar('title'), |
||||
| 602 | 'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'), |
||||
| 603 | // 'name' => $myblock->getVar('name'), |
||||
| 604 | 'side' => $myblock->getVar('side'), |
||||
| 605 | 'weight' => $myblock->getVar('weight'), |
||||
| 606 | 'visible' => $myblock->getVar('visible'), |
||||
| 607 | 'content' => $myblock->getVar('content', 'N'), |
||||
| 608 | 'modules' => $modules, |
||||
| 609 | 'is_custom' => $is_custom, |
||||
| 610 | 'ctype' => $myblock->getVar('c_type'), |
||||
| 611 | 'bcachetime' => $myblock->getVar('bcachetime'), |
||||
| 612 | 'op' => 'edit_ok', |
||||
| 613 | 'bid' => $myblock->getVar('bid'), |
||||
| 614 | 'edit_form' => $myblock->getOptions(), |
||||
| 615 | 'template' => $myblock->getVar('template'), |
||||
| 616 | 'options' => $myblock->getVar('options'), |
||||
| 617 | ]; |
||||
| 618 | |||||
| 619 | echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>'; |
||||
| 620 | |||||
| 621 | require_once __DIR__ . '/blockform.php'; |
||||
| 622 | |||||
| 623 | /** @var \XoopsThemeForm $form */ |
||||
| 624 | |||||
| 625 | $form->display(); |
||||
| 626 | |||||
| 627 | // xoops_cp_footer(); |
||||
| 628 | |||||
| 629 | require_once __DIR__ . '/admin_footer.php'; |
||||
| 630 | |||||
| 631 | exit(); |
||||
| 632 | } |
||||
| 633 | |||||
| 634 | /** |
||||
| 635 | * @param int $bid |
||||
| 636 | * @param string $btitle |
||||
| 637 | * @param string $bside |
||||
| 638 | * @param int $bweight |
||||
| 639 | * @param bool $bvisible |
||||
| 640 | * @param int $bcachetime |
||||
| 641 | * @param array $bmodule |
||||
| 642 | * @param null|array|string $options |
||||
| 643 | * @param null|array $groups |
||||
| 644 | */ |
||||
| 645 | |||||
| 646 | function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups) |
||||
| 647 | { |
||||
| 648 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 649 | |||||
| 650 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName |
||||
| 651 | |||||
| 652 | $myblock = new \XoopsBlock($bid); |
||||
| 653 | |||||
| 654 | $myblock->setVar('title', $btitle); |
||||
| 655 | |||||
| 656 | $myblock->setVar('weight', $bweight); |
||||
| 657 | |||||
| 658 | $myblock->setVar('visible', $bvisible); |
||||
| 659 | |||||
| 660 | $myblock->setVar('side', $bside); |
||||
| 661 | |||||
| 662 | $myblock->setVar('bcachetime', $bcachetime); |
||||
| 663 | |||||
| 664 | $myblock->store(); |
||||
|
0 ignored issues
–
show
The function
XoopsBlock::store() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 665 | |||||
| 666 | if (!empty($bmodule) && count($bmodule) > 0) { |
||||
| 667 | $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid); |
||||
| 668 | |||||
| 669 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 670 | |||||
| 671 | if (in_array(0, $bmodule)) { |
||||
| 672 | $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0); |
||||
| 673 | |||||
| 674 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 675 | } else { |
||||
| 676 | foreach ($bmodule as $bmid) { |
||||
| 677 | $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid); |
||||
| 678 | |||||
| 679 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 680 | } |
||||
| 681 | } |
||||
| 682 | } |
||||
| 683 | |||||
| 684 | $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid); |
||||
| 685 | |||||
| 686 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 687 | |||||
| 688 | if (!empty($groups)) { |
||||
| 689 | foreach ($groups as $grp) { |
||||
| 690 | $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid); |
||||
| 691 | |||||
| 692 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 693 | } |
||||
| 694 | } |
||||
| 695 | |||||
| 696 | redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||||
| 697 | } |
||||
| 698 | |||||
| 699 | if ('list' === $op) { |
||||
| 700 | xoops_cp_header(); |
||||
| 701 | |||||
| 702 | // mpu_adm_menu(); |
||||
| 703 | |||||
| 704 | listBlocks(); |
||||
| 705 | |||||
| 706 | require_once __DIR__ . '/admin_footer.php'; |
||||
| 707 | |||||
| 708 | exit(); |
||||
| 709 | } |
||||
| 710 | |||||
| 711 | if ('order' === $op) { |
||||
| 712 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
| 713 | redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||||
| 714 | } |
||||
| 715 | |||||
| 716 | foreach (array_keys($bid) as $i) { |
||||
| 717 | if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i] |
||||
| 718 | || $oldside[$i] !== $side[$i] |
||||
| 719 | || $oldbcachetime[$i] !== $bcachetime[$i]) { |
||||
| 720 | setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); |
||||
| 721 | } |
||||
| 722 | |||||
| 723 | if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) { |
||||
| 724 | $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]); |
||||
| 725 | |||||
| 726 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 727 | |||||
| 728 | if (in_array(0, $bmodule[$i])) { |
||||
| 729 | $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0); |
||||
| 730 | |||||
| 731 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 732 | } else { |
||||
| 733 | foreach ($bmodule[$i] as $bmid) { |
||||
| 734 | $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid); |
||||
| 735 | |||||
| 736 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 737 | } |
||||
| 738 | } |
||||
| 739 | } |
||||
| 740 | |||||
| 741 | $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]); |
||||
| 742 | |||||
| 743 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 744 | |||||
| 745 | if (!empty($groups[$i])) { |
||||
| 746 | foreach ($groups[$i] as $grp) { |
||||
| 747 | $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid[$i]); |
||||
| 748 | |||||
| 749 | $GLOBALS['xoopsDB']->query($sql); |
||||
| 750 | } |
||||
| 751 | } |
||||
| 752 | } |
||||
| 753 | |||||
| 754 | redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
||||
| 755 | } |
||||
| 756 | |||||
| 757 | if ('clone' === $op) { |
||||
| 758 | cloneBlock($bid); |
||||
| 759 | } |
||||
| 760 | |||||
| 761 | if ('edit' === $op) { |
||||
| 762 | editBlock($bid); |
||||
| 763 | } |
||||
| 764 | |||||
| 765 | if ('edit_ok' === $op) { |
||||
| 766 | updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups); |
||||
| 767 | } |
||||
| 768 | |||||
| 769 | if ('clone_ok' === $op) { |
||||
| 770 | isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options); |
||||
| 771 | } |
||||
| 772 | } else { |
||||
| 773 | echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'); |
||||
| 774 | } |
||||
| 775 |
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.