xos_kernel_Xoops2   A
last analyzed

Complexity

Total Complexity 34

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 34
eloc 55
dl 0
loc 161
rs 9.68
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 3 2
A path() 0 16 4
B gzipCompression() 0 14 7
A __construct() 0 8 1
A themeSelect() 0 7 5
A pathExists() 0 8 2
B pathTranslation() 0 21 8
A buildUrl() 0 19 5
1
<?php
2
/**
3
 * XOOPS kernel
4
 *
5
 * !IMPORTANT: The file should have not been created and will be removed
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
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
15
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package             kernel
17
 * @since               2.0.0
18
 * @deprecated
19
 */
20
21
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
22
23
/**
24
 * Class xos_kernel_Xoops2
25
 */
26
class xos_kernel_Xoops2
27
{
28
    public $paths = array('XOOPS' => array(), 'www' => array(), 'var' => array(), 'lib' => array(), 'modules' => array(), 'themes' => array());
29
30
    /**
31
     * Actual Xoops OS
32
     */
33
    public function __construct()
34
    {
35
        $this->paths['XOOPS']   = array(XOOPS_PATH, XOOPS_URL . 'browse.php');
36
        $this->paths['www']     = array(XOOPS_ROOT_PATH, XOOPS_URL);
37
        $this->paths['var']     = array(XOOPS_VAR_PATH, null);
38
        $this->paths['lib']     = array(XOOPS_PATH, XOOPS_URL . 'browse.php');
39
        $this->paths['modules'] = array(XOOPS_ROOT_PATH . '/modules', XOOPS_URL . '/modules');
40
        $this->paths['themes']  = array(XOOPS_ROOT_PATH . '/themes', XOOPS_URL . '/themes');
41
    }
42
43
    /**
44
     * Convert a XOOPS path to a physical one
45
     * @param               $url
46
     * @param  bool         $virtual
47
     * @return mixed|string
48
     */
49
    public function path($url, $virtual = false)
50
    {
51
        // removed , $error_type = E_USER_WARNING
52
        $path = '';
0 ignored issues
show
Unused Code introduced by beckmi
The assignment to $path is dead and can be removed.
Loading history...
53
        @list($root, $path) = explode('/', $url, 2);
54
        if (!isset($this->paths[$root])) {
55
            list($root, $path) = array('www', $url);
56
        }
57
        if (!$virtual) { // Returns a physical path
58
            $path = $this->paths[$root][0] . '/' . $path;
59
            $path = str_replace('/', DS, $path);
60
61
            return $path;
62
        }
63
64
        return !isset($this->paths[$root][1]) ? '' : ($this->paths[$root][1] . '/' . $path);
65
    }
66
67
    /**
68
     * Convert a XOOPS path to an URL
69
     * @param $url
70
     * @return mixed|string
71
     */
72
    public function url($url)
73
    {
74
        return (false !== strpos($url, '://') ? $url : $this->path($url, true));
75
    }
76
77
    /**
78
     * Build an URL with the specified request params
79
     * @param         $url
80
     * @param  array  $params
81
     * @return string
82
     */
83
    public function buildUrl($url, $params = array())
84
    {
85
        if ($url === '.') {
86
            $url = $_SERVER['REQUEST_URI'];
87
        }
88
        $split = explode('?', $url);
89
        if (count($split) > 1) {
90
            list($url, $query) = $split;
91
            parse_str($query, $query);
0 ignored issues
show
Bug introduced by beckmi
$query of type string is incompatible with the type array expected by parameter $result of parse_str(). ( Ignorable by Annotation )

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

91
            parse_str($query, /** @scrutinizer ignore-type */ $query);
Loading history...
92
            $params = array_merge($query, $params);
93
        }
94
        if (!empty($params)) {
95
            foreach ($params as $k => $v) {
96
                $params[$k] = $k . '=' . rawurlencode($v);
97
            }
98
            $url .= '?' . implode('&', $params);
99
        }
100
101
        return $url;
102
    }
103
104
    /**
105
     * xos_kernel_Xoops2::pathExists()
106
     *
107
     * @param $path
108
     * @param $error_type
109
     *
110
     * @return bool
111
     */
112
    public function pathExists($path, $error_type)
113
    {
114
        if (file_exists($path)) {
115
            return $path;
116
        } else {
117
            $GLOBALS['xoopsLogger']->triggerError($path, _XO_ER_FILENOTFOUND, __FILE__, __LINE__, $error_type);
118
119
            return false;
120
        }
121
    }
122
123
    /**
124
     * xos_kernel_Xoops2::gzipCompression()
125
     *
126
     * @return void
127
     */
128
    public function gzipCompression()
129
    {
130
        /**
131
         * Disable gzip compression if PHP is run under CLI mode and needs refactored to work correctly
132
         */
133
        if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) === 'cli') {
134
            xoops_setConfigOption('gzip_compression', 0);
0 ignored issues
show
Deprecated Code introduced by beckmi
The function xoops_setConfigOption() 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

134
            /** @scrutinizer ignore-deprecated */ xoops_setConfigOption('gzip_compression', 0);
Loading history...
135
        }
136
137
        if (xoops_getConfigOption('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
0 ignored issues
show
Deprecated Code introduced by mambax7
The function xoops_getConfigOption() 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

137
        if (/** @scrutinizer ignore-deprecated */ xoops_getConfigOption('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
Loading history...
138
            if (@ini_get('zlib.output_compression_level') < 0) {
139
                ini_set('zlib.output_compression_level', 6);
140
            }
141
            ob_start('ob_gzhandler');
142
        }
143
    }
144
145
    /**
146
     * xos_kernel_Xoops2::pathTranslation()
147
     *
148
     * @return void
149
     */
150
    public function pathTranslation()
151
    {
152
        /**
153
         * *#@+
154
         * Host abstraction layer
155
         */
156
        if (!isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME'])) {
157
            $_SERVER['PATH_TRANSLATED'] = $_SERVER['SCRIPT_FILENAME']; // For Apache CGI
158
        } elseif (isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME'])) {
159
            $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; // For IIS/2K now I think :-(
160
        }
161
        /**
162
         * User Mulitbytes
163
         */
164
        if (empty($_SERVER['REQUEST_URI'])) { // Not defined by IIS
165
            // Under some configs, IIS makes SCRIPT_NAME point to php.exe :-(
166
            if (!($_SERVER['REQUEST_URI'] = @$_SERVER['PHP_SELF'])) {
167
                $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
168
            }
169
            if (isset($_SERVER['QUERY_STRING'])) {
170
                $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
171
            }
172
        }
173
    }
174
175
    /**
176
     * xos_kernel_Xoops2::themeSelect()
177
     *
178
     * @return void
179
     */
180
    public function themeSelect()
181
    {
182
        if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], xoops_getConfigOption('theme_set_allowed'))) {
0 ignored issues
show
Deprecated Code introduced by mambax7
The function xoops_getConfigOption() 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

182
        if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], /** @scrutinizer ignore-deprecated */ xoops_getConfigOption('theme_set_allowed'))) {
Loading history...
Bug introduced by mambax7
xoops_getConfigOption('theme_set_allowed') of type boolean is incompatible with the type array expected by parameter $haystack of in_array(). ( Ignorable by Annotation )

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

182
        if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], /** @scrutinizer ignore-type */ xoops_getConfigOption('theme_set_allowed'))) {
Loading history...
183
            xoops_setConfigOption('theme_set', $_POST['xoops_theme_select']);
0 ignored issues
show
Deprecated Code introduced by beckmi
The function xoops_setConfigOption() 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

183
            /** @scrutinizer ignore-deprecated */ xoops_setConfigOption('theme_set', $_POST['xoops_theme_select']);
Loading history...
184
            $_SESSION['xoopsUserTheme'] = $_POST['xoops_theme_select'];
185
        } elseif (!empty($_SESSION['xoopsUserTheme']) && in_array($_SESSION['xoopsUserTheme'], xoops_getConfigOption('theme_set_allowed'))) {
0 ignored issues
show
Deprecated Code introduced by mambax7
The function xoops_getConfigOption() 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

185
        } elseif (!empty($_SESSION['xoopsUserTheme']) && in_array($_SESSION['xoopsUserTheme'], /** @scrutinizer ignore-deprecated */ xoops_getConfigOption('theme_set_allowed'))) {
Loading history...
186
            xoops_setConfigOption('theme_set', $_SESSION['xoopsUserTheme']);
0 ignored issues
show
Deprecated Code introduced by beckmi
The function xoops_setConfigOption() 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

186
            /** @scrutinizer ignore-deprecated */ xoops_setConfigOption('theme_set', $_SESSION['xoopsUserTheme']);
Loading history...
187
        }
188
    }
189
}
190