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