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