XPressME Integration Kit

Trac

source: branches/Ver2.4/xpressme_integration_kit/class/config_from_xoops.class.php @ 763

Last change on this file since 763 was 763, checked in by toemon, 13 years ago

XOOPS DB接続情報取得方法の変更

File size: 5.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 $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_cache_path;
23        var $xoops_db_prefix;
24        var $xoops_db_name;
25        var $xoops_db_user;
26        var $xoops_db_pass;
27        var $xoops_db_host;
28        var $module_name;
29        var $module_path;
30        var $module_url;
31        var $module_db_prefix;
32        var $module_version;
33        var $module_codename;   
34        var $xoops_upload_path;
35        var $xoops_upload_url;
36        var $xoops_db_salt;
37        var $xoops_salt;
38        var $is_impress;
39        var $impress_db_config_file;
40        var $wp_db_version;
41        var $wp_version;
42        var $is_wp_me;
43        var $xoops_language;
44        var $module_id;
45        var $module_config= array();
46        var $xoops_time_zone;
47        var $xoops_var_path;
48        var $xoops_db_charset;
49        var $xoops_db_pconnect;
50        var $xoops_path;
51       
52        function __constructor()        //for PHP5
53    {
54        $this->ConfigFromXoops();
55       
56    }
57   
58    function xpress_eval($str){
59        $eval_str = '$ret = ' . $str . ' ;';
60        eval($eval_str);
61        return $ret;
62    }
63
64    function ConfigFromXoops()  //for PHP4 constructor
65    { 
66        $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
67        $this->module_path=dirname(dirname(__FILE__));
68        $this->module_name=basename($this->module_path);
69        $this->xp_config_file_path = $this->module_path . '/xp-config.php';
70       
71        // start /admin/index.php page detect
72        $php_script_name = $_SERVER['SCRIPT_NAME'];
73                $php_query_string = $_SERVER['QUERY_STRING'];
74                $admin_page =   basename(dirname(dirname(__FILE__))) . '/admin/index.php';
75                $is_xoops_module_admin = false;
76                if (strstr($php_script_name,$admin_page) !== false) $is_xoops_module_admin = true;
77                if (strstr($php_query_string,$admin_page) !== false) $is_xoops_module_admin = true;
78        // end of /admin/index.php page detect
79       
80                $this->xoops_root_path = XOOPS_ROOT_PATH;
81                $this->xoops_url = XOOPS_URL;
82                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
83                if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
84                $this->xoops_db_prefix = XOOPS_DB_PREFIX;
85                $this->xoops_db_name = XOOPS_DB_NAME;
86                $this->xoops_db_user = XOOPS_DB_USER;
87                $this->xoops_db_pass = XOOPS_DB_PASS;
88                $this->xoops_db_host = XOOPS_DB_HOST;
89                if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
90                if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
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                $this->module_db_prefix = $this->xoops_db_prefix  . '_' . preg_replace('/wordpress/','wp',$this->module_name) . '_';
96               
97                $this->set_module_version();
98                $this->set_wp_version();
99                if (function_exists('date_default_timezone_get')){
100                        $this->xoops_time_zone = date_default_timezone_get();
101                }
102                $this->_get_cache_path();
103    }
104
105       
106        // call after the $this->xoops_trust_path is set
107        function _get_cache_path(){
108                $cache_path = $this->xoops_trust_path . '/cache';
109                if (file_exists($cache_path) && is_writable($cache_path)){
110                        $this->xoops_cache_path = $cache_path;
111                        return;
112                }
113                $this->xoops_cache_path = $this->xoops_root_path . '/cache';
114        }
115   
116    function get_xoops_mainfile_path(){
117        return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
118    }
119   
120    // set XPressME module virsion and codename from xoops_versions.php
121    function set_module_version(){
122        $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
123                if(file_exists($xoops_version_file)){
124                        $version_file = file($xoops_version_file);
125                        $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
126                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
127                        $version_found = false;
128                        $codename_found = false;
129                        for ($i = 0 ; $i <count($version_file) ; $i++){
130                                if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
131                                        $this->module_version = $v_matches[2];
132                                        $version_found = true;
133                                }
134                                if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
135                                        $this->module_codename = $c_matches[2];
136                                        $codename_found = true;
137                                }
138                                if ( $version_found && $codename_found ) break;
139                        }
140                }
141    }
142   
143    function set_wp_version(){
144        include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
145       
146        $this->wp_db_version = $wp_db_version;
147               
148                $this->wp_version = str_replace("ME", "", $wp_version);
149               
150                $pattern = 'ME.*';
151        if (preg_match('/' . $pattern . '/' ,$wp_version)){
152                        $this->is_wp_me = true;
153                } else {
154                        $this->is_wp_me = true;
155                }
156    }
157   
158}
159?>
Note: See TracBrowser for help on using the repository browser.