showExtFields()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 294
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 69
nc 2
nop 2
dl 0
loc 294
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

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
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      efqdirectory
16
 * @since
17
 * @author       Martijn Hertog (aka wtravel)
18
 * @author       XOOPS Development Team,
19
 */
20
21
require_once __DIR__ . '/admin_header.php';
22
//include __DIR__ . '/../../../include/cp_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...
23
24
include __DIR__ . '/../include/functions.php';
25
require_once XOOPS_ROOT_PATH . '/class/xoopstree.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...
26
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
27
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
28
require_once XOOPS_ROOT_PATH . '/include/xoopscodes.php';
29
require_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
30
$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...
31
$eh   = new ErrorHandler;
0 ignored issues
show
Bug introduced by
The type ErrorHandler 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...
32
if (isset($_GET['op'])) {
33
    $op = $_GET['op'];
34
} else {
35
    $op = 'showExtFields';
36
}
37
if (isset($_GET['type'])) {
38
    $type = $_GET['type'];
39
} else {
40
    $type = 'text';
41
}
42
if (isset($_GET['ext'])) {
43
    $ext = $_GET['ext'];
44
} else {
45
    $ext = '';
46
}
47
48
/**
49
 * @param string $type
50
 * @param string $ext
51
 */
52
function showExtFields($type = 'text', $ext = '')
0 ignored issues
show
Unused Code introduced by
The parameter $type 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

52
function showExtFields(/** @scrutinizer ignore-unused */ $type = 'text', $ext = '')

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...
Unused Code introduced by
The parameter $ext 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

52
function showExtFields($type = 'text', /** @scrutinizer ignore-unused */ $ext = '')

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...
53
{
54
    global $xoopsConfig, $xoopsDB, $_POST, $myts, $eh, $xoopsUser;
55
56
    //MHE - This is added code for the listings module, handling the extension manager.
57
    if (!headers_sent()) {
58
        header('Content-Type:text/html; charset=' . _CHARSET);
0 ignored issues
show
Bug introduced by
The constant _CHARSET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
59
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
60
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
61
        header('Cache-Control: no-store, no-cache, must-revalidate');
62
        header('Cache-Control: post-check=0, pre-check=0', false);
63
        header('Pragma: no-cache');
64
    }
65
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"\n';
66
    echo '"http://www.w3.org/TR/html4/strict.dtd">';
67
    echo "<html lang=\"en\" dir=\"ltr\">\n";
68
    echo "<head>\n";
69
    echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '">';
70
    echo '<meta http-equiv="content-language" content="' . _LANGCODE . '">';
0 ignored issues
show
Bug introduced by
The constant _LANGCODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
    echo '<title>Extension Manager</title>';
72
    echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css">';
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...
73
    echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/modules/system/style.css">';
74
    echo '<script type="text/javascript"><!--';
75
    echo '
76
        function ext_initial_adv(formName, obj, type)
77
        {
78
        typeid = opener.document.forms[formName].elements[type].value;
79
        if (typeid == 0) {
80
        alert("' . _MD_SELECT_FORMTYPE . "\");
81
        self.close();
82
        }
83
        var arr_fields = new makeArray(9);
84
        arr_fields[0] = 'width';
85
        arr_fields[1] = 'height';
86
        arr_fields[2] = 'rows';
87
        arr_fields[3] = 'cols';
88
        arr_fields[4] = 'size';
89
        arr_fields[5] = 'maxsize';
90
        arr_fields[6] = 'value';
91
        arr_fields[7] = 'multiple';
92
        arr_fields[8] = 'checked';
93
        length_fields = arr_fields.length;
94
        bgc_type_checkbox_grp = /checked|multiple/gi;
95
        bgc_type_date_grp = /value/gi;
96
        bgc_type_datetime_grp = /value/gi;
97
        bgc_type_radio_grp = /checked/gi;
98
        bgc_type_select_grp = /value|multiple/gi;
99
        bgc_type_textarea_grp = /rows|cols|value/gi;
100
        bgc_type_dhtml_grp = /rows|cols|value/gi;
101
        bgc_type_textbox_grp = /size|maxsize|value/gi;
102
        bgc_type_yesno_grp = /value/gi;
103
        x = 0;
104
        reg_checkboxes = /multiple|checked/gi;
105
        while (x<length_fields) {
106
        if (typeid == 'checkbox') {
107
        if (arr_fields[x].match(bgc_type_checkbox_grp)) {
108
        var fieldname = arr_fields[x];
109
        } else {
110
        var fieldname = arr_fields[x];
111
        ext_manager.elements[fieldname].disabled = true;
112
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
113
        }
114
        }
115
        if (typeid == 'date') {
116
        if (arr_fields[x].match(bgc_type_date_grp)) {
117
        var fieldname = arr_fields[x];
118
        } else {
119
        var fieldname = arr_fields[x];
120
        ext_manager.elements[fieldname].disabled = true;
121
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
122
        }
123
        }
124
        if (typeid == 'datetime') {
125
        if (arr_fields[x].match(bgc_type_datetime_grp)) {
126
        var fieldname = arr_fields[x];
127
        } else {
128
        var fieldname = arr_fields[x];
129
        ext_manager.elements[fieldname].disabled = true;
130
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
131
        }
132
        }
133
        if (typeid == 'radio') {
134
        if (arr_fields[x].match(bgc_type_radio_grp)) {
135
        var fieldname = arr_fields[x];
136
        } else {
137
        var fieldname = arr_fields[x];
138
        ext_manager.elements[fieldname].disabled = true;
139
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
140
        }
141
        }
142
        if (typeid == 'select') {
143
        if (arr_fields[x].match(bgc_type_select_grp)) {
144
        var fieldname = arr_fields[x];
145
        } else {
146
        var fieldname = arr_fields[x];
147
        ext_manager.elements[fieldname].disabled = true;
148
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
149
        }
150
        }
151
        if (typeid == 'textarea') {
152
        if (arr_fields[x].match(bgc_type_textarea_grp)) {
153
        var fieldname = arr_fields[x];
154
        } else {
155
        var fieldname = arr_fields[x];
156
        ext_manager.elements[fieldname].disabled = true;
157
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
158
        }
159
        }
160
        if (typeid == 'dhtml') {
161
        if (arr_fields[x].match(bgc_type_dhtml_grp)) {
162
        var fieldname = arr_fields[x];
163
        } else {
164
        var fieldname = arr_fields[x];
165
        ext_manager.elements[fieldname].disabled = true;
166
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
167
        }
168
        }
169
        if (typeid == 'textbox') {
170
        if (arr_fields[x].match(bgc_type_textbox_grp)) {
171
        var fieldname = arr_fields[x];
172
        } else {
173
        var fieldname = arr_fields[x];
174
        ext_manager.elements[fieldname].disabled = true;
175
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
176
        }
177
        }
178
        if (typeid == 'yesno') {
179
        if (arr_fields[x].match(bgc_type_yesno_grp)) {
180
        var fieldname = arr_fields[x];
181
        } else {
182
        var fieldname = arr_fields[x];
183
        ext_manager.elements[fieldname].disabled = true;
184
        ext_manager.elements[fieldname].style.backgroundColor = 'lightgrey';
185
        }
186
        }
187
        x ++;
188
        }
189
        var ext = opener.document.forms[formName].elements[obj].value;
190
        regx = \"|\";
191
        ext_array = ext.split(regx);
192
        length = ext_array.length;
193
        i = 0;
194
        while (i<length) {
195
        item = ext_array[i];
196
        regy = \"=\";
197
        item_array = item.split(regy);
198
        item_length = item_array.length;
199
        reg_textboxes = /width|height|rows|cols|size|maxsize|value/gi;
200
        reg_checkboxes = /multiple|checked/gi;
201
        if (item_array[0].match(reg_textboxes)) {
202
        var fieldname = item_array[0];
203
        var fieldvalue = item_array[1];
204
        ext_manager.elements[fieldname].value = fieldvalue;
205
        }
206
        if (item_array[0].match(reg_checkboxes)) {
207
        var fieldname = item_array[0];
208
        var fieldvalue = item_array[1];
209
        if (fieldvalue == 1) {
210
        self_check(ext_manager, fieldname, 1);
211
        } else {
212
        self_check(ext_manager, fieldname, 0);
213
        }
214
        }
215
        i ++;
216
        }
217
        }\n";
218
    echo "
219
        function makeArray(n)
220
        {
221
        this.length = n;
222
        for (var i=1; i <=n; i++) {
223
        this[i] = null;
224
        }
225
226
        return this;
227
        }\n";
228
    echo "
229
        function updatefield(formname, fieldname, fieldvalue)
230
        {
231
        myform.elements[fieldname].value = [fieldvalue];
232
        }\n";
233
    echo "
234
        function ext_input(formName, obj)
235
        {
236
        reg_checkboxes = /multiple|checked/gi;
237
        var arr_fields = new makeArray(9);
238
        arr_fields[0] = 'width';
239
        arr_fields[1] = 'height';
240
        arr_fields[2] = 'rows';
241
        arr_fields[3] = 'cols';
242
        arr_fields[4] = 'size';
243
        arr_fields[5] = 'maxsize';
244
        arr_fields[6] = 'value';
245
        arr_fields[7] = 'multiple';
246
        arr_fields[8] = 'checked';
247
        length_fields = arr_fields.length;
248
        i = 0;
249
        y = 0;
250
        var output = '';
251
        while (i<length_fields) {
252
        var fieldname = arr_fields[i];
253
        if (fieldname.match(reg_checkboxes)) {
254
        if (ext_manager.elements[fieldname].checked === true) {
255
        var fieldvalue = 1;
256
        } else {
257
        var fieldvalue = 0;
258
        }
259
        } else {
260
        var fieldvalue = ext_manager.elements[fieldname].value;
261
        }
262
        if (fieldvalue != '') {
263
        if (y == 0) {
264
        output += fieldname+'='+fieldvalue;
265
        } else {
266
        output +='|'+fieldname+'='+fieldvalue;
267
        }
268
        y ++;
269
        }
270
        i ++;
271
        }
272
        opener.document.forms[formName].elements[obj].value = output;
273
        opener.document.forms[formName].elements[obj].disabled = false;
274
        self.close();
275
        }\n";
276
    echo "
277
        function ext_select(formName, obj, idx)
278
        {
279
        opener.document.forms[formName].elements[obj].selectedIndex = idx;
280
        self.close();
281
        }\n";
282
    echo "
283
        function self_checkRadio(formName, obj, choice)
284
        {
285
        ext_manager.elements[obj][choice].checked = true;
286
        }\n";
287
    echo "
288
        function ext_checkRadio(formName, obj, choice)
289
        {
290
        opener.document.forms[formName].elements[obj][choice].checked = true;
291
        self.close();
292
        }\n";
293
    echo "
294
        function self_check(formName, obj, choice)
295
        {
296
        ext_manager.elements[obj].checked = choice;
297
        }\n";
298
    echo "//--></script>\n";
299
    echo "</head>\n";
300
    echo '<body onload="ext_initial_adv(\'submitform\', \'ext\', \'field_type\')">';
301
    echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'>
302
        <tr>
303
        <td bgcolor='#2F5376'><a href='http://www.xoops.org/' target='_blank'><img src='" . XOOPS_URL . "/images/logo.gif' alt='" . $GLOBALS['xoopsConfig']['sitename'] . "'></a></td>
304
        <td align='right' bgcolor='#2F5376'><img src='" . XOOPS_URL . "/images/logo.gif' alt=''></td>
305
        </tr><tr><td colspan='2'><div class='content'><br>";
306
    $form = new XoopsThemeForm(_MD_EXTMANAGER, 'ext_manager', 'fieldtypes.php');
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm 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...
307
308
    //TO DO: change type field to drop down field, based on available types.
309
    $fieldtypes = array(
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldtypes is dead and can be removed.
Loading history...
310
        '0'            => '---',
311
        'checkbox'     => _MD_FIELDNAMES_CHECKBOX,
312
        'date'         => _MD_FIELDNAMES_DATE,
313
        'datetime'     => _MD_FIELDNAMES_DATETIME,
314
        'radio'        => _MD_FIELDNAMES_RADIO,
315
        'select'       => _MD_FIELDNAMES_SELECT,
316
        'select_multi' => _MD_FIELDNAMES_SELECTMULTI,
317
        'textarea'     => _MD_FIELDNAMES_TEXTAREA,
318
        'dhtml'        => _MD_FIELDNAMES_DHTMLTEXTAREA,
319
        'textbox'      => _MD_FIELDNAMES_TEXTBOX,
320
        'yesno'        => _MD_FIELDNAMES_YESNO
321
    );
322
323
    $form->addElement(new XoopsFormText(_MD_WIDTH, 'width', 10, 20, ''));
0 ignored issues
show
Bug introduced by
The type XoopsFormText 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...
324
    $form->addElement(new XoopsFormText(_MD_HEIGHT, 'height', 10, 20, ''));
325
    $form->addElement(new XoopsFormText(_MD_ROWS, 'rows', 10, 20, ''));
326
    $form->addElement(new XoopsFormText(_MD_COLS, 'cols', 10, 20, ''));
327
    $form->addElement(new XoopsFormText(_MD_SIZE, 'size', 10, 20, ''));
328
    $form->addElement(new XoopsFormText(_MD_MAXSIZE, 'maxsize', 10, 20, ''));
329
    $form->addElement(new XoopsFormText(_MD_DEFAULTVALUE, 'value', 50, 100, ''));
330
    $form_multiple = new XoopsFormCheckBox(_MD_MULTIPLE, 'multiple', 0);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox 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...
331
    $form_multiple->addOption(1, _MD_YESNO);
332
    $form_checked = new XoopsFormCheckBox(_MD_CHECKED, 'checked', 0);
333
    $form_checked->addOption(1, _MD_YESNO);
334
    $form->addElement($form_multiple);
335
    $form->addElement($form_checked);
336
    $ext_update = new XoopsFormLabel('', '<INPUT type="button" value="' . _MD_UPDATE . "\" onClick=\"ext_input('submitform','ext')\" value=\"Update\">");
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel 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...
337
    $ext_cancel = new XoopsFormLabel('', '<INPUT type="button" value="' . _MD_CANCEL . '" onClick="self.close()" value="Cancel">');
338
    $ext_tray   = new XoopsFormElementTray('', '');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray 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...
339
    $ext_tray->addElement($ext_update);
340
    $ext_tray->addElement($ext_cancel);
341
    $form->addElement($ext_tray);
342
    $form->display();
343
    echo '</div>';
344
    echo '</td></tr></table>';
345
    echo '</body>';
346
}
347
348
switch ($op) {
349
    /*case "listNewLinks":
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
350
    listNewLinks();
351
    break;
352
    case "delLocs":
353
    delLocs();
354
    break;
355
    case "delLocs2":
356
    delLocationsToLink();
357
    break;*/
358
    default:
359
        showExtFields($type, $ext);
360
        break;
361
}
362