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