Passed
Push — master ( 40654a...b847d6 )
by Michael
06:43 queued 10s
created

editBlock()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 43
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 34
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 43
rs 9.376
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 48 and the first side effect is on line 27.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
use Xmf\Request;
16
17
require __DIR__ . '/admin_header.php';
18
19
$moduleDirName = basename(dirname(__DIR__));
20
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
22
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
23
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
24
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
25
}
26
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
27
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
28
    $op = 'list';
29
    if (isset($_POST)) {
30
        foreach ($_POST as $k => $v) {
31
            ${$k} = $v;
32
        }
33
    }
34
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
35
    if (\Xmf\Request::hasVar('op', 'GET')) {
36
        if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op']
37
            || 'edit' === $_GET['op']) {
38
            $op  = $_GET['op'];
39
            $bid = \Xmf\Request::getInt('bid', 0, 'GET');
40
        }
41
    */
42
43
    $op = Request::getString('op', $op);
44
    if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
45
        $bid = Request::getInt('bid', 0, 'GET');
46
    }
47
48
    function listBlocks()
49
    {
50
        global $xoopsModule, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
51
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
52
        $moduleDirName = basename(dirname(__DIR__));
53
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
55
        xoops_loadLanguage('admin', 'system');
56
        xoops_loadLanguage('admin/blocksadmin', 'system');
57
        xoops_loadLanguage('admin/groups', 'system');
58
59
        /** @var \XoopsModuleHandler $moduleHandler */
60
        $moduleHandler = xoops_getHandler('module');
61
        /** @var \XoopsMemberHandler $memberHandler */
62
        $memberHandler = xoops_getHandler('member');
63
        /** @var \XoopsGroupPermHandler $grouppermHandler */
64
        $grouppermHandler = xoops_getHandler('groupperm');
65
        $groups = $memberHandler->getGroups();
66
        $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1));
67
        $criteria->add(new \Criteria('isactive', 1));
68
        $module_list = $moduleHandler->getList($criteria);
69
        $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;
70
        $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES;
71
        ksort($module_list);
72
        echo "
73
        <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
74
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleHandler is dead and can be removed.
Loading history...
75
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
76
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
77
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
78
        <tr valign='middle'><th align='center'>"
79
             . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
80
             . "</th><th align='center' nowrap='nowrap'>"
81
             . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
82
             . '<br>'
83
             . _LEFT
84
             . '-'
85
             . _CENTER
86
             . '-'
87
             . _RIGHT
88
             . "</th><th align='center'>"
89
             . constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT')
90
             . "</th><th align='center'>"
91
             . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
92
             . "</th><th align='center'>"
93
             . _AM_SYSTEM_BLOCKS_VISIBLEIN
94
             . "</th><th align='center'>"
95
             . _AM_SYSTEM_ADGS
96
             . "</th><th align='center'>"
97
             . _AM_SYSTEM_BLOCKS_BCACHETIME
98
             . "</th><th align='center'>"
99
             . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION')
100
             . '</th></tr>
101
        ';
102
        $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

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

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
283
        xoops_cp_header();
284
285
        xoops_loadLanguage('admin', 'system');
286
        xoops_loadLanguage('admin/blocksadmin', 'system');
287
        xoops_loadLanguage('admin/groups', 'system');
288
289
        //        mpu_adm_menu();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
        $myblock = new \XoopsBlock($bid);
291
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
292
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
293
        $result = $db->query($sql);
294
        $modules = [];
295
        while (false !== ($row = $db->fetchArray($result))) {
296
            $modules[] = (int)$row['module_id'];
297
        }
298
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
299
        $block = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
300
            'title' => $myblock->getVar('title') . ' Clone',
301
            '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...
302
            'name' => $myblock->getVar('name'),
303
            'side' => $myblock->getVar('side'),
304
            'weight' => $myblock->getVar('weight'),
305
            'visible' => $myblock->getVar('visible'),
306
            'content' => $myblock->getVar('content', 'N'),
307
            'modules' => $modules,
308
            'is_custom' => $is_custom,
309
            'ctype' => $myblock->getVar('c_type'),
310
            'bcachetime' => $myblock->getVar('bcachetime'),
311
            'op' => 'clone_ok',
312
            'bid' => $myblock->getVar('bid'),
313
            'edit_form' => $myblock->getOptions(),
314
            'template' => $myblock->getVar('template'),
315
            'options' => $myblock->getVar('options'),
316
        ];
317
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
318
        require_once __DIR__ . '/blockform.php';
319
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
320
        //        xoops_cp_footer();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
321
        require_once __DIR__ . '/admin_footer.php';
322
        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...
323
    }
324
325
    /**
326
     * @param int               $bid
327
     * @param string            $bside
328
     * @param int               $bweight
329
     * @param bool              $bvisible
330
     * @param int               $bcachetime
331
     * @param array             $bmodule
332
     * @param null|array|string $options
333
     */
334
    function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
335
    {
336
        xoops_loadLanguage('admin', 'system');
337
        xoops_loadLanguage('admin/blocksadmin', 'system');
338
        xoops_loadLanguage('admin/groups', 'system');
339
340
        /** @var \XoopsBlock $block */
341
        $block = new \XoopsBlock($bid);
342
        $clone = $block->xoopsClone();
343
        if (empty($bmodule)) {
344
            xoops_cp_header();
345
            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...
346
            xoops_cp_footer();
347
            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...
348
        }
349
        $clone->setVar('side', $bside);
350
        $clone->setVar('weight', $bweight);
351
        $clone->setVar('visible', $bvisible);
352
        //$clone->setVar('content', $_POST['bcontent']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
353
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
354
        $clone->setVar('bcachetime', $bcachetime);
355
        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

355
        if (isset($options) && (count(/** @scrutinizer ignore-type */ $options) > 0)) {
Loading history...
356
            $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

356
            $options = implode('|', /** @scrutinizer ignore-type */ $options);
Loading history...
357
            $clone->setVar('options', $options);
358
        }
359
        $clone->setVar('bid', 0);
360
        if ('C' === $block->getVar('block_type') || 'E' === $block->getVar('block_type')) {
361
            $clone->setVar('block_type', 'E');
362
        } else {
363
            $clone->setVar('block_type', 'D');
364
        }
365
        $newid = $clone->store();
366
        if (!$newid) {
367
            xoops_cp_header();
368
            $clone->getHtmlErrors();
369
            xoops_cp_footer();
370
            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...
371
        }
372
        if ('' !== $clone->getVar('template')) {
373
            /** @var \XoopsTplfileHandler $tplfileHandler */
374
            $tplfileHandler = xoops_getHandler('tplfile');
375
            $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
376
            if (count($btemplate) > 0) {
377
                $tplclone = $btemplate[0]->xoopsClone();
378
                $tplclone->setVar('tpl_id', 0);
379
                $tplclone->setVar('tpl_refid', $newid);
380
                $tplfileHandler->insert($tplclone);
381
            }
382
        }
383
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
384
        foreach ($bmodule as $bmid) {
385
            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
386
            $db->query($sql);
387
        }
388
        $groups = &$GLOBALS['xoopsUser']->getGroups();
389
        $count = count($groups);
390
        for ($i = 0; $i < $count; ++$i) {
391
            $sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $groups[$i] . ', ' . $newid . ", 1, 'block_read')";
392
            $db->query($sql);
393
        }
394
        redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
395
    }
396
397
    /**
398
     * @param int               $bid
399
     * @param string            $title
400
     * @param int               $weight
401
     * @param bool              $visible
402
     * @param string            $side
403
     * @param int               $bcachetime
404
     */
405
    function setOrder($bid, $title, $weight, $visible, $side, $bcachetime)
406
    {
407
        $myblock = new \XoopsBlock($bid);
408
        $myblock->setVar('title', $title);
409
        $myblock->setVar('weight', $weight);
410
        $myblock->setVar('visible', $visible);
411
        $myblock->setVar('side', $side);
412
        $myblock->setVar('bcachetime', $bcachetime);
413
        $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

413
        $myblock->/** @scrutinizer ignore-call */ 
414
                  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...
414
    }
415
416
    /**
417
     * @param int $bid
418
     */
419
    function editBlock($bid)
420
    {
421
        require_once __DIR__ . '/admin_header.php';
422
        //require_once __DIR__ . '/admin_header.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
423
        xoops_cp_header();
424
425
        xoops_loadLanguage('admin', 'system');
426
        xoops_loadLanguage('admin/blocksadmin', 'system');
427
        xoops_loadLanguage('admin/groups', 'system');
428
        //        mpu_adm_menu();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
429
        $myblock = new \XoopsBlock($bid);
430
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
431
        $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
432
        $result = $db->query($sql);
433
        $modules = [];
434
        while (false !== ($row = $db->fetchArray($result))) {
435
            $modules[] = (int)$row['module_id'];
436
        }
437
        $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type'));
438
        $block = [
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
439
            'title' => $myblock->getVar('title'),
440
            'form_title' => constant('CO_' . $moduleDirNameUpper . '_' . 'BLOCKS_EDITBLOCK'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper seems to be never defined.
Loading history...
441
            //        'name'       => $myblock->getVar('name'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
442
            'side' => $myblock->getVar('side'),
443
            'weight' => $myblock->getVar('weight'),
444
            'visible' => $myblock->getVar('visible'),
445
            'content' => $myblock->getVar('content', 'N'),
446
            'modules' => $modules,
447
            'is_custom' => $is_custom,
448
            'ctype' => $myblock->getVar('c_type'),
449
            'bcachetime' => $myblock->getVar('bcachetime'),
450
            'op' => 'edit_ok',
451
            'bid' => $myblock->getVar('bid'),
452
            'edit_form' => $myblock->getOptions(),
453
            'template' => $myblock->getVar('template'),
454
            'options' => $myblock->getVar('options'),
455
        ];
456
        echo '<a href="blocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
457
        require_once __DIR__ . '/blockform.php';
458
        $form->display();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
459
        //        xoops_cp_footer();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
460
        require_once __DIR__ . '/admin_footer.php';
461
        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...
462
    }
463
464
    /**
465
     * @param int $bid
466
     * @param $btitle
467
     * @param $bside
468
     * @param $bweight
469
     * @param $bvisible
470
     * @param $bcachetime
471
     * @param $bmodule
472
     * @param $options
473
     * @param $groups
474
     */
475
    function updateBlock($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

475
    function updateBlock($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...
476
    {
477
        $myblock = new \XoopsBlock($bid);
478
        $myblock->setVar('title', $btitle);
479
        $myblock->setVar('weight', $bweight);
480
        $myblock->setVar('visible', $bvisible);
481
        $myblock->setVar('side', $bside);
482
        $myblock->setVar('bcachetime', $bcachetime);
483
        $myblock->store();
484
485
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
486
487
        $moduleDirName = basename(dirname(__DIR__));
488
        $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
489
490
        if (!empty($bmodule) && count($bmodule) > 0) {
491
            $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $xoopsDB->prefix('block_module_link'), $bid);
492
            $xoopsDB->query($sql);
493
            if (in_array(0, $bmodule)) {
494
                $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, 0);
495
                $xoopsDB->query($sql);
496
            } else {
497
                foreach ($bmodule as $bmid) {
498
                    $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $xoopsDB->prefix('block_module_link'), $bid, (int)$bmid);
499
                    $xoopsDB->query($sql);
500
                }
501
            }
502
        }
503
        $sql = sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $xoopsDB->prefix('group_permission'), $bid);
504
        $xoopsDB->query($sql);
505
        if (!empty($groups)) {
506
            foreach ($groups as $grp) {
507
                $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);
508
                $xoopsDB->query($sql);
509
            }
510
        }
511
        redirect_header($_SERVER['PHP_SELF'], 1, constant('CO_' . $moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
512
    }
513
514
    if ('list' === $op) {
515
        xoops_cp_header();
516
        //        mpu_adm_menu();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
517
        listBlocks();
518
        require_once __DIR__ . '/admin_footer.php';
519
        exit();
520
    }
521
522
    if ('order' === $op) {
523
        if (!$GLOBALS['xoopsSecurity']->check()) {
524
            redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
525
        }
526
        foreach (array_keys($bid) as $i) {
527
            if ($oldtitle[$i] != $title[$i] || $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i]
528
                || $oldside[$i] != $side[$i]
529
                || $oldbcachetime[$i] != $bcachetime[$i]) {
530
                xtubeSetOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
0 ignored issues
show
Bug introduced by
The function xtubeSetOrder was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

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