[92] | 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();
|
---|
[326] | 17 | var $external_define_path;
|
---|
[92] | 18 | var $xoops_root_path;
|
---|
| 19 | var $xoops_url;
|
---|
| 20 | var $xoops_trust_path;
|
---|
| 21 | var $xoops_db_prefix;
|
---|
| 22 | var $xoops_db_name;
|
---|
| 23 | var $xoops_db_user;
|
---|
| 24 | var $xoops_db_pass;
|
---|
| 25 | var $xoops_db_host;
|
---|
| 26 | var $module_name;
|
---|
| 27 | var $module_path;
|
---|
| 28 | var $module_url;
|
---|
[95] | 29 | var $module_db_prefix;
|
---|
[113] | 30 | var $module_version;
|
---|
| 31 | var $module_codename;
|
---|
[95] | 32 | var $xoops_upload_path;
|
---|
| 33 | var $xoops_upload_url;
|
---|
[129] | 34 | var $xoops_db_salt;
|
---|
[159] | 35 | var $xoops_salt;
|
---|
[129] | 36 | var $is_impress;
|
---|
| 37 | var $impress_db_config_file;
|
---|
[209] | 38 | var $is_wpmu;
|
---|
| 39 | var $mu_domain_current_site;
|
---|
| 40 | var $mu_path_current_site;
|
---|
[252] | 41 | var $wp_db_version;
|
---|
| 42 | var $is_wp20;
|
---|
[92] | 43 |
|
---|
| 44 | function __constructor() //for PHP5
|
---|
| 45 | {
|
---|
| 46 | $this->ConfigFromXoops();
|
---|
[95] | 47 |
|
---|
[92] | 48 | }
|
---|
[159] | 49 |
|
---|
| 50 | function xpress_eval($str){
|
---|
| 51 | $eval_str = '$ret = ' . $str . ' ;';
|
---|
| 52 | eval($eval_str);
|
---|
| 53 | return $ret;
|
---|
| 54 | }
|
---|
[92] | 55 |
|
---|
| 56 | function ConfigFromXoops() //for PHP4 constructor
|
---|
| 57 | {
|
---|
| 58 | $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
|
---|
[326] | 59 | $this->module_path=dirname(dirname(__FILE__));
|
---|
[92] | 60 | $this->module_name=basename($this->module_path);
|
---|
[326] | 61 | if (defined('XOOPS_MAINFILE_INCLUDED')){
|
---|
| 62 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
| 63 | $this->xoops_url = XOOPS_URL;
|
---|
| 64 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
| 65 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
| 66 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
| 67 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
| 68 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
| 69 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
| 70 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
| 71 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
| 72 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
| 73 | } else {
|
---|
| 74 | if(file_exists($this->xoops_mainfile_path)){
|
---|
| 75 | $array_file = file($this->xoops_mainfile_path);
|
---|
| 76 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
|
---|
| 77 | $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
|
---|
| 78 | $external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
|
---|
[129] | 79 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
| 80 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
| 81 | $keys = $matchs[1];
|
---|
| 82 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
| 83 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
| 84 | $key_value = $matchs[2];
|
---|
[159] | 85 |
|
---|
[129] | 86 | switch ($keys){
|
---|
[326] | 87 | case 'XOOPS_ROOT_PATH':
|
---|
| 88 | $this->xoops_root_path = $this->xpress_eval($key_value);
|
---|
[129] | 89 | break;
|
---|
[326] | 90 | case 'XOOPS_URL':
|
---|
| 91 | $this->xoops_url = $this->xpress_eval($key_value);
|
---|
| 92 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
| 93 | break;
|
---|
| 94 | case 'XOOPS_TRUST_PATH':
|
---|
| 95 | $this->xoops_trust_path = $this->xpress_eval($key_value);
|
---|
| 96 | break;
|
---|
| 97 | case 'XOOPS_DB_PREFIX':
|
---|
[159] | 98 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
[129] | 99 | break;
|
---|
[326] | 100 | case 'XOOPS_DB_NAME':
|
---|
[159] | 101 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
[129] | 102 | break;
|
---|
[326] | 103 | case 'XOOPS_DB_USER':
|
---|
[159] | 104 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
[129] | 105 | break;
|
---|
[326] | 106 | case 'XOOPS_DB_PASS':
|
---|
[159] | 107 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
[129] | 108 | break;
|
---|
[326] | 109 | case 'XOOPS_DB_HOST':
|
---|
[159] | 110 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
[129] | 111 | break;
|
---|
[326] | 112 | case 'XOOPS_DB_SALT':
|
---|
| 113 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
| 114 | break;
|
---|
| 115 | case 'XOOPS_SALT':
|
---|
| 116 | $this->xoops_salt = $this->xpress_eval($key_value);
|
---|
| 117 | break;
|
---|
[129] | 118 | default :
|
---|
| 119 |
|
---|
| 120 | } // end of switch
|
---|
[326] | 121 | } // end of if preg_match
|
---|
| 122 |
|
---|
| 123 | // Check External Define File
|
---|
| 124 | if (preg_match('/' . $external_define_file_pattern . '/' ,$array_file[$i],$trust_main_matchs)){
|
---|
| 125 | $include_path = $this->xpress_eval($trust_main_matchs[2]);
|
---|
| 126 | if (file_exists($include_path))
|
---|
| 127 | $this->external_define_path = $include_path;
|
---|
[92] | 128 | }
|
---|
[326] | 129 |
|
---|
| 130 | // Check ImpressCMS
|
---|
| 131 | if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
|
---|
| 132 | $this->is_impress = true;
|
---|
| 133 | $this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
|
---|
| 134 | }
|
---|
| 135 | } // end of for loop
|
---|
| 136 | } // end of if file_exists
|
---|
| 137 |
|
---|
| 138 | // DB Config from Impress CMS impress_db_config file
|
---|
| 139 | if ($this->is_impress){
|
---|
| 140 | if(file_exists($this->impress_db_config_file)){
|
---|
| 141 | $array_file = file($this->impress_db_config_file);
|
---|
| 142 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
|
---|
| 143 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
| 144 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
| 145 | $keys = $matchs[1];
|
---|
| 146 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
| 147 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
| 148 | $key_value = $matchs[2];
|
---|
| 149 |
|
---|
| 150 | switch ($keys){
|
---|
| 151 | case 'SDATA_DB_SALT':
|
---|
| 152 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
| 153 | break;
|
---|
| 154 | case 'SDATA_DB_PREFIX':
|
---|
| 155 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
| 156 | break;
|
---|
| 157 | case 'SDATA_DB_NAME':
|
---|
| 158 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
| 159 | break;
|
---|
| 160 | case 'SDATA_DB_USER':
|
---|
| 161 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
| 162 | break;
|
---|
| 163 | case 'SDATA_DB_PASS':
|
---|
| 164 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
| 165 | break;
|
---|
| 166 | case 'SDATA_DB_HOST':
|
---|
| 167 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
| 168 | break;
|
---|
| 169 | default :
|
---|
| 170 |
|
---|
| 171 | } // end of switch
|
---|
| 172 | }
|
---|
| 173 | } // end of for
|
---|
| 174 | } // end of if file_exists
|
---|
| 175 | } // end ofImpress CMS
|
---|
| 176 |
|
---|
| 177 | // DB Config from external define file
|
---|
| 178 | if(!empty($this->external_define_path)){
|
---|
| 179 | if(file_exists($this->external_define_path)){
|
---|
| 180 | require_once($this->external_define_path);
|
---|
| 181 |
|
---|
| 182 | $this->xoops_root_path = XOOPS_ROOT_PATH;
|
---|
| 183 | $this->xoops_url = XOOPS_URL;
|
---|
| 184 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
| 185 | if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
|
---|
| 186 | $this->xoops_db_prefix = XOOPS_DB_PREFIX;
|
---|
| 187 | $this->xoops_db_name = XOOPS_DB_NAME;
|
---|
| 188 | $this->xoops_db_user = XOOPS_DB_USER;
|
---|
| 189 | $this->xoops_db_pass = XOOPS_DB_PASS;
|
---|
| 190 | $this->xoops_db_host = XOOPS_DB_HOST;
|
---|
| 191 | if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
|
---|
| 192 | if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
|
---|
| 193 | } // end of if file_exists
|
---|
[92] | 194 | }
|
---|
| 195 | }
|
---|
[326] | 196 |
|
---|
[129] | 197 |
|
---|
[95] | 198 | // define from /settings/definition.inc.php (XCL) or /include/common.php(2016a-JP)
|
---|
| 199 | $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
|
---|
| 200 | $this->xoops_upload_url = $this->xoops_url . '/uploads';
|
---|
| 201 |
|
---|
| 202 | if ($this->module_name == 'wordpress')
|
---|
| 203 | $this->module_db_prefix = $this->xoops_db_prefix . '_wp_';
|
---|
| 204 | else
|
---|
| 205 | $this->module_db_prefix = $this->xoops_db_prefix . '_' . $this->module_name . '_';
|
---|
| 206 |
|
---|
[113] | 207 | $this->set_module_version();
|
---|
[252] | 208 | $this->set_wp_version();
|
---|
[209] | 209 | $this->set_mu_current_site();
|
---|
[92] | 210 | }
|
---|
| 211 |
|
---|
| 212 | function get_xoops_mainfile_path(){
|
---|
| 213 | return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
|
---|
| 214 | }
|
---|
[113] | 215 |
|
---|
| 216 | // set XPressME module virsion and codename from xoops_versions.php
|
---|
| 217 | function set_module_version(){
|
---|
| 218 | $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
|
---|
| 219 | if(file_exists($xoops_version_file)){
|
---|
| 220 | $version_file = file($xoops_version_file);
|
---|
[129] | 221 | $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
| 222 | $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
[113] | 223 | $version_found = false;
|
---|
| 224 | $codename_found = false;
|
---|
| 225 | for ($i = 0 ; $i <count($version_file) ; $i++){
|
---|
| 226 | if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
|
---|
| 227 | $this->module_version = $v_matches[2];
|
---|
| 228 | $version_found = true;
|
---|
| 229 | }
|
---|
| 230 | if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
|
---|
| 231 | $this->module_codename = $c_matches[2];
|
---|
| 232 | $codename_found = true;
|
---|
| 233 | }
|
---|
| 234 | if ( $version_found && $codename_found ) break;
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[252] | 239 | function set_wp_version(){
|
---|
[209] | 240 | include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
|
---|
| 241 |
|
---|
| 242 | if (empty($wpmu_version))
|
---|
| 243 | $this->is_wpmu = false;
|
---|
| 244 | else
|
---|
| 245 | $this->is_wpmu = true;
|
---|
[252] | 246 |
|
---|
| 247 | $this->wp_db_version = $wp_db_version;
|
---|
| 248 | if ($wp_db_version == 3441)
|
---|
| 249 | $this->is_wp20 = true;
|
---|
| 250 | else
|
---|
| 251 | $this->is_wp20 = false;
|
---|
| 252 |
|
---|
[209] | 253 | }
|
---|
| 254 |
|
---|
| 255 | function set_mu_current_site(){
|
---|
| 256 | $pattern = 'http:\/\/([^\/]*).*';
|
---|
| 257 | if (preg_match('/' . $pattern . '/' ,$this->xoops_url,$matchs)){
|
---|
| 258 | $this->mu_domain_current_site = $matchs[1];
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | $pattern = 'http:\/\/[^\/]*(\/.*)';
|
---|
| 262 | if (preg_match('/' . $pattern . '/' ,$this->module_url,$matchs)){
|
---|
| 263 | $this->mu_path_current_site = $matchs[1] . '/';
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[92] | 267 | }
|
---|
| 268 | ?>
|
---|