XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/onupdate.php @ 428

Last change on this file since 428 was 428, checked in by toemon, 15 years ago

WPMUで閲覧数が正常に機能しないバグ修正 Fixes #241

File size: 8.4 KB
Line 
1<?php
2$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
3
4eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return xpress_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
5
6
7if( ! function_exists( 'xpress_onupdate_base' ) ) :
8function xpress_onupdate_base( $module , $mydirname )
9{
10        // transations on module update
11
12        global $msgs ; // TODO :-D
13        // for Cube 2.1
14        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
15                $root =& XCube_Root::getSingleton();
16                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpress_message_append_onupdate' ) ;
17                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpress_message_append_onupdate' ) ;
18                $msgs = array() ;
19        } else {
20                if( ! is_array( $msgs ) ) $msgs = array() ;
21        }
22
23        $db =& Database::getInstance() ;
24        $mid = $module->getVar('mid') ;
25       
26
27
28//XPressME Update
29        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query;
30        global $xoops_db;
31        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
32        $path = $mydirpath . '/';
33
34// permission and wordpress files check
35        require_once ($path . 'include/pre_check.php');
36        if(! xp_permission_check($mydirname, $mydirpath)){
37                $msgs = $GLOBALS["err_log"];
38                return false;
39        }
40
41//Site_url and home of an optional table are repaired.
42        $site_url= XOOPS_URL."/modules/".$mydirname;
43        xpress_put_siteurl($mydirname,$site_url);
44        xpress_put_home($mydirname,$site_url);
45
46// XPressME orignal table update
47        $t_mess = xpress_table_make($module , $mydirname);
48        $msgs = array_merge($msgs,$t_mess);
49
50// make templates
51        include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
52        $t_mess = xpress_templates_make($mid,$mydirname);
53       
54        $msgs = array_merge($msgs,$t_mess);
55
56// The activation processing of the XPressME plugin is omitted.
57// Because the XPressME plugin is done with wp-config in activation
58
59        /* activate the xpressme plugin */
60//      require_once dirname( __FILE__ ).'/xpress_active_plugin.php';
61//      if (xpress_pulugin_activation('xpressme/xpressme.php')){
62//              $msgs[] = 'The xpressme plug-in was activated.';
63//      }
64       
65        return true ;
66}
67endif;
68
69if( ! function_exists( 'xpress_put_siteurl' ) ) :
70function xpress_put_siteurl($mydirname,$url){
71                global $xoopsModule;
72                $wp_prefix = $mydirname;
73                if ($wp_prefix == 'wordpress'){
74                        $wp_prefix = 'wp';
75                }
76                $xoopsDB =& Database::getInstance();
77                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
78
79                $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'";
80                $res = $xoopsDB->queryF($sql, 0, 0);
81}
82endif;
83
84if( ! function_exists( 'xpress_put_home' ) ) :
85function xpress_put_home($mydirname,$url){
86                global $xoopsModule;
87                $wp_prefix = $mydirname;
88                if ($wp_prefix == 'wordpress'){
89                        $wp_prefix = 'wp';
90                }
91                $xoopsDB =& Database::getInstance();
92                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
93
94                $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'";
95                $res = $xoopsDB->queryF($sql, 0, 0);
96}
97endif;
98
99
100if( ! function_exists( 'xpress_message_append_onupdate' ) ) :
101function xpress_message_append_onupdate( &$module_obj , &$log )
102{
103        if( is_array( @$GLOBALS['msgs'] ) ) {
104                foreach( $GLOBALS['msgs'] as $message ) {
105                        $log->add( strip_tags( $message ) ) ;
106                }
107        }
108
109        // use mLog->addWarning() or mLog->addError() if necessary
110}
111endif;
112
113if( ! function_exists( 'get_db_version' ) ) :
114function get_db_version($mydirname){
115                global $xoopsModule;
116                $wp_prefix = $mydirname;
117                if ($wp_prefix == 'wordpress'){
118                        $wp_prefix = 'wp';
119                }
120                $xoopsDB =& Database::getInstance();
121                $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
122
123                $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'";
124                $res = $xoopsDB->query($sql, 0, 0);
125                if ($res === false){
126                        return false;
127                } else {
128                        $row = $xoopsDB->fetchArray($res);
129                        return $row['option_value'];
130                }
131}
132endif;
133
134if( ! function_exists( 'xpress_block_check' ) ) :
135function xpress_block_check($mydirname){
136        include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php');
137
138        $xoops_block_check =& xoops_block_check::getInstance();
139
140        if ( !$xoops_block_check->is_admin() )
141        {
142                $cont = 'Block Check Pass';
143                return cont;
144        }
145
146        switch ( $xoops_block_check->get_op() )
147        {
148                case "remove_block":
149                        $cont = $xoops_block_check->remove_block();
150                        break;
151
152                default:
153                        $cont = $xoops_block_check->check_blocks($mydirname);
154                        break;
155        }
156        return $cont;
157}
158endif;
159
160if( ! function_exists( 'xpress_table_make' ) ) :
161function xpress_table_make($module, $mydirname)
162{
163        $xp_prefix = $mydirname;
164        if ($xp_prefix == 'wordpress'){
165                $xp_prefix = 'wp';
166        }
167        $db =& Database::getInstance() ;
168        $mid = $module->getVar('mid') ;
169
170// XPressME orignal table update
171        $xp_prefix = $mydirname;
172        if ($xp_prefix == 'wordpress'){
173                $xp_prefix = 'wp';
174        }
175        $msgs = array();
176
177        $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
178        if (! enhanced_table_check($mydirname,'views')){
179                $queries ="CREATE TABLE $views_table (
180                blog_id bigint(20) unsigned NOT NULL default '0',
181                post_id bigint(20) unsigned NOT NULL default '0',
182                post_views bigint(20) unsigned NOT NULL default '0',
183                KEY post_id (post_id)
184                ) TYPE=MyISAM";
185                $db->queryF( $queries ) ;
186                $msgs[] = "$views_table table of XPressME was made.";
187        } else {
188                if (!is_found_table_column($views_table,'blog_id')){
189                        $queries ="ALTER TABLE $views_table ADD blog_id bigint(20)  FIRST";
190                        $db->queryF( $queries ) ;
191                        $msgs[] = "$views_table  ADD blog_id .";
192                }
193        }
194       
195        if (! enhanced_table_check($mydirname,'d3forum_link')){
196                $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
197                $queries ="CREATE TABLE $d3forum_link (
198                        comment_ID bigint(20) unsigned NOT NULL default '0',
199                        post_id int(10) unsigned NOT NULL default '0' ,
200                        wp_post_ID bigint(20) unsigned NOT NULL default '0',
201                        KEY post_id (post_id)
202                        )TYPE=MyISAM";
203                $db->queryF( $queries ) ;
204                $msgs[] = "$d3forum_link table of XPressME was made.";
205        }
206
207        if (! enhanced_table_check($mydirname,'group_role')){
208                $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
209                $queries ="CREATE TABLE $group_role (
210                        groupid smallint(5) unsigned NOT NULL default '0',
211                        name varchar(50)  NOT NULL default '' ,
212                        description text  NOT NULL default '',
213                        group_type varchar(50)  NOT NULL default '' ,
214                        role varchar(20)  NOT NULL default '' ,
215                        login_all smallint(5) unsigned NOT NULL default '0' ,
216                        KEY groupid (groupid)
217                        )TYPE=MyISAM";
218                $db->queryF( $queries ) ;
219                $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
220                $db->queryF( $sql ) ;
221                $msgs[] = "$group_role table of XPressME was made.";
222        }
223       
224        if (! enhanced_table_check($mydirname,'notify_reserve')){
225                $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ;
226                $queries ="CREATE TABLE $notify_reserve (
227                        notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT ,
228                        notify_reserve_status varchar(20)  NOT NULL default '' ,
229                        category text  NOT NULL default '',
230                        item_id bigint(20) unsigned NOT NULL default '0',
231                        event varchar(20) NOT NULL default '',
232                        extra_tags_arry longtext NOT NULL default '' ,
233                        user_list_arry longtext NOT NULL default '' ,
234                        module_id smallint(5) unsigned NOT NULL default '0' ,
235                        omit_user_id varchar(20) NOT NULL default '' ,
236                        KEY notify_reserve_id (notify_reserve_id)
237                        )TYPE=MyISAM";
238                $db->queryF( $queries ) ;
239                $msgs[] = "$notify_reserve table of XPressME was made.";
240        }
241        return $msgs;
242}
243endif;
244
245if( ! function_exists( 'enhanced_table_check' ) ) :
246function enhanced_table_check($mydirname,$table_name){
247                global $xoopsModule;
248               
249                $xoopsDB =& Database::getInstance();
250                if ($mydirname == 'wordpress'){
251                        $xpress_prefix=  $xoopsDB->prefix('wp_');
252                } else {
253                        $xpress_prefix=  $xoopsDB->prefix($mydirname . '_');
254                }
255                $db_enhanced = $xpress_prefix . $table_name;
256
257                $sql = "show tables like '$db_enhanced'";
258                $res = $xoopsDB->query($sql, 0, 0);
259                if ($res === false){
260                        return false;
261                } else {
262                        if ($xoopsDB->getRowsNum($res)  > 0)
263                                return true;
264                        else
265                                return false;
266                }
267}
268endif;
269
270if( ! function_exists( 'is_found_table_column' ) ) :
271function is_found_table_column($table,$column){
272                global $xoopsModule;
273                $xoopsDB =& Database::getInstance();
274
275                $sql = "DESCRIBE $table $column";
276                $res = $xoopsDB->queryF($sql, 0, 0);
277                if ($res === false){
278                        return false;
279                } else {
280                        if ($xoopsDB->getRowsNum($res)  > 0)
281                                return true;
282                        else
283                                return false;
284                }
285}
286endif;
287
288
289?>
Note: See TracBrowser for help on using the repository browser.