XPressME Integration Kit

Trac

source: branches/Ver2.0/xpressme_integration_kit/class/config_from_xoops.class.php @ 326

Last change on this file since 326 was 326, checked in by toemon, 15 years ago

XOOPS mainfile.phpの構成によりDB接続情報が取得できない場合への対応 fixes #174

  1. trust_path側の定義ファイル名はmainfile.phpであること。
  2. trust_path側の定義ファイルmainfile.phpにはdefine()部分だけを置くこと(パターンマッチングではなくinclude_onceすることにより、条件分岐を可能にする)
  3. XOOPS_ROOT_PATH/mainfile.php側では、require_once(trust_path側の定義ファイルmainfile.php) とXOOPSロードの部分を置くこと。

の条件下ででの対応を行う

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