XPressME Integration Kit

Trac

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

Last change on this file since 531 was 531, checked in by toemon, 14 years ago

WordPressMU対応コードの削除 Fixes #294

File size: 13.9 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 $xp_config_file_path;
19        var $xoops_root_path;
20        var $xoops_url;
21        var $xoops_trust_path;
22        var $xoops_db_prefix;
23        var $xoops_db_name;
24        var $xoops_db_user;
25        var $xoops_db_pass;
26        var $xoops_db_host;
27        var $module_name;
28        var $module_path;
29        var $module_url;
30        var $module_db_prefix;
31        var $module_version;
32        var $module_codename;   
33        var $xoops_upload_path;
34        var $xoops_upload_url;
35        var $xoops_db_salt;
36        var $xoops_salt;
37        var $is_impress;
38        var $impress_db_config_file;
39        var $wp_db_version;
40        var $wp_version;
41        var $is_wp_me;
42        var $xoops_language;
43        var $module_id;
44        var $module_config= array();
45       
46        function __constructor()        //for PHP5
47    {
48        $this->ConfigFromXoops();
49       
50    }
51   
52    function xpress_eval($str){
53        $eval_str = '$ret = ' . $str . ' ;';
54        eval($eval_str);
55        return $ret;
56    }
57
58    function ConfigFromXoops()  //for PHP4 constructor
59    { 
60        $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
61        $this->module_path=dirname(dirname(__FILE__));
62        $this->module_name=basename($this->module_path);
63        $this->xp_config_file_path = $this->module_path . '/xp-config.php';
64       
65        // start /admin/index.php page detect
66        $php_script_name = $_SERVER['SCRIPT_NAME'];
67                $php_query_string = $_SERVER['QUERY_STRING'];
68                $admin_page =   basename(dirname(dirname(__FILE__))) . '/admin/index.php';
69                $is_xoops_module_admin = false;
70                if (strstr($php_script_name,$admin_page) !== false) $is_xoops_module_admin = true;
71                if (strstr($php_query_string,$admin_page) !== false) $is_xoops_module_admin = true;
72        // end of /admin/index.php page detect
73       
74        if (file_exists($this->xp_config_file_path)){   // file exists xp-config.php
75                $this->_get_value_by_xp_config_file();
76        }else if (defined('XOOPS_MAINFILE_INCLUDED') && !$is_xoops_module_admin){ // loaded XOOPS mainfile.php
77                $this->_get_value_by_xoops_define();
78        } else {  // A set value is acquired from mainfile.php by the pattern match.
79                        if(file_exists($this->xoops_mainfile_path)){
80                        $this->_get_value_by_xoops_mainfile();
81                        // Value 'is_impress' and value 'external_define_path' used in the under
82                        // are set in _get_value_by_xoops_mainfile().
83                                if ($this->is_impress){         // DB Config from Impress CMS impress_db_config file
84                                        $this->_get_value_by_impress_db_config_file();
85                                } else if(!empty($this->external_define_path)){ // file exists mainfile.php in the trust pass.
86                                        $this->_get_value_by_trust_mainfile();
87                                }
88                        } // end of if file_exists
89                       
90                }
91
92                //  define from /settings/definition.inc.php (XCL)  or /include/common.php(2016a-JP)
93                $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
94                $this->xoops_upload_url = $this->xoops_url . '/uploads';
95               
96                if ($this->module_name == 'wordpress')
97                        $this->module_db_prefix =  $this->xoops_db_prefix  . '_wp_';
98                else
99                        $this->module_db_prefix =  $this->xoops_db_prefix  . '_' . $this->module_name . '_';
100               
101                $this->set_module_version();
102                $this->set_wp_version();
103                $this->xpress_get_module_id();
104                $this->xoops_language = $this->xpress_get_xoops_config('language');
105                $this->xpress_get_module_config();
106    }
107
108        // A set value is acquired from XOOPS mainfile.php by the pattern match.
109        function _get_value_by_xoops_mainfile(){
110                $array_file = file($this->xoops_mainfile_path);
111                $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
112                $impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
113                $external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
114                for ($i = 0 ; $i <count($array_file) ; $i++){
115                        if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
116                                $keys = $matchs[1];
117                                if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
118                                if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
119                                $key_value = $matchs[2];
120
121                                switch ($keys){
122                                        case  'XOOPS_ROOT_PATH':
123                                                $this->xoops_root_path = $this->xpress_eval($key_value);
124                                                break;
125                                        case  'XOOPS_URL':
126                                                $this->xoops_url = $this->xpress_eval($key_value);
127                                                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
128                                                break;
129                                        case  'XOOPS_TRUST_PATH':
130                                                $this->xoops_trust_path = $this->xpress_eval($key_value);
131                                                break;
132                                        case  'XOOPS_DB_PREFIX':
133                                                $this->xoops_db_prefix = $this->xpress_eval($key_value);
134                                                break;
135                                        case  'XOOPS_DB_NAME':
136                                                $this->xoops_db_name = $this->xpress_eval($key_value);
137                                                break;
138                                        case  'XOOPS_DB_USER':
139                                                $this->xoops_db_user = $this->xpress_eval($key_value);
140                                                break;
141                                        case  'XOOPS_DB_PASS':
142                                                $this->xoops_db_pass = $this->xpress_eval($key_value);
143                                                break;
144                                        case  'XOOPS_DB_HOST':
145                                                $this->xoops_db_host = $this->xpress_eval($key_value);
146                                                break;
147                                        case  'XOOPS_DB_SALT':
148                                                $this->xoops_db_salt = $this->xpress_eval($key_value);
149                                                break;
150                                        case  'XOOPS_SALT':
151                                                $this->xoops_salt = $this->xpress_eval($key_value);
152                                                break;
153                                        default :
154                                               
155                                }       // end of switch
156                        }        // end of if preg_match
157                       
158                        // Check External Define File
159                        if (preg_match('/' . $external_define_file_pattern . '/' ,$array_file[$i],$trust_main_matchs)){
160                                $include_path = $this->xpress_eval($trust_main_matchs[2]);
161                                if (file_exists($include_path))
162                                        $this->external_define_path = $include_path;
163                        }
164                       
165                        // Check ImpressCMS
166                        if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
167                                $this->is_impress = true;
168                                $this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
169                        }
170                } // end of for loop           
171        }
172        // A set value is acquired from XOOPS define value .
173        function _get_value_by_xoops_define(){
174                $this->xoops_root_path = XOOPS_ROOT_PATH;
175                $this->xoops_url = XOOPS_URL;
176                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
177                if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
178                $this->xoops_db_prefix = XOOPS_DB_PREFIX;
179                $this->xoops_db_name = XOOPS_DB_NAME;
180                $this->xoops_db_user = XOOPS_DB_USER;
181                $this->xoops_db_pass = XOOPS_DB_PASS;
182                $this->xoops_db_host = XOOPS_DB_HOST;
183                if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
184                if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
185        }
186        // A set value is acquired from xp-config.php .
187        function _get_value_by_xp_config_file(){
188            require_once($this->xp_config_file_path);
189                $this->xoops_root_path =XP_XOOPS_ROOT_PATH;
190                $this->xoops_url = XP_XOOPS_URL;
191                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
192                if(defined('XP_XOOPS_TRUST_PATH')) $this->xoops_trust_path = XP_XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
193                $this->xoops_db_prefix = XP_XOOPS_DB_PREFIX;
194                $this->xoops_db_name = XP_XOOPS_DB_NAME;
195                $this->xoops_db_user = XP_XOOPS_DB_USER;
196                $this->xoops_db_pass = XP_XOOPS_DB_PASS;
197                $this->xoops_db_host = XP_XOOPS_DB_HOST;
198                if(defined('XP_XOOPS_DB_SALT')) $this->xoops_db_salt = XP_XOOPS_DB_SALT; else $this->xoops_db_salt = '';
199                if(defined('XOOPS_SALT')) $this->xoops_salt = XP_XOOPS_SALT; else $this->xoops_salt = '';
200        }
201       
202        // A set value is acquired from config file in the trust pass by the pattern match.
203    function _get_value_by_impress_db_config_file(){
204                if(file_exists($this->impress_db_config_file)){
205                        $array_file = file($this->impress_db_config_file);
206                        $pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
207                        for ($i = 0 ; $i <count($array_file) ; $i++){
208                                if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
209                                        $keys = $matchs[1];
210                                        if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
211                                        if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
212                                        $key_value = $matchs[2];
213
214                                        switch ($keys){
215                                                case  'SDATA_DB_SALT':
216                                                        $this->xoops_db_salt = $this->xpress_eval($key_value);
217                                                        break;
218                                                case  'SDATA_DB_PREFIX':
219                                                        $this->xoops_db_prefix = $this->xpress_eval($key_value);
220                                                        break;
221                                                case  'SDATA_DB_NAME':
222                                                        $this->xoops_db_name = $this->xpress_eval($key_value);
223                                                        break;
224                                                case  'SDATA_DB_USER':
225                                                        $this->xoops_db_user = $this->xpress_eval($key_value);
226                                                        break;
227                                                case  'SDATA_DB_PASS':
228                                                        $this->xoops_db_pass = $this->xpress_eval($key_value);
229                                                        break;
230                                                case  'SDATA_DB_HOST':
231                                                        $this->xoops_db_host = $this->xpress_eval($key_value);
232                                                        break;
233                                                default :
234                                                       
235                                        }       // end of switch
236                                }
237                        } // end of for
238                } // end of if file_exists
239    }
240   
241    function _get_value_by_trust_mainfile(){
242                // When the definition is written in mainfile.php in the trust passing
243                if(file_exists($this->external_define_path)){
244                        require_once($this->external_define_path);
245                       
246                        $this->xoops_root_path = XOOPS_ROOT_PATH;
247                $this->xoops_url = XOOPS_URL;
248                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
249                if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
250                $this->xoops_db_prefix = XOOPS_DB_PREFIX;
251                $this->xoops_db_name = XOOPS_DB_NAME;
252                $this->xoops_db_user = XOOPS_DB_USER;
253                $this->xoops_db_pass = XOOPS_DB_PASS;
254                $this->xoops_db_host = XOOPS_DB_HOST;
255                        if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
256                        if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
257                } // end of if file_exists
258        }       
259   
260    function get_xoops_mainfile_path(){
261        return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
262    }
263   
264    // set XPressME module virsion and codename from xoops_versions.php
265    function set_module_version(){
266        $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
267                if(file_exists($xoops_version_file)){
268                        $version_file = file($xoops_version_file);
269                        $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
270                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
271                        $version_found = false;
272                        $codename_found = false;
273                        for ($i = 0 ; $i <count($version_file) ; $i++){
274                                if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
275                                        $this->module_version = $v_matches[2];
276                                        $version_found = true;
277                                }
278                                if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
279                                        $this->module_codename = $c_matches[2];
280                                        $codename_found = true;
281                                }
282                                if ( $version_found && $codename_found ) break;
283                        }
284                }
285    }
286   
287    function set_wp_version(){
288        include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
289       
290        $this->wp_db_version = $wp_db_version;
291               
292                $this->wp_version = str_replace("ME", "", $wp_version);
293               
294                $pattern = 'ME.*';
295        if (preg_match('/' . $pattern . '/' ,$wp_version)){
296                        $this->is_wp_me = true;
297                } else {
298                        $this->is_wp_me = true;
299                }
300    }
301   
302        function xpress_get_xoops_config($config_name = '',$mid = 0){
303                $ret = '';
304                $cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
305                if (!$cn) return $ret;
306               
307                $db_selected = mysql_select_db($this->xoops_db_name, $cn);
308                if ($db_selected){
309                        $table_name = $this->xoops_db_prefix . '_config';
310                        $sql = "SELECT conf_value AS value FROM $table_name WHERE `conf_modid` = $mid AND `conf_name` = '$config_name'";
311                        if($result = mysql_query($sql)){
312                                $row = mysql_fetch_assoc($result);
313                                $ret = $row['value'];
314                        } else {
315                                $ret = $sql;
316                        }
317                }
318                if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
319                return $ret;
320        }
321
322        function xpress_get_module_config(){
323                $this->module_config= array();
324                $cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
325                if (!$cn) return $ret;
326               
327                $db_selected = mysql_select_db($this->xoops_db_name, $cn);
328                if ($db_selected){
329                        $table_name = $this->xoops_db_prefix . '_config';
330                        $sql = "SELECT conf_name AS name, conf_value AS value FROM $table_name WHERE `conf_modid` = $this->module_id";
331                        if($result = mysql_query($sql)){
332                                while ($row = mysql_fetch_assoc($result)) {
333                                $this->module_config[$row['name']] = $row['value'];
334                                }
335                        }
336                }
337                if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
338                return $this->module_config;
339        }
340
341        function xpress_get_module_id(){
342                $this->module_id = '';
343                $cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
344                if ($cn){
345                        $db_selected = mysql_select_db($this->xoops_db_name, $cn);
346                        if ($db_selected){
347                                $table_name = $this->xoops_db_prefix . '_modules';
348                                $sql = "SELECT mid FROM $table_name WHERE `dirname` = '$this->module_name'";
349                                if($result = mysql_query($sql)){
350                                        $row = mysql_fetch_assoc($result);
351                                        $this->module_id = $row['mid'];
352                                }
353                        }
354                        if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
355                }
356                return $this->module_id;
357        }
358       
359       
360        // Set XPressME memory limit
361        function xpress_set_memory_limmit(){
362                $memory = $this->module_config['memory_limit'];
363                if (empty($memory)) return;
364                if ( !defined('WP_MEMORY_LIMIT') )
365                        define('WP_MEMORY_LIMIT', $memory . 'M');
366                if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
367                        @ini_set('memory_limit', WP_MEMORY_LIMIT);
368        }
369
370
371
372}
373?>
Note: See TracBrowser for help on using the repository browser.