Test Failed
Push — master ( b9c986...b643ba )
by Michael
09:41
created

system_CleanVars()   C

Complexity

Conditions 13
Paths 28

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 20
c 1
b 0
f 0
nc 28
nop 4
dl 0
loc 26
rs 6.6166

How to fix   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
 * System functions
4
 *
5
 * LICENSE
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 *
11
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
12
 * @license             GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
13
 * @package             system
14
 */
15
16
/**
17
 * Get variables passed by GET or POST method
18
 *
19
 * Comment by Taiwen Jiang (a.k.a. phppp): THE METHOD IS NOT COMPLETE AND NOT SAFE. YOU ARE ENCOURAGED TO USE PHP'S NATIVE FILTER_VAR OR FILTER_INPUT FUNCTIONS DIRECTLY BEFORE WE MIGRATE TO XOOPS 3.
20
 * @param                   $global
21
 * @param                   $key
22
 * @param  string           $default
23
 * @param  string           $type
24
 * @return int|mixed|string
25
 */
26
function system_CleanVars(&$global, $key, $default = '', $type = 'int')
27
{
28
    switch ($type) {
29
        case 'array':
30
            $ret = (isset($global[$key]) && is_array($global[$key])) ? $global[$key] : $default;
31
            break;
32
        case 'date':
33
            $ret = isset($global[$key]) ? strtotime($global[$key]) : $default;
34
            break;
35
        case 'string':
36
            if(defined('FILTER_SANITIZE_ADD_SLASHES')){
37
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_ADD_SLASHES) : $default;
38
            } else {
39
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
40
            }
41
            break;
42
        case 'int':
43
        default:
44
            $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
45
            break;
46
    }
47
    if ($ret === false) {
48
        return $default;
49
    }
50
51
    return $ret;
52
}
53
54
/**
55
 * System language loader wrapper
56
 *
57
 *
58
 * @param  string  $name     Name of language file to be loaded, without extension
59
 * @param  string  $domain   Module dirname; global language file will be loaded if $domain is set to 'global' or not specified
60
 * @param  string  $language Language to be loaded, current language content will be loaded if not specified
61
 * @return boolean
62
 * @todo    expand domain to multiple categories, e.g. module:system, framework:filter, etc.
63
 *
64
 */
65
function system_loadLanguage($name, $domain = '', $language = null)
66
{
67
    /**
68
     * We must check later for an empty value. As xoops_getPageOption could be empty
69
     */
70
    if (empty($name)) {
71
        return false;
72
    }
73
    $language = empty($language) ? $GLOBALS['xoopsConfig']['language'] : $language;
74
    $path     = 'modules/' . $domain . '/language/';
75
    if (file_exists($file = $GLOBALS['xoops']->path($path . $language . '/admin/' . $name . '.php'))) {
76
        $ret = include_once $file;
77
    } else {
78
        $ret = include_once $GLOBALS['xoops']->path($path . 'english/admin/' . $name . '.php');
79
    }
80
81
    return $ret;
82
}
83
84
/**
85
 * @param        $version
86
 * @param string $value
87
 *
88
 * @return mixed
89
 */
90
function system_adminVersion($version, $value = '')
91
{
92
    static $tblVersion = array();
93
    if (is_array($tblVersion) && array_key_exists($version . '.' . $value, $tblVersion)) {
94
        return $tblVersion[$version . '.' . $value];
95
    }
96
    $path = XOOPS_ROOT_PATH . '/modules/system/admin/' . $version . '/xoops_version.php';
97
    if (file_exists($path)) {
98
        include $path;
99
100
        $retvalue                            = $modversion[$value];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modversion does not exist. Did you maybe mean $version?
Loading history...
101
        $tblVersion[$version . '.' . $value] = $retvalue;
102
103
        return $retvalue;
104
    }
105
106
    return null;
107
}
108
109
/**
110
 * @param $img
111
 *
112
 * @return mixed
113
 */
114
function system_AdminIcons($img)
115
{
116
    $style = xoops_getModuleOption('typeicons', 'system');
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

116
    $style = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('typeicons', 'system');
Loading history...
117
    if ($style == '') {
118
        $style = 'default';
119
    }
120
121
    $url = $GLOBALS['xoops']->url('modules/system/images/icons/' . $style . '/' . $img);
122
123
    return $url;
124
}
125
126
/**
127
 * @param $name
128
 */
129
function system_loadTemplate($name)
130
{
131
    global $sysTpl, $xoopsModule;
132
133
    $path = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/templates/admin/' . $name . '.tpl';
134
    if (file_exists($path)) {
135
        echo $sysTpl->fetch($path);
136
    } else {
137
        echo 'Unable to read ' . $name;
138
    }
139
}
140
141
/**
142
 * @param $value_chmod
143
 * @param $path_file
144
 * @param $id
145
 *
146
 * @return string
147
 */
148
function modify_chmod($value_chmod, $path_file, $id)
149
{
150
    $chmod = '<div id="loading_' . $id . '" align="center" style="display:none;">' . '<img src="./images/mimetypes/spinner.gif" title="Loading" alt="Loading" width="12px"/></div>' . '<div id="chmod' . $id . '">' . '<select size="1" onChange="filemanager_modify_chmod(\'' . $path_file . '\', \'' . $id . '\')" name="chmod" id="chmod">';
151
    if ($value_chmod == 777) {
152
        $chmod .= '<option value="777" selected><span style="color:green;">777</span></option>';
153
    } else {
154
        $chmod .= '<option value="777"><span style="color:green;">777</span></option>';
155
    }
156
157
    if ($value_chmod == 776) {
158
        $chmod .= '<option value="776" selected>776</option>';
159
    } else {
160
        $chmod .= '<option value="776">776</option>';
161
    }
162
163
    if ($value_chmod == 766) {
164
        $chmod .= '<option value="766" selected>766</option>';
165
    } else {
166
        $chmod .= '<option value="766">766</option>';
167
    }
168
169
    if ($value_chmod == 666) {
170
        $chmod .= '<option value="666" selected>666</option>';
171
    } else {
172
        $chmod .= '<option value="666">666</option>';
173
    }
174
175
    if ($value_chmod == 664) {
176
        $chmod .= '<option value="664" selected>664</option>';
177
    } else {
178
        $chmod .= '<option value="664">664</option>';
179
    }
180
181
    if ($value_chmod == 644) {
182
        $chmod .= '<option value="644" selected>644</option>';
183
    } else {
184
        $chmod .= '<option value="644">644</option>';
185
    }
186
187
    if ($value_chmod == 444) {
188
        $chmod .= '<option value="444" selected><span style="color:red;">444</span></option>';
189
    } else {
190
        $chmod .= '<option value="444">444</option>';
191
    }
192
193
    if ($value_chmod == 440) {
194
        $chmod .= '<option value="440" selected>440</option>';
195
    } else {
196
        $chmod .= '<option value="440">440</option>';
197
    }
198
199
    if ($value_chmod == 400) {
200
        $chmod .= '<option value="400" selected>400</option>';
201
    } else {
202
        $chmod .= '<option value="400">400</option>';
203
    }
204
    $chmod .= '</select>';
205
206
    return $chmod;
207
}
208