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 | */
|
---|
14 | class ConfigFromXoops{
|
---|
15 | var $xoops_mainfile_path;
|
---|
16 | var $define_arry = array();
|
---|
17 | var $xoops_root_path;
|
---|
18 | var $xoops_url;
|
---|
19 | var $xoops_trust_path;
|
---|
20 | var $xoops_db_prefix;
|
---|
21 | var $xoops_db_name;
|
---|
22 | var $xoops_db_user;
|
---|
23 | var $xoops_db_pass;
|
---|
24 | var $xoops_db_host;
|
---|
25 | var $module_name;
|
---|
26 | var $module_path;
|
---|
27 | var $module_url;
|
---|
28 | var $module_db_prefix;
|
---|
29 | var $module_version;
|
---|
30 | var $module_codename;
|
---|
31 | var $xoops_upload_path;
|
---|
32 | var $xoops_upload_url;
|
---|
33 |
|
---|
34 |
|
---|
35 | function __constructor() //for PHP5
|
---|
36 | {
|
---|
37 | $this->ConfigFromXoops();
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | function ConfigFromXoops() //for PHP4 constructor
|
---|
42 | {
|
---|
43 | $this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
|
---|
44 | $this->module_path=dirname(dirname(__FILE__));
|
---|
45 | $this->module_name=basename($this->module_path);
|
---|
46 | if(file_exists($this->xoops_mainfile_path)){
|
---|
47 | $array_file = file($this->xoops_mainfile_path);
|
---|
48 | for ($i = 0 ; $i <count($array_file) ; $i++){
|
---|
49 | /* Ref. ImpressCMS
|
---|
50 |
|
---|
51 | mainfile.php
|
---|
52 | define( 'XOOPS_TRUST_PATH', 'C:/xampp/trust_pathf6fac' );
|
---|
53 |
|
---|
54 | include_once(XOOPS_TRUST_PATH . '/3aec9eefada2c57b3705952094b7b070.php');
|
---|
55 |
|
---|
56 | define( 'XOOPS_DB_PREFIX', SDATA_DB_PREFIX );
|
---|
57 | define( 'XOOPS_DB_HOST', SDATA_DB_HOST );
|
---|
58 | define( 'XOOPS_DB_USER', SDATA_DB_USER );
|
---|
59 | define( 'XOOPS_DB_PASS', SDATA_DB_PASS );
|
---|
60 | define( 'XOOPS_DB_NAME', SDATA_DB_NAME );
|
---|
61 | define( 'XOOPS_DB_SALT', SDATA_DB_SALT );
|
---|
62 |
|
---|
63 | XOOPS_TRUST_PATH . '/3aec9eefada2c57b3705952094b7b070.php'
|
---|
64 | define( 'SDATA_DB_HOST', 'localhost' );
|
---|
65 | define( 'SDATA_DB_USER', 'root' );
|
---|
66 | define( 'SDATA_DB_PASS', '' );
|
---|
67 | define( 'SDATA_DB_NAME', 'impress' );
|
---|
68 | define( 'SDATA_DB_PREFIX', 'id85d03cc' );
|
---|
69 | define( 'SDATA_DB_SALT', '3mhUHMrsTU3CTifQbenOtK1ULG5QN2Dwx8zCfwtynudub4TS9AnmZAhmdQr43Uvot' );
|
---|
70 |
|
---|
71 | ref. code C:\xampp\htdocs\impress\install\page_configsave.php
|
---|
72 | $sdata_rewrite = array();
|
---|
73 | $sdata_rewrite['DB_HOST'] = $vars['DB_HOST'];
|
---|
74 | $sdata_rewrite['DB_USER'] = $vars['DB_USER'];
|
---|
75 | $sdata_rewrite['DB_PASS'] = $vars['DB_PASS'];
|
---|
76 | $sdata_rewrite['DB_NAME'] = $vars['DB_NAME'];
|
---|
77 | $sdata_rewrite['DB_PREFIX'] = $vars['DB_PREFIX'];
|
---|
78 | $sdata_rewrite['DB_SALT'] = $vars['DB_SALT'];
|
---|
79 |
|
---|
80 |
|
---|
81 | foreach( $sdata_rewrite as $key => $val ) {
|
---|
82 | if( preg_match( "/(define\()([\"'])(SDATA_$key)\\2,\s*([\"'])(.*?)\\4\s*\)/", $content ) ) {
|
---|
83 | $val = addslashes( $val );
|
---|
84 | $content = preg_replace( "/(define\()([\"'])(SDATA_$key)\\2,\s*([\"'])(.*?)\\4\s*\)/",
|
---|
85 | "define( 'SDATA_$key', '$val' )", $content );
|
---|
86 | } else {
|
---|
87 | //$this->error = true;
|
---|
88 | //$this->report .= _NGIMG.sprintf( ERR_WRITING_CONSTANT, "<b>$val</b>")."<br />\n";
|
---|
89 | }
|
---|
90 | }
|
---|
91 | */
|
---|
92 |
|
---|
93 | $array_file[$i] = trim($array_file[$i]);
|
---|
94 | $array_file[$i] = str_replace(' ','',$array_file[$i]);
|
---|
95 |
|
---|
96 | $array_file[$i] = preg_replace('/\s\s+/', '', $array_file[$i]);
|
---|
97 | $array_file[$i] = preg_replace('/^include.*/','',$array_file[$i]);
|
---|
98 | $array_file[$i] = preg_replace('/^\/\/.*/','',$array_file[$i]);
|
---|
99 | $array_file[$i] = preg_replace('/^if.*/','',$array_file[$i]);
|
---|
100 | if (strstr($array_file[$i],'define')!== false){
|
---|
101 | $array_file[$i] = preg_replace('/\"/', '', $array_file[$i]);
|
---|
102 | $array_file[$i] = preg_replace('/\(/', '', $array_file[$i]);
|
---|
103 | $array_file[$i] = preg_replace('/\)/', '', $array_file[$i]);
|
---|
104 | $array_file[$i] = preg_replace('/\;/', '', $array_file[$i]);
|
---|
105 | $array_file[$i] = preg_replace('/\'/', '', $array_file[$i]);
|
---|
106 | $array_file[$i] = preg_replace('/define/', '', $array_file[$i]);
|
---|
107 | $define = explode(',',$array_file[$i] );
|
---|
108 | $define[0] = trim($define[0]);
|
---|
109 | $define[1] = trim($define[1]);
|
---|
110 | switch ($define[0]){
|
---|
111 | case 'XOOPS_ROOT_PATH':
|
---|
112 | $this->xoops_root_path = $define[1];
|
---|
113 | $this->xoops_url . '/modules/' . $this->module_name;
|
---|
114 | break;
|
---|
115 | case 'XOOPS_URL':
|
---|
116 | $this->xoops_url = $define[1];
|
---|
117 | $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
|
---|
118 | break;
|
---|
119 | case 'XOOPS_TRUST_PATH':
|
---|
120 | $this->xoops_trust_path = $define[1];
|
---|
121 | break;
|
---|
122 | case 'XOOPS_DB_PREFIX':
|
---|
123 | $this->xoops_db_prefix = $define[1];
|
---|
124 | break;
|
---|
125 | case 'XOOPS_DB_NAME':
|
---|
126 | $this->xoops_db_name = $define[1];
|
---|
127 | break;
|
---|
128 | case 'XOOPS_DB_USER':
|
---|
129 | $this->xoops_db_user = $define[1];
|
---|
130 | break;
|
---|
131 | case 'XOOPS_DB_PASS':
|
---|
132 | $this->xoops_db_pass = $define[1];
|
---|
133 | break;
|
---|
134 | case 'XOOPS_DB_HOST':
|
---|
135 | $this->xoops_db_host = $define[1];
|
---|
136 | break;
|
---|
137 | default :
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | // define from /settings/definition.inc.php (XCL) or /include/common.php(2016a-JP)
|
---|
144 | $this->xoops_upload_path = $this->xoops_root_path .'/uploads';
|
---|
145 | $this->xoops_upload_url = $this->xoops_url . '/uploads';
|
---|
146 |
|
---|
147 | if ($this->module_name == 'wordpress')
|
---|
148 | $this->module_db_prefix = $this->xoops_db_prefix . '_wp_';
|
---|
149 | else
|
---|
150 | $this->module_db_prefix = $this->xoops_db_prefix . '_' . $this->module_name . '_';
|
---|
151 |
|
---|
152 | $this->set_module_version();
|
---|
153 |
|
---|
154 | }
|
---|
155 |
|
---|
156 | function get_xoops_mainfile_path(){
|
---|
157 | return dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php';
|
---|
158 | }
|
---|
159 |
|
---|
160 | // set XPressME module virsion and codename from xoops_versions.php
|
---|
161 | function set_module_version(){
|
---|
162 | $xoops_version_file = dirname(dirname(__FILE__)) . '/xoops_version.php';
|
---|
163 | if(file_exists($xoops_version_file)){
|
---|
164 | $version_file = file($xoops_version_file);
|
---|
165 | $version_pattern = '(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
166 | $codename_pattern = '(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
|
---|
167 | $version_found = false;
|
---|
168 | $codename_found = false;
|
---|
169 | for ($i = 0 ; $i <count($version_file) ; $i++){
|
---|
170 | if (preg_match( "/$version_pattern/", $version_file[$i] ,$v_matches )){
|
---|
171 | $this->module_version = $v_matches[2];
|
---|
172 | $version_found = true;
|
---|
173 | }
|
---|
174 | if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
|
---|
175 | $this->module_codename = $c_matches[2];
|
---|
176 | $codename_found = true;
|
---|
177 | }
|
---|
178 | if ( $version_found && $codename_found ) break;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | }
|
---|
184 | ?>
|
---|