XPressME Integration Kit

Trac

source: trunk/class/config_from_xoops.class.php @ 167

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

Bump Ver0.29 #92 の修正がうまくいっていなかったので再修正

File size: 6.5 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       
38       
39        function __constructor()        //for PHP5
40    {
41        $this->ConfigFromXoops();
42       
43    }
44   
45    function xpress_eval($str){
46        $eval_str = '$ret = ' . $str . ' ;';
47        eval($eval_str);
48        return $ret;
49    }
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);
58                        $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
59                        $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
60                        for ($i = 0 ; $i <count($array_file) ; $i++){
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];
66
67                                        switch ($keys){
68                                                case  'XOOPS_ROOT_PATH':
69                                                        $this->xoops_root_path = $this->xpress_eval($key_value);
70                                                        $this->xoops_url . '/modules/' . $this->module_name;
71                                                        break;
72                                                case  'XOOPS_URL':
73                                                        $this->xoops_url = $this->xpress_eval($key_value);
74                                                        $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
75                                                        break;
76                                                case  'XOOPS_TRUST_PATH':
77                                                        $this->xoops_trust_path = $this->xpress_eval($key_value);
78                                                        break;
79                                                case  'XOOPS_DB_PREFIX':
80                                                        $this->xoops_db_prefix = $this->xpress_eval($key_value);
81                                                        break;
82                                                case  'XOOPS_DB_NAME':
83                                                        $this->xoops_db_name = $this->xpress_eval($key_value);
84                                                        break;
85                                                case  'XOOPS_DB_USER':
86                                                        $this->xoops_db_user = $this->xpress_eval($key_value);
87                                                        break;
88                                                case  'XOOPS_DB_PASS':
89                                                        $this->xoops_db_pass = $this->xpress_eval($key_value);
90                                                        break;
91                                                case  'XOOPS_DB_HOST':
92                                                        $this->xoops_db_host = $this->xpress_eval($key_value);
93                                                        break;
94                                                case  'XOOPS_DB_SALT':
95                                                        $this->xoops_db_salt = $this->xpress_eval($key_value);
96                                                        break;
97                                                case  'XOOPS_SALT':
98                                                        $this->xoops_salt = $this->xpress_eval($key_value);
99                                                        break;
100                                                default :
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];
124
125                                                switch ($keys){
126                                                        case  'SDATA_DB_SALT':
127                                                                $this->xoops_db_salt = $this->xpress_eval($key_value);
128                                                                break;
129                                                        case  'SDATA_DB_PREFIX':
130                                                                $this->xoops_db_prefix = $this->xpress_eval($key_value);
131                                                                break;
132                                                        case  'SDATA_DB_NAME':
133                                                                $this->xoops_db_name = $this->xpress_eval($key_value);
134                                                                break;
135                                                        case  'SDATA_DB_USER':
136                                                                $this->xoops_db_user = $this->xpress_eval($key_value);
137                                                                break;
138                                                        case  'SDATA_DB_PASS':
139                                                                $this->xoops_db_pass = $this->xpress_eval($key_value);
140                                                                break;
141                                                        case  'SDATA_DB_HOST':
142                                                                $this->xoops_db_host = $this->xpress_eval($key_value);
143                                                                break;
144                                                        default :
145                                                               
146                                                }       // end of switch
147                                        }
148                                } // end of for
149                        }
150                }
151                       
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               
161                $this->set_module_version();
162               
163    }
164   
165    function get_xoops_mainfile_path(){
166        return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
167    }
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);
174                        $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
175                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
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   
192}
193?>
Note: See TracBrowser for help on using the repository browser.