XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/class/modInfo_class.php @ 789

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

wp_installer.php で拡張データベースのプレフィックスが正常に取得出来ないバグ修正

File size: 12.9 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
11if (defined( 'XOOPS_MAINFILE_INCLUDED')|| defined( 'XOOPS_BOOTSTRAP')) :
12
13class modInfoClass {
14        var $db_name;
15        var $db_user;
16        var $db_pass;
17        var $db_host;
18        var $db_salt;
19        var $xoops_db_prefix;
20        var $module_db_prefix;
21       
22        var $xoops_mainfile_path;
23        var $xoops_root_path;
24        var $xoops_url;
25        var $xoops_trust_path;
26        var $xoops_var_path;
27        var $xoops_cache_path;
28        var $xoops_upload_path;
29        var $xoops_upload_url;
30        var $xoops_db_salt;
31        var $xoops_salt;
32        var $xoops_language;
33        var $module_name;
34        var $module_path;
35        var $module_url;
36        var $module_version;
37        var $module_codename;
38        var $module_id;
39        var $xoops_version;
40        var $is_impress_cms;
41        var $is_cube_legacy;
42        var $is_xoops2jp;
43        var $is_xoops2;
44        var $is_xoops_legacy;
45        var $is_jpex;
46        var $xoops_time_zone;
47        var $wp_version;
48        var $wpConfigInfo;
49        var $factory;
50        var $module;
51        var $langInfo;
52        function __constructor()        //for PHP5
53    {
54        $this->modInfoClass();
55       
56    }
57   
58    function modInfoClass()     //for PHP4 constructor
59    { 
60        global $xoopsModule;
61
62               
63        if (! is_object($xoopsModule)){
64//                      $module_handler =& xoops_gethandler('module');
65//                      $xoopsModule =& $module_handler->getByDirname(basename(dirname(dirname(__FILE__))));
66                }
67                $this->_branches_cores();
68                if ($this->is_xoops_legacy) $this->factory = XOOPS::factory();
69                if (is_object($this->factory)){
70//                      $module_handler = & XOOPS::getHandle('module');
71                } else {
72//                      $module_handler =& xoops_gethandler('module');
73                }
74//              $this->module =& $module_handler->getByDirname(basename(dirname(dirname(__FILE__))));
75                $this->_get_db_ini();
76                $this->module_db_prefix = $this->_get_module_db_prefix();
77        $this->xoops_root_path = $this->_get_xoops_root_path();
78                $this->xoops_trust_path = (defined('XOOPS_TRUST_PATH')) ? XOOPS_TRUST_PATH : '';
79                $this->xoops_var_path = $this->_get_xoops_var_path();
80                $this->xoops_url = $this->_get_xoops_url();
81        $this->xoops_mainfile_path = $this->xoops_root_path . '/mainfile.php';
82                $this->xoops_upload_path = $this->_get_xoops_upload_path();
83                $this->xoops_upload_url = $this->_get_xoops_upload_url();
84                $this->xoops_cache_path = $this->_get_xoops_cache_path();
85        $this->module_name = basename(dirname(dirname(__FILE__)));
86        $this->module_path = $this->xoops_root_path . '/modules/' . $this->module_name;
87                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
88                $this->xoops_lang =  @$GLOBALS["xoopsConfig"]['language'];
89                $this->module_id = ! empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
90                $this->module_version = ! empty($xoopsModule) ? $xoopsModule->getVar('version')/100 : '';
91                $this->module_codename = $this->_get_module_codename();
92                $this->wp_version = $this->_get_wp_version();
93               
94                $this->xoops_version = (defined('XOOPS_VERSION')) ? XOOPS_VERSION : '';
95        $this->_branches_cores();
96               
97                if (function_exists('date_default_timezone_get')){
98                        $this->xoops_time_zone = date_default_timezone_get();
99                } else {
100                        $this->xoops_time_zone = $xoopsConfig['default_TZ'];
101                }
102                require_once dirname( __FILE__ ).'/langInfo_class.php' ;
103                $this->langInfo = new langInfoClass;
104    }
105    function _get_xoops_root_path(){
106        if (defined('XOOPS_ROOT_PATH')) return XOOPS_ROOT_PATH;
107        return $this->factory->path('www');     //XOOPS Engine
108        }
109    function _get_xoops_var_path(){
110        if (defined('XOOPS_VAR_PATH')) return XOOPS_VAR_PATH;
111        return $this->factory->path('var');     //XOOPS Engine
112        }
113    function _get_xoops_cache_path(){
114        if (defined('XOOPS_CACHE_PATH')) return XOOPS_CACHE_PATH;
115        return $this->factory->path('var'). "/cache/system";    //XOOPS Engine
116        }
117    function _get_xoops_url(){
118        if (defined('XOOPS_URL')) return XOOPS_URL;
119        return $this->factory->url('',true);    //XOOPS Engine
120        }
121    function _get_xoops_upload_path(){
122        if (defined('XOOPS_UPLOAD_PATH')) return XOOPS_UPLOAD_PATH;
123        return $this->factory->path('upload');  //XOOPS Engine
124        }
125    function _get_xoops_upload_url(){
126        if (defined('XOOPS_UPLOAD_URL')) return XOOPS_UPLOAD_URL;
127        return $this->factory->url('upload',true);      //XOOPS Engine
128        }       
129       
130        function _get_db_ini(){
131                if (defined('XOOPS_DB_NAME')){
132                        $this->xoops_db_prefix = XOOPS_DB_PREFIX . '_';
133                        $this->db_name = XOOPS_DB_NAME;
134                        $this->db_user = XOOPS_DB_USER;
135                        $this->db_pass = XOOPS_DB_PASS;
136                        $this->db_host = XOOPS_DB_HOST;
137                        return;
138                }
139
140                if(!defined('XOOPS_VAR_PATH') ) {
141                        $var_path = $this->factory->path('var');        //XOOPS Engine
142                } else {
143                        $var_path = XOOPS_VAR_PATH;
144                }
145                $def_file = $var_path . '/etc/resource.db.ini.php';
146                if(! file_exists($def_file)) return;
147                $array_file = file($def_file);
148                foreach ($array_file as $line){
149                        if (preg_match('/^\s*dbname\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
150                                $this->db_name = $matchs[1];
151                        if (preg_match('/^\s*host\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
152                                $this->db_host = $matchs[1];
153                        if (preg_match('/^\s*username\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
154                                $this->db_user = $matchs[1];
155                        if (preg_match('/^\s*password\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
156                                $this->db_pass = $matchs[1];
157                        if (preg_match('/^\s*prefix\s*=\s*[\'"](.*)[\'"]/' ,$line,$matchs))
158                                $this->xoops_db_prefix = $matchs[1].'_';
159                }
160        }
161        function _get_module_db_prefix(){
162                $module_name = basename(dirname(dirname(__FILE__)));
163        $module_db_prefix = $this->xoops_db_prefix . preg_replace('/wordpress/','wp',$module_name) . '_';
164        return $module_db_prefix;
165        }
166
167    function _branches_cores(){
168        /*  XOOPS include/version.php define value */
169                //define("XOOPS_VERSION","XOOPS 2.0.16a JP");
170                //define("XOOPS_VERSION", "XOOPS Cube Legacy 2.2");
171                //define('XOOPS_VERSION', 'ImpressCMS 1.1.2 Final');
172                //define("XOOPS_VERSION", "XOOPS JPEx 1.6");
173                //define("XOOPS_VERSION", "XOOPS 2.3.3");
174                //define("XOOPS_VERSION", "Xoops Legacy");      define("XOOPS_ENGINE", "legacy");
175        $this->is_impress_cms = false;
176                $this->is_cube_legacy = false;
177                $this->is_xoops2jp = false;
178                $this->is_xoops2 = false;
179                $this->is_xoops_legacy = false;
180                $this->is_jpex = false;
181                if (!defined('XOOPS_VERSION')){
182                        $root_path = dirname(dirname(dirname(dirname(__FILE__))));
183                        include_once $root_path . '/include/version.php';
184                }
185                $version = XOOPS_VERSION;
186               
187               
188        // branches by cores
189                if( preg_match('/JP$/', $version))
190                        $this->is_xoops2jp = true;
191                if( preg_match('/Cube\s*Legacy/', $version))
192                        $this->is_cube_legacy = true;
193                if( preg_match('/ImpressCMS/', $version))
194                        $this->is_impress_cms = true;
195                if( preg_match('/JPEx/', $version))
196                        $this->is_jpex = true;
197                if( preg_match('/XOOPS\s*[0-9|\.]*$/', $version))
198                        $this->is_xoops2 = true;
199                if( preg_match('/Xoops\s*Legacy/', $version))
200                        $this->is_xoops_legacy = true;
201        }
202    function _get_wp_version(){
203        $wp_version_file =  dirname(dirname(__FILE__)) . '/wp-includes/version.php';
204        if (file_exists($wp_version_file)){
205                include $wp_version_file;
206                return str_replace("ME", "", $wp_version);
207        }
208        return '';
209    }
210       
211    // get XPressME module virsion and codename from xoops_versions.php
212    function _get_module_codename(){
213        $xoops_version_file = $this->module_path . '/xoops_version.php';
214                if(file_exists($xoops_version_file)){
215                        $version_file = file($xoops_version_file);
216                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
217                        for ($i = 0 ; $i <count($version_file) ; $i++){
218                                if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
219                                        return $c_matches[2];
220                                }
221                        }
222                }
223                return '';
224    }
225        function get_xoops_db_prefix(){
226                return $this->xoops_db_prefix;
227        }
228        function get_module_db_prefix($module_dirnam=''){
229                if (empty($module_dirname)){
230                        return $this->module_db_prefix;
231                } else {
232                $module_db_prefix = $this->xoops_db_prefix . preg_replace('/wordpress/','wp',$module_dirname) . '_';
233                return $module_db_prefix;               
234                }
235        }
236        function get_db_name(){
237                return $this->db_name;
238        }
239        function get_db_user(){
240                return $this->db_user;
241        }
242        function get_db_pass(){
243                return $this->db_pass;
244        }
245        function get_db_host(){
246                return $this->db_host;
247        }
248        function get_db_salt(){
249                return $this->db_salt;
250        }
251        function get_wpLang($xoops_lang=''){
252                return $this->langInfo->get_wpLang($xoops_lang);
253        }
254       
255        function get_xoops_root_path(){
256                return $this->xoops_root_path;
257        }
258        function get_xoops_trust_path(){
259                return $this->xoops_trust_path;
260        }
261        function get_xoops_mainfile_path(){
262                return $this->xoops_mainfile_path;
263        }
264        function get_xoops_header_path(){
265                return $this->xoops_root_path ."/header.php";
266        }
267        function get_xoops_footer_path(){
268                return $this->xoops_root_path . '/footer.php';
269        }
270        function get_xoops_cache_path(){
271                return $this->xoops_cache_path;
272        }
273        function get_xoops_url(){
274                return $this->xoops_url;
275        }
276        function get_xoops_upload_path(){
277                return $this->xoops_upload_path;
278        }
279        function get_xoops_upload_url(){
280                return $this->xoops_upload_url;
281        }
282        function get_module_path(){
283                return $this->module_path;
284        }
285        function get_module_templates_path(){
286                return $this->module_path . '/templates';
287        }
288       
289        function get_module_name(){
290                return $this->module_name;
291        }
292        function get_module_dirname(){
293                return $this->module_name;
294        }
295        function get_module_url(){
296                return $this->module_url;
297        }
298        function get_xoops_time_zone(){
299                return $this->xoops_time_zone;
300        }
301        function get_module_version(){
302                return $this->module_version;
303        }
304        function get_module_codename(){
305                return $this->module_codename;
306        }
307        function get_wp_version(){
308                return $this->wp_version;
309        }
310        function get_module_full_version(){
311                return $this->module_version . $this->module_codename;
312        }
313       
314        function is_impress_cms(){
315                return $this->is_impress_cms;
316        }
317        function is_cube_legacy(){
318                return $this->is_cube_legacy;
319        }
320        function is_xoops2jp(){
321                return $this->is_xoops2jp;
322        }
323        function is_xoops2(){
324                return $this->is_xoops2;
325        }
326        function is_xoops_legacy(){
327                return $this->is_xoops_legacy;
328        }
329        function is_jpex(){
330                return $this->is_jpex;
331        }
332       
333        function get_moduleID_ByDirname($dir_name){
334                if (! function_exists('xoops_gethandler')) return '';
335                $module_handler =& xoops_gethandler('module');
336                $module =& $module_handler->getByDirname($dir_name);
337                $module_id = $module->getVar('mid');
338                return $module_id;
339        }
340
341        function get_moduleID(){
342                global $xoopsModule;
343                $module_id = $xoopsModule->getVar('mid');
344                return $module_id;
345        }
346       
347        function get_ModuleConfig($key_name=''){
348                if (empty($key_name)) return '';
349                global $xoopsModuleConfig;
350                $value = isset($xoopsModuleConfig[$key_name]) ? $xoopsModuleConfig[$key_name] : '';
351        }
352       
353        function get_ModuleConfig_ByDirname($dir_name,$key_name=''){
354                $mid = $this->get_moduleID_ByDirname($dir_name);
355                $conf_handler =& xoops_gethandler('config');
356                $modConfig = $conf_handler->getConfigsByCat(0, $mid);
357                if(empty($modConfig)) return '';
358                if(empty($key_name)) return $modConfig;
359                return isset($modConfig[$key_name]) ? $modConfig[$key_name] : '';
360        }
361   
362        function is_wpdb_installed(){
363                global $xoopsDB;
364                $mydirname = basename(dirname( dirname( __FILE__ ) )) ;
365                $prefix_mod = XOOPS_DB_PREFIX .'_' . preg_replace('/wordpress/','wp',$mydirname) . '_';
366                $sql = "SHOW TABLES LIKE '$prefix_mod%'";
367                if ($result = $xoopsDB->queryf($sql)){
368                        if($xoopsDB->getRowsNum($result))  return true;
369                }
370                return false;
371        }
372        function is_wp_file_found()
373        {
374                if (!file_exists($this->module_path . '/wp-settings.php')){
375                        return false;
376                }
377                return true;
378        }
379
380        function is_writeable_mode($check_file) {
381        if (!is_dir($check_file)) {
382           if ( file_exists($check_file) ) {
383                if (! is_writeable($check_file)) {
384                    return false;
385                                }
386            }
387        } else {
388            if (! is_writeable($check_file)) {
389                return false;
390            } else {
391                // Windows parmission check
392                $src_file = __FILE__ ;
393                                $newfile = $check_file . 'write_check.txt';
394                                if (!@copy($src_file, $newfile)) {
395                        return false;
396                                } else {
397                                        unlink($newfile);
398                                }
399                        }
400        }
401        return true;
402        }
403        function get_php_version()
404        {
405                if (function_exists('phpversion'))
406                        return phpversion();
407                else
408                        return '';
409        }
410        function get_mysql_version()
411        {
412                global $xoopsDB;
413                list($SV) = $xoopsDB->fetchRow($xoopsDB->query('SELECT version()'));
414                return $SV;
415        }
416        function get_mod_image_link($file_name='')
417        {
418                $link_url = '';
419                if(!empty($file_name)){
420                        if(file_exists($this->module_path.'/images/'.$file_name)){
421                                $link_url = '<img alt="'.$file_name.'" src="'. $this->mod_url .'/images/'.$file_name.'" title="'.$file_name.'" align=top>';
422                        }
423                }
424                return $link_url;
425        }
426       
427}
428endif;
429?>
Note: See TracBrowser for help on using the repository browser.