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 (http://www.gnu.org/licenses/gpl-2.0.html)
16 * @package             kernel
17 * @since               2.0.0
18 * @deprecated
19 */
20
21defined('XOOPS_ROOT_PATH') || exit('Restricted access');
22
23/**
24 * Class xos_kernel_Xoops2
25 */
26class 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 = '';
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);
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);
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     * 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'))) {
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