Issues (67)

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 declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsmembers\Common;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 *
11
 * @category        Module
12
 * @author          XOOPS Development Team
13
 * @copyright       XOOPS Project
14
 * @link            https://xoops.org
15
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 */
17
18
use Xmf\Request;
19
use XoopsModules\Xoopsmembers\{
20
    Helper
21
};
22
23
//require __DIR__ . '/admin_header.php';
24
25
/**
26
 * class Blocksadmin
27
 */
28
class Blocksadmin
29
{
30
    /**
31
     * @var \XoopsMySQLDatabase|null
32
     */
33
    public $db;
34
    /**
35
     * @var \XoopsModules\Tag\Helper
36
     */
37
    public $helper;
38
    /**
39
     * @var string
40
     */
41
    public $moduleDirName;
42
    /**
43
     * @var string
44
     */
45
    public $moduleDirNameUpper;
46
47
    /**
48
     * Blocksadmin constructor.
49
     */
50
    public function __construct(?\XoopsDatabase $db, Helper $helper)
51
    {
52
        if (null === $db) {
53
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
54
        }
55
        $this->db                 = $db;
56
        $this->helper             = $helper;
0 ignored issues
show
Documentation Bug introduced by
It seems like $helper of type XoopsModules\Xoopsmembers\Helper is incompatible with the declared type XoopsModules\Tag\Helper of property $helper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->moduleDirName      = \basename(\dirname(__DIR__, 2));
58
        $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName);
59
        \xoops_loadLanguage('admin', 'system');
60
        \xoops_loadLanguage('admin/blocksadmin', 'system');
61
        \xoops_loadLanguage('admin/groups', 'system');
62
        \xoops_loadLanguage('common', $this->moduleDirName);
63
        \xoops_loadLanguage('blocksadmin', $this->moduleDirName);
64
    }
65
66
    public function listBlocks()
67
    : void
68
    {
69
        global $xoopsModule, $pathIcon16;
70
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
71
        //        xoops_loadLanguage('admin', 'system');
72
        //        xoops_loadLanguage('admin/blocksadmin', 'system');
73
        //        xoops_loadLanguage('admin/groups', 'system');
74
        //        xoops_loadLanguage('common', $moduleDirName);
75
        //        xoops_loadLanguage('blocks', $moduleDirName);
76
77
        /** @var \XoopsModuleHandler $moduleHandler */
78
        $moduleHandler = \xoops_getHandler('module');
79
        /** @var \XoopsMemberHandler $memberHandler */
80
        $memberHandler = \xoops_getHandler('member');
81
        /** @var \XoopsGroupPermHandler $grouppermHandler */
82
        $grouppermHandler = \xoops_getHandler('groupperm');
83
        $groups           = $memberHandler->getGroups();
84
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', '1'));
85
        $criteria->add(new \Criteria('isactive', '1'));
86
        $moduleList     = $moduleHandler->getList($criteria);
87
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
88
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
89
        \ksort($moduleList);
90
        echo "
91
        <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
92
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
93
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
94
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
95
        <tr valign='middle'><th align='center'>"
96
             . \_AM_SYSTEM_BLOCKS_TITLE
97
             . "</th><th align='center' nowrap='nowrap'>"
98
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE')
99
             . '<br>'
100
             . _LEFT
101
             . '-'
102
             . _CENTER
103
             . '-'
104
             . _RIGHT
105
             . "</th><th align='center'>"
106
             . \constant(
107
                 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'
108
             )
109
             . "</th><th align='center'>"
110
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE')
111
             . "</th><th align='center'>"
112
             . \_AM_SYSTEM_BLOCKS_VISIBLEIN
113
             . "</th><th align='center'>"
114
             . \_AM_SYSTEM_ADGS
115
             . "</th><th align='center'>"
116
             . \_AM_SYSTEM_BLOCKS_BCACHETIME
117
             . "</th><th align='center'>"
118
             . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION')
119
             . '</th></tr>
120
        ';
121
        $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

121
        $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...
122
        $blockCount = \count($blockArray);
0 ignored issues
show
The assignment to $blockCount is dead and can be removed.
Loading history...
123
        $class      = 'even';
124
        $cachetimes = [
125
            0       => _NOCACHE,
126
            30      => \sprintf(_SECONDS, 30),
127
            60      => _MINUTE,
128
            300     => \sprintf(_MINUTES, 5),
129
            1800    => \sprintf(_MINUTES, 30),
130
            3600    => _HOUR,
131
            18000   => \sprintf(_HOURS, 5),
132
            86400   => _DAY,
133
            259200  => \sprintf(_DAYS, 3),
134
            604800  => _WEEK,
135
            2592000 => _MONTH,
136
        ];
137
        foreach ($blockArray as $i) {
138
            $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
139
            $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

139
            $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...
140
            $result            = $this->db->query($sql);
141
            $modules           = [];
142
            if (!$result instanceof \mysqli_result) {
143
                \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
144
            }
145
            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

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

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

392
        echo /** @scrutinizer ignore-type */ $this->render($block);
Loading history...
393
        //        xoops_cp_footer();
394
        //        require_once __DIR__ . '/admin_footer.php';
395
        //        exit();
396
    }
397
398
    /**
399
     * @param int               $bid
400
     * @param string            $bside
401
     * @param string            $bweight
402
     * @param string            $bvisible
403
     * @param string            $bcachetime
404
     * @param array             $bmodule
405
     * @param null|array|string $options
406
     * @return void
407
     */
408
    public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
409
    {
410
        \xoops_loadLanguage('admin', 'system');
411
        \xoops_loadLanguage('admin/blocksadmin', 'system');
412
        \xoops_loadLanguage('admin/groups', 'system');
413
414
        $block = new \XoopsBlock($bid);
415
        $clone = $block->xoopsClone();
416
        if (empty($bmodule)) {
417
            //            \xoops_cp_header();
418
            \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
419
            \xoops_cp_footer();
420
            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...
421
        }
422
        $clone->setVar('side', $bside);
423
        $clone->setVar('weight', $bweight);
424
        $clone->setVar('visible', $bvisible);
425
        //$clone->setVar('content', $_POST['bcontent']);
426
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
427
        $clone->setVar('bcachetime', $bcachetime);
428
        if (\is_array($options) && (\count($options) > 0)) {
429
            $options = \implode('|', $options);
430
            $clone->setVar('options', $options);
431
        }
432
        $clone->setVar('bid', 0);
433
        if (\in_array($block->getVar('block_type'), ['C', 'E'])) {
434
            $clone->setVar('block_type', 'E');
435
        }
436
        else {
437
            $clone->setVar('block_type', 'D');
438
        }
439
        //        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
440
        if ($clone->store()) {
441
            $newid = $clone->id();  //get the id of the cloned block
442
        }
443
        if (!$newid) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $newid does not seem to be defined for all execution paths leading up to this point.
Loading history...
444
            //            \xoops_cp_header();
445
            $clone->getHtmlErrors();
446
            \xoops_cp_footer();
447
            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...
448
        }
449
        if ('' !== $clone->getVar('template')) {
450
            /** @var \XoopsTplfileHandler $tplfileHandler */
451
            $tplfileHandler = \xoops_getHandler('tplfile');
452
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid);
453
            if (\count($btemplate) > 0) {
454
                $tplclone = $btemplate[0]->xoopsClone();
455
                $tplclone->setVar('tpl_id', 0);
456
                $tplclone->setVar('tpl_refid', $newid);
457
                $tplfileHandler->insert($tplclone);
458
            }
459
        }
460
461
        foreach ($bmodule as $bmid) {
462
            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
463
            $this->db->query($sql);
464
        }
465
        //$groups = &$GLOBALS['xoopsUser']->getGroups();
466
        foreach ($groups as $iValue) {
467
            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
468
            $this->db->query($sql);
469
        }
470
        $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
471
    }
472
473
    /**
474
     * @param int    $bid
475
     * @param string $title
476
     * @param int    $weight
477
     * @param bool   $visible
478
     * @param string $side
479
     * @param int    $bcachetime
480
     * @return void
481
     */
482
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $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 ignore-unused  annotation

482
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, /** @scrutinizer ignore-unused */ ?array $bmodule = null)

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...
483
    : void {
484
        $myblock = new \XoopsBlock($bid);
485
        $myblock->setVar('title', $title);
486
        $myblock->setVar('weight', $weight);
487
        $myblock->setVar('visible', $visible);
488
        $myblock->setVar('side', $side);
489
        $myblock->setVar('bcachetime', $bcachetime);
490
        $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

490
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
491
        //        /** @var \XoopsBlockHandler $blockHandler */
492
        //        $blockHandler = \xoops_getHandler('block');
493
        //        return $blockHandler->insert($myblock);
494
    }
495
496
    /**
497
     * @param int $bid
498
     * @return void
499
     */
500
    public function editBlock(int $bid): void 
501
    {
502
        //        require_once \dirname(__DIR__,2) . '/admin/admin_header.php';
503
        //        \xoops_cp_header();
504
        \xoops_loadLanguage('admin', 'system');
505
        \xoops_loadLanguage('admin/blocksadmin', 'system');
506
        \xoops_loadLanguage('admin/groups', 'system');
507
        //        mpu_adm_menu();
508
        $myblock = new \XoopsBlock($bid);
509
        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
510
        $result  = $this->db->query($sql);
511
        $modules = [];
512
        if ($result instanceof \mysqli_result) {
513
            while (false !== ($row = $this->db->fetchArray($result))) {
514
                $modules[] = (int)$row['module_id'];
515
            }
516
        }
517
        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']);
518
        $block    = [
519
            'title'      => $myblock->getVar('title'),
520
            'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK,
521
            //        'name'       => $myblock->getVar('name'),
522
            'side'       => $myblock->getVar('side'),
523
            'weight'     => $myblock->getVar('weight'),
524
            'visible'    => $myblock->getVar('visible'),
525
            'content'    => $myblock->getVar('content', 'N'),
526
            'modules'    => $modules,
527
            'is_custom'  => $isCustom,
528
            'ctype'      => $myblock->getVar('c_type'),
529
            'bcachetime' => $myblock->getVar('bcachetime'),
530
            'op'         => 'edit_ok',
531
            'bid'        => $myblock->getVar('bid'),
532
            'edit_form'  => $myblock->getOptions(),
533
            'template'   => $myblock->getVar('template'),
534
            'options'    => $myblock->getVar('options'),
535
        ];
536
        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>';
537
538
        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...
Are you sure $this->render($block) of type void can be used in echo? ( Ignorable by Annotation )

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

538
        echo /** @scrutinizer ignore-type */ $this->render($block);
Loading history...
539
    }
540
541
    /**
542
     * @param int               $bid
543
     * @param string            $btitle
544
     * @param string            $bside
545
     * @param string            $bweight
546
     * @param string            $bvisible
547
     * @param string            $bcachetime
548
     * @param array             $bmodule
549
     * @param null|array|string $options
550
     * @param null|array        $groups
551
     * @return void
552
     */
553
    public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void 
554
    {
555
        $myblock = new \XoopsBlock($bid);
556
        $myblock->setVar('title', $btitle);
557
        $myblock->setVar('weight', $bweight);
558
        $myblock->setVar('visible', $bvisible);
559
        $myblock->setVar('side', $bside);
560
        $myblock->setVar('bcachetime', $bcachetime);
561
        //update block options
562
        if (isset($options)) {
563
            $optionsCount = \count($options);
564
            if ($optionsCount > 0) {
565
                //Convert array values to comma-separated
566
                foreach ($options as $i => $iValue) {
567
                    if (\is_array($iValue)) {
568
                        $options[$i] = \implode(',', $iValue);
569
                    }
570
                }
571
                $options = \implode('|', $options);
572
                $myblock->setVar('options', $options);
573
            }
574
        }
575
        $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

575
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
576
        //        /** @var \XoopsBlockHandler $blockHandler */
577
        //        $blockHandler = \xoops_getHandler('block');
578
        //        $blockHandler->insert($myblock);
579
580
        if (!empty($bmodule) && \count($bmodule) > 0) {
581
            $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
582
            $this->db->query($sql);
583
            if (\in_array(0, $bmodule)) {
584
                $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0);
585
                $this->db->query($sql);
586
            }
587
            else {
588
                foreach ($bmodule as $bmid) {
589
                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
590
                    $this->db->query($sql);
591
                }
592
            }
593
        }
594
        $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid);
595
        $this->db->query($sql);
596
        if (!empty($groups)) {
597
            foreach ($groups as $grp) {
598
                $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);
599
                $this->db->query($sql);
600
            }
601
        }
602
        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
603
    }
604
605
    /**
606
     * @param array $bid
607
     * @return void
608
     */
609
    public function orderBlock(
610
        array $bid,
611
        array $oldtitle,
612
        array $oldside,
613
        array $oldweight,
614
        array $oldvisible,
615
        array $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

615
        /** @scrutinizer ignore-unused */ array $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...
616
        array $oldbcachetime,
617
        array $oldbmodule,
618
        array $title,
619
        array $weight,
620
        array $visible,
621
        array $side,
622
        array $bcachetime,
623
        array $groups,
624
        array $bmodule
625
    ): void {
626
        if (!$GLOBALS['xoopsSecurity']->check()) {
627
            \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
628
        }
629
        foreach (\array_keys($bid) as $i) {
630
            if ($oldtitle[$i] !== $title[$i]
631
                || $oldweight[$i] !== $weight[$i]
632
                || $oldvisible[$i] !== $visible[$i]
633
                || $oldside[$i] !== $side[$i]
634
                || $oldbcachetime[$i] !== $bcachetime[$i]
635
                || $oldbmodule[$i] !== $bmodule[$i]) {
636
                $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
637
            }
638
            if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
639
                $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
640
                $this->db->query($sql);
641
                if (\in_array(0, $bmodule[$i], true)) {
642
                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0);
643
                    $this->db->query($sql);
644
                }
645
                else {
646
                    foreach ($bmodule[$i] as $bmid) {
647
                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
648
                        $this->db->query($sql);
649
                    }
650
                }
651
            }
652
            $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]);
653
            $this->db->query($sql);
654
            if (!empty($groups[$i])) {
655
                foreach ($groups[$i] as $grp) {
656
                    $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]);
657
                    $this->db->query($sql);
658
                }
659
            }
660
        }
661
662
        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
663
    }
664
665
    /**
666
     * @param array|null $block
667
     * @return void
668
     */
669
    public function render(?array $block = null)
670
    {
671
        \xoops_load('XoopsFormLoader');
672
        \xoops_loadLanguage('common', $this->moduleDirNameUpper);
673
674
        $form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
675
        if (isset($block['name'])) {
676
            $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name']));
677
        }
678
        $sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']);
679
        $sideSelect->addOptionArray([
680
                                        0 => \_AM_SYSTEM_BLOCKS_SBLEFT,
681
                                        1 => \_AM_SYSTEM_BLOCKS_SBRIGHT,
682
                                        3 => \_AM_SYSTEM_BLOCKS_CBLEFT,
683
                                        4 => \_AM_SYSTEM_BLOCKS_CBRIGHT,
684
                                        5 => \_AM_SYSTEM_BLOCKS_CBCENTER,
685
                                        7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT,
686
                                        8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT,
687
                                        9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
688
                                    ]);
689
        $form->addElement($sideSelect);
690
        $form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
691
        $form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
692
        $modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
693
        /** @var \XoopsModuleHandler $moduleHandler */
694
        $moduleHandler = \xoops_getHandler('module');
695
        $criteria      = new \CriteriaCompo(new \Criteria('hasmain', '1'));
696
        $criteria->add(new \Criteria('isactive', '1'));
697
        $moduleList     = $moduleHandler->getList($criteria);
698
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
699
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
700
        \ksort($moduleList);
701
        $modSelect->addOptionArray($moduleList);
702
        $form->addElement($modSelect);
703
        $form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
704
        if ($block['is_custom']) {
705
            $textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
706
            $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>');
707
            $form->addElement($textarea, true);
708
            $ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
709
            $ctypeSelect->addOptionArray([
710
                                             'H' => \_AM_SYSTEM_BLOCKS_HTML,
711
                                             'P' => \_AM_SYSTEM_BLOCKS_PHP,
712
                                             'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE,
713
                                             'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE,
714
                                         ]);
715
            $form->addElement($ctypeSelect);
716
        }
717
        else {
718
            if ('' !== $block['template']) {
719
                /** @var \XoopsTplfileHandler $tplfileHandler */
720
                $tplfileHandler = \xoops_getHandler('tplfile');
721
                $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']);
722
                if (\count($btemplate) > 0) {
723
                    $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>'));
724
                }
725
                else {
726
                    $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
727
                    if (\count($btemplate2) > 0) {
728
                        $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>'));
729
                    }
730
                }
731
            }
732
            if (false !== $block['edit_form']) {
733
                $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
734
            }
735
        }
736
        $cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
737
        $cache_select->addOptionArray([
738
                                          0       => _NOCACHE,
739
                                          30      => \sprintf(_SECONDS, 30),
740
                                          60      => _MINUTE,
741
                                          300     => \sprintf(_MINUTES, 5),
742
                                          1800    => \sprintf(_MINUTES, 30),
743
                                          3600    => _HOUR,
744
                                          18000   => \sprintf(_HOURS, 5),
745
                                          86400   => _DAY,
746
                                          259200  => \sprintf(_DAYS, 3),
747
                                          604800  => _WEEK,
748
                                          2592000 => _MONTH,
749
                                      ]);
750
        $form->addElement($cache_select);
751
752
        /** @var \XoopsGroupPermHandler $grouppermHandler */
753
        $grouppermHandler = \xoops_getHandler('groupperm');
754
        $groups           = $grouppermHandler->getGroupIds('block_read', $block['bid']);
755
756
        $form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true));
757
758
        if (isset($block['bid'])) {
759
            $form->addElement(new \XoopsFormHidden('bid', $block['bid']));
760
        }
761
        $form->addElement(new \XoopsFormHidden('op', $block['op']));
762
        $form->addElement(new \XoopsFormHidden('fct', 'blocksadmin'));
763
        $buttonTray = new \XoopsFormElementTray('', '&nbsp;');
764
        if ($block['is_custom']) {
765
            $buttonTray->addElement(new \XoopsFormButton('', 'previewblock', _PREVIEW, 'submit'));
766
        }
767
768
        //Submit buttons
769
        $buttonTray   = new \XoopsFormElementTray('', '');
770
        $submitButton = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit');
771
        $buttonTray->addElement($submitButton);
772
773
        $cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button');
774
        $cancelButton->setExtra('onclick="history.go(-1)"');
775
        $buttonTray->addElement($cancelButton);
776
777
        $form->addElement($buttonTray);
778
        $form->display();
779
    }
780
}
781