Passed
Pull Request — master (#19)
by Michael
02:30
created

listBlocks()   F

Complexity

Conditions 22
Paths 3457

Size

Total Lines 222
Code Lines 174

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 174
nc 3457
nop 0
dl 0
loc 222
rs 0
c 0
b 0
f 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
 * Module: XoopsTube
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Xoopstube
13
 * @author          Fernando Santos (topet05), [email protected]
14
 * @copyright       Mastop InfoDigital (c) 2003-2007
15
 * @link            http://www.mastop.com.br
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @since           1.0.6
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Xoopstube;
22
23
require __DIR__ . '/admin_header.php';
24
25
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
26
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
27
    exit(_AM_XOOPSTUBE_ERROR403);
28
}
29
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
30
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
31
    $op = 'list';
32
    if (isset($_POST)) {
33
        foreach ($_POST as $k => $v) {
34
            ${$k} = $v;
35
        }
36
    }
37
    /*
38
        if (Request::hasVar('op')) {
39
            if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
40
                || $_GET['op'] === "edit"
41
            ) {
42
                $op  = $_GET['op'];
43
                $bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
44
            }
45
        }
46
    */
47
48
    $op = Request::getString('op', $op);
49
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
50
        $bid = Request::getInt('bid', 0, 'GET');
51
    }
52
53
    function listBlocks()
54
    {
55
        global $xoopsModule, $pathIcon16;
56
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
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;'>" . _AM_XOOPSTUBE_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
             . _AM_XOOPSTUBE_TITLE
84
             . "</th><th align='center' nowrap='nowrap'>"
85
             . _AM_XOOPSTUBE_SIDE
86
             . '<br>'
87
             . _LEFT
88
             . '-'
89
             . _CENTER
90
             . '-'
91
             . _RIGHT
92
             . "</th><th align='center'>"
93
             . _AM_XOOPSTUBE_WEIGHT
94
             . "</th><th align='center'>"
95
             . _AM_XOOPSTUBE_VISIBLE
96
             . "</th><th align='center'>"
97
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
98
             . "</th><th align='center'>"
99
             . _AM_SYSTEM_ADGS
100
             . "</th><th align='center'>"
101
             . _AM_SYSTEM_BLOCKS_BCACHETIME
102
             . "</th><th align='center'>"
103
             . _AM_XOOPSTUBE_ACTION
104
             . '</th></tr>
105
        ';
106
        $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

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

415
        $myblock->/** @scrutinizer ignore-call */ 
416
                  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...
416
    }
417
418
    /**
419
     * @param int $bid
420
     */
421
    function xtubeEditBlock($bid)
422
    {
423
        require_once __DIR__ . '/admin_header.php';
424
        //require_once __DIR__ . '/admin_header.php';
425
        xoops_cp_header();
426
427
        xoops_loadLanguage('admin', 'system');
428
        xoops_loadLanguage('admin/blocksadmin', 'system');
429
        xoops_loadLanguage('admin/groups', 'system');
430
        //        mpu_adm_menu();
431
        $myblock = new \XoopsBlock($bid);
432
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
433
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
434
        $result  = $db->query($sql);
435
        $modules = [];
436
        while (false !== ($row = $db->fetchArray($result))) {
437
            $modules[] = (int)$row['module_id'];
438
        }
439
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
440
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
441
            'title'      => $myblock->getVar('title'),
442
            'form_title' => _AM_XOOPSTUBE_BLOCKS_EDITBLOCK,
443
            //        'name'       => $myblock->getVar('name'),
444
            'side'       => $myblock->getVar('side'),
445
            'weight'     => $myblock->getVar('weight'),
446
            'visible'    => $myblock->getVar('visible'),
447
            'content'    => $myblock->getVar('content', 'N'),
448
            'modules'    => $modules,
449
            'is_custom'  => $is_custom,
450
            'ctype'      => $myblock->getVar('c_type'),
451
            'bcachetime' => $myblock->getVar('bcachetime'),
452
            'op'         => 'edit_ok',
453
            'bid'        => $myblock->getVar('bid'),
454
            'edit_form'  => $myblock->getOptions(),
455
            'template'   => $myblock->getVar('template'),
456
            'options'    => $myblock->getVar('options'),
457
        ];
458
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
459
        require_once __DIR__ . '/blockform.php';
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 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

477
    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...
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
        $myblock->store();
486
487
        if (!empty($bmodule) && count($bmodule) > 0) {
488
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
489
            $GLOBALS['xoopsDB']->query($sql);
490
            if (in_array(0, $bmodule)) {
491
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
492
                $GLOBALS['xoopsDB']->query($sql);
493
            } else {
494
                foreach ($bmodule as $bmid) {
495
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
496
                    $GLOBALS['xoopsDB']->query($sql);
497
                }
498
            }
499
        }
500
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
501
        $GLOBALS['xoopsDB']->query($sql);
502
        if (!empty($groups)) {
503
            foreach ($groups as $grp) {
504
                $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);
505
                $GLOBALS['xoopsDB']->query($sql);
506
            }
507
        }
508
        redirect_header($_SERVER['SCRIPT_NAME'], 1, _AM_XOOPSTUBE_UPDATE_SUCCESS);
509
    }
510
511
    if ('list' === $op) {
512
        xoops_cp_header();
513
        //        mpu_adm_menu();
514
        listBlocks();
515
        require_once __DIR__ . '/admin_footer.php';
516
        exit();
517
    }
518
519
    if ('order' === $op) {
520
        if (!$GLOBALS['xoopsSecurity']->check()) {
521
            redirect_header($_SERVER['SCRIPT_NAME'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
522
        }
523
        foreach (array_keys($bid) as $i) {
524
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
525
                || $oldside[$i] !== $side[$i]
526
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
527
                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

527
                /** @scrutinizer ignore-call */ 
528
                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...
528
            }
529
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
530
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]);
531
                $GLOBALS['xoopsDB']->query($sql);
532
                if (in_array(0, $bmodule[$i])) {
533
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0);
534
                    $GLOBALS['xoopsDB']->query($sql);
535
                } else {
536
                    foreach ($bmodule[$i] as $bmid) {
537
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid);
538
                        $GLOBALS['xoopsDB']->query($sql);
539
                    }
540
                }
541
            }
542
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]);
543
            $GLOBALS['xoopsDB']->query($sql);
544
            if (!empty($groups[$i])) {
545
                foreach ($groups[$i] as $grp) {
546
                    $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]);
547
                    $GLOBALS['xoopsDB']->query($sql);
548
                }
549
            }
550
        }
551
        redirect_header($_SERVER['SCRIPT_NAME'], 1, _AM_XOOPSTUBE_UPDATE_SUCCESS);
552
    }
553
    if ('clone' === $op) {
554
        cloneBlock($bid);
555
    }
556
557
    if ('edit' === $op) {
558
        xtubeEditBlock($bid);
559
    }
560
561
    if ('edit_ok' === $op) {
562
        xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
563
    }
564
565
    if ('clone_ok' === $op) {
566
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
567
    }
568
} else {
569
    echo _AM_XOOPSTUBE_ERROR403;
570
}
571