Issues (1844)

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

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

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

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

384
        echo /** @scrutinizer ignore-type */ $this->render($block);
Loading history...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Are you sure the usage of $this->render($block) targeting XoopsModules\Xhelp\Common\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...
385
        //        xoops_cp_footer();
386
        //        require_once __DIR__ . '/admin_footer.php';
387
        //        exit();
388
    }
389
390
    /**
391
     * @param int        $bid
392
     * @param string     $bside
393
     * @param string     $bweight
394
     * @param string     $bvisible
395
     * @param string     $bcachetime
396
     * @param array|null $bmodule
397
     * @param array|null $options
398
     * @param array|null $groups
399
     */
400
    public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void
401
    {
402
        \xoops_loadLanguage('admin', 'system');
403
        \xoops_loadLanguage('admin/blocksadmin', 'system');
404
        \xoops_loadLanguage('admin/groups', 'system');
405
406
        $block = new \XoopsBlock($bid);
407
        $clone = $block->xoopsClone();
408
        if (empty($bmodule)) {
409
            //            \xoops_cp_header();
410
            \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
411
            \xoops_cp_footer();
412
            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...
413
        }
414
        $clone->setVar('side', $bside);
415
        $clone->setVar('weight', $bweight);
416
        $clone->setVar('visible', $bvisible);
417
        //$clone->setVar('content', $_POST['bcontent']);
418
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
419
        $clone->setVar('bcachetime', $bcachetime);
420
        if (\is_array($options) && (\count($options) > 0)) {
421
            $options = \implode('|', $options);
422
            $clone->setVar('options', $options);
423
        }
424
        $clone->setVar('bid', 0);
425
        if (\in_array($block->getVar('block_type'), ['C', 'E'])) {
426
            $clone->setVar('block_type', 'E');
427
        } else {
428
            $clone->setVar('block_type', 'D');
429
        }
430
        //        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
431
        if ($clone->store()) {
432
            $newid = $clone->id();  //get the id of the cloned block
433
        }
434
        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...
435
            //            \xoops_cp_header();
436
            $clone->getHtmlErrors();
437
            \xoops_cp_footer();
438
            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...
439
        }
440
        if ('' !== $clone->getVar('template')) {
441
            /** @var \XoopsTplfileHandler $tplfileHandler */
442
            $tplfileHandler = \xoops_getHandler('tplfile');
443
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid);
444
            if (\count($btemplate) > 0) {
445
                $tplclone = $btemplate[0]->xoopsClone();
446
                $tplclone->setVar('tpl_id', 0);
447
                $tplclone->setVar('tpl_refid', $newid);
448
                $tplfileHandler->insert($tplclone);
449
            }
450
        }
451
452
        foreach ($bmodule as $bmid) {
453
            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
454
            $this->db->query($sql);
455
        }
456
        //$groups = &$GLOBALS['xoopsUser']->getGroups();
457
        foreach ($groups as $iValue) {
458
            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
459
            $this->db->query($sql);
460
        }
461
        $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
462
    }
463
464
    /**
465
     * @param string     $bid
466
     * @param string     $title
467
     * @param string     $weight
468
     * @param string     $visible
469
     * @param string     $side
470
     * @param string     $bcachetime
471
     * @param array|null $bmodule
472
     */
473
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): 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

473
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, /** @scrutinizer ignore-unused */ ?array $bmodule = null): 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...
474
    {
475
        $myblock = new \XoopsBlock($bid);
476
        $myblock->setVar('title', $title);
477
        $myblock->setVar('weight', $weight);
478
        $myblock->setVar('visible', $visible);
479
        $myblock->setVar('side', $side);
480
        $myblock->setVar('bcachetime', $bcachetime);
481
        $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

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

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

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

612
        array $bid, array $oldtitle, array $oldside, array $oldweight, array $oldvisible, /** @scrutinizer ignore-unused */ array $oldgroups, array $oldbcachetime, array $oldbmodule, array $title, array $weight, array $visible, array $side, array $bcachetime, array $groups, array $bmodule

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

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