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