1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20:
21: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
22:
23: 24: 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: 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: 45: 46: 47: 48:
49: public function path($url, $virtual = false)
50: {
51:
52: $path = '';
53: @list($root, $path) = explode('/', $url, 2);
54: if (!isset($this->paths[$root])) {
55: list($root, $path) = array('www', $url);
56: }
57: if (!$virtual) {
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: 69: 70: 71:
72: public function url($url)
73: {
74: return (false !== strpos($url, '://') ? $url : $this->path($url, true));
75: }
76:
77: 78: 79: 80: 81: 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);
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: 106: 107: 108: 109: 110: 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: 125: 126: 127:
128: public function gzipCompression()
129: {
130: 131: 132:
133: if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) === 'cli') {
134: xoops_setConfigOption('gzip_compression', 0);
135: }
136:
137: if (xoops_getConfigOption('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
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: 147: 148: 149:
150: public function pathTranslation()
151: {
152: 153: 154: 155:
156: if (!isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME'])) {
157: $_SERVER['PATH_TRANSLATED'] = $_SERVER['SCRIPT_FILENAME'];
158: } elseif (isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME'])) {
159: $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
160: }
161: 162: 163:
164: if (empty($_SERVER['REQUEST_URI'])) {
165:
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: 177: 178: 179:
180: public function themeSelect()
181: {
182: if (!empty($_POST['xoops_theme_select']) && in_array($_POST['xoops_theme_select'], xoops_getConfigOption('theme_set_allowed'))) {
183: xoops_setConfigOption('theme_set', $_POST['xoops_theme_select']);
184: $_SESSION['xoopsUserTheme'] = $_POST['xoops_theme_select'];
185: } elseif (!empty($_SESSION['xoopsUserTheme']) && in_array($_SESSION['xoopsUserTheme'], xoops_getConfigOption('theme_set_allowed'))) {
186: xoops_setConfigOption('theme_set', $_SESSION['xoopsUserTheme']);
187: }
188: }
189: }
190: