XPressME Integration Kit

Trac

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

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

$xoopsModuleがロードされていないときディレクトリー名指定でモジュール情報を取得するように変更

File size: 9.6 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')) :
12
13class modInfoClass {
14        var $xoops_mainfile_path;
15        var $xoops_root_path;
16        var $xoops_url;
17        var $xoops_trust_path;
18        var $xoops_var_path;
19        var $xoops_cache_path;
20        var $xoops_upload_path;
21        var $xoops_upload_url;
22        var $xoops_db_salt;
23        var $xoops_salt;
24        var $xoops_db_prefix;
25        var $xoops_language;
26        var $module_db_prefix;
27        var $module_name;
28        var $module_path;
29        var $module_url;
30        var $module_version;
31        var $module_codename;
32        var $module_id;
33        var $xoops_version;
34        var $is_impress_cms;
35        var $is_cube_legacy;
36        var $is_xoops2jp;
37        var $is_xoops2;
38        var $is_xoops_legacy;
39        var $is_jpex;
40        var $xoops_time_zone;
41        var $wp_version;
42        var $wpConfigInfo;
43       
44        function __constructor()        //for PHP5
45    {
46        $this->modInfoClass();
47       
48    }
49   
50    function modInfoClass()     //for PHP4 constructor
51    { 
52        global $xoopsModule,$wpConfigInfo,$xoopsConfig;
53        if (!is_object($wpConfigInfo)){
54                include_once dirname(__FILE__).'/wpConfigInfo_class.php';
55                $this->wpConfigInfo = new wpConfigInfoClass;
56        }
57        if (! is_object($xoopsModule)){
58                        $module_handler =& xoops_gethandler('module');
59                        $xoopsModule =& $module_handler->getByDirname(basename(dirname(dirname(__FILE__))));
60                }       
61
62        $this->xoops_root_path = XOOPS_ROOT_PATH;
63                $this->xoops_trust_path = (defined('XOOPS_TRUST_PATH')) ? XOOPS_TRUST_PATH : '';
64                $this->xoops_url = XOOPS_URL;
65        $this->xoops_mainfile_path = XOOPS_ROOT_PATH . '/mainfile.php';
66                $this->xoops_upload_path = XOOPS_UPLOAD_PATH;
67                $this->xoops_upload_url = XOOPS_UPLOAD_URL;
68                $this->xoops_cache_path = XOOPS_CACHE_PATH;
69        $this->module_path=dirname(dirname(__FILE__));
70        $this->module_name=basename($this->module_path);
71                $this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
72                $this->xoops_db_prefix = XOOPS_DB_PREFIX . '_';
73                $this->module_db_prefix = $this->_get_module_db_prefix();
74                $this->xoops_lang =  @$GLOBALS["xoopsConfig"]['language'];
75                $this->module_id = ! empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
76                $this->module_version = ! empty($xoopsModule) ? $xoopsModule->getVar('version')/100 : '';
77                $this->module_codename = $this->_get_module_codename();
78                $this->wp_version = $this->_get_wp_version();
79               
80                $this->xoops_version = (defined('XOOPS_VERSION')) ? XOOPS_VERSION : '';
81        $this->_branches_cores();
82               
83                if (function_exists('date_default_timezone_get')){
84                        $this->xoops_time_zone = date_default_timezone_get();
85                } else {
86                        $this->xoops_time_zone = $xoopsConfig['default_TZ'];
87                }
88    }
89
90        function _get_module_db_prefix(){
91        $module_db_prefix = XOOPS_DB_PREFIX . '_' . preg_replace('/wordpress/','wp',$this->module_name);
92        return $module_db_prefix;
93        }
94    function _branches_cores(){
95        /*  XOOPS include/version.php define value */
96                //define("XOOPS_VERSION","XOOPS 2.0.16a JP");
97                //define("XOOPS_VERSION", "XOOPS Cube Legacy 2.2");
98                //define('XOOPS_VERSION', 'ImpressCMS 1.1.2 Final');
99                //define("XOOPS_VERSION", "XOOPS JPEx 1.6");
100                //define("XOOPS_VERSION", "XOOPS 2.3.3");
101                //define("XOOPS_VERSION", "Xoops Legacy");      define("XOOPS_ENGINE", "legacy");
102        $this->is_impress_cms = false;
103                $this->is_cube_legacy = false;
104                $this->is_xoops2jp = false;
105                $this->is_xoops2 = false;
106                $this->is_xoops_legacy = false;
107                $this->is_jpex = false;
108               
109                $version = XOOPS_VERSION;
110               
111               
112        // branches by cores
113                if( preg_match('/JP$/', $this->xoops_version))
114                        $this->is_xoops2jp = true;
115                if( preg_match('/Cube\s*Legacy/', $this->xoops_version))
116                        $this->is_cube_legacy = true;
117                if( preg_match('/ImpressCMS/', $this->xoops_version))
118                        $this->is_impress_cms = true;
119                if( preg_match('/JPEx/', $this->xoops_version))
120                        $this->is_jpex = true;
121                if( preg_match('/XOOPS\s*[0-9|\.]*$/', $this->xoops_version))
122                        $this->is_xoops2 = true;
123                if( preg_match('/Xoops\s*Legacy/', $this->xoops_version))
124                        $this->is_xoops_legacy = true;
125        }
126    function _get_wp_version(){
127        $wp_version_file =  dirname(dirname(__FILE__)) . '/wp-includes/version.php';
128        if (file_exists($wp_version_file)){
129                include $wp_version_file;
130                return str_replace("ME", "", $wp_version);
131        }
132        return '';
133    }
134       
135    // get XPressME module virsion and codename from xoops_versions.php
136    function _get_module_codename(){
137        $xoops_version_file = $this->module_path . '/xoops_version.php';
138                if(file_exists($xoops_version_file)){
139                        $version_file = file($xoops_version_file);
140                        $codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
141                        for ($i = 0 ; $i <count($version_file) ; $i++){
142                                if (preg_match( "/$codename_pattern/", $version_file[$i] ,$c_matches )){
143                                        return $c_matches[2];
144                                }
145                        }
146                }
147                return '';
148    }
149        function get_xoops_db_prefix(){
150                return $this->xoops_db_prefix;
151        }
152       
153        function get_xoops_root_path(){
154                return $this->xoops_root_path;
155        }
156        function get_xoops_trust_path(){
157                return $this->xoops_trust_path;
158        }
159        function get_xoops_mainfile_path(){
160                return $this->xoops_mainfile_path;
161        }
162        function get_xoops_header_path(){
163                return $this->xoops_root_path ."/header.php";
164        }
165        function get_xoops_footer_path(){
166                return $this->xoops_root_path . '/footer.php';
167        }
168        function get_xoops_cache_path(){
169                return $this->xoops_cache_path;
170        }
171        function get_xoops_url(){
172                return $this->xoops_url;
173        }
174        function get_xoops_upload_path(){
175                return $this->xoops_upload_path;
176        }
177        function get_xoops_upload_url(){
178                return $this->xoops_upload_url;
179        }
180        function get_module_path(){
181                return $this->module_path;
182        }
183        function get_module_templates_path(){
184                return $this->module_path . '/templates';
185        }
186       
187        function get_module_name(){
188                return $this->module_name;
189        }
190        function get_module_dirname(){
191                return $this->module_name;
192        }
193        function get_module_url(){
194                return $this->module_url;
195        }
196        function get_module_db_prefix(){
197                return $this->xpress_db_prefix;
198        }
199        function get_xoops_time_zone(){
200                return $this->xoops_time_zone;
201        }
202        function get_module_version(){
203                return $this->module_version;
204        }
205        function get_module_codename(){
206                return $this->module_codename;
207        }
208        function get_wp_version(){
209                return $this->wp_version;
210        }
211        function get_module_full_version(){
212                return $this->module_version . $this->module_codename;
213        }
214       
215        function is_impress_cms(){
216                return $this->is_impress_cms;
217        }
218        function is_cube_legacy(){
219                return $this->is_cube_legacy;
220        }
221        function is_xoops2jp(){
222                return $this->is_xoops2jp;
223        }
224        function is_xoops2(){
225                return $this->is_xoops2;
226        }
227        function is_xoops_legacy(){
228                return $this->is_xoops_legacy;
229        }
230        function is_jpex(){
231                return $this->is_jpex;
232        }
233       
234        function get_moduleID_ByDirname($dir_name){
235                $module_handler =& xoops_gethandler('module');
236                $module =& $module_handler->getByDirname($dir_name);
237                $module_id = $module->getVar('mid');
238                return $module_id;
239        }
240
241        function get_moduleID(){
242                global $xoopsModule;
243                $module_id = $xoopsModule->getVar('mid');
244                return $module_id;
245        }
246       
247        function get_ModuleConfig($key_name=''){
248                if (empty($key_name)) return '';
249                global $xoopsModuleConfig;
250                $value = isset($xoopsModuleConfig[$key_name]) ? $xoopsModuleConfig[$key_name] : '';
251        }
252       
253        function get_ModuleConfig_ByDirname($dir_name,$key_name=''){
254                $mid = $this->get_moduleID_ByDirname($dir_name);
255                $conf_handler =& xoops_gethandler('config');
256                $modConfig = $conf_handler->getConfigsByCat(0, $mid);
257                if(empty($modConfig)) return '';
258                if(empty($key_name)) return $modConfig;
259                return isset($modConfig[$key_name]) ? $modConfig[$key_name] : '';
260        }
261   
262        function is_wpdb_installed(){
263                global $xoopsDB;
264                $mydirname = basename(dirname( dirname( __FILE__ ) )) ;
265                $prefix_mod = XOOPS_DB_PREFIX .'_' . preg_replace('/wordpress/','wp',$mydirname) . '_';
266                $sql = "SHOW TABLES LIKE '$prefix_mod%'";
267                if ($result = $xoopsDB->queryf($sql)){
268                        if($xoopsDB->getRowsNum($result))  return true;
269                }
270                return false;
271        }
272        function is_wp_file_found()
273        {
274                if (!file_exists($this->module_path . '/wp-settings.php')){
275                        return false;
276                }
277                return true;
278        }
279
280        function is_writeable_mode($check_file) {
281        if (!is_dir($check_file)) {
282           if ( file_exists($check_file) ) {
283                if (! is_writeable($check_file)) {
284                    return false;
285                                }
286            }
287        } else {
288            if (! is_writeable($check_file)) {
289                return false;
290            } else {
291                // Windows parmission check
292                $src_file = __FILE__ ;
293                                $newfile = $check_file . 'write_check.txt';
294                                if (!@copy($src_file, $newfile)) {
295                        return false;
296                                } else {
297                                        unlink($newfile);
298                                }
299                        }
300        }
301        return true;
302        }
303        function get_php_version()
304        {
305                if (function_exists('phpversion'))
306                        return phpversion();
307                else
308                        return '';
309        }
310        function get_mysql_version()
311        {
312                global $xoopsDB;
313                list($SV) = $xoopsDB->fetchRow($xoopsDB->query('SELECT version()'));
314                return $SV;
315        }
316        public function get_mod_image_link($file_name='')
317        {
318                $link_url = '';
319                if(!empty($file_name)){
320                        if(file_exists($this->module_path.'/images/'.$file_name)){
321                                $link_url = '<img alt="'.$file_name.'" src="'. $this->mod_url .'/images/'.$file_name.'" title="'.$file_name.'" align=top>';
322                        }
323                }
324                return $link_url;
325        }
326        function get_wpLang($xoops_lang=''){
327                return $this->wpConfigInfo->get_wpLang($xoops_lang);
328        }
329       
330}
331endif;
332?>
Note: See TracBrowser for help on using the repository browser.