Passed
Push — master ( be4646...73e318 )
by Michael
03:39
created

isBlockCloned()   B

Complexity

Conditions 11
Paths 53

Size

Total Lines 61
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

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

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

420
        $myblock->/** @scrutinizer ignore-call */ 
421
                  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...
421
    }
422
423
    /**
424
     * @param $bid
425
     */
426
    function xtubeEditBlock($bid)
427
    {
428
        require_once __DIR__ . '/admin_header.php';
429
        //require_once __DIR__ . '/admin_header.php';
430
        xoops_cp_header();
431
432
        xoops_loadLanguage('admin', 'system');
433
        xoops_loadLanguage('admin/blocksadmin', 'system');
434
        xoops_loadLanguage('admin/groups', 'system');
435
        //        mpu_adm_menu();
436
        $myblock = new \XoopsBlock($bid);
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))) {
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 $bid
473
     * @param $btitle
474
     * @param $bside
475
     * @param $bweight
476
     * @param $bvisible
477
     * @param $bcachetime
478
     * @param $bmodule
479
     * @param $options
480
     * @param $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['PHP_SELF'], 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['PHP_SELF'], 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['PHP_SELF'], 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