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_cache_path;
|
---|
23 | var $xoops_db_prefix;
|
---|
24 | var $xoops_db_name;
|
---|
25 | var $xoops_db_user;
|
---|
26 | var $xoops_db_pass;
|
---|
27 | var $xoops_db_host;
|
---|
28 | var $module_name;
|
---|
29 | var $module_path;
|
---|
30 | var $module_url;
|
---|
31 | var $module_db_prefix;
|
---|
32 | var $module_version;
|
---|
33 | var $module_codename;
|
---|
34 | var $xoops_upload_path;
|
---|
35 | var $xoops_upload_url;
|
---|
36 | var $xoops_db_salt;
|
---|
37 | var $xoops_salt;
|
---|
38 | var $is_impress;
|
---|
39 | var $impress_db_config_file;
|
---|
40 | var $wp_db_version;
|
---|
41 | var $wp_version;
|
---|
42 | var $is_wp_me;
|
---|
43 | var $xoops_language;
|
---|
44 | var $module_id;
|
---|
45 | var $module_config= array();
|
---|
46 | var $xoops_time_zone;
|
---|
47 | var $xoops_var_path;
|
---|
48 | var $xoops_db_charset;
|
---|
49 | var $xoops_db_pconnect;
|
---|
50 |
|
---|
51 | function __constructor() //for PHP5
|
---|
52 | {
|
---|
53 | $this->ConfigFromXoops();
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | function xpress_eval($str){
|
---|
58 | $eval_str = '$ret = ' . $str . ' ;';
|
---|
59 | eval($eval_str);
|
---|
60 | return $ret;
|
---|
61 | }
|
---|
62 |
|
---|
63 | function ConfigFromXoops() //for PHP4 constructor
|
---|
64 | {
|
---|
65 | $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
|
---|
66 | $this->module_path=dirname(dirname(__FILE__));
|
---|
67 | $this->module_name=basename($this->module_path);
|
---|
68 | $this->xp_config_file_path = $this->module_path . '/xp-config.php';
|
---|
69 |
|
---|
70 | // start /admin/index.php page detect
|
---|
71 | $php_script_name = $_SERVER['SCRIPT_NAME'];
|
---|
72 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
73 | $admin_page = basename(dirname(dirname(__FILE__))) . '/admin/index.php';
|
---|
74 | $is_xoops_module_admin = false;
|
---|
75 | if (strstr($php_script_name,$admin_page) !== false) $is_xoops_module_admin = true;
|
---|
76 | if (strstr($php_query_string,$admin_page) !== false) $is_xoops_module_admin = true;
|
---|
77 | // end of /admin/index.php page detect
|
---|
78 |
|
---|
79 | if (file_exists($this->xp_config_file_path)){ // file exists xp-config.php
|
---|
80 | $this->_get_value_by_xp_config_file();
|
---|
81 | }else if (defined('XOOPS_MAINFILE_INCLUDED') && !$is_xoops_module_admin){ // loaded XOOPS mainfile.php
|
---|
82 | $this->_get_value_by_xoops_define();
|
---|
83 | } else { // A set value is acquired from mainfile.php by the pattern match.
|
---|
84 | if(file_exists($this->xoops_mainfile_path)){
|
---|
85 | $this->_get_value_by_xoops_mainfile();
|
---|
86 |
|
---|
87 | // Xoops2.5 secure.php
|
---|
88 | if (!empty($this->xoops_var_path)){
|
---|
89 | $secure_path = $this->xoops_var_path . "/data/secure.php";
|
---|
90 | if (file_exists($secure_path)){
|
---|
91 | $this->_get_value_by_xoops_secure($secure_path);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | // Value 'is_impress' and value 'external_define_path' used in the under
|
---|
96 | // are set in _get_value_by_xoops_mainfile().
|
---|
97 | if ($this->is_impress){ // DB Config from Impress CMS impress_db_config file
|
---|
98 | $this->_get_value_by_impress_db_config_file();
|
---|
99 | } else if(!empty($this->external_define_path)){ // file exists mainfile.php in the trust pass.
|
---|
100 | $this->_get_value_by_trust_mainfile();
|
---|
101 | }
|
---|
102 | } // end of if file_exists
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 | // define from /settings/definition.inc.php (XCL) or /include/common.php(2016a-JP)
|
---|
107 | $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
|
---|
108 | $this->xoops_upload_url = $this->xoops_url . '/uploads';
|
---|
109 | $this->module_db_prefix = $this->xoops_db_prefix . '_' . preg_replace('/wordpress/','wp',$this->module_name) . '_';
|
---|
110 |
|
---|
111 | $this->set_module_version();
|
---|
112 | $this->set_wp_version();
|
---|
113 | if (function_exists('date_default_timezone_get')){
|
---|
114 | $this->xoops_time_zone = date_default_timezone_get();
|
---|
115 | }
|
---|
116 | $this->_get_cache_path();
|
---|
117 | }
|
---|
118 |
|
---|
119 | // A set value is acquired from XOOPS mainfile.php by the pattern match.
|
---|
120 | function _get_value_by_xoops_mainfile(){
|
---|
121 | $array_file = file($this->xoops_mainfile_path);
|
---|
122 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
|
---|
123 | $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
|
---|
124 | $external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
|
---|
125 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
126 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
127 | $keys = $matchs[1];
|
---|
128 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
129 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
130 | $key_value = $matchs[2];
|
---|
131 |
|
---|
132 | switch ($keys){
|
---|
133 | case 'XOOPS_ROOT_PATH':
|
---|
134 | $this->xoops_root_path = $this->xpress_eval($key_value);
|
---|
135 | break;
|
---|
136 | case 'XOOPS_URL':
|
---|
137 | $this->xoops_url = $this->xpress_eval($key_value);
|
---|
138 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
139 | break;
|
---|
140 | case 'XOOPS_TRUST_PATH':
|
---|
141 | $this->xoops_trust_path = $this->xpress_eval($key_value);
|
---|
142 | break;
|
---|
143 | case 'XOOPS_DB_PREFIX':
|
---|
144 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
145 | break;
|
---|
146 | case 'XOOPS_DB_NAME':
|
---|
147 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
148 | break;
|
---|
149 | case 'XOOPS_DB_USER':
|
---|
150 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
151 | break;
|
---|
152 | case 'XOOPS_DB_PASS':
|
---|
153 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
154 | break;
|
---|
155 | case 'XOOPS_DB_HOST':
|
---|
156 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
157 | break;
|
---|
158 | case 'XOOPS_DB_SALT':
|
---|
159 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
160 | break;
|
---|
161 | case 'XOOPS_SALT':
|
---|
162 | $this->xoops_salt = $this->xpress_eval($key_value);
|
---|
163 | break;
|
---|
164 | case 'XOOPS_VAR_PATH':
|
---|
165 | $this->xoops_var_path = $this->xpress_eval($key_value);
|
---|
166 | break;
|
---|
167 | default :
|
---|
168 |
|
---|
169 | } // end of switch
|
---|
170 | } // end of if preg_match
|
---|
171 |
|
---|
172 | // Check External Define File
|
---|
173 | if (preg_match('/' . $external_define_file_pattern . '/' ,$array_file[$i],$trust_main_matchs)){
|
---|
174 | $include_path = $this->xpress_eval($trust_main_matchs[2]);
|
---|
175 | if (file_exists($include_path))
|
---|
176 | $this->external_define_path = $include_path;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Check ImpressCMS
|
---|
180 | if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
|
---|
181 | $this->is_impress = true;
|
---|
182 | $this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
|
---|
183 | }
|
---|
184 | } // end of for loop
|
---|
185 | }
|
---|
186 | // A set value is acquired from XOOPS mainfile.php by the pattern match.
|
---|
187 | function _get_value_by_xoops_secure($secure_path){
|
---|
188 | $array_file = file($secure_path);
|
---|
189 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
|
---|
190 | $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
|
---|
191 | $external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
|
---|
192 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
193 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
194 | $keys = $matchs[1];
|
---|
195 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
196 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
197 | $key_value = $matchs[2];
|
---|
198 |
|
---|
199 | switch ($keys){
|
---|
200 | case 'XOOPS_DB_PREFIX':
|
---|
201 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
202 | break;
|
---|
203 | case 'XOOPS_DB_NAME':
|
---|
204 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
205 | break;
|
---|
206 | case 'XOOPS_DB_USER':
|
---|
207 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
208 | break;
|
---|
209 | case 'XOOPS_DB_PASS':
|
---|
210 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
211 | break;
|
---|
212 | case 'XOOPS_DB_HOST':
|
---|
213 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
214 | break;
|
---|
215 | case 'XOOPS_DB_SALT':
|
---|
216 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
217 | break;
|
---|
218 | case 'XOOPS_SALT':
|
---|
219 | $this->xoops_salt = $this->xpress_eval($key_value);
|
---|
220 | break;
|
---|
221 | case 'XOOPS_DB_CHARSET':
|
---|
222 | $this->xoops_db_charset = $this->xpress_eval($key_value);
|
---|
223 | break;
|
---|
224 | case 'XOOPS_DB_PCONNECT':
|
---|
225 | $this->xoops_db_pconnect = $this->xpress_eval($key_value);
|
---|
226 | break;
|
---|
227 | default :
|
---|
228 |
|
---|
229 | } // end of switch
|
---|
230 | } // end of if preg_match
|
---|
231 |
|
---|
232 | } // end of for loop
|
---|
233 | }
|
---|
234 | // A set value is acquired from XOOPS define value .
|
---|
235 | function _get_value_by_xoops_define(){
|
---|
236 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
237 | $this->xoops_url = XOOPS_URL;
|
---|
238 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
239 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
240 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
241 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
242 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
243 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
244 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
245 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
246 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
247 | }
|
---|
248 | // A set value is acquired from xp-config.php .
|
---|
249 | function _get_value_by_xp_config_file(){
|
---|
250 | require_once($this->xp_config_file_path);
|
---|
251 | $this->xoops_root_path =XP_XOOPS_ROOT_PATH;
|
---|
252 | $this->xoops_url = XP_XOOPS_URL;
|
---|
253 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
254 | if(defined('XP_XOOPS_TRUST_PATH')) $this->xoops_trust_path = XP_XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
255 | $this->xoops_db_prefix = XP_XOOPS_DB_PREFIX;
|
---|
256 | $this->xoops_db_name = XP_XOOPS_DB_NAME;
|
---|
257 | $this->xoops_db_user = XP_XOOPS_DB_USER;
|
---|
258 | $this->xoops_db_pass = XP_XOOPS_DB_PASS;
|
---|
259 | $this->xoops_db_host = XP_XOOPS_DB_HOST;
|
---|
260 | if(defined('XP_XOOPS_DB_SALT')) $this->xoops_db_salt = XP_XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
261 | if(defined('XOOPS_SALT')) $this->xoops_salt = XP_XOOPS_SALT; else $this->xoops_salt = '';
|
---|
262 | }
|
---|
263 |
|
---|
264 | // A set value is acquired from config file in the trust pass by the pattern match.
|
---|
265 | function _get_value_by_impress_db_config_file(){
|
---|
266 | if(file_exists($this->impress_db_config_file)){
|
---|
267 | $array_file = file($this->impress_db_config_file);
|
---|
268 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
|
---|
269 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
270 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
271 | $keys = $matchs[1];
|
---|
272 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
273 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
274 | $key_value = $matchs[2];
|
---|
275 |
|
---|
276 | switch ($keys){
|
---|
277 | case 'SDATA_DB_SALT':
|
---|
278 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
279 | break;
|
---|
280 | case 'SDATA_DB_PREFIX':
|
---|
281 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
282 | break;
|
---|
283 | case 'SDATA_DB_NAME':
|
---|
284 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
285 | break;
|
---|
286 | case 'SDATA_DB_USER':
|
---|
287 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
288 | break;
|
---|
289 | case 'SDATA_DB_PASS':
|
---|
290 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
291 | break;
|
---|
292 | case 'SDATA_DB_HOST':
|
---|
293 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
294 | break;
|
---|
295 | default :
|
---|
296 |
|
---|
297 | } // end of switch
|
---|
298 | }
|
---|
299 | } // end of for
|
---|
300 | } // end of if file_exists
|
---|
301 | }
|
---|
302 |
|
---|
303 | function _get_value_by_trust_mainfile(){
|
---|
304 | // When the definition is written in mainfile.php in the trust passing
|
---|
305 | if(file_exists($this->external_define_path)){
|
---|
306 | require_once($this->external_define_path);
|
---|
307 |
|
---|
308 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
309 | $this->xoops_url = XOOPS_URL;
|
---|
310 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
311 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
312 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
313 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
314 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
315 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
316 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
317 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
318 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
319 | } // end of if file_exists
|
---|
320 | }
|
---|
321 |
|
---|
322 | // call after the $this->xoops_trust_path is set
|
---|
323 | function _get_cache_path(){
|
---|
324 | $cache_path = $this->xoops_trust_path . '/cache';
|
---|
325 | if (file_exists($cache_path) && is_writable($cache_path)){
|
---|
326 | $this->xoops_cache_path = $cache_path;
|
---|
327 | return;
|
---|
328 | }
|
---|
329 | $this->xoops_cache_path = $this->xoops_root_path . '/cache';
|
---|
330 | }
|
---|
331 |
|
---|
332 | function get_xoops_mainfile_path(){
|
---|
333 | return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
|
---|
334 | }
|
---|
335 |
|
---|
336 | // set XPressME module virsion and codename from xoops_versions.php
|
---|
337 | function set_module_version(){
|
---|
338 | $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
|
---|
339 | if(file_exists($xoops_version_file)){
|
---|
340 | $version_file = file($xoops_version_file);
|
---|
341 | $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
342 | $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
343 | $version_found = false;
|
---|
344 | $codename_found = false;
|
---|
345 | for ($i = 0 ; $i <count($version_file) ; $i++){
|
---|
346 | if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
|
---|
347 | $this->module_version = $v_matches[2];
|
---|
348 | $version_found = true;
|
---|
349 | }
|
---|
350 | if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
|
---|
351 | $this->module_codename = $c_matches[2];
|
---|
352 | $codename_found = true;
|
---|
353 | }
|
---|
354 | if ( $version_found && $codename_found ) break;
|
---|
355 | }
|
---|
356 | }
|
---|
357 | }
|
---|
358 |
|
---|
359 | function set_wp_version(){
|
---|
360 | include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
|
---|
361 |
|
---|
362 | $this->wp_db_version = $wp_db_version;
|
---|
363 |
|
---|
364 | $this->wp_version = str_replace("ME", "", $wp_version);
|
---|
365 |
|
---|
366 | $pattern = 'ME.*';
|
---|
367 | if (preg_match('/' . $pattern . '/' ,$wp_version)){
|
---|
368 | $this->is_wp_me = true;
|
---|
369 | } else {
|
---|
370 | $this->is_wp_me = true;
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | }
|
---|
375 | ?> |
---|