Issues (411)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/blocksadmin.php (15 issues)

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\Wfdownloads\{
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 = \Xmf\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());
0 ignored issues
show
The method getByModule() does not exist on XoopsBlock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

114
        /** @scrutinizer ignore-call */ 
115
        $blockArray = \XoopsBlock::getByModule($xoopsModule->mid());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
115
        $blockCount = count($blockArray);
0 ignored issues
show
The assignment to $blockCount is dead and can be removed.
Loading history...
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 = '&nbsp;';
173
            } else {
174
                $title = $i->getVar('title');
175
            }
176
            $name = $i->getVar('name');
0 ignored issues
show
The assignment to $name is dead and can be removed.
Loading history...
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
                 . "&nbsp;<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&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>
261
                 </a> <a href='blocksadmin.php?op=clone&amp;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 "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;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 = [
0 ignored issues
show
The assignment to $block is dead and can be removed.
Loading history...
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>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _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
The variable $form seems to be never defined.
Loading history...
337
        //        xoops_cp_footer();
338
        require_once __DIR__ . '/admin_footer.php';
339
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
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();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
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();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
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)
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 ignore-unused  annotation

421
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime, /** @scrutinizer ignore-unused */ $bmodule)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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();
0 ignored issues
show
The method store() does not exist on XoopsBlock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

429
        $myblock->/** @scrutinizer ignore-call */ 
430
                  store();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
430
    }
431
432
    /**
433
     * @param int $bid
434
     */
435
    function editBlock($bid)
436
    {
437
        require_once __DIR__ . '/admin_header.php';
438
        xoops_cp_header();
439
        $adminObject = Admin::getInstance();
440
        $adminObject->displayNavigation(basename(__FILE__));
441
        $moduleDirName = basename(dirname(__DIR__));
442
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
443
        xoops_loadLanguage('admin', 'system');
444
        xoops_loadLanguage('admin/blocksadmin', 'system');
445
        xoops_loadLanguage('admin/groups', 'system');
446
        //        mpu_adm_menu();
447
        $myblock = new \XoopsBlock($bid);
448
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
449
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
450
        $result = $db->query($sql);
451
        $modules = [];
452
        while (false !== ($row = $db->fetchArray($result))) {
453
            $modules[] = (int)$row['module_id'];
454
        }
455
        $isCustom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
456
        $block = [
0 ignored issues
show
The assignment to $block is dead and can be removed.
Loading history...
457
            'title' => $myblock->getVar('title'),
458
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
459
            //        'name'       => $myblock->getVar('name'),
460
            'side' => $myblock->getVar('side'),
461
            'weight' => $myblock->getVar('weight'),
462
            'visible' => $myblock->getVar('visible'),
463
            'content' => $myblock->getVar('content', 'N'),
464
            'modules' => $modules,
465
            'is_custom'  => $isCustom,
466
            'ctype' => $myblock->getVar('c_type'),
467
            'bcachetime' => $myblock->getVar('bcachetime'),
468
            'op' => 'edit_ok',
469
            'bid' => $myblock->getVar('bid'),
470
            'edit_form' => $myblock->getOptions(),
471
            'template' => $myblock->getVar('template'),
472
            'options' => $myblock->getVar('options'),
473
        ];
474
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
475
        require_once __DIR__ . '/blockform.php';
476
        /** @var XoopsThemeForm $form */
477
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
478
        //        xoops_cp_footer();
479
        require_once __DIR__ . '/admin_footer.php';
480
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
481
    }
482
483
    /**
484
     * @param int $bid
485
     * @param string            $btitle
486
     * @param string            $bside
487
     * @param int               $bweight
488
     * @param bool              $bvisible
489
     * @param int               $bcachetime
490
     * @param array             $bmodule
491
     * @param null|array|string $options
492
     * @param null|array        $groups
493
     */
494
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
495
    {
496
        $myblock = new XoopsBlock($bid);
497
        $myblock->setVar('title', $btitle);
498
        $myblock->setVar('weight', $bweight);
499
        $myblock->setVar('visible', $bvisible);
500
        $myblock->setVar('side', $bside);
501
        $myblock->setVar('bcachetime', $bcachetime);
502
        $helper = Helper::getInstance();
503
        $helper->loadLanguage('common');
504
        //update block options
505
        if (isset($options)) {
506
            $optionsCount = count($options);
0 ignored issues
show
It seems like $options can also be of type string; however, parameter $var 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 ignore-type  annotation

506
            $optionsCount = count(/** @scrutinizer ignore-type */ $options);
Loading history...
507
            if ($optionsCount > 0) {
508
                //Convert array values to comma-separated
509
                foreach ($options as $i => $iValue) {
510
                    if (is_array($iValue)) {
511
                        $options[$i] = implode(',', $iValue);
512
                    }
513
                }
514
                $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 ignore-type  annotation

514
                $options = implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
515
                $myblock->setVar('options', $options);
516
            }
517
        }
518
        $myblock->store();
519
520
        global $xoopsDB;
521
522
        $moduleDirName = basename(dirname(__DIR__));
523
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
524
525
        if (!empty($bmodule) && count($bmodule) > 0) {
526
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
527
            $xoopsDB->query($sql);
528
            if (in_array(0, $bmodule)) {
529
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, 0);
530
                $xoopsDB->query($sql);
531
            } else {
532
                foreach ($bmodule as $bmid) {
533
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, (int)$bmid);
534
                    $xoopsDB->query($sql);
535
                }
536
            }
537
        }
538
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
539
        $xoopsDB->query($sql);
540
        if (!empty($groups)) {
541
            foreach ($groups as $grp) {
542
                $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);
543
                $xoopsDB->query($sql);
544
            }
545
        }
546
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
547
    }
548
549
    if ('list' === $op) {
550
        xoops_cp_header();
551
        //        mpu_adm_menu();
552
        listBlocks();
553
        require_once __DIR__ . '/admin_footer.php';
554
        exit();
555
    }
556
557
    if ('order' === $op) {
558
        if (!$GLOBALS['xoopsSecurity']->check()) {
559
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
560
        }
561
        foreach (array_keys($bid) as $i) {
562
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i]
563
                || $oldside[$i] != $side[$i]
564
                || $oldbcachetime[$i] != $bcachetime[$i]) {
565
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
566
            }
567
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
568
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid[$i]);
569
                $xoopsDB->query($sql);
570
                if (in_array(0, $bmodule[$i])) {
571
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], 0);
572
                    $xoopsDB->query($sql);
573
                } else {
574
                    foreach ($bmodule[$i] as $bmid) {
575
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], (int)$bmid);
576
                        $xoopsDB->query($sql);
577
                    }
578
                }
579
            }
580
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid[$i]);
581
            $xoopsDB->query($sql);
582
            if (!empty($groups[$i])) {
583
                foreach ($groups[$i] as $grp) {
584
                    $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]);
585
                    $xoopsDB->query($sql);
586
                }
587
            }
588
        }
589
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
590
    }
591
    if ('clone' === $op) {
592
        cloneBlock($bid);
593
    }
594
595
    if ('edit' === $op) {
596
        editBlock($bid);
597
    }
598
599
    if ('edit_ok' === $op) {
600
        updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
601
    }
602
603
    if ('clone_ok' === $op) {
604
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
605
    }
606
} else {
607
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
608
}
609