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
|
|
|
$path = ''; |
52
|
|
|
$parts = explode('/', $url, 2); |
53
|
|
|
|
54
|
|
|
if (count($parts) < 2) { |
55
|
|
|
$root = 'www'; // Default root |
56
|
|
|
$path = $url; // Entire URL is treated as the path |
57
|
|
|
} else { |
58
|
|
|
list($root, $path) = $parts; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!isset($this->paths[$root])) { |
62
|
|
|
list($root, $path) = array('www', $url); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!$virtual) { // Returns a physical path |
66
|
|
|
$path = $this->paths[$root][0] . '/' . $path; |
67
|
|
|
$path = str_replace('/', DS, $path); |
68
|
|
|
|
69
|
|
|
return $path; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return !isset($this->paths[$root][1]) ? '' : ($this->paths[$root][1] . '/' . $path); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Convert a XOOPS path to a URL |
77
|
|
|
* @param $url |
78
|
|
|
* @return mixed|string |
79
|
|
|
*/ |
80
|
|
|
public function url($url) |
81
|
|
|
{ |
82
|
|
|
return (false !== strpos($url, '://') ? $url : $this->path($url, true)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Build a URL with the specified request params |
87
|
|
|
* @param $url |
88
|
|
|
* @param array $params |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function buildUrl($url, $params = array()) |
92
|
|
|
{ |
93
|
|
|
if ($url === '.') { |
94
|
|
|
$url = $_SERVER['REQUEST_URI']; |
95
|
|
|
} |
96
|
|
|
$split = explode('?', $url); |
97
|
|
|
if (count($split) > 1) { |
98
|
|
|
list($url, $query) = $split; |
99
|
|
|
parse_str($query, $query); |
|
|
|
|
100
|
|
|
$params = array_merge($query, $params); |
101
|
|
|
} |
102
|
|
|
if (!empty($params)) { |
103
|
|
|
foreach ($params as $k => $v) { |
104
|
|
|
$params[$k] = $k . '=' . rawurlencode((string)$v); |
105
|
|
|
} |
106
|
|
|
$url .= '?' . implode('&', $params); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $url; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* xos_kernel_Xoops2::pathExists() |
114
|
|
|
* |
115
|
|
|
* @param $path |
116
|
|
|
* @param $error_type |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function pathExists($path, $error_type) |
121
|
|
|
{ |
122
|
|
|
if (file_exists($path)) { |
123
|
|
|
return $path; |
124
|
|
|
} else { |
125
|
|
|
$GLOBALS['xoopsLogger']->triggerError($path, _XO_ER_FILENOTFOUND, __FILE__, __LINE__, $error_type); |
126
|
|
|
|
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* xos_kernel_Xoops2::gzipCompression() |
133
|
|
|
* |
134
|
|
|
* @return void |
135
|
|
|
*/ |
136
|
|
|
public function gzipCompression() |
137
|
|
|
{ |
138
|
|
|
/** |
139
|
|
|
* Disable gzip compression if PHP is run under CLI mode and needs to be refactored to work correctly |
140
|
|
|
*/ |
141
|
|
|
if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) === 'cli') { |
142
|
|
|
xoops_setConfigOption('gzip_compression', 0); |
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if (xoops_getConfigOption('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) { |
|
|
|
|
146
|
|
|
if (@ini_get('zlib.output_compression_level') < 0) { |
147
|
|
|
ini_set('zlib.output_compression_level', 6); |
148
|
|
|
} |
149
|
|
|
ob_start('ob_gzhandler'); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* xos_kernel_Xoops2::pathTranslation() |
155
|
|
|
* |
156
|
|
|
* @return void |
157
|
|
|
*/ |
158
|
|
|
public function pathTranslation() |
159
|
|
|
{ |
160
|
|
|
/** |
161
|
|
|
* *#@+ |
162
|
|
|
* Host abstraction layer |
163
|
|
|
*/ |
164
|
|
|
if (!isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME'])) { |
165
|
|
|
$_SERVER['PATH_TRANSLATED'] = $_SERVER['SCRIPT_FILENAME']; // For Apache CGI |
166
|
|
|
} elseif (isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME'])) { |
167
|
|
|
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; // For IIS/2K now I think :-( |
168
|
|
|
} |
169
|
|
|
/** |
170
|
|
|
* User Mulitbytes |
171
|
|
|
*/ |
172
|
|
|
if (empty($_SERVER['REQUEST_URI'])) { // Not defined by IIS |
173
|
|
|
// Under some configs, IIS makes SCRIPT_NAME point to php.exe :-( |
174
|
|
|
if (!(isset($_SERVER['PHP_SELF']) && ($_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']))) { |
175
|
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if (isset($_SERVER['QUERY_STRING'])) { |
179
|
|
|
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* xos_kernel_Xoops2::themeSelect() |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function themeSelect() |
190
|
|
|
{ |
191
|
|
|
if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], xoops_getConfigOption('theme_set_allowed'))) { |
|
|
|
|
192
|
|
|
xoops_setConfigOption('theme_set', $_POST['xoops_theme_select']); |
|
|
|
|
193
|
|
|
$_SESSION['xoopsUserTheme'] = $_POST['xoops_theme_select']; |
194
|
|
|
} elseif (!empty($_SESSION['xoopsUserTheme']) && in_array($_SESSION['xoopsUserTheme'], xoops_getConfigOption('theme_set_allowed'))) { |
|
|
|
|
195
|
|
|
xoops_setConfigOption('theme_set', $_SESSION['xoopsUserTheme']); |
|
|
|
|
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|