XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/class/config_from_xoops.class.php @ 232

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

external追加に伴うフォルダー構成変更

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