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