[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();
|
---|
| 17 | var $xoops_root_path;
|
---|
| 18 | var $xoops_url;
|
---|
| 19 | var $xoops_trust_path;
|
---|
| 20 | var $xoops_db_prefix;
|
---|
| 21 | var $xoops_db_name;
|
---|
| 22 | var $xoops_db_user;
|
---|
| 23 | var $xoops_db_pass;
|
---|
| 24 | var $xoops_db_host;
|
---|
| 25 | var $module_name;
|
---|
| 26 | var $module_path;
|
---|
| 27 | var $module_url;
|
---|
[95] | 28 | var $module_db_prefix;
|
---|
[113] | 29 | var $module_version;
|
---|
| 30 | var $module_codename;
|
---|
[95] | 31 | var $xoops_upload_path;
|
---|
| 32 | var $xoops_upload_url;
|
---|
[129] | 33 | var $xoops_db_salt;
|
---|
[159] | 34 | var $xoops_salt;
|
---|
[129] | 35 | var $is_impress;
|
---|
| 36 | var $impress_db_config_file;
|
---|
[92] | 37 |
|
---|
[95] | 38 |
|
---|
[92] | 39 | function __constructor() //for PHP5
|
---|
| 40 | {
|
---|
| 41 | $this->ConfigFromXoops();
|
---|
[95] | 42 |
|
---|
[92] | 43 | }
|
---|
[159] | 44 |
|
---|
| 45 | function xpress_eval($str){
|
---|
| 46 | $eval_str = '$ret = ' . $str . ' ;';
|
---|
| 47 | eval($eval_str);
|
---|
| 48 | return $ret;
|
---|
| 49 | }
|
---|
[92] | 50 |
|
---|
| 51 | function ConfigFromXoops() //for PHP4 constructor
|
---|
| 52 | {
|
---|
| 53 | $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
|
---|
| 54 | $this->module_path=dirname(dirname(__FILE__));
|
---|
| 55 | $this->module_name=basename($this->module_path);
|
---|
| 56 | if(file_exists($this->xoops_mainfile_path)){
|
---|
| 57 | $array_file = file($this->xoops_mainfile_path);
|
---|
[167] | 58 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
|
---|
[129] | 59 | $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
|
---|
[92] | 60 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
[129] | 61 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
| 62 | $keys = $matchs[1];
|
---|
| 63 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
| 64 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
| 65 | $key_value = $matchs[2];
|
---|
[159] | 66 |
|
---|
[129] | 67 | switch ($keys){
|
---|
[92] | 68 | case 'XOOPS_ROOT_PATH':
|
---|
[159] | 69 | $this->xoops_root_path = $this->xpress_eval($key_value);
|
---|
[92] | 70 | $this->xoops_url . '/modules/' . $this->module_name;
|
---|
| 71 | break;
|
---|
| 72 | case 'XOOPS_URL':
|
---|
[159] | 73 | $this->xoops_url = $this->xpress_eval($key_value);
|
---|
[92] | 74 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
| 75 | break;
|
---|
| 76 | case 'XOOPS_TRUST_PATH':
|
---|
[159] | 77 | $this->xoops_trust_path = $this->xpress_eval($key_value);
|
---|
[92] | 78 | break;
|
---|
| 79 | case 'XOOPS_DB_PREFIX':
|
---|
[159] | 80 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
[92] | 81 | break;
|
---|
| 82 | case 'XOOPS_DB_NAME':
|
---|
[159] | 83 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
[92] | 84 | break;
|
---|
| 85 | case 'XOOPS_DB_USER':
|
---|
[159] | 86 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
[92] | 87 | break;
|
---|
| 88 | case 'XOOPS_DB_PASS':
|
---|
[159] | 89 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
[92] | 90 | break;
|
---|
| 91 | case 'XOOPS_DB_HOST':
|
---|
[159] | 92 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
[92] | 93 | break;
|
---|
[129] | 94 | case 'XOOPS_DB_SALT':
|
---|
[159] | 95 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
[129] | 96 | break;
|
---|
[159] | 97 | case 'XOOPS_SALT':
|
---|
| 98 | $this->xoops_salt = $this->xpress_eval($key_value);
|
---|
| 99 | break;
|
---|
[92] | 100 | default :
|
---|
[129] | 101 |
|
---|
| 102 | } // end of switch
|
---|
| 103 | } // end of if preg_match
|
---|
| 104 |
|
---|
| 105 | // Check ImpressCMS
|
---|
| 106 | if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
|
---|
| 107 | $this->is_impress = true;
|
---|
| 108 | $this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
|
---|
| 109 | }
|
---|
| 110 | } // end of for loop
|
---|
| 111 | } // end of if file_exists
|
---|
| 112 |
|
---|
| 113 | // DB Config from Impress CMS impress_db_config file
|
---|
| 114 | if ($this->is_impress){
|
---|
| 115 | if(file_exists($this->impress_db_config_file)){
|
---|
| 116 | $array_file = file($this->impress_db_config_file);
|
---|
| 117 | $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
|
---|
| 118 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
| 119 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
| 120 | $keys = $matchs[1];
|
---|
| 121 | if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
|
---|
| 122 | if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
|
---|
| 123 | $key_value = $matchs[2];
|
---|
[159] | 124 |
|
---|
[129] | 125 | switch ($keys){
|
---|
| 126 | case 'SDATA_DB_SALT':
|
---|
[159] | 127 | $this->xoops_db_salt = $this->xpress_eval($key_value);
|
---|
[129] | 128 | break;
|
---|
| 129 | case 'SDATA_DB_PREFIX':
|
---|
[159] | 130 | $this->xoops_db_prefix = $this->xpress_eval($key_value);
|
---|
[129] | 131 | break;
|
---|
| 132 | case 'SDATA_DB_NAME':
|
---|
[159] | 133 | $this->xoops_db_name = $this->xpress_eval($key_value);
|
---|
[129] | 134 | break;
|
---|
| 135 | case 'SDATA_DB_USER':
|
---|
[159] | 136 | $this->xoops_db_user = $this->xpress_eval($key_value);
|
---|
[129] | 137 | break;
|
---|
| 138 | case 'SDATA_DB_PASS':
|
---|
[159] | 139 | $this->xoops_db_pass = $this->xpress_eval($key_value);
|
---|
[129] | 140 | break;
|
---|
| 141 | case 'SDATA_DB_HOST':
|
---|
[159] | 142 | $this->xoops_db_host = $this->xpress_eval($key_value);
|
---|
[129] | 143 | break;
|
---|
| 144 | default :
|
---|
| 145 |
|
---|
| 146 | } // end of switch
|
---|
[92] | 147 | }
|
---|
[129] | 148 | } // end of for
|
---|
[92] | 149 | }
|
---|
| 150 | }
|
---|
[129] | 151 |
|
---|
[95] | 152 | // define from /settings/definition.inc.php (XCL) or /include/common.php(2016a-JP)
|
---|
| 153 | $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
|
---|
| 154 | $this->xoops_upload_url = $this->xoops_url . '/uploads';
|
---|
| 155 |
|
---|
| 156 | if ($this->module_name == 'wordpress')
|
---|
| 157 | $this->module_db_prefix = $this->xoops_db_prefix . '_wp_';
|
---|
| 158 | else
|
---|
| 159 | $this->module_db_prefix = $this->xoops_db_prefix . '_' . $this->module_name . '_';
|
---|
| 160 |
|
---|
[113] | 161 | $this->set_module_version();
|
---|
| 162 |
|
---|
[92] | 163 | }
|
---|
| 164 |
|
---|
| 165 | function get_xoops_mainfile_path(){
|
---|
| 166 | return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
|
---|
| 167 | }
|
---|
[113] | 168 |
|
---|
| 169 | // set XPressME module virsion and codename from xoops_versions.php
|
---|
| 170 | function set_module_version(){
|
---|
| 171 | $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
|
---|
| 172 | if(file_exists($xoops_version_file)){
|
---|
| 173 | $version_file = file($xoops_version_file);
|
---|
[129] | 174 | $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
| 175 | $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
[113] | 176 | $version_found = false;
|
---|
| 177 | $codename_found = false;
|
---|
| 178 | for ($i = 0 ; $i <count($version_file) ; $i++){
|
---|
| 179 | if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
|
---|
| 180 | $this->module_version = $v_matches[2];
|
---|
| 181 | $version_found = true;
|
---|
| 182 | }
|
---|
| 183 | if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
|
---|
| 184 | $this->module_codename = $c_matches[2];
|
---|
| 185 | $codename_found = true;
|
---|
| 186 | }
|
---|
| 187 | if ( $version_found && $codename_found ) break;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[92] | 192 | }
|
---|
| 193 | ?>
|
---|