Issues (68)

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.

class/Common/Blocksadmin.php (18 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Xoopsmembers\Common;
6
7
/**
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 *
12
 *
13
 * @category        Module
14
 * @author          XOOPS Development Team
15
 * @copyright       XOOPS Project
16
 * @link            https://xoops.org
17
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 */
19
20
use Xmf\Request;
21
22
//require __DIR__ . '/admin_header.php';
23
24
/**
25
 * class Blocksadmin
26
 */
27
class Blocksadmin
28
{
29
    /**
30
     * @var \XoopsMySQLDatabase|null
31
     */
32
    public $db;
33
    public $modHelper;
34
    public $moduleDirName;
35
    public $moduleDirNameUpper;
36
37
    /**
38
     * @param $db
39
     * @param $modHelper
40
     */
41
    public function __construct($db, $modHelper)
42
    {
43
        if (null === $db){
44
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
45
        }
46
        $this->db                 = $db;
47
        $this->modHelper          = $modHelper;
48
        $this->moduleDirName      = \basename(\dirname(__DIR__, 2));
49
        $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName);
50
        \xoops_loadLanguage('admin', 'system');
51
        \xoops_loadLanguage('admin/blocksadmin', 'system');
52
        \xoops_loadLanguage('admin/groups', 'system');
53
        \xoops_loadLanguage('common', $this->moduleDirName);
54
        \xoops_loadLanguage('blocksadmin', $this->moduleDirName);
55
    }
56
57
    public function listBlocks(): void
58
    {
59
        global $xoopsModule, $pathIcon16;
60
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
61
        //        xoops_loadLanguage('admin', 'system');
62
        //        xoops_loadLanguage('admin/blocksadmin', 'system');
63
        //        xoops_loadLanguage('admin/groups', 'system');
64
        //        xoops_loadLanguage('common', $moduleDirName);
65
        //        xoops_loadLanguage('blocks', $moduleDirName);
66
67
        /** @var \XoopsModuleHandler $moduleHandler */
68
        $moduleHandler = \xoops_getHandler('module');
69
        /** @var \XoopsMemberHandler $memberHandler */
70
        $memberHandler = \xoops_getHandler('member');
71
        /** @var \XoopsGroupPermHandler $grouppermHandler */
72
        $grouppermHandler = \xoops_getHandler('groupperm');
73
        $groups           = $memberHandler->getGroups();
74
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
75
        $criteria->add(new \Criteria('isactive', 1));
76
        $moduleList     = $moduleHandler->getList($criteria);
77
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
78
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
79
        \ksort($moduleList);
80
        echo "
81
        <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
82
        /** @var \XoopsModuleHandler $moduleHandler */
83
        $moduleHandler = \xoops_getHandler('module');
0 ignored issues
show
The assignment to $moduleHandler is dead and can be removed.
Loading history...
84
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
85
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
86
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
87
        <tr valign='middle'><th align='center'>"
88
             . \_AM_SYSTEM_BLOCKS_TITLE
89
             . "</th><th align='center' nowrap='nowrap'>"
90
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE')
91
             . '<br>'
92
             . _LEFT
93
             . '-'
94
             . _CENTER
95
             . '-'
96
             . _RIGHT
97
             . "</th><th align='center'>"
98
             . \constant(
99
                 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'
100
             )
101
             . "</th><th align='center'>"
102
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE')
103
             . "</th><th align='center'>"
104
             . \_AM_SYSTEM_BLOCKS_VISIBLEIN
105
             . "</th><th align='center'>"
106
             . \_AM_SYSTEM_ADGS
107
             . "</th><th align='center'>"
108
             . \_AM_SYSTEM_BLOCKS_BCACHETIME
109
             . "</th><th align='center'>"
110
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION')
111
             . '</th></tr>
112
        ';
113
        $blockArray = \XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

113
        $blockArray = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($xoopsModule->mid());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
114
        $blockCount = \count($blockArray);
0 ignored issues
show
The assignment to $blockCount is dead and can be removed.
Loading history...
115
        $class      = 'even';
116
        $cachetimes = [
117
            0       => _NOCACHE,
118
            30      => \sprintf(_SECONDS, 30),
119
            60      => _MINUTE,
120
            300     => \sprintf(_MINUTES, 5),
121
            1800    => \sprintf(_MINUTES, 30),
122
            3600    => _HOUR,
123
            18000   => \sprintf(_HOURS, 5),
124
            86400   => _DAY,
125
            259200  => \sprintf(_DAYS, 3),
126
            604800  => _WEEK,
127
            2592000 => _MONTH,
128
        ];
129
        foreach ($blockArray as $i) {
130
            $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
131
            $sql               = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
0 ignored issues
show
The method prefix() does not exist on null. ( Ignorable by Annotation )

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

131
            $sql               = 'SELECT module_id FROM ' . $this->db->/** @scrutinizer ignore-call */ prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');

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...
132
            $result            = $this->db->query($sql);
133
            $modules           = [];
134
            while (false !== ($row = $this->db->fetchArray($result))) {
0 ignored issues
show
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, 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

134
            while (false !== ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
135
                $modules[] = (int)$row['module_id'];
136
            }
137
138
            $cachetimeOptions = '';
139
            foreach ($cachetimes as $cachetime => $cachetimeName) {
140
                if ($i->getVar('bcachetime') == $cachetime) {
141
                    $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
142
                } else {
143
                    $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
144
                }
145
            }
146
147
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
148
            if (1 === $i->getVar('visible')) {
149
                $sel1 = ' checked';
150
            } else {
151
                $sel0 = ' checked';
152
            }
153
            if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
154
                $ssel0 = ' checked';
155
            } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
156
                $ssel1 = ' checked';
157
            } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
158
                $ssel2 = ' checked';
159
            } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
160
                $ssel4 = ' checked';
161
            } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
162
                $ssel3 = ' checked';
163
            } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
164
                $ssel5 = ' checked';
165
            } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
166
                $ssel6 = ' checked';
167
            } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
168
                $ssel7 = ' checked';
169
            }
170
            if ('' === $i->getVar('title')) {
171
                $title = '&nbsp;';
172
            } else {
173
                $title = $i->getVar('title');
174
            }
175
            $name = $i->getVar('name');
0 ignored issues
show
The assignment to $name is dead and can be removed.
Loading history...
176
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
177
                 . $i->getVar('bid')
178
                 . "]' value='"
179
                 . $title
180
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
181
                    <div align='center' >
182
                    <input type='radio' name='side["
183
                 . $i->getVar('bid')
184
                 . "]' value='"
185
                 . \XOOPS_CENTERBLOCK_LEFT
186
                 . "'$ssel2>
187
                        <input type='radio' name='side["
188
                 . $i->getVar('bid')
189
                 . "]' value='"
190
                 . \XOOPS_CENTERBLOCK_CENTER
191
                 . "'$ssel3>
192
                    <input type='radio' name='side["
193
                 . $i->getVar('bid')
194
                 . "]' value='"
195
                 . \XOOPS_CENTERBLOCK_RIGHT
196
                 . "'$ssel4>
197
                    </div>
198
                    <div>
199
                        <span style='float:right;'><input type='radio' name='side["
200
                 . $i->getVar('bid')
201
                 . "]' value='"
202
                 . \XOOPS_SIDEBLOCK_RIGHT
203
                 . "'$ssel1></span>
204
                    <div align='left'><input type='radio' name='side["
205
                 . $i->getVar('bid')
206
                 . "]' value='"
207
                 . \XOOPS_SIDEBLOCK_LEFT
208
                 . "'$ssel0></div>
209
                    </div>
210
                    <div align='center'>
211
                    <input type='radio' name='side["
212
                 . $i->getVar('bid')
213
                 . "]' value='"
214
                 . \XOOPS_CENTERBLOCK_BOTTOMLEFT
215
                 . "'$ssel5>
216
                        <input type='radio' name='side["
217
                 . $i->getVar('bid')
218
                 . "]' value='"
219
                 . \XOOPS_CENTERBLOCK_BOTTOM
220
                 . "'$ssel7>
221
                    <input type='radio' name='side["
222
                 . $i->getVar('bid')
223
                 . "]' value='"
224
                 . \XOOPS_CENTERBLOCK_BOTTOMRIGHT
225
                 . "'$ssel6>
226
                    </div>
227
                </td><td class='$class' align='center'><input type='text' name='weight["
228
                 . $i->getVar('bid')
229
                 . "]' value='"
230
                 . $i->getVar('weight')
231
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
232
                 . $i->getVar('bid')
233
                 . "]' value='1'$sel1>"
234
                 . _YES
235
                 . "&nbsp;<input type='radio' name='visible["
236
                 . $i->getVar('bid')
237
                 . "]' value='0'$sel0>"
238
                 . _NO
239
                 . '</td>';
240
241
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
242
            foreach ($moduleList as $k => $v) {
243
                echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
244
            }
245
            echo '</select></td>';
246
247
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
248
            foreach ($groups as $grp) {
249
                echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
250
            }
251
            echo '</select></td>';
252
253
            // Cache lifetime
254
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
255
                                    </td>';
256
257
            // Actions
258
259
            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 . "'>
260
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
261
                 </a>";
262
            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
263
            //                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 . "'>
264
            //                     </a>";
265
            //            }
266
267
            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
268
            if (!\in_array($i->getVar('block_type'), ['M', 'S'])) {
269
                echo "&nbsp;
270
                <a href='blocksadmin.php?op=delete&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
271
                     </a>";
272
            }
273
            echo "
274
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
275
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
276
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
277
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
278
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
279
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
280
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
281
            </td></tr>
282
            ";
283
            $class = ('even' === $class) ? 'odd' : 'even';
284
        }
285
        echo "<tr><td class='foot' align='center' colspan='8'>
286
        <input type='hidden' name='op' value='order'>
287
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
288
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
289
        </td></tr></table>
290
        </form>
291
        <br><br>";
292
    }
293
294
    /**
295
     * @param int $bid
296
     */
297
    public function deleteBlock($bid)
298
    {
299
        //        \xoops_cp_header();
300
301
        \xoops_loadLanguage('admin', 'system');
302
        \xoops_loadLanguage('admin/blocksadmin', 'system');
303
        \xoops_loadLanguage('admin/groups', 'system');
304
305
        $myblock = new \XoopsBlock($bid);
0 ignored issues
show
The assignment to $myblock is dead and can be removed.
Loading history...
306
307
        $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid);
308
        if (!$result = $this->db->queryF($sql)) {
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
309
            return false;
310
        }
311
        $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
312
        $this->db->queryF($sql);
313
314
        $this->modHelper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
315
    }
316
317
    /**
318
     * @param int $bid
319
     */
320
    public function cloneBlock($bid): void
321
    {
322
        //require __DIR__ . '/admin_header.php';
323
        //        \xoops_cp_header();
324
325
        \xoops_loadLanguage('admin', 'system');
326
        \xoops_loadLanguage('admin/blocksadmin', 'system');
327
        \xoops_loadLanguage('admin/groups', 'system');
328
329
        $myblock = new \XoopsBlock($bid);
330
        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
331
        $result  = $this->db->query($sql);
332
        $modules = [];
333
        if ($result instanceof \mysqli_result) {
334
            while (false !== ($row = $this->db->fetchArray($result))) {
335
                $modules[] = (int)$row['module_id'];
336
            }
337
        }
338
        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']);
339
        $block    = [
340
            'title'      => $myblock->getVar('title') . ' Clone',
341
            'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
342
            'name'       => $myblock->getVar('name'),
343
            'side'       => $myblock->getVar('side'),
344
            'weight'     => $myblock->getVar('weight'),
345
            'visible'    => $myblock->getVar('visible'),
346
            'content'    => $myblock->getVar('content', 'N'),
347
            'modules'    => $modules,
348
            'is_custom'  => $isCustom,
349
            'ctype'      => $myblock->getVar('c_type'),
350
            'bcachetime' => $myblock->getVar('bcachetime'),
351
            'op'         => 'clone_ok',
352
            'bid'        => $myblock->getVar('bid'),
353
            'edit_form'  => $myblock->getOptions(),
354
            'template'   => $myblock->getVar('template'),
355
            'options'    => $myblock->getVar('options'),
356
        ];
357
        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
358
        //        $form = new Blockform();
359
        //        $form->render();
360
361
        echo $this->render($block);
0 ignored issues
show
Are you sure the usage of $this->render($block) targeting XoopsModules\Xoopsmember...n\Blocksadmin::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
362
        //        xoops_cp_footer();
363
        //        require_once __DIR__ . '/admin_footer.php';
364
        //        exit();
365
    }
366
367
    /**
368
     * @param int               $bid
369
     * @param string            $bside
370
     * @param string            $bweight
371
     * @param string            $bvisible
372
     * @param string            $bcachetime
373
     * @param array             $bmodule
374
     * @param null|array|string $options
375
     */
376
    public function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups): void
377
    {
378
        \xoops_loadLanguage('admin', 'system');
379
        \xoops_loadLanguage('admin/blocksadmin', 'system');
380
        \xoops_loadLanguage('admin/groups', 'system');
381
382
        $block = new \XoopsBlock($bid);
383
        $clone = $block->xoopsClone();
384
        if (empty($bmodule)) {
385
            //            \xoops_cp_header();
386
            \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
387
            \xoops_cp_footer();
388
            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...
389
        }
390
        $clone->setVar('side', $bside);
391
        $clone->setVar('weight', $bweight);
392
        $clone->setVar('visible', $bvisible);
393
        //$clone->setVar('content', $_POST['bcontent']);
394
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
395
        $clone->setVar('bcachetime', $bcachetime);
396
        if (isset($options) && (\count($options) > 0)) {
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 ignore-type  annotation

396
        if (isset($options) && (\count(/** @scrutinizer ignore-type */ $options) > 0)) {
Loading history...
397
            $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

397
            $options = \implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
398
            $clone->setVar('options', $options);
399
        }
400
        $clone->setVar('bid', 0);
401
        if (\in_array($block->getVar('block_type'), ['C', 'E'])) {
402
            $clone->setVar('block_type', 'E');
403
        } else {
404
            $clone->setVar('block_type', 'D');
405
        }
406
        $newid = $clone->store();
407
        if (!$newid) {
408
            //            \xoops_cp_header();
409
            $clone->getHtmlErrors();
410
            \xoops_cp_footer();
411
            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...
412
        }
413
        if ('' !== $clone->getVar('template')) {
414
            /** @var \XoopsTplfileHandler $tplfileHandler */
415
            $tplfileHandler = \xoops_getHandler('tplfile');
416
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
417
            if (\count($btemplate) > 0) {
418
                $tplclone = $btemplate[0]->xoopsClone();
419
                $tplclone->setVar('tpl_id', 0);
420
                $tplclone->setVar('tpl_refid', $newid);
421
                $tplfileHandler->insert($tplclone);
422
            }
423
        }
424
425
        foreach ($bmodule as $bmid) {
426
            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
427
            $this->db->query($sql);
428
        }
429
        //$groups = &$GLOBALS['xoopsUser']->getGroups();
430
        foreach ($groups as $iValue) {
431
            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
432
            $this->db->query($sql);
433
        }
434
        $this->modHelper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
435
    }
436
437
    /**
438
     * @param int    $bid
439
     * @param string $title
440
     * @param int    $weight
441
     * @param bool   $visible
442
     * @param string $side
443
     * @param int    $bcachetime
444
     */
445
    public function setOrder($bid, $title, $weight, $visible, $side, $bcachetime, $bmodule): void
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

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

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...
446
    {
447
        $myblock = new \XoopsBlock($bid);
448
        $myblock->setVar('title', $title);
449
        $myblock->setVar('weight', $weight);
450
        $myblock->setVar('visible', $visible);
451
        $myblock->setVar('side', $side);
452
        $myblock->setVar('bcachetime', $bcachetime);
453
        $myblock->store();
0 ignored issues
show
Deprecated Code introduced by
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 ignore-deprecated  annotation

453
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
454
        //        /** @var \XoopsBlockHandler $blockHandler */
455
        //        $blockHandler = \xoops_getHandler('block');
456
        //        return $blockHandler->insert($myblock);
457
    }
458
459
    /**
460
     * @param int $bid
461
     */
462
    public function editBlock($bid): void
463
    {
464
        //        require_once \dirname(__DIR__,2) . '/admin/admin_header.php';
465
        //        \xoops_cp_header();
466
        \xoops_loadLanguage('admin', 'system');
467
        \xoops_loadLanguage('admin/blocksadmin', 'system');
468
        \xoops_loadLanguage('admin/groups', 'system');
469
        //        mpu_adm_menu();
470
        $myblock = new \XoopsBlock($bid);
471
        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
472
        $result  = $this->db->query($sql);
473
        $modules = [];
474
        if ($result instanceof \mysqli_result) {
475
            while (false !== ($row = $this->db->fetchArray($result))) {
476
                $modules[] = (int)$row['module_id'];
477
            }
478
        }
479
        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']);
480
        $block    = [
481
            'title'      => $myblock->getVar('title'),
482
            'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK,
483
            //        'name'       => $myblock->getVar('name'),
484
            'side'       => $myblock->getVar('side'),
485
            'weight'     => $myblock->getVar('weight'),
486
            'visible'    => $myblock->getVar('visible'),
487
            'content'    => $myblock->getVar('content', 'N'),
488
            'modules'    => $modules,
489
            'is_custom'  => $isCustom,
490
            'ctype'      => $myblock->getVar('c_type'),
491
            'bcachetime' => $myblock->getVar('bcachetime'),
492
            'op'         => 'edit_ok',
493
            'bid'        => $myblock->getVar('bid'),
494
            'edit_form'  => $myblock->getOptions(),
495
            'template'   => $myblock->getVar('template'),
496
            'options'    => $myblock->getVar('options'),
497
        ];
498
        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
499
500
        /** @var \XoopsThemeForm $form */ //                $form = new Blockform();
501
        //        $form->render($block);
502
        //        $form = new \XoopsThemeForm();
503
504
        echo $this->render($block);
0 ignored issues
show
Are you sure the usage of $this->render($block) targeting XoopsModules\Xoopsmember...n\Blocksadmin::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
505
    }
506
507
    /**
508
     * @param int               $bid
509
     * @param string            $btitle
510
     * @param string            $bside
511
     * @param string            $bweight
512
     * @param string            $bvisible
513
     * @param string            $bcachetime
514
     * @param array             $bmodule
515
     * @param null|array|string $options
516
     * @param null|array        $groups
517
     */
518
    public function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups): void
519
    {
520
        $myblock = new \XoopsBlock($bid);
521
        $myblock->setVar('title', $btitle);
522
        $myblock->setVar('weight', $bweight);
523
        $myblock->setVar('visible', $bvisible);
524
        $myblock->setVar('side', $bside);
525
        $myblock->setVar('bcachetime', $bcachetime);
526
        //update block options
527
        if (isset($options) && \is_array($options)) {
528
            $optionsCount = \count($options);
529
            if ($optionsCount > 0) {
530
                //Convert array values to comma-separated
531
                foreach ($options as $i => $iValue) {
532
                    if (\is_array($iValue)) {
533
                        $options[$i] = \implode(',', $iValue);
534
                    }
535
                }
536
                $options = \implode('|', $options);
537
                $myblock->setVar('options', $options);
538
            }
539
        }
540
        $myblock->store();
0 ignored issues
show
Deprecated Code introduced by
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 ignore-deprecated  annotation

540
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
541
        //        /** @var \XoopsBlockHandler $blockHandler */
542
        //        $blockHandler = \xoops_getHandler('block');
543
        //        $blockHandler->insert($myblock);
544
545
        if (!empty($bmodule) && \count($bmodule) > 0) {
546
            $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
547
            $this->db->query($sql);
548
            if (\in_array(0, $bmodule)) {
549
                $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0);
550
                $this->db->query($sql);
551
            } else {
552
                foreach ($bmodule as $bmid) {
553
                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
554
                    $this->db->query($sql);
555
                }
556
            }
557
        }
558
        $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid);
559
        $this->db->query($sql);
560
        if (!empty($groups)) {
561
            foreach ($groups as $grp) {
562
                $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid);
563
                $this->db->query($sql);
564
            }
565
        }
566
        $this->modHelper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
567
    }
568
569
    /**
570
     * @param array $bid
571
     */
572
    public function orderBlock(
573
        $bid,
574
        $oldtitle,
575
        $oldside,
576
        $oldweight,
577
        $oldvisible,
578
        $oldgroups,
0 ignored issues
show
The parameter $oldgroups 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

578
        /** @scrutinizer ignore-unused */ $oldgroups,

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...
579
        $oldbcachetime,
580
        $title,
581
        $weight,
582
        $visible,
583
        $side,
584
        $bcachetime,
585
        $groups,
586
        $bmodule = null
587
    ): void {
588
        if (!$GLOBALS['xoopsSecurity']->check()) {
589
            \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
590
        }
591
        foreach (\array_keys($bid) as $i) {
592
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
593
                || $oldside[$i] !== $side[$i]
594
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
595
                $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
596
            }
597
            if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
598
                $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
599
                $this->db->query($sql);
600
                if (\in_array(0, $bmodule[$i], true)) {
601
                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0);
602
                    $this->db->query($sql);
603
                } else {
604
                    foreach ($bmodule[$i] as $bmid) {
605
                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
606
                        $this->db->query($sql);
607
                    }
608
                }
609
            }
610
            $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]);
611
            $this->db->query($sql);
612
            if (!empty($groups[$i])) {
613
                foreach ($groups[$i] as $grp) {
614
                    $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]);
615
                    $this->db->query($sql);
616
                }
617
            }
618
        }
619
620
        $this->modHelper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
621
    }
622
623
    /**
624
     * @param null|\array $block
625
     */
626
    public function render($block = null)
627
    {
628
        \xoops_load('XoopsFormLoader');
629
        \xoops_loadLanguage('common', $this->moduleDirNameUpper);
630
631
        $form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
632
        if (isset($block['name'])) {
633
            $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name']));
634
        }
635
        $sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']);
636
        $sideSelect->addOptionArray([
637
                                        0 => \_AM_SYSTEM_BLOCKS_SBLEFT,
638
                                        1 => \_AM_SYSTEM_BLOCKS_SBRIGHT,
639
                                        3 => \_AM_SYSTEM_BLOCKS_CBLEFT,
640
                                        4 => \_AM_SYSTEM_BLOCKS_CBRIGHT,
641
                                        5 => \_AM_SYSTEM_BLOCKS_CBCENTER,
642
                                        7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT,
643
                                        8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT,
644
                                        9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
645
                                    ]);
646
        $form->addElement($sideSelect);
647
        $form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
648
        $form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
649
        $modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
650
        /** @var \XoopsModuleHandler $moduleHandler */
651
        $moduleHandler = \xoops_getHandler('module');
652
        $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
653
        $criteria->add(new \Criteria('isactive', 1));
654
        $moduleList     = $moduleHandler->getList($criteria);
655
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
656
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
657
        \ksort($moduleList);
658
        $modSelect->addOptionArray($moduleList);
659
        $form->addElement($modSelect);
660
        $form->addElement(new \XoopsFormText(_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
661
        if ($block['is_custom']) {
662
            $textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
663
            $textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
664
            $form->addElement($textarea, true);
665
            $ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
666
            $ctypeSelect->addOptionArray([
667
                                             'H' => \_AM_SYSTEM_BLOCKS_HTML,
668
                                             'P' => \_AM_SYSTEM_BLOCKS_PHP,
669
                                             'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE,
670
                                             'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE,
671
                                         ]);
672
            $form->addElement($ctypeSelect);
673
        } else {
674
            if ('' !== $block['template']) {
675
                /** @var \XoopsTplfileHandler $tplfileHandler */
676
                $tplfileHandler = \xoops_getHandler('tplfile');
677
                $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']);
678
                if (\count($btemplate) > 0) {
679
                    $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
680
                } else {
681
                    $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
682
                    if (\count($btemplate2) > 0) {
683
                        $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
684
                    }
685
                }
686
            }
687
            if (false !== $block['edit_form']) {
688
                $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
689
            }
690
        }
691
        $cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
692
        $cache_select->addOptionArray([
693
                                          0       => _NOCACHE,
694
                                          30      => \sprintf(_SECONDS, 30),
695
                                          60      => _MINUTE,
696
                                          300     => \sprintf(_MINUTES, 5),
697
                                          1800    => \sprintf(_MINUTES, 30),
698
                                          3600    => _HOUR,
699
                                          18000   => \sprintf(_HOURS, 5),
700
                                          86400   => _DAY,
701
                                          259200  => \sprintf(_DAYS, 3),
702
                                          604800  => _WEEK,
703
                                          2592000 => _MONTH,
704
                                      ]);
705
        $form->addElement($cache_select);
706
707
        /** @var \XoopsGroupPermHandler $grouppermHandler */
708
        $grouppermHandler = \xoops_getHandler('groupperm');
709
        $groups           = $grouppermHandler->getGroupIds('block_read', $block['bid']);
710
711
        $form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true));
712
713
        if (isset($block['bid'])) {
714
            $form->addElement(new \XoopsFormHidden('bid', $block['bid']));
715
        }
716
        $form->addElement(new \XoopsFormHidden('op', $block['op']));
717
        $form->addElement(new \XoopsFormHidden('fct', 'blocksadmin'));
718
        $buttonTray = new \XoopsFormElementTray('', '&nbsp;');
719
        if ($block['is_custom']) {
720
            $buttonTray->addElement(new \XoopsFormButton('', 'previewblock', _PREVIEW, 'submit'));
721
        }
722
723
        //Submit buttons
724
        $buttonTray   = new \XoopsFormElementTray('', '');
725
        $submitButton = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit');
726
        $buttonTray->addElement($submitButton);
727
728
        $cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button');
729
        $cancelButton->setExtra('onclick="history.go(-1)"');
730
        $buttonTray->addElement($cancelButton);
731
732
        $form->addElement($buttonTray);
733
        $form->display();
734
    }
735
}
736
737
738