Passed
Push — master ( 6d0bec...700d12 )
by Michael
05:09 queued 02:42
created

listBlocks()   F

Complexity

Conditions 22
Paths 3457

Size

Total Lines 226
Code Lines 177

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 177
c 1
b 1
f 1
dl 0
loc 226
rs 0
cc 22
nc 3457
nop 0

How to fix   Long Method    Complexity   

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:

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\Request;
17
18
require __DIR__ . '/admin_header.php';
19
20
$moduleDirName      = basename(dirname(__DIR__));
21
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
22
23
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
24
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
25
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
26
}
27
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
28
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
29
    $op = 'list';
30
    if (isset($_POST)) {
31
        foreach ($_POST as $k => $v) {
32
            ${$k} = $v;
33
        }
34
    }
35
    /*
36
        if (Request::hasVar('op')) {
37
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
38
                || $_GET['op'] === "edit"
39
            ) {
40
                $op  = $_GET['op'];
41
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
42
            }
43
        }
44
    */
45
46
    $op = Request::getString('op', $op);
47
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
48
        $bid = Request::getInt('bid', 0, 'GET');
49
    }
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
        xoops_loadLanguage('admin', 'system');
59
        xoops_loadLanguage('admin/blocksadmin', 'system');
60
        xoops_loadLanguage('admin/groups', 'system');
61
62
        /** @var \XoopsModuleHandler $moduleHandler */
63
        $moduleHandler = xoops_getHandler('module');
64
        /** @var \XoopsMemberHandler $memberHandler */
65
        $memberHandler = xoops_getHandler('member');
66
        /** @var \XoopsGroupPermHandler $grouppermHandler */
67
        $grouppermHandler = xoops_getHandler('groupperm');
68
        $groups           = $memberHandler->getGroups();
69
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
70
        $criteria->add(new \Criteria('isactive', 1));
71
        $module_list     = $moduleHandler->getList($criteria);
72
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
73
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
74
        ksort($module_list);
75
        echo "
76
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
77
        /** @var \XoopsModuleHandler $moduleHandler */
78
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleHandler is dead and can be removed.
Loading history...
79
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
80
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
81
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
82
        <tr valign='middle'><th align='center'>"
83
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
84
             . "</th><th align='center' nowrap='nowrap'>"
85
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
86
             . '<br>'
87
             . _LEFT
88
             . '-'
89
             . _CENTER
90
             . '-'
91
             . _RIGHT
92
             . "</th><th align='center'>"
93
             . constant(
94
                 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'
95
             )
96
             . "</th><th align='center'>"
97
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
98
             . "</th><th align='center'>"
99
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
100
             . "</th><th align='center'>"
101
             . _AM_SYSTEM_ADGS
102
             . "</th><th align='center'>"
103
             . _AM_SYSTEM_BLOCKS_BCACHETIME
104
             . "</th><th align='center'>"
105
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
106
             . '</th></tr>
107
        ';
108
        $block_arr   = \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

108
        /** @scrutinizer ignore-call */ 
109
        $block_arr   = \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...
109
        $block_count = count($block_arr);
0 ignored issues
show
Unused Code introduced by
The assignment to $block_count is dead and can be removed.
Loading history...
110
        $class       = 'even';
111
        $cachetimes  = [
112
            '0'       => _NOCACHE,
113
            '30'      => sprintf(_SECONDS, 30),
114
            '60'      => _MINUTE,
115
            '300'     => sprintf(_MINUTES, 5),
116
            '1800'    => sprintf(_MINUTES, 30),
117
            '3600'    => _HOUR,
118
            '18000'   => sprintf(_HOURS, 5),
119
            '86400'   => _DAY,
120
            '259200'  => sprintf(_DAYS, 3),
121
            '604800'  => _WEEK,
122
            '2592000' => _MONTH,
123
        ];
124
        foreach ($block_arr as $i) {
125
            $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
126
            $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
127
            $result       = $db->query($sql);
128
            $modules      = [];
129
            while (false !== ($row = $db->fetchArray($result))) {
130
                $modules[] = (int)$row['module_id'];
131
            }
132
133
            $cachetime_options = '';
134
            foreach ($cachetimes as $cachetime => $cachetime_name) {
135
                if ($i->getVar('bcachetime') == $cachetime) {
136
                    $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n";
137
                } else {
138
                    $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
139
                }
140
            }
141
142
            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';
143
            if (1 === $i->getVar('visible')) {
144
                $sel1 = ' checked';
145
            } else {
146
                $sel0 = ' checked';
147
            }
148
            if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
149
                $ssel0 = ' checked';
150
            } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
151
                $ssel1 = ' checked';
152
            } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
153
                $ssel2 = ' checked';
154
            } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
155
                $ssel4 = ' checked';
156
            } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
157
                $ssel3 = ' checked';
158
            } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
159
                $ssel5 = ' checked';
160
            } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
161
                $ssel6 = ' checked';
162
            } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
163
                $ssel7 = ' checked';
164
            }
165
            if ('' === $i->getVar('title')) {
166
                $title = '&nbsp;';
167
            } else {
168
                $title = $i->getVar('title');
169
            }
170
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
171
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["
172
                 . $i->getVar('bid')
173
                 . "]' value='"
174
                 . $title
175
                 . "'></td><td class='$class' align='center' nowrap='nowrap'>
176
                    <div align='center' >
177
                    <input type='radio' name='side["
178
                 . $i->getVar('bid')
179
                 . "]' value='"
180
                 . XOOPS_CENTERBLOCK_LEFT
181
                 . "'$ssel2>
182
                        <input type='radio' name='side["
183
                 . $i->getVar('bid')
184
                 . "]' value='"
185
                 . XOOPS_CENTERBLOCK_CENTER
186
                 . "'$ssel3>
187
                    <input type='radio' name='side["
188
                 . $i->getVar('bid')
189
                 . "]' value='"
190
                 . XOOPS_CENTERBLOCK_RIGHT
191
                 . "'$ssel4>
192
                    </div>
193
                    <div>
194
                        <span style='float:right;'><input type='radio' name='side["
195
                 . $i->getVar('bid')
196
                 . "]' value='"
197
                 . XOOPS_SIDEBLOCK_RIGHT
198
                 . "'$ssel1></span>
199
                    <div align='left'><input type='radio' name='side["
200
                 . $i->getVar('bid')
201
                 . "]' value='"
202
                 . XOOPS_SIDEBLOCK_LEFT
203
                 . "'$ssel0></div>
204
                    </div>
205
                    <div align='center'>
206
                    <input type='radio' name='side["
207
                 . $i->getVar('bid')
208
                 . "]' value='"
209
                 . XOOPS_CENTERBLOCK_BOTTOMLEFT
210
                 . "'$ssel5>
211
                        <input type='radio' name='side["
212
                 . $i->getVar('bid')
213
                 . "]' value='"
214
                 . XOOPS_CENTERBLOCK_BOTTOM
215
                 . "'$ssel7>
216
                    <input type='radio' name='side["
217
                 . $i->getVar('bid')
218
                 . "]' value='"
219
                 . XOOPS_CENTERBLOCK_BOTTOMRIGHT
220
                 . "'$ssel6>
221
                    </div>
222
                </td><td class='$class' align='center'><input type='text' name='weight["
223
                 . $i->getVar('bid')
224
                 . "]' value='"
225
                 . $i->getVar('weight')
226
                 . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["
227
                 . $i->getVar('bid')
228
                 . "]' value='1'$sel1>"
229
                 . _YES
230
                 . "&nbsp;<input type='radio' name='visible["
231
                 . $i->getVar('bid')
232
                 . "]' value='0'$sel0>"
233
                 . _NO
234
                 . '</td>';
235
236
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
237
            foreach ($module_list as $k => $v) {
238
                echo "<option value='$k'" . (in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
239
            }
240
            echo '</select></td>';
241
242
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
243
            foreach ($groups as $grp) {
244
                echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
245
            }
246
            echo '</select></td>';
247
248
            // Cache lifetime
249
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select>
250
                                    </td>';
251
252
            // Actions
253
254
            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 . "'>
255
                 </a> <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'>
256
                 </a>";
257
            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
258
                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 . "'>
259
                     </a>";
260
            }
261
            echo "
262
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
263
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
264
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
265
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
266
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
267
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
268
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
269
            </td></tr>
270
            ";
271
            $class = ('even' === $class) ? 'odd' : 'even';
272
        }
273
        echo "<tr><td class='foot' align='center' colspan='8'>
274
        <input type='hidden' name='op' value='order'>
275
        " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "
276
        <input type='submit' name='submit' value='" . _SUBMIT . "'>
277
        </td></tr></table>
278
        </form>
279
        <br><br>";
280
    }
281
282
    /**
283
     * @param int $bid
284
     */
285
    function cloneBlock($bid)
286
    {
287
        require_once __DIR__ . '/admin_header.php';
288
        //require_once __DIR__ . '/admin_header.php';
289
        xoops_cp_header();
290
291
        xoops_loadLanguage('admin', 'system');
292
        xoops_loadLanguage('admin/blocksadmin', 'system');
293
        xoops_loadLanguage('admin/groups', 'system');
294
295
        //        mpu_adm_menu();
296
        $myblock = new \XoopsBlock($bid);
297
        /** @var \XoopsMySQLDatabase $db */
298
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
299
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
300
        $result  = $db->query($sql);
301
        $modules = [];
302
        while (false !== ($row = $db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
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

302
        while (false !== ($row = $db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
303
            $modules[] = (int)$row['module_id'];
304
        }
305
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
306
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
307
            'title'      => $myblock->getVar('title') . ' Clone',
308
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper seems to be never defined.
Loading history...
309
            'name'       => $myblock->getVar('name'),
310
            'side'       => $myblock->getVar('side'),
311
            'weight'     => $myblock->getVar('weight'),
312
            'visible'    => $myblock->getVar('visible'),
313
            'content'    => $myblock->getVar('content', 'N'),
314
            'modules'    => $modules,
315
            'is_custom'  => $is_custom,
316
            'ctype'      => $myblock->getVar('c_type'),
317
            'bcachetime' => $myblock->getVar('bcachetime'),
318
            'op'         => 'clone_ok',
319
            'bid'        => $myblock->getVar('bid'),
320
            'edit_form'  => $myblock->getOptions(),
321
            'template'   => $myblock->getVar('template'),
322
            'options'    => $myblock->getVar('options'),
323
        ];
324
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
0 ignored issues
show
Bug introduced by
The constant _AM_BADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
325
        require_once __DIR__ . '/blockform.php';
326
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
327
        //        xoops_cp_footer();
328
        require_once __DIR__ . '/admin_footer.php';
329
        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...
330
    }
331
332
    /**
333
     * @param int $bid
334
     * @param     $bside
335
     * @param     $bweight
336
     * @param     $bvisible
337
     * @param     $bcachetime
338
     * @param     $bmodule
339
     * @param     $options
340
     */
341
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
342
    {
343
        xoops_loadLanguage('admin', 'system');
344
        xoops_loadLanguage('admin/blocksadmin', 'system');
345
        xoops_loadLanguage('admin/groups', 'system');
346
347
        /** @var \XoopsBlock $block */
348
        $block = new \XoopsBlock($bid);
349
        $clone = $block->xoopsClone();
350
        if (empty($bmodule)) {
351
            xoops_cp_header();
352
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
0 ignored issues
show
Bug introduced by
The constant _AM_VISIBLEIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _AM_NOTSELNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
353
            xoops_cp_footer();
354
            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...
355
        }
356
        $clone->setVar('side', $bside);
357
        $clone->setVar('weight', $bweight);
358
        $clone->setVar('visible', $bvisible);
359
        //$clone->setVar('content', $_POST['bcontent']);
360
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
361
        $clone->setVar('bcachetime', $bcachetime);
362
        if (isset($options) && (count($options) > 0)) {
363
            $options = implode('|', $options);
364
            $clone->setVar('options', $options);
365
        }
366
        $clone->setVar('bid', 0);
367
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
368
            $clone->setVar('block_type', 'E');
369
        } else {
370
            $clone->setVar('block_type', 'D');
371
        }
372
        $newid = $clone->store();
373
        if (!$newid) {
374
            xoops_cp_header();
375
            $clone->getHtmlErrors();
376
            xoops_cp_footer();
377
            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...
378
        }
379
        if ('' !== $clone->getVar('template')) {
380
            /** @var \XoopsTplfileHandler $tplfileHandler */
381
            $tplfileHandler = xoops_getHandler('tplfile');
382
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
383
            if (count($btemplate) > 0) {
384
                $tplclone = $btemplate[0]->xoopsClone();
385
                $tplclone->setVar('tpl_id', 0);
386
                $tplclone->setVar('tpl_refid', $newid);
387
                $tplfileHandler->insert($tplclone);
388
            }
389
        }
390
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
391
        foreach ($bmodule as $bmid) {
392
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
393
            $db->query($sql);
394
        }
395
        $groups = &$GLOBALS['xoopsUser']->getGroups();
396
        foreach ($groups as $iValue) {
397
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
398
            $db->query($sql);
399
        }
400
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
401
    }
402
403
    /**
404
     * @param int    $bid
405
     * @param string $title
406
     * @param int    $weight
407
     * @param bool   $visible
408
     * @param string $side
409
     * @param int    $bcachetime
410
     */
411
    function xtubeSetOrder($bid, $title, $weight, $visible, $side, $bcachetime)
412
    {
413
        $myblock = new \XoopsBlock($bid);
414
        $myblock->setVar('title', $title);
415
        $myblock->setVar('weight', $weight);
416
        $myblock->setVar('visible', $visible);
417
        $myblock->setVar('side', $side);
418
        $myblock->setVar('bcachetime', $bcachetime);
419
        $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

419
        $myblock->/** @scrutinizer ignore-call */ 
420
                  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...
420
    }
421
422
    /**
423
     * @param int $bid
424
     */
425
    function xtubeEditBlock($bid)
426
    {
427
        require_once __DIR__ . '/admin_header.php';
428
        //require_once __DIR__ . '/admin_header.php';
429
        xoops_cp_header();
430
431
        xoops_loadLanguage('admin', 'system');
432
        xoops_loadLanguage('admin/blocksadmin', 'system');
433
        xoops_loadLanguage('admin/groups', 'system');
434
        //        mpu_adm_menu();
435
        $myblock = new \XoopsBlock($bid);
436
        /** @var \XoopsMySQLDatabase $db */
437
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
438
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
439
        $result  = $db->query($sql);
440
        $modules = [];
441
        while (false !== ($row = $db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
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

441
        while (false !== ($row = $db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
442
            $modules[] = (int)$row['module_id'];
443
        }
444
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
445
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
446
            'title'      => $myblock->getVar('title'),
447
            'form_title' => _AM_SYSTEM_BLOCKS_EDITBLOCK,
448
            //        'name'       => $myblock->getVar('name'),
449
            'side'       => $myblock->getVar('side'),
450
            'weight'     => $myblock->getVar('weight'),
451
            'visible'    => $myblock->getVar('visible'),
452
            'content'    => $myblock->getVar('content', 'N'),
453
            'modules'    => $modules,
454
            'is_custom'  => $is_custom,
455
            'ctype'      => $myblock->getVar('c_type'),
456
            'bcachetime' => $myblock->getVar('bcachetime'),
457
            'op'         => 'edit_ok',
458
            'bid'        => $myblock->getVar('bid'),
459
            'edit_form'  => $myblock->getOptions(),
460
            'template'   => $myblock->getVar('template'),
461
            'options'    => $myblock->getVar('options'),
462
        ];
463
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
0 ignored issues
show
Bug introduced by
The constant _AM_BADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
464
        require_once __DIR__ . '/blockform.php';
465
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
466
        //        xoops_cp_footer();
467
        require_once __DIR__ . '/admin_footer.php';
468
        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...
469
    }
470
471
    /**
472
     * @param int               $bid
473
     * @param string            $btitle
474
     * @param string            $bside
475
     * @param int               $bweight
476
     * @param bool              $bvisible
477
     * @param int               $bcachetime
478
     * @param array             $bmodule
479
     * @param null|array|string $options
480
     * @param null|array        $groups
481
     */
482
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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
    function xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, /** @scrutinizer ignore-unused */ $options, $groups)

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
    {
484
        $myblock = new \XoopsBlock($bid);
485
        $myblock->setVar('title', $btitle);
486
        $myblock->setVar('weight', $bweight);
487
        $myblock->setVar('visible', $bvisible);
488
        $myblock->setVar('side', $bside);
489
        $myblock->setVar('bcachetime', $bcachetime);
490
        $myblock->store();
491
492
        if (!empty($bmodule) && count($bmodule) > 0) {
493
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
494
            $GLOBALS['xoopsDB']->query($sql);
495
            if (in_array(0, $bmodule)) {
496
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
497
                $GLOBALS['xoopsDB']->query($sql);
498
            } else {
499
                foreach ($bmodule as $bmid) {
500
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
501
                    $GLOBALS['xoopsDB']->query($sql);
502
                }
503
            }
504
        }
505
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
506
        $GLOBALS['xoopsDB']->query($sql);
507
        if (!empty($groups)) {
508
            foreach ($groups as $grp) {
509
                $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid);
510
                $GLOBALS['xoopsDB']->query($sql);
511
            }
512
        }
513
        redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
514
    }
515
516
    if ('list' === $op) {
517
        xoops_cp_header();
518
        //        mpu_adm_menu();
519
        listBlocks();
520
        require_once __DIR__ . '/admin_footer.php';
521
        exit();
522
    }
523
524
    if ('order' === $op) {
525
        if (!$GLOBALS['xoopsSecurity']->check()) {
526
            redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
527
        }
528
        foreach (array_keys($bid) as $i) {
529
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
530
                || $oldside[$i] !== $side[$i]
531
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
532
                xtubeSetOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
0 ignored issues
show
Unused Code introduced by
The call to xtubeSetOrder() has too many arguments starting with $bmodule[$i]. ( Ignorable by Annotation )

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

532
                /** @scrutinizer ignore-call */ 
533
                xtubeSetOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
533
            }
534
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
535
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]);
536
                $GLOBALS['xoopsDB']->query($sql);
537
                if (in_array(0, $bmodule[$i])) {
538
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0);
539
                    $GLOBALS['xoopsDB']->query($sql);
540
                } else {
541
                    foreach ($bmodule[$i] as $bmid) {
542
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid);
543
                        $GLOBALS['xoopsDB']->query($sql);
544
                    }
545
                }
546
            }
547
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]);
548
            $GLOBALS['xoopsDB']->query($sql);
549
            if (!empty($groups[$i])) {
550
                foreach ($groups[$i] as $grp) {
551
                    $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $GLOBALS['xoopsDB']->prefix('group_permission'), $grp, $bid[$i]);
552
                    $GLOBALS['xoopsDB']->query($sql);
553
                }
554
            }
555
        }
556
        redirect_header($_SERVER['SCRIPT_NAME'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
557
    }
558
    if ('clone' === $op) {
559
        cloneBlock($bid);
560
    }
561
562
    if ('edit' === $op) {
563
        xtubeEditBlock($bid);
564
    }
565
566
    if ('edit_ok' === $op) {
567
        xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
568
    }
569
570
    if ('clone_ok' === $op) {
571
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
572
    }
573
} else {
574
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
575
}
576