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