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 | if (defined( 'XOOPS_MAINFILE_INCLUDED')|| defined( 'XOOPS_BOOTSTRAP')) :
|
---|
12 | require_once dirname( __FILE__ ).'/langInfo_class.php' ;
|
---|
13 |
|
---|
14 | class wpConfigInfoClass {
|
---|
15 | var $xoops_db_prefix;
|
---|
16 | var $db_prefix;
|
---|
17 | var $db_name;
|
---|
18 | var $db_user;
|
---|
19 | var $db_pass;
|
---|
20 | var $db_host;
|
---|
21 | var $db_salt;
|
---|
22 | var $langInfo;
|
---|
23 |
|
---|
24 | function __constructor() //for PHP5
|
---|
25 | {
|
---|
26 | $this->wpConfigInfoClass();
|
---|
27 | }
|
---|
28 |
|
---|
29 | function wpConfigInfoClass() //for PHP4 constructor
|
---|
30 | {
|
---|
31 | global $xoopsModule;
|
---|
32 | $this->xoops_db_prefix = XOOPS_DB_PREFIX . '_';
|
---|
33 | $this->db_name = XOOPS_DB_NAME;
|
---|
34 | $this->db_user = XOOPS_DB_USER;
|
---|
35 | $this->db_pass = XOOPS_DB_PASS;
|
---|
36 | $this->db_host = XOOPS_DB_HOST;
|
---|
37 | if(!defined('XOOPS_DB_NAME') ) $this->_get_resource_db_ini();
|
---|
38 | $this->db_prefix = $this->_get_wp_db_prefix();
|
---|
39 | $this->db_salt = (defined('XOOPS_DB_SALT')) ? XOOPS_DB_SALT : '';
|
---|
40 | require_once dirname( __FILE__ ).'/langInfo_class.php' ;
|
---|
41 | $this->langInfo = new langInfoClass;
|
---|
42 | }
|
---|
43 | function _get_wp_db_prefix(){
|
---|
44 | $module_name = basename(dirname(dirname(__FILE__)));
|
---|
45 | $module_db_prefix = $this->xoops_db_prefix . preg_replace('/wordpress/','wp',$module_name) . '_';
|
---|
46 | return $module_db_prefix;
|
---|
47 | }
|
---|
48 |
|
---|
49 | // XOOPS3 doesn't define the DB connection information in the constant.
|
---|
50 | function _get_resource_db_ini(){
|
---|
51 | if(!defined('XOOPS_VAR_PATH') ) return;
|
---|
52 | $def_file = XOOPS_VAR_PATH . '/etc/resource.db.ini.php';
|
---|
53 | if(! file_exists($def_file)) return;
|
---|
54 | $array_file = file($def_file);
|
---|
55 | foreach ($array_file as $line){
|
---|
56 | if (preg_match('/^\s*dbname\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
|
---|
57 | $this->db_name = $matchs[1];
|
---|
58 | if (preg_match('/^\s*host\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
|
---|
59 | $this->db_host = $matchs[1];
|
---|
60 | if (preg_match('/^\s*username\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
|
---|
61 | $this->db_user = $matchs[1];
|
---|
62 | if (preg_match('/^\s*password\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
|
---|
63 | $this->db_pass = $matchs[1];
|
---|
64 | if (preg_match('/^\s*prefix\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
|
---|
65 | $this->xoops_db_prefix = $matchs[1].'_';
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | function get_xoops_db_prefix(){
|
---|
70 | return $this->xoops_db_prefix;
|
---|
71 | }
|
---|
72 | function get_db_prefix($module_dirname){
|
---|
73 | if (empty($module_dirname)){
|
---|
74 | return $this->db_prefix;
|
---|
75 | } else {
|
---|
76 | $module_db_prefix = $this->xoops_db_prefix . preg_replace('/wordpress/','wp',$module_dirname) . '_';
|
---|
77 | return $module_db_prefix;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | function get_wp_db_prefix(){
|
---|
81 | return $this->db_prefix;
|
---|
82 | }
|
---|
83 | function get_db_name(){
|
---|
84 | return $this->db_name;
|
---|
85 | }
|
---|
86 | function get_db_user(){
|
---|
87 | return $this->db_user;
|
---|
88 | }
|
---|
89 | function get_db_pass(){
|
---|
90 | return $this->db_pass;
|
---|
91 | }
|
---|
92 | function get_db_host(){
|
---|
93 | return $this->db_host;
|
---|
94 | }
|
---|
95 | function get_db_salt(){
|
---|
96 | return $this->db_salt;
|
---|
97 | }
|
---|
98 | function get_wpLang($xoops_lang=''){
|
---|
99 | return $this->langInfo->get_wpLang($xoops_lang);
|
---|
100 | }
|
---|
101 | }
|
---|
102 | endif;
|
---|
103 | ?> |
---|