Passed
Pull Request — master (#18)
by Michael
04:31
created

listBlocks()   F

Complexity

Conditions 22
Paths 3457

Size

Total Lines 223
Code Lines 176

Duplication

Lines 0
Ratio 0 %

Importance

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

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * PHP version 5
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project
12
 * @link            https://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
use XoopsModules\Xoopspoll\Helper;
18
19
require __DIR__ . '/admin_header.php';
20
21
$moduleDirName = basename(dirname(__DIR__));
22
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
23
24
/** @var Helper $helper */
25
$helper = Helper::getInstance();
26
27
$helper->loadLanguage('blocksadmin');
28
29
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
30
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
31
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
32
}
33
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
34
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
35
    $op = 'list';
36
    if (isset($_POST)) {
37
        foreach ($_POST as $k => $v) {
38
            ${$k} = $v;
39
        }
40
    }
41
    /*
42
    if (\Xmf\Request::hasVar('op', 'GET')) {
43
        if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op']
44
            || 'edit' === $_GET['op']) {
45
            $op  = $_GET['op'];
46
            $bid = \Xmf\Request::getInt('bid', 0, 'GET');
47
        }
48
    */
49
50
    $op = Request::getString('op', $op);
51
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
52
        $bid = Request::getInt('bid', 0, 'GET');
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 = mb_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['SCRIPT_NAME'] . "' 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>$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' : '') . ">$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' : '') . '>' . $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 int $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>';
325
        require_once __DIR__ . '/blockform.php';
326
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
327
        //        xoops_cp_footer();
328
        require_once __DIR__ . '/admin_footer.php';
329
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
330
    }
331
332
    /**
333
     * @param int               $bid
334
     * @param string            $bside
335
     * @param int               $bweight
336
     * @param bool              $bvisible
337
     * @param int               $bcachetime
338
     * @param array             $bmodule
339
     * @param null|array|string $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));
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)) {
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

362
        if (isset($options) && (count(/** @scrutinizer ignore-type */ $options) > 0)) {
Loading history...
363
            $options = implode('|', $options);
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type string; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

363
            $options = implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
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 int               $bid
406
     * @param string            $title
407
     * @param int               $weight
408
     * @param bool              $visible
409
     * @param string            $side
410
     * @param int               $bcachetime
411
     */
412
    function setOrder($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 int $bid
425
     */
426
    function editBlock($bid)
427
    {
428
        require_once __DIR__ . '/admin_header.php';
429
        //require_once __DIR__ . '/admin_header.php';
430
        xoops_cp_header();
431
        $moduleDirName = basename(dirname(__DIR__));
432
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
433
        xoops_loadLanguage('admin', 'system');
434
        xoops_loadLanguage('admin/blocksadmin', 'system');
435
        xoops_loadLanguage('admin/groups', 'system');
436
        //        mpu_adm_menu();
437
        $myblock = new \XoopsBlock($bid);
438
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
439
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
440
        $result = $db->query($sql);
441
        $modules = [];
442
        while (false !== ($row = $db->fetchArray($result))) {
443
            $modules[] = (int)$row['module_id'];
444
        }
445
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
446
        $block = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
447
            'title' => $myblock->getVar('title'),
448
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
449
            //        'name'       => $myblock->getVar('name'),
450
            'side' => $myblock->getVar('side'),
451
            'weight' => $myblock->getVar('weight'),
452
            'visible' => $myblock->getVar('visible'),
453
            'content' => $myblock->getVar('content', 'N'),
454
            'modules' => $modules,
455
            'is_custom' => $is_custom,
456
            'ctype' => $myblock->getVar('c_type'),
457
            'bcachetime' => $myblock->getVar('bcachetime'),
458
            'op' => 'edit_ok',
459
            'bid' => $myblock->getVar('bid'),
460
            'edit_form' => $myblock->getOptions(),
461
            'template' => $myblock->getVar('template'),
462
            'options' => $myblock->getVar('options'),
463
        ];
464
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
465
        require_once __DIR__ . '/blockform.php';
466
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
467
        //        xoops_cp_footer();
468
        require_once __DIR__ . '/admin_footer.php';
469
        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...
470
    }
471
472
    /**
473
     * @param int $bid
474
     * @param $btitle
475
     * @param $bside
476
     * @param $bweight
477
     * @param $bvisible
478
     * @param $bcachetime
479
     * @param $bmodule
480
     * @param $options
481
     * @param $groups
482
     */
483
    function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
484
    {
485
        $myblock = new XoopsBlock($bid);
486
        $myblock->setVar('title', $btitle);
487
        $myblock->setVar('weight', $bweight);
488
        $myblock->setVar('visible', $bvisible);
489
        $myblock->setVar('side', $bside);
490
        $myblock->setVar('bcachetime', $bcachetime);
491
        //update block options
492
        if (isset($options)) {
493
            $options_count = count($options);
494
            if ($options_count > 0) {
495
                //Convert array values to comma-separated
496
                for ($i = 0; $i < $options_count; ++$i) {
497
                    if (is_array($options[$i])) {
498
                        $options[$i] = implode(',', $options[$i]);
499
                    }
500
                }
501
                $options = implode('|', $options);
502
                $myblock->setVar('options', $options);
503
            }
504
        }
505
        $myblock->store();
506
507
        global $xoopsDB;
508
509
        $moduleDirName = basename(dirname(__DIR__));
510
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
511
512
        if (!empty($bmodule) && count($bmodule) > 0) {
513
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
514
            $xoopsDB->query($sql);
515
            if (in_array(0, $bmodule)) {
516
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, 0);
517
                $xoopsDB->query($sql);
518
            } else {
519
                foreach ($bmodule as $bmid) {
520
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, (int)$bmid);
521
                    $xoopsDB->query($sql);
522
                }
523
            }
524
        }
525
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
526
        $xoopsDB->query($sql);
527
        if (!empty($groups)) {
528
            foreach ($groups as $grp) {
529
                $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid);
530
                $xoopsDB->query($sql);
531
            }
532
        }
533
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
534
    }
535
536
    if ('list' === $op) {
537
        xoops_cp_header();
538
        //        mpu_adm_menu();
539
        listBlocks();
540
        require_once __DIR__ . '/admin_footer.php';
541
        exit();
542
    }
543
544
    if ('order' === $op) {
545
        if (!$GLOBALS['xoopsSecurity']->check()) {
546
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
547
        }
548
        foreach (array_keys($bid) as $i) {
549
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i]
550
                || $oldside[$i] != $side[$i]
551
                || $oldbcachetime[$i] != $bcachetime[$i]) {
552
                setOrder($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 setOrder() 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

552
                /** @scrutinizer ignore-call */ 
553
                setOrder($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...
553
            }
554
            if (!empty($bmodule[$i]) && count($bmodule[$i]) > 0) {
555
                $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid[$i]);
556
                $xoopsDB->query($sql);
557
                if (in_array(0, $bmodule[$i])) {
558
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], 0);
559
                    $xoopsDB->query($sql);
560
                } else {
561
                    foreach ($bmodule[$i] as $bmid) {
562
                        $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid[$i], (int)$bmid);
563
                        $xoopsDB->query($sql);
564
                    }
565
                }
566
            }
567
            $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid[$i]);
568
            $xoopsDB->query($sql);
569
            if (!empty($groups[$i])) {
570
                foreach ($groups[$i] as $grp) {
571
                    $sql = sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $xoopsDB->prefix('group_permission'), $grp, $bid[$i]);
572
                    $xoopsDB->query($sql);
573
                }
574
            }
575
        }
576
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
577
    }
578
    if ('clone' === $op) {
579
        cloneBlock($bid);
580
    }
581
582
    if ('edit' === $op) {
583
        editBlock($bid);
584
    }
585
586
    if ('edit_ok' === $op) {
587
        updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
588
    }
589
590
    if ('clone_ok' === $op) {
591
        isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
592
    }
593
} else {
594
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
595
}
596