XPressME Integration Kit

Trac

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

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

wp-configのWPLANGをXOOPSのlangを元に設定する機能を追加 Fixed#401

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