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