Passed
Branch master (4e30dc)
by Michael
02:20
created

list_blocks()   F

Complexity

Conditions 14
Paths 253

Size

Total Lines 169
Code Lines 114

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 169
rs 3.7522
c 1
b 0
f 0
cc 14
eloc 114
nc 253
nop 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
// ------------------------------------------------------------------------- //
10
//                            myblocksadmin.php                              //
11
//                - XOOPS block admin for each modules -                     //
12
//                          GIJOE <http://www.peak.ne.jp>                   //
13
// ------------------------------------------------------------------------- //
14
15
use XoopsModules\Smartfaq;
16
17
require_once __DIR__ . '/../../../include/cp_header.php';
18
require_once __DIR__ . '/mygrouppermform.php';
19
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
20
//require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php';
21
22
$xoops_system_path = XOOPS_ROOT_PATH . '/modules/system';
23
24
// language files
25
$language = $xoopsConfig['language'];
26
if (!file_exists("$xoops_system_path/language/$language/admin/blocksadmin.php")) {
27
    $language = 'english';
28
}
29
30
// to prevent from notice that constants already defined
31
$error_reporting_level = error_reporting(0);
32
require_once __DIR__ . '/../../system/constants.php';
33
require_once __DIR__ . "/../../language/$language/admin.php";
34
require_once __DIR__ . "/../../language/$language/admin/blocksadmin.php";
35
//require_once __DIR__ . '/../include/functions.php';
36
error_reporting($error_reporting_level);
37
38
$group_defs = file("$xoops_system_path/language/$language/admin/groups.php");
39
foreach ($group_defs as $def) {
40
    if (false !== strpos($def, '_AM_ACCESSRIGHTS') || false !== strpos($def, '_AM_ACTIVERIGHTS')) {
41
        eval($def);
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
42
    }
43
}
44
45
// check $xoopsModule
46
if (!is_object($xoopsModule)) {
47
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header 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

47
    /** @scrutinizer ignore-call */ 
48
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
Loading history...
48
}
49
50
// check access right (needs system_admin of BLOCK)
51
$syspermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler 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

51
$syspermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
52
if (!$syspermHandler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) {
0 ignored issues
show
Bug introduced by
The constant XOOPS_SYSTEM_BLOCK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
54
}
55
56
// get blocks owned by the module
57
$block_arr = XoopsBlock::getByModule($xoopsModule->mid());
0 ignored issues
show
Bug introduced by
The type XoopsBlock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
59
function list_blocks()
60
{
61
    global $block_arr, $xoopsModule;
62
63
    // cachetime options
64
    $cachetimes = [
65
        '0'       => _NOCACHE,
0 ignored issues
show
Bug introduced by
The constant _NOCACHE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
        '30'      => sprintf(_SECONDS, 30),
0 ignored issues
show
Bug introduced by
The constant _SECONDS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
67
        '60'      => _MINUTE,
0 ignored issues
show
Bug introduced by
The constant _MINUTE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
68
        '300'     => sprintf(_MINUTES, 5),
0 ignored issues
show
Bug introduced by
The constant _MINUTES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
69
        '1800'    => sprintf(_MINUTES, 30),
70
        '3600'    => _HOUR,
0 ignored issues
show
Bug introduced by
The constant _HOUR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
        '18000'   => sprintf(_HOURS, 5),
0 ignored issues
show
Bug introduced by
The constant _HOURS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
72
        '86400'   => _DAY,
0 ignored issues
show
Bug introduced by
The constant _DAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
73
        '259200'  => sprintf(_DAYS, 3),
0 ignored issues
show
Bug introduced by
The constant _DAYS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
74
        '604800'  => _WEEK,
0 ignored issues
show
Bug introduced by
The constant _WEEK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
75
        '2592000' => _MONTH
0 ignored issues
show
Bug introduced by
The constant _MONTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
76
    ];
77
78
    // displaying TH
79
    Smartfaq\Utility::collapsableBar('toptable', 'toptableicon');
80
    echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . _AM_SF_BLOCKS . '</h3>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
81
    echo "<div id='toptable'>";
82
    echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_BLOCKSTXT . '</span>';
83
84
    echo "
85
    <form action='admin.php' name='blockadmin' method='post'>
86
        <table width='100%' class='outer' cellpadding='4' cellspacing='1'>
87
        <tr valign='middle'>
88
            <th>" . _AM_TITLE . "</th>
89
            <th align='center' nowrap='nowrap'>" . _AM_SF_POSITION . "</th>
90
            <th align='center'>" . _AM_WEIGHT . "</th>
91
            <th align='center'>" . _AM_VISIBLEIN . "</th>
92
            <th align='center'>" . _AM_BCACHETIME . "</th>
93
            <th align='center'>" . _AM_ACTION . "</th>
94
        </tr>\n";
95
96
    // blocks displaying loop
97
    $class = 'even';
98
    foreach (array_keys($block_arr) as $i) {
99
        $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = '';
100
101
        $weight     = $block_arr[$i]->getVar('weight');
102
        $title      = $block_arr[$i]->getVar('title');
103
        $name       = $block_arr[$i]->getVar('name');
104
        $bcachetime = $block_arr[$i]->getVar('bcachetime');
105
        $bid        = $block_arr[$i]->getVar('bid');
106
107
        // visible and side
108
        if (1 != $block_arr[$i]->getVar('visible')) {
109
            $sseln = " checked style='background-color:#FF0000;'";
110
        } else {
111
            switch ($block_arr[$i]->getVar('side')) {
112
                default:
113
                case XOOPS_SIDEBLOCK_LEFT:
0 ignored issues
show
Bug introduced by
The constant XOOPS_SIDEBLOCK_LEFT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
114
                    $ssel0 = " checked style='background-color:#00FF00;'";
115
                    break;
116
                case XOOPS_SIDEBLOCK_RIGHT:
0 ignored issues
show
Bug introduced by
The constant XOOPS_SIDEBLOCK_RIGHT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
                    $ssel1 = " checked style='background-color:#00FF00;'";
118
                    break;
119
                case XOOPS_CENTERBLOCK_LEFT:
0 ignored issues
show
Bug introduced by
The constant XOOPS_CENTERBLOCK_LEFT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
120
                    $ssel2 = " checked style='background-color:#00FF00;'";
121
                    break;
122
                case XOOPS_CENTERBLOCK_RIGHT:
0 ignored issues
show
Bug introduced by
The constant XOOPS_CENTERBLOCK_RIGHT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
123
                    $ssel4 = " checked style='background-color:#00FF00;'";
124
                    break;
125
                case XOOPS_CENTERBLOCK_CENTER:
0 ignored issues
show
Bug introduced by
The constant XOOPS_CENTERBLOCK_CENTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
126
                    $ssel3 = " checked style='background-color:#00FF00;'";
127
                    break;
128
            }
129
        }
130
131
        // bcachetime
132
        $cachetime_options = '';
133
        foreach ($cachetimes as $cachetime => $cachetime_name) {
134
            if ($bcachetime == $cachetime) {
135
                $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n";
136
            } else {
137
                $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";
138
            }
139
        }
140
141
        // target modules
142
        $db            = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
143
        $result        = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'");
144
        $selected_mids = [];
145
        while (list($selected_mid) = $db->fetchRow($result)) {
146
            $selected_mids[] = (int)$selected_mid;
147
        }
148
        /** @var XoopsModuleHandler $moduleHandler */
149
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler 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

149
        $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
150
        $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
151
        $criteria->add(new \Criteria('isactive', 1));
152
        $module_list     = $moduleHandler->getList($criteria);
153
        $module_list[-1] = _AM_TOPPAGE;
154
        $module_list[0]  = _AM_ALLPAGES;
155
        ksort($module_list);
156
        $module_options = '';
157
        $myts           = \MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
158
        foreach ($module_list as $mid => $mname) {
159
            if (in_array($mid, $selected_mids)) {
160
                $module_options .= "<option value='$mid' selected>" . $myts->displayTarea($mname) . "</option>\n";
161
            } else {
162
                $module_options .= "<option value='$mid'>" . $myts->displayTarea($mname) . "</option>\n";
163
            }
164
        }
165
166
        // displaying part
167
        echo "
168
        <tr valign='middle'>
169
            <td class='$class'>
170
                $name
171
                <br>
172
                <input type='text' name='title[$bid]' value='$title' size='20'>
173
            </td>
174
            <td class='$class' align='center' nowrap='nowrap'>
175
                <input type='radio' name='side[$bid]' value='"
176
             . XOOPS_SIDEBLOCK_LEFT
177
             . "'$ssel0>-<input type='radio' name='side[$bid]' value='"
178
             . XOOPS_CENTERBLOCK_LEFT
179
             . "'$ssel2><input type='radio' name='side[$bid]' value='"
180
             . XOOPS_CENTERBLOCK_CENTER
181
             . "'$ssel3><input type='radio' name='side[$bid]' value='"
182
             . XOOPS_CENTERBLOCK_RIGHT
183
             . "'$ssel4>-<input type='radio' name='side[$bid]' value='"
184
             . XOOPS_SIDEBLOCK_RIGHT
185
             . "'$ssel1>
186
                <br>
187
                <br>
188
                <input type='radio' name='side[$bid]' value='-1'$sseln>
189
                "
190
             . _NONE
0 ignored issues
show
Bug introduced by
The constant _NONE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
191
             . "
192
            </td>
193
            <td class='$class' align='center'>
194
                <input type='text' name=weight[$bid] value='$weight' size='5' maxlength='5' style='text-align:right;'>
195
            </td>
196
            <td class='$class' align='center'>
197
                <select name='bmodule[$bid][]' size='5' multiple='multiple'>
198
                    $module_options
199
                </select>
200
            </td>
201
            <td class='$class' align='center'>
202
                <select name='bcachetime[$bid]' size='1'>
203
                    $cachetime_options
204
                </select>
205
            </td>
206
            <td class='$class' align='center'>
207
                <a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid=$bid'>"
208
             . _EDIT
0 ignored issues
show
Bug introduced by
The constant _EDIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
209
             . "</a>
210
                <input type='hidden' name='bid[$bid]' value='$bid'>
211
            </td>
212
        </tr>\n";
213
214
        $class = ('even' === $class) ? 'odd' : 'even';
215
    }
216
217
    echo "
218
        <tr>
219
            <td class='foot' align='center' colspan='6'>
220
                <input type='hidden' name='fct' value='blocksadmin'>
221
                <input type='hidden' name='op' value='order'>
222
                <input type='submit' name='submit' value='" . _SUBMIT . "'>
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
223
            </td>
224
        </tr>
225
        </table>
226
    </form>\n";
227
    echo '</div>';
228
}
229
230
function list_groups()
231
{
232
    global $xoopsModule, $block_arr;
233
    $myts = \MyTextSanitizer::getInstance();
234
235
    Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon');
236
237
    foreach (array_keys($block_arr) as $i) {
238
        $item_list[$block_arr[$i]->getVar('bid')] = $block_arr[$i]->getVar('title');
239
    }
240
241
    $form = new GroupPermForm('', 1, 'block_read', "<img id='bottomtableicon' src="
242
                                                          . XOOPS_URL
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
243
                                                          . '/modules/'
244
                                                          . $xoopsModule->dirname()
245
                                                          . "/assets/images/icon/close12.gif alt=''></a>&nbsp;"
246
                                                          . _AM_SF_GROUPS
247
                                                          . "</h3><div id='bottomtable'><span style=\"color: #567; margin: 3px 0 0 0; font-size: small; display: block; \">"
248
                                                          . _AM_SF_GROUPSINFO
249
                                                          . '</span>');
250
    $form->addAppendix('module_admin', $xoopsModule->mid(), $xoopsModule->name() . ' ' . _AM_ACTIVERIGHTS);
251
    $form->addAppendix('module_read', $xoopsModule->mid(), $xoopsModule->name() . ' ' . _AM_ACCESSRIGHTS);
252
    foreach ($item_list as $item_id => $item_name) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item_list seems to be defined by a foreach iteration on line 237. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
253
        $form->addItem($item_id, $myts->displayTarea($item_name));
254
    }
255
    echo $form->render();
256
    echo '</div>';
257
}
258
259
if (!empty($_POST['submit'])) {
260
    include __DIR__ . '/mygroupperm.php';
261
    require_once "$xoops_system_path/language/$language/admin.php";
262
    redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/admin/myblocksadmin.php', 1, _AM_DBUPDATED);
0 ignored issues
show
Bug introduced by
The constant _AM_DBUPDATED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
263
}
264
265
xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header 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

265
/** @scrutinizer ignore-call */ 
266
xoops_cp_header();
Loading history...
266
if (file_exists('./mymenu.php')) {
267
    include __DIR__ . '/mymenu.php';
268
}
269
270
list_blocks();
271
list_groups();
272
xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer 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

272
/** @scrutinizer ignore-call */ 
273
xoops_cp_footer();
Loading history...
273