XPressME Integration Kit

Trac

source: branches/Ver3.0/xpressme_integration_kit/class/config_from_xoops.class.php @ 733

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

XOOPS mainfile.phpからDB接続情報を取得する方法の変更

File size: 5.1 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 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        $this->_get_value_by_xoops_define();
73                //  define from /settings/definition.inc.php (XCL)  or /include/common.php(2016a-JP)
74                $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
75                $this->xoops_upload_url = $this->xoops_url . '/uploads';
76                $this->module_db_prefix = $this->xoops_db_prefix  . '_' . preg_replace('/wordpress/','wp',$this->module_name) . '_';
77               
78                $this->set_module_version();
79                $this->set_wp_version();
80                if (function_exists('date_default_timezone_get')){
81                        $this->xoops_time_zone = date_default_timezone_get();
82                }
83                $this->_get_cache_path();
84    }
85
86        // A set value is acquired from XOOPS define value .
87        function _get_value_by_xoops_define(){
88                $this->xoops_root_path = XOOPS_ROOT_PATH;
89                $this->xoops_url = XOOPS_URL;
90                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
91                if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
92                $this->xoops_db_prefix = XOOPS_DB_PREFIX;
93                $this->xoops_db_name = XOOPS_DB_NAME;
94                $this->xoops_db_user = XOOPS_DB_USER;
95                $this->xoops_db_pass = XOOPS_DB_PASS;
96                $this->xoops_db_host = XOOPS_DB_HOST;
97                if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
98                if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
99        }
100       
101        // call after the $this->xoops_trust_path is set
102        function _get_cache_path(){
103                $cache_path = $this->xoops_trust_path . '/cache';
104                if (file_exists($cache_path) && is_writable($cache_path)){
105                        $this->xoops_cache_path = $cache_path;
106                        return;
107                }
108                $this->xoops_cache_path = $this->xoops_root_path . '/cache';
109        }
110   
111    function get_xoops_mainfile_path(){
112        return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
113    }
114   
115    // set XPressME module virsion and codename from xoops_versions.php
116    function set_module_version(){
117        $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
118                if(file_exists($xoops_version_file)){
119                        $version_file = file($xoops_version_file);
120                        $version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
121                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
122                        $version_found = false;
123                        $codename_found = false;
124                        for ($i = 0 ; $i <count($version_file) ; $i++){
125                                if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
126                                        $this->module_version = $v_matches[2];
127                                        $version_found = true;
128                                }
129                                if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
130                                        $this->module_codename = $c_matches[2];
131                                        $codename_found = true;
132                                }
133                                if ( $version_found && $codename_found ) break;
134                        }
135                }
136    }
137   
138    function set_wp_version(){
139        include dirname(dirname(__FILE__)) . '/wp-includes/version.php';
140       
141        $this->wp_db_version = $wp_db_version;
142               
143                $this->wp_version = str_replace("ME", "", $wp_version);
144               
145                $pattern = 'ME.*';
146        if (preg_match('/' . $pattern . '/' ,$wp_version)){
147                        $this->is_wp_me = true;
148                } else {
149                        $this->is_wp_me = true;
150                }
151    }
152   
153}
154?>
Note: See TracBrowser for help on using the repository browser.