1 | <?php
|
---|
2 | /*
|
---|
3 | * XPressME - WordPress for XOOPS
|
---|
4 | *
|
---|
5 | * @copyright XPressME Project http://www.toemon.com
|
---|
6 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license
|
---|
7 | * @author toemon
|
---|
8 | * @package module::xpress
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*
|
---|
12 | * The function to acquire only a set value without calling the XOOPS system is here.
|
---|
13 | */
|
---|
14 | class ConfigFromXoops{
|
---|
15 | var $xoops_mainfile_path;
|
---|
16 | var $define_arry = array();
|
---|
17 | var $external_define_path;
|
---|
18 | var $xp_config_file_path;
|
---|
19 | var $xoops_root_path;
|
---|
20 | var $xoops_url;
|
---|
21 | var $xoops_trust_path;
|
---|
22 | var $xoops_db_prefix;
|
---|
23 | var $xoops_db_name;
|
---|
24 | var $xoops_db_user;
|
---|
25 | var $xoops_db_pass;
|
---|
26 | var $xoops_db_host;
|
---|
27 | var $module_name;
|
---|
28 | var $module_path;
|
---|
29 | var $module_url;
|
---|
30 | var $module_db_prefix;
|
---|
31 | var $module_version;
|
---|
32 | var $module_codename;
|
---|
33 | var $xoops_upload_path;
|
---|
34 | var $xoops_upload_url;
|
---|
35 | var $xoops_db_salt;
|
---|
36 | var $xoops_salt;
|
---|
37 | var $is_impress;
|
---|
38 | var $impress_db_config_file;
|
---|
39 | var $is_wpmu;
|
---|
40 | var $mu_domain_current_site;
|
---|
41 | var $mu_path_current_site;
|
---|
42 | var $wp_db_version;
|
---|
43 | var $wp_version;
|
---|
44 | var $is_wp_me;
|
---|
45 |
|
---|
46 | function __constructor() //for PHP5
|
---|
47 | {
|
---|
48 | $this->ConfigFromXoops();
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 | function xpress_eval($str){
|
---|
53 | $eval_str = '$ret = ' . $str . ' ;';
|
---|
54 | eval($eval_str);
|
---|
55 | return $ret;
|
---|
56 | }
|
---|
57 |
|
---|
58 | function ConfigFromXoops() //for PHP4 constructor
|
---|
59 | {
|
---|
60 | $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
|
---|
61 | $this->module_path=dirname(dirname(__FILE__));
|
---|
62 | $this->module_name=basename($this->module_path);
|
---|
63 | $this->xp_config_file_path = $this->module_path . '/xp-config.php';
|
---|
64 |
|
---|
65 | // start /admin/index.php page detect
|
---|
66 | $php_script_name = $_SERVER['SCRIPT_NAME'];
|
---|
67 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
68 | $admin_page = basename(dirname(dirname(__FILE__))) . '/admin/index.php';
|
---|
69 | $is_xoops_module_admin = false;
|
---|
70 | if (strstr($php_script_name,$admin_page) !== false) $is_xoops_module_admin = true;
|
---|
71 | if (strstr($php_query_string,$admin_page) !== false) $is_xoops_module_admin = true;
|
---|
72 | // end of /admin/index.php page detect
|
---|
73 |
|
---|
74 | if (file_exists($this->xp_config_file_path)){ // file exists xp-config.php
|
---|
75 | $this->_get_value_by_xp_config_file();
|
---|
76 | }else if (defined('XOOPS_MAINFILE_INCLUDED') && !$is_xoops_module_admin){ // loaded XOOPS mainfile.php
|
---|
77 | $this->_get_value_by_xoops_define();
|
---|
78 | } else { // A set value is acquired from mainfile.php by the pattern match.
|
---|
79 | if(file_exists($this->xoops_mainfile_path)){
|
---|
80 | $this->_get_value_by_xoops_mainfile();
|
---|
81 | // Value 'is_impress' and value 'external_define_path' used in the under
|
---|
82 | // are set in _get_value_by_xoops_mainfile().
|
---|
83 | if ($this->is_impress){ // DB Config from Impress CMS impress_db_config file
|
---|
84 | $this->_get_value_by_impress_db_config_file();
|
---|
85 | } else if(!empty($this->external_define_path)){ // file exists mainfile.php in the trust pass.
|
---|
86 | $this->_get_value_by_trust_mainfile();
|
---|
87 | }
|
---|
88 | } // end of if file_exists
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 | // define from /settings/definition.inc.php (XCL) or /include/common.php(2016a-JP)
|
---|
93 | $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
|
---|
94 | $this->xoops_upload_url = $this->xoops_url . '/uploads';
|
---|
95 |
|
---|
96 | if ($this->module_name == 'wordpress')
|
---|
97 | $this->module_db_prefix = $this->xoops_db_prefix . '_wp_';
|
---|
98 | else
|
---|
99 | $this->module_db_prefix = $this->xoops_db_prefix . '_' . $this->module_name . '_';
|
---|
100 |
|
---|
101 | $this->set_module_version();
|
---|
102 | $this->set_wp_version();
|
---|
103 | $this->set_mu_current_site();
|
---|
104 | }
|
---|
105 |
|
---|
106 | // A set value is acquired from XOOPS mainfile.php by the pattern match.
|
---|
107 | function _get_value_by_xoops_mainfile(){
|
---|
108 | $array_file = file($this->xoops_mainfile_path);
|
---|
109 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
|
---|
110 | $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
|
---|
111 | $external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
|
---|
112 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
113 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
114 | $keys = $matchs[1];
|
---|
115 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
116 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
117 | $key_value = $matchs[2];
|
---|
118 |
|
---|
119 | switch ($keys){
|
---|
120 | case 'XOOPS_ROOT_PATH':
|
---|
121 | $this->xoops_root_path = $this->xpress_eval($key_value);
|
---|
122 | break;
|
---|
123 | case 'XOOPS_URL':
|
---|
124 | $this->xoops_url = $this->xpress_eval($key_value);
|
---|
125 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
126 | break;
|
---|
127 | case 'XOOPS_TRUST_PATH':
|
---|
128 | $this->xoops_trust_path = $this->xpress_eval($key_value);
|
---|
129 | break;
|
---|
130 | case 'XOOPS_DB_PREFIX':
|
---|
131 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
132 | break;
|
---|
133 | case 'XOOPS_DB_NAME':
|
---|
134 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
135 | break;
|
---|
136 | case 'XOOPS_DB_USER':
|
---|
137 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
138 | break;
|
---|
139 | case 'XOOPS_DB_PASS':
|
---|
140 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
141 | break;
|
---|
142 | case 'XOOPS_DB_HOST':
|
---|
143 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
144 | break;
|
---|
145 | case 'XOOPS_DB_SALT':
|
---|
146 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
147 | break;
|
---|
148 | case 'XOOPS_SALT':
|
---|
149 | $this->xoops_salt = $this->xpress_eval($key_value);
|
---|
150 | break;
|
---|
151 | default :
|
---|
152 |
|
---|
153 | } // end of switch
|
---|
154 | } // end of if preg_match
|
---|
155 |
|
---|
156 | // Check External Define File
|
---|
157 | if (preg_match('/' . $external_define_file_pattern . '/' ,$array_file[$i],$trust_main_matchs)){
|
---|
158 | $include_path = $this->xpress_eval($trust_main_matchs[2]);
|
---|
159 | if (file_exists($include_path))
|
---|
160 | $this->external_define_path = $include_path;
|
---|
161 | }
|
---|
162 |
|
---|
163 | // Check ImpressCMS
|
---|
164 | if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
|
---|
165 | $this->is_impress = true;
|
---|
166 | $this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
|
---|
167 | }
|
---|
168 | } // end of for loop
|
---|
169 | }
|
---|
170 | // A set value is acquired from XOOPS define value .
|
---|
171 | function _get_value_by_xoops_define(){
|
---|
172 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
173 | $this->xoops_url = XOOPS_URL;
|
---|
174 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
175 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
176 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
177 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
178 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
179 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
180 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
181 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
182 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
183 | }
|
---|
184 | // A set value is acquired from xp-config.php .
|
---|
185 | function _get_value_by_xp_config_file(){
|
---|
186 | require_once($this->xp_config_file_path);
|
---|
187 | $this->xoops_root_path =XP_XOOPS_ROOT_PATH;
|
---|
188 | $this->xoops_url = XP_XOOPS_URL;
|
---|
189 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
190 | if(defined('XP_XOOPS_TRUST_PATH')) $this->xoops_trust_path = XP_XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
191 | $this->xoops_db_prefix = XP_XOOPS_DB_PREFIX;
|
---|
192 | $this->xoops_db_name = XP_XOOPS_DB_NAME;
|
---|
193 | $this->xoops_db_user = XP_XOOPS_DB_USER;
|
---|
194 | $this->xoops_db_pass = XP_XOOPS_DB_PASS;
|
---|
195 | $this->xoops_db_host = XP_XOOPS_DB_HOST;
|
---|
196 | if(defined('XP_XOOPS_DB_SALT')) $this->xoops_db_salt = XP_XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
197 | if(defined('XOOPS_SALT')) $this->xoops_salt = XP_XOOPS_SALT; else $this->xoops_salt = '';
|
---|
198 | }
|
---|
199 |
|
---|
200 | // A set value is acquired from config file in the trust pass by the pattern match.
|
---|
201 | function _get_value_by_impress_db_config_file(){
|
---|
202 | if(file_exists($this->impress_db_config_file)){
|
---|
203 | $array_file = file($this->impress_db_config_file);
|
---|
204 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
|
---|
205 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
206 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
207 | $keys = $matchs[1];
|
---|
208 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
209 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
210 | $key_value = $matchs[2];
|
---|
211 |
|
---|
212 | switch ($keys){
|
---|
213 | case 'SDATA_DB_SALT':
|
---|
214 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
215 | break;
|
---|
216 | case 'SDATA_DB_PREFIX':
|
---|
217 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
218 | break;
|
---|
219 | case 'SDATA_DB_NAME':
|
---|
220 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
221 | break;
|
---|
222 | case 'SDATA_DB_USER':
|
---|
223 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
224 | break;
|
---|
225 | case 'SDATA_DB_PASS':
|
---|
226 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
227 | break;
|
---|
228 | case 'SDATA_DB_HOST':
|
---|
229 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
230 | break;
|
---|
231 | default :
|
---|
232 |
|
---|
233 | } // end of switch
|
---|
234 | }
|
---|
235 | } // end of for
|
---|
236 | } // end of if file_exists
|
---|
237 | }
|
---|
238 |
|
---|
239 | function _get_value_by_trust_mainfile(){
|
---|
240 | // When the definition is written in mainfile.php in the trust passing
|
---|
241 | if(file_exists($this->external_define_path)){
|
---|
242 | require_once($this->external_define_path);
|
---|
243 |
|
---|
244 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
245 | $this->xoops_url = XOOPS_URL;
|
---|
246 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
247 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
248 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
249 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
250 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
251 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
252 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
253 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
254 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
255 | } // end of if file_exists
|
---|
256 | }
|
---|
257 |
|
---|
258 | function get_xoops_mainfile_path(){
|
---|
259 | return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
|
---|
260 | }
|
---|
261 |
|
---|
262 | // set XPressME module virsion and codename from xoops_versions.php
|
---|
263 | function set_module_version(){
|
---|
264 | $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
|
---|
265 | if(file_exists($xoops_version_file)){
|
---|
266 | $version_file = file($xoops_version_file);
|
---|
267 | $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
268 | $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
269 | $version_found = false;
|
---|
270 | $codename_found = false;
|
---|
271 | for ($i = 0 ; $i <count($version_file) ; $i++){
|
---|
272 | if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
|
---|
273 | $this->module_version = $v_matches[2];
|
---|
274 | $version_found = true;
|
---|
275 | }
|
---|
276 | if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
|
---|
277 | $this->module_codename = $c_matches[2];
|
---|
278 | $codename_found = true;
|
---|
279 | }
|
---|
280 | if ( $version_found && $codename_found ) break;
|
---|
281 | }
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | function set_wp_version(){
|
---|
286 | include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
|
---|
287 |
|
---|
288 | if (empty($wpmu_version))
|
---|
289 | $this->is_wpmu = false;
|
---|
290 | else
|
---|
291 | $this->is_wpmu = true;
|
---|
292 |
|
---|
293 | $this->wp_db_version = $wp_db_version;
|
---|
294 |
|
---|
295 | $this->wp_version = str_replace("ME", "", $wp_version);
|
---|
296 |
|
---|
297 | $pattern = 'ME.*';
|
---|
298 | if (preg_match('/' . $pattern . '/' ,$wp_version)){
|
---|
299 | $this->is_wp_me = true;
|
---|
300 | } else {
|
---|
301 | $this->is_wp_me = true;
|
---|
302 | }
|
---|
303 | }
|
---|
304 |
|
---|
305 | function set_mu_current_site(){
|
---|
306 | $pattern = 'http:\/\/([^\/]*).*';
|
---|
307 | if (preg_match('/' . $pattern . '/' ,$this->xoops_url,$matchs)){
|
---|
308 | $this->mu_domain_current_site = $matchs[1];
|
---|
309 | }
|
---|
310 |
|
---|
311 | $pattern = 'http:\/\/[^\/]*(\/.*)';
|
---|
312 | if (preg_match('/' . $pattern . '/' ,$this->module_url,$matchs)){
|
---|
313 | $this->mu_path_current_site = $matchs[1] . '/';
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | }
|
---|
318 | ?>
|
---|