Passed
Branch master (294c87)
by Michael
02:12
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 1
Metric Value
cc 11
eloc 47
nc 53
nop 7
dl 0
loc 61
rs 7.3166
c 1
b 0
f 1

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://www.xoops.org
13
 * @license         GNU GPL 2 or later (http://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($xoopsModule) || !is_object($GLOBALS['xoopsUser'])
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'], true)) {
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
        /** @var \XoopsDatabase $db */
58
        $db                 = \XoopsDatabaseFactory::getDatabaseConnection();
59
        xoops_loadLanguage('admin', 'system');
60
        xoops_loadLanguage('admin/blocksadmin', 'system');
61
        xoops_loadLanguage('admin/groups', 'system');
62
63
        /** @var \XoopsModuleHandler $moduleHandler */
64
        $moduleHandler = xoops_getHandler('module');
65
        /** @var \XoopsMemberHandler $memberHandler */
66
        $memberHandler = xoops_getHandler('member');
67
        /** @var \XoopsGroupPermHandler $grouppermHandler */
68
        $grouppermHandler = xoops_getHandler('groupperm');
69
        $groups           = $memberHandler->getGroups();
70
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1));
71
        $criteria->add(new \Criteria('isactive', 1));
72
        $module_list     = $moduleHandler->getList($criteria);
73
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
74
        $module_list[0]  = _AM_SYSTEM_BLOCKS_ALLPAGES;
75
        ksort($module_list);
76
        echo "
77
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
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='" . \Xmf\Request::getString('PHP_SELF', '', 'SERVER') . "' 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('CO_'
94
                        . $moduleDirNameUpper
95
                        . '_'
96
                        . '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, true) ? " 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, true) ? " 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
290
        xoops_cp_header();
291
292
        /** @var \Xmf\Module\Admin $adminObject */
293
        $adminObject = \Xmf\Module\Admin::getInstance();
294
        $adminObject->displayNavigation(basename(__FILE__));
295
        $moduleDirName      = basename(dirname(__DIR__));
296
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
297
298
        xoops_loadLanguage('admin', 'system');
299
        xoops_loadLanguage('admin/blocksadmin', 'system');
300
        xoops_loadLanguage('admin/groups', 'system');
301
302
        //        mpu_adm_menu();
303
        $myblock = new \XoopsBlock($bid);
304
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
305
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
306
        $result  = $db->query($sql);
307
        $modules = [];
308
        while (false !== ($row = $db->fetchArray($result))) {
309
            $modules[] = (int)$row['module_id'];
310
        }
311
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
312
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
313
            'title'      => $myblock->getVar('title') . ' Clone',
314
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
315
            'name'       => $myblock->getVar('name'),
316
            'side'       => $myblock->getVar('side'),
317
            'weight'     => $myblock->getVar('weight'),
318
            'visible'    => $myblock->getVar('visible'),
319
            'content'    => $myblock->getVar('content', 'N'),
320
            'modules'    => $modules,
321
            'is_custom'  => $is_custom,
322
            'ctype'      => $myblock->getVar('c_type'),
323
            'bcachetime' => $myblock->getVar('bcachetime'),
324
            'op'         => 'clone_ok',
325
            'bid'        => $myblock->getVar('bid'),
326
            'edit_form'  => $myblock->getOptions(),
327
            'template'   => $myblock->getVar('template'),
328
            'options'    => $myblock->getVar('options'),
329
        ];
330
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
331
        require_once __DIR__ . '/blockform.php';
332
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
333
        //        xoops_cp_footer();
334
        require_once __DIR__ . '/admin_footer.php';
335
        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...
336
    }
337
338
    /**
339
     * @param int               $bid
340
     * @param string            $bside
341
     * @param int               $bweight
342
     * @param bool              $bvisible
343
     * @param int               $bcachetime
344
     * @param array             $bmodule
345
     * @param null|array|string $options
346
     */
347
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options = null)
348
    {
349
        xoops_loadLanguage('admin', 'system');
350
        xoops_loadLanguage('admin/blocksadmin', 'system');
351
        xoops_loadLanguage('admin/groups', 'system');
352
353
        /** @var \XoopsBlock $block */
354
        $block = new \XoopsBlock($bid);
355
        $clone = $block->xoopsClone();
356
        if (empty($bmodule)) {
357
            xoops_cp_header();
358
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
0 ignored issues
show
Bug introduced by
The constant _AM_NOTSELNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _AM_VISIBLEIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
359
            xoops_cp_footer();
360
            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...
361
        }
362
        $clone->setVar('side', $bside);
363
        $clone->setVar('weight', $bweight);
364
        $clone->setVar('visible', $bvisible);
365
        //$clone->setVar('content', $_POST['bcontent']);
366
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
367
        $clone->setVar('bcachetime', $bcachetime);
368
        if ($options && is_array($options)) {
369
            $options = implode('|', $options);
370
            $clone->setVar('options', $options);
371
        }
372
        $clone->setVar('bid', 0);
373
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
374
            $clone->setVar('block_type', 'E');
375
        } else {
376
            $clone->setVar('block_type', 'D');
377
        }
378
        $newid = $clone->store();
379
        if (!$newid) {
380
            xoops_cp_header();
381
            $clone->getHtmlErrors();
382
            xoops_cp_footer();
383
            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...
384
        }
385
        if ('' !== $clone->getVar('template')) {
386
            /** @var \XoopsTplfileHandler $tplfileHandler */
387
            $tplfileHandler = xoops_getHandler('tplfile');
388
            $btemplate      = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
389
            if (count($btemplate) > 0) {
390
                $tplclone = $btemplate[0]->xoopsClone();
391
                $tplclone->setVar('tpl_id', 0);
392
                $tplclone->setVar('tpl_refid', $newid);
393
                $tplfileHandler->insert($tplclone);
394
            }
395
        }
396
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
397
        foreach ($bmodule as $bmid) {
398
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
399
            $db->query($sql);
400
        }
401
        $groups = &$GLOBALS['xoopsUser']->getGroups();
402
        $count  = count($groups);
403
        for ($i = 0; $i < $count; ++$i) {
404
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
405
            $db->query($sql);
406
        }
407
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
408
    }
409
410
    /**
411
     * @param $bid
412
     * @param $title
413
     * @param $weight
414
     * @param $visible
415
     * @param $side
416
     * @param $bcachetime
417
     */
418
    function xtubeSetOrder($bid, $title, $weight, $visible, $side, $bcachetime)
419
    {
420
        $myblock = new \XoopsBlock($bid);
421
        $myblock->setVar('title', $title);
422
        $myblock->setVar('weight', $weight);
423
        $myblock->setVar('visible', $visible);
424
        $myblock->setVar('side', $side);
425
        $myblock->setVar('bcachetime', $bcachetime);
426
        $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

426
        $myblock->/** @scrutinizer ignore-call */ 
427
                  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...
427
    }
428
429
    /**
430
     * @param $bid
431
     */
432
    function xtubeEditBlock($bid)
433
    {
434
        require_once __DIR__ . '/admin_header.php';
435
        xoops_cp_header();
436
        /** @var \Xmf\Module\Admin $adminObject */
437
        $adminObject = \Xmf\Module\Admin::getInstance();
438
        $adminObject->displayNavigation(basename(__FILE__));
439
        $moduleDirName      = basename(dirname(__DIR__));
440
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
441
442
        xoops_loadLanguage('admin', 'system');
443
        xoops_loadLanguage('admin/blocksadmin', 'system');
444
        xoops_loadLanguage('admin/groups', 'system');
445
        //        mpu_adm_menu();
446
        $myblock = new \XoopsBlock($bid);
447
        $db      = \XoopsDatabaseFactory::getDatabaseConnection();
448
        $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
449
        $result  = $db->query($sql);
450
        $modules = [];
451
        while (false !== ($row = $db->fetchArray($result))) {
452
            $modules[] = (int)$row['module_id'];
453
        }
454
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
455
        $block     = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
456
            'title'      => $myblock->getVar('title'),
457
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
458
            //        'name'       => $myblock->getVar('name'),
459
            'side'       => $myblock->getVar('side'),
460
            'weight'     => $myblock->getVar('weight'),
461
            'visible'    => $myblock->getVar('visible'),
462
            'content'    => $myblock->getVar('content', 'N'),
463
            'modules'    => $modules,
464
            'is_custom'  => $is_custom,
465
            'ctype'      => $myblock->getVar('c_type'),
466
            'bcachetime' => $myblock->getVar('bcachetime'),
467
            'op'         => 'edit_ok',
468
            'bid'        => $myblock->getVar('bid'),
469
            'edit_form'  => $myblock->getOptions(),
470
            'template'   => $myblock->getVar('template'),
471
            'options'    => $myblock->getVar('options'),
472
        ];
473
        echo '<a href="blocksadmin.php">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
474
        require_once __DIR__ . '/blockform.php';
475
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
476
        //        xoops_cp_footer();
477
        require_once __DIR__ . '/admin_footer.php';
478
        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...
479
    }
480
481
    /**
482
     * @param $bid
483
     * @param $btitle
484
     * @param $bside
485
     * @param $bweight
486
     * @param $bvisible
487
     * @param $bcachetime
488
     * @param $bmodule
489
     * @param $options
490
     * @param $groups
491
     */
492
    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

492
    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...
493
    {
494
        $myblock = new \XoopsBlock($bid);
495
        $myblock->setVar('title', $btitle);
496
        $myblock->setVar('weight', $bweight);
497
        $myblock->setVar('visible', $bvisible);
498
        $myblock->setVar('side', $bside);
499
        $myblock->setVar('bcachetime', $bcachetime);
500
        $myblock->store();
501
502
        if (!empty($bmodule) && count($bmodule) > 0) {
503
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
504
            $GLOBALS['xoopsDB']->query($sql);
505
            if (in_array(0, $bmodule, true)) {
506
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, 0);
507
                $GLOBALS['xoopsDB']->query($sql);
508
            } else {
509
                foreach ($bmodule as $bmid) {
510
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid, (int)$bmid);
511
                    $GLOBALS['xoopsDB']->query($sql);
512
                }
513
            }
514
        }
515
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid);
516
        $GLOBALS['xoopsDB']->query($sql);
517
        if (!empty($groups)) {
518
            foreach ($groups as $grp) {
519
                $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);
520
                $GLOBALS['xoopsDB']->query($sql);
521
            }
522
        }
523
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
524
    }
525
526
    if ('list' === $op) {
527
        xoops_cp_header();
528
        $adminObject->displayNavigation(basename(__FILE__));
529
        listBlocks();
530
        require_once __DIR__ . '/admin_footer.php';
531
        exit();
532
    }
533
534
    if ('order' === $op) {
535
        if (!$GLOBALS['xoopsSecurity']->check()) {
536
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
537
        }
538
        foreach (array_keys($bid) as $i) {
539
            if ($oldtitle[$i] !== $title[$i] || $oldweight[$i] !== $weight[$i] || $oldvisible[$i] !== $visible[$i]
540
                || $oldside[$i] !== $side[$i]
541
                || $oldbcachetime[$i] !== $bcachetime[$i]) {
542
                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

542
                /** @scrutinizer ignore-call */ 
543
                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...
543
            }
544
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
545
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i]);
546
                $GLOBALS['xoopsDB']->query($sql);
547
                if (in_array(0, $bmodule[$i], true)) {
548
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], 0);
549
                    $GLOBALS['xoopsDB']->query($sql);
550
                } else {
551
                    foreach ($bmodule[$i] as $bmid) {
552
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid[$i], (int)$bmid);
553
                        $GLOBALS['xoopsDB']->query($sql);
554
                    }
555
                }
556
            }
557
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $GLOBALS['xoopsDB']->prefix('group_permission'), $bid[$i]);
558
            $GLOBALS['xoopsDB']->query($sql);
559
            if (!empty($groups[$i])) {
560
                foreach ($groups[$i] as $grp) {
561
                    $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]);
562
                    $GLOBALS['xoopsDB']->query($sql);
563
                }
564
            }
565
        }
566
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
567
    }
568
    if ('clone' === $op) {
569
        cloneBlock($bid);
570
    }
571
572
    if ('edit' === $op) {
573
        xtubeEditBlock($bid);
574
    }
575
576
    if ('edit_ok' === $op) {
577
        xtubeUpdateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
578
    }
579
580
    if ('clone_ok' === $op) {
581
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
582
    }
583
} else {
584
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
585
}
586