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