[1] | 1 | <?php |
---|
| 2 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; |
---|
| 3 | |
---|
| 4 | eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return xpress_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ; |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | if( ! function_exists( 'xpress_onupdate_base' ) ) : |
---|
| 8 | function xpress_onupdate_base( $module , $mydirname ) |
---|
| 9 | { |
---|
| 10 | // transations on module update |
---|
| 11 | |
---|
[128] | 12 | global $msgs ; // TODO :-D |
---|
[1] | 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' ) ; |
---|
[384] | 17 | $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpress_message_append_onupdate' ) ; |
---|
[128] | 18 | $msgs = array() ; |
---|
[1] | 19 | } else { |
---|
[128] | 20 | if( ! is_array( $msgs ) ) $msgs = array() ; |
---|
[1] | 21 | } |
---|
| 22 | |
---|
| 23 | $mid = $module->getVar('mid') ; |
---|
[384] | 24 | |
---|
[1] | 25 | |
---|
[384] | 26 | |
---|
[208] | 27 | //XPressME Update |
---|
| 28 | global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query; |
---|
[252] | 29 | global $xoops_db; |
---|
[208] | 30 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; |
---|
| 31 | $path = $mydirpath . '/'; |
---|
[384] | 32 | |
---|
| 33 | |
---|
[277] | 34 | //Site_url and home of an optional table are repaired. |
---|
| 35 | $site_url= XOOPS_URL."/modules/".$mydirname; |
---|
| 36 | xpress_put_siteurl($mydirname,$site_url); |
---|
[474] | 37 | $home = get_xpress_option($mydirname,'home'); |
---|
| 38 | $home_check = 'home option is right'; |
---|
| 39 | if (strcmp($site_url,$home) !== 0 ){ |
---|
| 40 | if (!@fclose(@fopen($home . '/xoops_version.php', "r"))){ |
---|
| 41 | xpress_put_home($mydirname,$site_url); |
---|
| 42 | $home_check = 'Change home option $home to $site_url'; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | $msgs[] = $home_check; |
---|
[208] | 46 | // XPressME orignal table update |
---|
[277] | 47 | $t_mess = xpress_table_make($module , $mydirname); |
---|
| 48 | $msgs = array_merge($msgs,$t_mess); |
---|
[1] | 49 | |
---|
[187] | 50 | // make templates |
---|
[102] | 51 | include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; |
---|
[462] | 52 | $mod_version = $module->getVar('version') ; |
---|
| 53 | |
---|
| 54 | $t_mess = xpress_clean_templates_file($mydirname,$mod_version); |
---|
| 55 | $msgs = array_merge($msgs,$t_mess); |
---|
| 56 | |
---|
[102] | 57 | $t_mess = xpress_templates_make($mid,$mydirname); |
---|
[128] | 58 | $msgs = array_merge($msgs,$t_mess); |
---|
[187] | 59 | |
---|
[277] | 60 | // The activation processing of the XPressME plugin is omitted. |
---|
| 61 | // Because the XPressME plugin is done with wp-config in activation |
---|
[187] | 62 | |
---|
| 63 | /* activate the xpressme plugin */ |
---|
[277] | 64 | // require_once dirname( __FILE__ ).'/xpress_active_plugin.php'; |
---|
| 65 | // if (xpress_pulugin_activation('xpressme/xpressme.php')){ |
---|
| 66 | // $msgs[] = 'The xpressme plug-in was activated.'; |
---|
| 67 | // } |
---|
[187] | 68 | |
---|
[1] | 69 | return true ; |
---|
| 70 | } |
---|
| 71 | endif; |
---|
| 72 | |
---|
[187] | 73 | if( ! function_exists( 'xpress_put_siteurl' ) ) : |
---|
| 74 | function xpress_put_siteurl($mydirname,$url){ |
---|
[749] | 75 | global $xoopsModule,$xoopsDB; |
---|
[583] | 76 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
[187] | 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 | } |
---|
| 82 | endif; |
---|
| 83 | |
---|
[277] | 84 | if( ! function_exists( 'xpress_put_home' ) ) : |
---|
| 85 | function xpress_put_home($mydirname,$url){ |
---|
[749] | 86 | global $xoopsModule,$xoopsDB; |
---|
[583] | 87 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
[277] | 88 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 89 | |
---|
| 90 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'"; |
---|
| 91 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 92 | } |
---|
| 93 | endif; |
---|
| 94 | |
---|
[474] | 95 | if( ! function_exists( 'get_xpress_option' ) ) { |
---|
| 96 | function get_xpress_option($mydirname,$option_name){ |
---|
[749] | 97 | global $xoopsModule,$xoopsDB; |
---|
[583] | 98 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
[474] | 99 | $option_table = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
[277] | 100 | |
---|
[474] | 101 | $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'"; |
---|
| 102 | |
---|
| 103 | $result = $xoopsDB->query($sql, 0, 0); |
---|
| 104 | if ($xoopsDB->getRowsNum($result) > 0){ |
---|
| 105 | $row = $xoopsDB->fetchArray($result); |
---|
| 106 | return $row['option_value']; |
---|
| 107 | } |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
[1] | 112 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
| 113 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
| 114 | { |
---|
| 115 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
| 116 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
| 117 | $log->add( strip_tags( $message ) ) ; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
| 122 | } |
---|
| 123 | endif; |
---|
| 124 | |
---|
| 125 | if( ! function_exists( 'get_db_version' ) ) : |
---|
| 126 | function get_db_version($mydirname){ |
---|
[749] | 127 | global $xoopsModule,$xoopsDB; |
---|
[583] | 128 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
[1] | 129 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 130 | |
---|
| 131 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
| 132 | $res = $xoopsDB->query($sql, 0, 0); |
---|
| 133 | if ($res === false){ |
---|
| 134 | return false; |
---|
| 135 | } else { |
---|
| 136 | $row = $xoopsDB->fetchArray($res); |
---|
| 137 | return $row['option_value']; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | endif; |
---|
| 141 | |
---|
[277] | 142 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
| 143 | function xpress_block_check($mydirname){ |
---|
| 144 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
[1] | 145 | |
---|
[277] | 146 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
| 147 | |
---|
| 148 | if ( !$xoops_block_check->is_admin() ) |
---|
| 149 | { |
---|
| 150 | $cont = 'Block Check Pass'; |
---|
| 151 | return cont; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | switch ( $xoops_block_check->get_op() ) |
---|
| 155 | { |
---|
| 156 | case "remove_block": |
---|
| 157 | $cont = $xoops_block_check->remove_block(); |
---|
| 158 | break; |
---|
| 159 | |
---|
| 160 | default: |
---|
| 161 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
| 162 | break; |
---|
| 163 | } |
---|
| 164 | return $cont; |
---|
| 165 | } |
---|
| 166 | endif; |
---|
| 167 | |
---|
| 168 | if( ! function_exists( 'xpress_table_make' ) ) : |
---|
| 169 | function xpress_table_make($module, $mydirname) |
---|
| 170 | { |
---|
[749] | 171 | global $xoopsDB; |
---|
[277] | 172 | $mid = $module->getVar('mid') ; |
---|
| 173 | |
---|
| 174 | // XPressME orignal table update |
---|
[583] | 175 | $xp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
[277] | 176 | $msgs = array(); |
---|
| 177 | |
---|
[428] | 178 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
[277] | 179 | if (! enhanced_table_check($mydirname,'views')){ |
---|
| 180 | $queries ="CREATE TABLE $views_table ( |
---|
[428] | 181 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
[277] | 182 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
| 183 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
| 184 | KEY post_id (post_id) |
---|
| 185 | ) TYPE=MyISAM"; |
---|
[749] | 186 | $xoopsDB->queryF( $queries ) ; |
---|
[277] | 187 | $msgs[] = "$views_table table of XPressME was made."; |
---|
[428] | 188 | } else { |
---|
| 189 | if (!is_found_table_column($views_table,'blog_id')){ |
---|
| 190 | $queries ="ALTER TABLE $views_table ADD blog_id bigint(20) FIRST"; |
---|
[749] | 191 | $xoopsDB->queryF( $queries ) ; |
---|
[428] | 192 | $msgs[] = "$views_table ADD blog_id ."; |
---|
| 193 | } |
---|
[481] | 194 | |
---|
| 195 | // The table is repaired. |
---|
| 196 | $non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1"; |
---|
[749] | 197 | $non_blogid_res = $xoopsDB->query($non_blogid_sql, 0, 0); |
---|
| 198 | while($row = $xoopsDB->fetchArray($non_blogid_res)){ |
---|
[481] | 199 | $total_view = $row['post_views']; |
---|
| 200 | $post_id = $row['post_id']; |
---|
| 201 | $new_blogid_sql ="SELECT SUM(post_views) as post_views_sum FROM $views_table WHERE post_id = $post_id AND blog_id = 1 GROUP BY post_id"; |
---|
[749] | 202 | $new_blogid_res = $xoopsDB->query($new_blogid_sql, 0, 0); |
---|
| 203 | if ($xoopsDB->getRowsNum($new_blogid_res) > 0){ |
---|
| 204 | $new_row = $xoopsDB->fetchArray($new_blogid_res); |
---|
[481] | 205 | $total_view = $total_view + $new_row['post_views_sum']; |
---|
| 206 | $del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1"; |
---|
[749] | 207 | $xoopsDB->queryF( $del_sql ) ; |
---|
[481] | 208 | } |
---|
| 209 | $update_sql = "UPDATE $views_table SET post_views = $total_view , blog_id = 1 WHERE post_id = $post_id AND (blog_id IS NULL OR blog_id < 1)"; |
---|
[749] | 210 | $xoopsDB->queryF( $update_sql ) ; |
---|
[481] | 211 | } |
---|
[277] | 212 | } |
---|
| 213 | |
---|
[590] | 214 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
[277] | 215 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
| 216 | $queries ="CREATE TABLE $d3forum_link ( |
---|
| 217 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
| 218 | post_id int(10) unsigned NOT NULL default '0' , |
---|
| 219 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
[590] | 220 | forum_id bigint(20) unsigned NOT NULL default '0', |
---|
| 221 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
[277] | 222 | KEY post_id (post_id) |
---|
| 223 | )TYPE=MyISAM"; |
---|
[749] | 224 | $xoopsDB->queryF( $queries ) ; |
---|
[277] | 225 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
[590] | 226 | } else { |
---|
| 227 | if (!is_found_table_column($d3forum_link,'forum_id')){ |
---|
| 228 | $queries ="ALTER TABLE $d3forum_link ADD forum_id bigint(20) unsigned NOT NULL default '0' AFTER wp_post_ID"; |
---|
[749] | 229 | $xoopsDB->queryF( $queries ) ; |
---|
[590] | 230 | $msgs[] = "$d3forum_link ADD forum_id ."; |
---|
| 231 | // The table is repaired. |
---|
| 232 | // $update_sql = "UPDATE $d3forum_link SET forum_id = 1 WHERE(forum_id IS NULL OR forum_id < 1)"; |
---|
[749] | 233 | // $xoopsDB->queryF( $update_sql ) ; |
---|
[590] | 234 | } |
---|
| 235 | if (!is_found_table_column($d3forum_link,'blog_id')){ |
---|
| 236 | $queries ="ALTER TABLE $d3forum_link ADD blog_id bigint(20) unsigned NOT NULL default '0' AFTER forum_id"; |
---|
[749] | 237 | $xoopsDB->queryF( $queries ) ; |
---|
[590] | 238 | $msgs[] = "$d3forum_link ADD blog_id ."; |
---|
| 239 | // The table is repaired. |
---|
| 240 | $update_sql = "UPDATE $d3forum_link SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)"; |
---|
[749] | 241 | $xoopsDB->queryF( $update_sql ) ; |
---|
[590] | 242 | } |
---|
[277] | 243 | } |
---|
| 244 | |
---|
[534] | 245 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
[277] | 246 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
| 247 | $queries ="CREATE TABLE $group_role ( |
---|
| 248 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
[534] | 249 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
[277] | 250 | name varchar(50) NOT NULL default '' , |
---|
| 251 | description text NOT NULL default '', |
---|
| 252 | group_type varchar(50) NOT NULL default '' , |
---|
| 253 | role varchar(20) NOT NULL default '' , |
---|
| 254 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
| 255 | KEY groupid (groupid) |
---|
| 256 | )TYPE=MyISAM"; |
---|
[749] | 257 | $xoopsDB->queryF( $queries ) ; |
---|
[277] | 258 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
[749] | 259 | $xoopsDB->queryF( $sql ) ; |
---|
[277] | 260 | $msgs[] = "$group_role table of XPressME was made."; |
---|
[534] | 261 | } else { |
---|
| 262 | if (!is_found_table_column($group_role,'blog_id')){ |
---|
| 263 | $queries ="ALTER TABLE $group_role ADD blog_id bigint(20) AFTER groupid"; |
---|
[749] | 264 | $xoopsDB->queryF( $queries ) ; |
---|
[534] | 265 | $msgs[] = "$group_role ADD blog_id ."; |
---|
| 266 | } |
---|
| 267 | // The table is repaired. |
---|
| 268 | $update_sql = "UPDATE $group_role SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)"; |
---|
[749] | 269 | $xoopsDB->queryF( $update_sql ) ; |
---|
[277] | 270 | } |
---|
| 271 | |
---|
[352] | 272 | if (! enhanced_table_check($mydirname,'notify_reserve')){ |
---|
| 273 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
| 274 | $queries ="CREATE TABLE $notify_reserve ( |
---|
| 275 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
| 276 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
| 277 | category text NOT NULL default '', |
---|
| 278 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
| 279 | event varchar(20) NOT NULL default '', |
---|
| 280 | extra_tags_arry longtext NOT NULL default '' , |
---|
| 281 | user_list_arry longtext NOT NULL default '' , |
---|
| 282 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
| 283 | omit_user_id varchar(20) NOT NULL default '' , |
---|
| 284 | KEY notify_reserve_id (notify_reserve_id) |
---|
| 285 | )TYPE=MyISAM"; |
---|
[749] | 286 | $xoopsDB->queryF( $queries ) ; |
---|
[352] | 287 | $msgs[] = "$notify_reserve table of XPressME was made."; |
---|
| 288 | } |
---|
[277] | 289 | return $msgs; |
---|
| 290 | } |
---|
| 291 | endif; |
---|
| 292 | |
---|
[1] | 293 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
| 294 | function enhanced_table_check($mydirname,$table_name){ |
---|
[749] | 295 | global $xoopsModule,$xoopsDB; |
---|
[1] | 296 | |
---|
[583] | 297 | $xpress_prefix = $xoopsDB->prefix(preg_replace('/wordpress/','wp',$mydirname) . '_'); |
---|
[1] | 298 | $db_enhanced = $xpress_prefix . $table_name; |
---|
| 299 | |
---|
| 300 | $sql = "show tables like '$db_enhanced'"; |
---|
| 301 | $res = $xoopsDB->query($sql, 0, 0); |
---|
| 302 | if ($res === false){ |
---|
| 303 | return false; |
---|
| 304 | } else { |
---|
| 305 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
| 306 | return true; |
---|
| 307 | else |
---|
| 308 | return false; |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | endif; |
---|
| 312 | |
---|
[428] | 313 | if( ! function_exists( 'is_found_table_column' ) ) : |
---|
| 314 | function is_found_table_column($table,$column){ |
---|
[749] | 315 | global $xoopsModule,$xoopsDB; |
---|
[151] | 316 | |
---|
[428] | 317 | $sql = "DESCRIBE $table $column"; |
---|
| 318 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 319 | if ($res === false){ |
---|
| 320 | return false; |
---|
| 321 | } else { |
---|
| 322 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
| 323 | return true; |
---|
| 324 | else |
---|
| 325 | return false; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | endif; |
---|
[151] | 329 | |
---|
[428] | 330 | |
---|
[1] | 331 | ?> |
---|