Passed
Push — master ( da394c...44937f )
by Michael
05:20
created

updateBlock()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 50
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 37
nc 18
nop 9
dl 0
loc 50
rs 7.3166
c 1
b 0
f 0

How to fix   Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * PHP version 5
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project
12
 * @link            https://xoops.org
13
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
14
 */
15
16
use Xmf\Module\Admin;
17
use Xmf\Request;
18
use XoopsModules\Marquee\{Helper
19
};
20
21
/** @var Admin $adminObject */
22
/** @var Helper $helper */
23
require __DIR__ . '/admin_header.php';
24
$moduleDirName      = basename(dirname(__DIR__));
25
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
26
$helper->loadLanguage('blocksadmin');
27
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
28
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
29
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
30
}
31
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
32
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
33
    $op = 'list';
34
    if (isset($_POST)) {
35
        foreach ($_POST as $k => $v) {
36
            ${$k} = $v;
37
        }
38
    }
39
    /*
40
    if (Request::hasVar('op', 'GET')) {
41
        if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op']
42
            || 'edit' === $_GET['op']) {
43
            $op  = $_GET['op'];
44
            $bid = \Xmf\Request::getInt('bid', 0, 'GET');
45
        }
46
    */
47
    $op = Request::getString('op', $op);
48
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
49
        $bid = Request::getInt('bid', 0, 'GET');
50
    }
51
    function listBlocks()
52
    {
53
        global $xoopsModule, $pathIcon16;
54
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
55
        $moduleDirName      = basename(dirname(__DIR__));
56
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
57
        $db                 = \XoopsDatabaseFactory::getDatabaseConnection();
58
        $adminObject = Admin::getInstance();
59
        $adminObject->displayNavigation(basename(__FILE__));
60
        xoops_loadLanguage('admin', 'system');
61
        xoops_loadLanguage('admin/blocksadmin', 'system');
62
        xoops_loadLanguage('admin/groups', 'system');
63
        /** @var \XoopsModuleHandler $moduleHandler */
64
        $moduleHandler = xoops_getHandler('module');
65
        /** @var \XoopsMemberHandler $memberHandler */
66
        $memberHandler = xoops_getHandler('member');
67
        /** @var \XoopsGroupPermHandler $grouppermHandler */
68
        $grouppermHandler = xoops_getHandler('groupperm');
69
        $groups           = $memberHandler->getGroups();
70
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
71
        $criteria->add(new \Criteria('isactive', 1));
72
        $moduleList     = $moduleHandler->getList($criteria);
73
        $moduleList[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
74
        $moduleList[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
75
        ksort($moduleList);
76
        echo "
77
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
78
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
79
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
80
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
81
        <tr valign='middle'><th align='center'>"
82
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
83
             . "</th><th align='center' nowrap='nowrap'>"
84
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
85
             . '<br>'
86
             . _LEFT
87
             . '-'
88
             . _CENTER
89
             . '-'
90
             . _RIGHT
91
             . "</th><th align='center'>"
92
             . constant(
93
                 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'
94
             )
95
             . "</th><th align='center'>"
96
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
97
             . "</th><th align='center'>"
98
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
99
             . "</th><th align='center'>"
100
             . _AM_SYSTEM_ADGS
101
             . "</th><th align='center'>"
102
             . _AM_SYSTEM_BLOCKS_BCACHETIME
103
             . "</th><th align='center'>"
104
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
105
             . '</th></tr>
106
        ';
107
        $blockArray = \XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
Bug introduced by
The method getByModule() does not exist on XoopsBlock. ( Ignorable by Annotation )

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

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

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

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

Loading history...
108
        $blockCount = count($blockArray);
0 ignored issues
show
Unused Code introduced by
The assignment to $blockCount is dead and can be removed.
Loading history...
109
        $class      = 'even';
110
        $cachetimes = [
111
            '0'       => _NOCACHE,
112
            '30'      => sprintf(_SECONDS, 30),
113
            '60'      => _MINUTE,
114
            '300'     => sprintf(_MINUTES, 5),
115
            '1800'    => sprintf(_MINUTES, 30),
116
            '3600'    => _HOUR,
117
            '18000'   => sprintf(_HOURS, 5),
118
            '86400'   => _DAY,
119
            '259200'  => sprintf(_DAYS, 3),
120
            '604800'  => _WEEK,
121
            '2592000' => _MONTH,
122
        ];
123
        foreach ($blockArray as $i) {
124
            $groupsPerms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
125
            $sql         = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
126
            $result      = $db->query($sql);
127
            $modules     = [];
128
            while (false !== ($row = $db->fetchArray($result))) {
129
                $modules[] = (int)$row['module_id'];
130
            }
131
            $cachetimeOptions = '';
132
            foreach ($cachetimes as $cachetime => $cachetimeName) {
133
                if ($i->getVar('bcachetime') == $cachetime) {
134
                    $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
135
                } else {
136
                    $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
137
                }
138
            }
139
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
140
            if (1 === $i->getVar('visible')) {
141
                $sel1 = ' checked';
142
            } else {
143
                $sel0 = ' checked';
144
            }
145
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
146
                $ssel0 = ' checked';
147
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
148
                $ssel1 = ' checked';
149
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
150
                $ssel2 = ' checked';
151
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
152
                $ssel4 = ' checked';
153
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
154
                $ssel3 = ' checked';
155
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
156
                $ssel5 = ' checked';
157
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
158
                $ssel6 = ' checked';
159
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
160
                $ssel7 = ' checked';
161
            }
162
            if ('' === $i->getVar('title')) {
163
                $title = '&nbsp;';
164
            } else {
165
                $title = $i->getVar('title');
166
            }
167
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
168
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
169
                 . $i->getVar('bid')
170
                 . "]' value='"
171
                 . $title
172
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
173
                    <div align='center' >
174
                    <input type='radio' name='side["
175
                 . $i->getVar('bid')
176
                 . "]' value='"
177
                 . XOOPS_CENTERBLOCK_LEFT
178
                 . "'$ssel2>
179
                        <input type='radio' name='side["
180
                 . $i->getVar('bid')
181
                 . "]' value='"
182
                 . XOOPS_CENTERBLOCK_CENTER
183
                 . "'$ssel3>
184
                    <input type='radio' name='side["
185
                 . $i->getVar('bid')
186
                 . "]' value='"
187
                 . XOOPS_CENTERBLOCK_RIGHT
188
                 . "'$ssel4>
189
                    </div>
190
                    <div>
191
                        <span style='float:right;'><input type='radio' name='side["
192
                 . $i->getVar('bid')
193
                 . "]' value='"
194
                 . XOOPS_SIDEBLOCK_RIGHT
195
                 . "'$ssel1></span>
196
                    <div align='left'><input type='radio' name='side["
197
                 . $i->getVar('bid')
198
                 . "]' value='"
199
                 . XOOPS_SIDEBLOCK_LEFT
200
                 . "'$ssel0></div>
201
                    </div>
202
                    <div align='center'>
203
                    <input type='radio' name='side["
204
                 . $i->getVar('bid')
205
                 . "]' value='"
206
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
207
                 . "'$ssel5>
208
                        <input type='radio' name='side["
209
                 . $i->getVar('bid')
210
                 . "]' value='"
211
                 . XOOPS_CENTERBLOCK_BOTTOM
212
                 . "'$ssel7>
213
                    <input type='radio' name='side["
214
                 . $i->getVar('bid')
215
                 . "]' value='"
216
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
217
                 . "'$ssel6>
218
                    </div>
219
                </td><td class='$class' align='center'><input type='text' name='weight["
220
                 . $i->getVar('bid')
221
                 . "]' value='"
222
                 . $i->getVar('weight')
223
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
224
                 . $i->getVar('bid')
225
                 . "]' value='1'$sel1>"
226
                 . _YES
227
                 . "&nbsp;<input type='radio' name='visible["
228
                 . $i->getVar('bid')
229
                 . "]' value='0'$sel0>"
230
                 . _NO
231
                 . '</td>';
232
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
233
            foreach ($moduleList as $k => $v) {
234
                echo "<option value='$k'" . (in_array($k, $modules) ? 'selected' : '') . ">$v</option>";
235
            }
236
            echo '</select></td>';
237
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
238
            foreach ($groups as $grp) {
239
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groupsPerms) ? 'selected' : '') . '>' . $grp->getVar('name') . '</option>';
240
            }
241
            echo '</select></td>';
242
            // Cache lifetime
243
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
244
                                    </td>';
245
            // Actions
246
            echo "<td class='$class' align='center'><a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>
247
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
248
                 </a>";
249
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
250
                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 . "'>
251
                     </a>";
252
            }
253
            echo "
254
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
255
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
256
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
257
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
258
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
259
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
260
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
261
            </td></tr>
262
            ";
263
            $class = ('even' === $class) ? 'odd' : 'even';
264
        }
265
        echo "<tr><td class='foot' align='center' colspan='8'>
266
        <input type='hidden' name='op' value='order'>
267
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
268
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
269
        </td></tr></table>
270
        </form>
271
        <br><br>";
272
    }
273
274
    /**
275
     * @param int $bid
276
     */
277
    function cloneBlock($bid)
278
    {
279
        require_once __DIR__ . '/admin_header.php';
280
        xoops_cp_header();
281
        $adminObject = Admin::getInstance();
282
        $adminObject->displayNavigation(basename(__FILE__));
283
        $moduleDirName      = basename(dirname(__DIR__));
284
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
285
        xoops_loadLanguage('admin', 'system');
286
        xoops_loadLanguage('admin/blocksadmin', 'system');
287
        xoops_loadLanguage('admin/groups', 'system');
288
        //        mpu_adm_menu();
289
        $myblock = new \XoopsBlock($bid);
290
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
291
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
292
        $result  = $db->query($sql);
293
        $modules = [];
294
        while (false !== ($row = $db->fetchArray($result))) {
295
            $modules[] = (int)$row['module_id'];
296
        }
297
        $isCustom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
298
        $block    = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
299
            'title'      => $myblock->getVar('title') . ' Clone',
300
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
301
            'name'       => $myblock->getVar('name'),
302
            'side'       => $myblock->getVar('side'),
303
            'weight'     => $myblock->getVar('weight'),
304
            'visible'    => $myblock->getVar('visible'),
305
            'content'    => $myblock->getVar('content', 'N'),
306
            'modules'    => $modules,
307
            'is_custom'  => $isCustom,
308
            'ctype'      => $myblock->getVar('c_type'),
309
            'bcachetime' => $myblock->getVar('bcachetime'),
310
            'op'         => 'clone_ok',
311
            'bid'        => $myblock->getVar('bid'),
312
            'edit_form'  => $myblock->getOptions(),
313
            'template'   => $myblock->getVar('template'),
314
            'options'    => $myblock->getVar('options'),
315
        ];
316
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
317
        require_once __DIR__ . '/blockform.php';
318
        /** @var XoopsThemeForm $form */
319
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
320
        //        xoops_cp_footer();
321
        require_once __DIR__ . '/admin_footer.php';
322
        exit();
0 ignored issues
show
Best Practice introduced by
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...
323
    }
324
325
    /**
326
     * @param int               $bid
327
     * @param string            $bside
328
     * @param int               $bweight
329
     * @param bool              $bvisible
330
     * @param int               $bcachetime
331
     * @param array             $bmodule
332
     * @param null|array|string $options
333
     */
334
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options = null)
335
    {
336
        xoops_loadLanguage('admin', 'system');
337
        xoops_loadLanguage('admin/blocksadmin', 'system');
338
        xoops_loadLanguage('admin/groups', 'system');
339
        $block = new \XoopsBlock($bid);
340
        $clone = $block->xoopsClone();
341
        if (empty($bmodule)) {
342
            xoops_cp_header();
343
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
344
            xoops_cp_footer();
345
            exit();
0 ignored issues
show
Best Practice introduced by
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...
346
        }
347
        $clone->setVar('side', $bside);
348
        $clone->setVar('weight', $bweight);
349
        $clone->setVar('visible', $bvisible);
350
        //$clone->setVar('content', $_POST['bcontent']);
351
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
352
        $clone->setVar('bcachetime', $bcachetime);
353
        if ($options && is_array($options)) {
354
            $options = implode('|', $options);
355
            $clone->setVar('options', $options);
356
        }
357
        $clone->setVar('bid', 0);
358
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
359
            $clone->setVar('block_type', 'E');
360
        } else {
361
            $clone->setVar('block_type', 'D');
362
        }
363
        $newid = $clone->store();
364
        if (!$newid) {
365
            xoops_cp_header();
366
            $clone->getHtmlErrors();
367
            xoops_cp_footer();
368
            exit();
0 ignored issues
show
Best Practice introduced by
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...
369
        }
370
        if ('' !== $clone->getVar('template')) {
371
            /** @var \XoopsTplfileHandler $tplfileHandler */
372
            $tplfileHandler = xoops_getHandler('tplfile');
373
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
374
            if (count($btemplate) > 0) {
375
                $tplclone = $btemplate[0]->xoopsClone();
376
                $tplclone->setVar('tpl_id', 0);
377
                $tplclone->setVar('tpl_refid', $newid);
378
                $tplfileHandler->insert($tplclone);
379
            }
380
        }
381
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
382
        foreach ($bmodule as $bmid) {
383
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
384
            $db->query($sql);
385
        }
386
        $groups = &$GLOBALS['xoopsUser']->getGroups();
387
        $count  = count($groups);
388
        for ($i = 0; $i < $count; ++$i) {
389
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
390
            $db->query($sql);
391
        }
392
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
393
    }
394
395
    /**
396
     * @param int    $bid
397
     * @param string $title
398
     * @param int    $weight
399
     * @param bool   $visible
400
     * @param string $side
401
     * @param int    $bcachetime
402
     * @param int    $bmodule
403
     */
404
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime, $bmodule)
0 ignored issues
show
Unused Code introduced by
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

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

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

Loading history...
405
    {
406
        $myblock = new \XoopsBlock($bid);
407
        $myblock->setVar('title', $title);
408
        $myblock->setVar('weight', $weight);
409
        $myblock->setVar('visible', $visible);
410
        $myblock->setVar('side', $side);
411
        $myblock->setVar('bcachetime', $bcachetime);
412
        $myblock->store();
0 ignored issues
show
Bug introduced by
The method store() does not exist on XoopsBlock. ( Ignorable by Annotation )

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

412
        $myblock->/** @scrutinizer ignore-call */ 
413
                  store();

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

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

Loading history...
413
    }
414
415
    /**
416
     * @param int $bid
417
     */
418
    function editBlock($bid)
419
    {
420
        require_once __DIR__ . '/admin_header.php';
421
        xoops_cp_header();
422
        $adminObject = Admin::getInstance();
423
        $adminObject->displayNavigation(basename(__FILE__));
424
        $moduleDirName      = basename(dirname(__DIR__));
425
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
426
        xoops_loadLanguage('admin', 'system');
427
        xoops_loadLanguage('admin/blocksadmin', 'system');
428
        xoops_loadLanguage('admin/groups', 'system');
429
        //        mpu_adm_menu();
430
        $myblock = new \XoopsBlock($bid);
431
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
432
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
433
        $result  = $db->query($sql);
434
        $modules = [];
435
        while (false !== ($row = $db->fetchArray($result))) {
436
            $modules[] = (int)$row['module_id'];
437
        }
438
        $isCustom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
439
        $block    = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
440
            'title'      => $myblock->getVar('title'),
441
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
442
            //        'name'       => $myblock->getVar('name'),
443
            'side'       => $myblock->getVar('side'),
444
            'weight'     => $myblock->getVar('weight'),
445
            'visible'    => $myblock->getVar('visible'),
446
            'content'    => $myblock->getVar('content', 'N'),
447
            'modules'    => $modules,
448
            'is_custom'  => $isCustom,
449
            'ctype'      => $myblock->getVar('c_type'),
450
            'bcachetime' => $myblock->getVar('bcachetime'),
451
            'op'         => 'edit_ok',
452
            'bid'        => $myblock->getVar('bid'),
453
            'edit_form'  => $myblock->getOptions(),
454
            'template'   => $myblock->getVar('template'),
455
            'options'    => $myblock->getVar('options'),
456
        ];
457
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
458
        require_once __DIR__ . '/blockform.php';
459
        /** @var XoopsThemeForm $form */
460
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
461
        //        xoops_cp_footer();
462
        require_once __DIR__ . '/admin_footer.php';
463
        exit();
0 ignored issues
show
Best Practice introduced by
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...
464
    }
465
466
    /**
467
     * @param int               $bid
468
     * @param string            $btitle
469
     * @param string            $bside
470
     * @param int               $bweight
471
     * @param bool              $bvisible
472
     * @param int               $bcachetime
473
     * @param array             $bmodule
474
     * @param null|array|string $options
475
     * @param null|array        $groups
476
     */
477
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
478
    {
479
        $myblock = new XoopsBlock($bid);
480
        $myblock->setVar('title', $btitle);
481
        $myblock->setVar('weight', $bweight);
482
        $myblock->setVar('visible', $bvisible);
483
        $myblock->setVar('side', $bside);
484
        $myblock->setVar('bcachetime', $bcachetime);
485
        $helper = Helper::getInstance();
486
        $helper->loadLanguage('common');
487
        //update block options
488
        if (isset($options)) {
489
            $optionsCount = count($options);
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

489
            $optionsCount = count(/** @scrutinizer ignore-type */ $options);
Loading history...
490
            if ($optionsCount > 0) {
491
                //Convert array values to comma-separated
492
                for ($i = 0; $i < $optionsCount; ++$i) {
493
                    if (is_array($options[$i])) {
494
                        $options[$i] = implode(',', $options[$i]);
495
                    }
496
                }
497
                $options = implode('|', $options);
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

497
                $options = implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
498
                $myblock->setVar('options', $options);
499
            }
500
        }
501
        $myblock->store();
502
        global $xoopsDB;
503
        $moduleDirName      = basename(dirname(__DIR__));
504
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
505
        if (!empty($bmodule) && count($bmodule) > 0) {
506
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
507
            $xoopsDB->query($sql);
508
            if (in_array(0, $bmodule)) {
509
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, 0);
510
                $xoopsDB->query($sql);
511
            } else {
512
                foreach ($bmodule as $bmid) {
513
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, (int)$bmid);
514
                    $xoopsDB->query($sql);
515
                }
516
            }
517
        }
518
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
519
        $xoopsDB->query($sql);
520
        if (!empty($groups)) {
521
            foreach ($groups as $grp) {
522
                $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid);
523
                $xoopsDB->query($sql);
524
            }
525
        }
526
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
527
    }
528
529
    if ('list' === $op) {
530
        xoops_cp_header();
531
        //        mpu_adm_menu();
532
        listBlocks();
533
        require_once __DIR__ . '/admin_footer.php';
534
        exit();
535
    }
536
    if ('order' === $op) {
537
        if (!$GLOBALS['xoopsSecurity']->check()) {
538
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
539
        }
540
        foreach (array_keys($bid) as $i) {
541
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i]
542
                || $oldside[$i] != $side[$i]
543
                || $oldbcachetime[$i] != $bcachetime[$i]) {
544
                setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
545
            }
546
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
547
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid[$i]);
548
                $xoopsDB->query($sql);
549
                if (in_array(0, $bmodule[$i])) {
550
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], 0);
551
                    $xoopsDB->query($sql);
552
                } else {
553
                    foreach ($bmodule[$i] as $bmid) {
554
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], (int)$bmid);
555
                        $xoopsDB->query($sql);
556
                    }
557
                }
558
            }
559
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid[$i]);
560
            $xoopsDB->query($sql);
561
            if (!empty($groups[$i])) {
562
                foreach ($groups[$i] as $grp) {
563
                    $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid[$i]);
564
                    $xoopsDB->query($sql);
565
                }
566
            }
567
        }
568
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
569
    }
570
    if ('clone' === $op) {
571
        cloneBlock($bid);
572
    }
573
    if ('edit' === $op) {
574
        editBlock($bid);
575
    }
576
    if ('edit_ok' === $op) {
577
        updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
578
    }
579
    if ('clone_ok' === $op) {
580
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
581
    }
582
} else {
583
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
584
}
585