[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); |
---|
[488] | 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' ; |
---|
[488] | 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; |
---|
| 83 | $wp_prefix = $mydirname; |
---|
| 84 | if ($wp_prefix == 'wordpress'){ |
---|
| 85 | $wp_prefix = 'wp'; |
---|
| 86 | } |
---|
| 87 | $xoopsDB =& Database::getInstance(); |
---|
| 88 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 89 | |
---|
| 90 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'"; |
---|
| 91 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 92 | } |
---|
| 93 | endif; |
---|
| 94 | |
---|
[277] | 95 | if( ! function_exists( 'xpress_put_home' ) ) : |
---|
| 96 | function xpress_put_home($mydirname,$url){ |
---|
| 97 | global $xoopsModule; |
---|
| 98 | $wp_prefix = $mydirname; |
---|
| 99 | if ($wp_prefix == 'wordpress'){ |
---|
| 100 | $wp_prefix = 'wp'; |
---|
| 101 | } |
---|
| 102 | $xoopsDB =& Database::getInstance(); |
---|
| 103 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 104 | |
---|
| 105 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'"; |
---|
| 106 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 107 | } |
---|
| 108 | endif; |
---|
| 109 | |
---|
[488] | 110 | if( ! function_exists( 'get_xpress_option' ) ) { |
---|
| 111 | function get_xpress_option($mydirname,$option_name){ |
---|
| 112 | global $xoopsModule; |
---|
| 113 | $wp_prefix = $mydirname; |
---|
| 114 | if ($wp_prefix == 'wordpress'){ |
---|
| 115 | $wp_prefix = 'wp'; |
---|
| 116 | } |
---|
| 117 | $xoopsDB =& Database::getInstance(); |
---|
| 118 | $option_table = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
[277] | 119 | |
---|
[488] | 120 | $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'"; |
---|
| 121 | |
---|
| 122 | $result = $xoopsDB->query($sql, 0, 0); |
---|
| 123 | if ($xoopsDB->getRowsNum($result) > 0){ |
---|
| 124 | $row = $xoopsDB->fetchArray($result); |
---|
| 125 | return $row['option_value']; |
---|
| 126 | } |
---|
| 127 | return 0; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
[1] | 131 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
| 132 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
| 133 | { |
---|
| 134 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
| 135 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
| 136 | $log->add( strip_tags( $message ) ) ; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
| 141 | } |
---|
| 142 | endif; |
---|
| 143 | |
---|
| 144 | if( ! function_exists( 'get_db_version' ) ) : |
---|
| 145 | function get_db_version($mydirname){ |
---|
| 146 | global $xoopsModule; |
---|
| 147 | $wp_prefix = $mydirname; |
---|
| 148 | if ($wp_prefix == 'wordpress'){ |
---|
| 149 | $wp_prefix = 'wp'; |
---|
| 150 | } |
---|
| 151 | $xoopsDB =& Database::getInstance(); |
---|
| 152 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 153 | |
---|
| 154 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
| 155 | $res = $xoopsDB->query($sql, 0, 0); |
---|
| 156 | if ($res === false){ |
---|
| 157 | return false; |
---|
| 158 | } else { |
---|
| 159 | $row = $xoopsDB->fetchArray($res); |
---|
| 160 | return $row['option_value']; |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | endif; |
---|
| 164 | |
---|
[277] | 165 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
| 166 | function xpress_block_check($mydirname){ |
---|
| 167 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
[1] | 168 | |
---|
[277] | 169 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
| 170 | |
---|
| 171 | if ( !$xoops_block_check->is_admin() ) |
---|
| 172 | { |
---|
| 173 | $cont = 'Block Check Pass'; |
---|
| 174 | return cont; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | switch ( $xoops_block_check->get_op() ) |
---|
| 178 | { |
---|
| 179 | case "remove_block": |
---|
| 180 | $cont = $xoops_block_check->remove_block(); |
---|
| 181 | break; |
---|
| 182 | |
---|
| 183 | default: |
---|
| 184 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
| 185 | break; |
---|
| 186 | } |
---|
| 187 | return $cont; |
---|
| 188 | } |
---|
| 189 | endif; |
---|
| 190 | |
---|
| 191 | if( ! function_exists( 'xpress_table_make' ) ) : |
---|
| 192 | function xpress_table_make($module, $mydirname) |
---|
| 193 | { |
---|
| 194 | $xp_prefix = $mydirname; |
---|
| 195 | if ($xp_prefix == 'wordpress'){ |
---|
| 196 | $xp_prefix = 'wp'; |
---|
| 197 | } |
---|
| 198 | $db =& Database::getInstance() ; |
---|
| 199 | $mid = $module->getVar('mid') ; |
---|
| 200 | |
---|
| 201 | // XPressME orignal table update |
---|
| 202 | $xp_prefix = $mydirname; |
---|
| 203 | if ($xp_prefix == 'wordpress'){ |
---|
| 204 | $xp_prefix = 'wp'; |
---|
| 205 | } |
---|
| 206 | $msgs = array(); |
---|
| 207 | |
---|
[428] | 208 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
[277] | 209 | if (! enhanced_table_check($mydirname,'views')){ |
---|
| 210 | $queries ="CREATE TABLE $views_table ( |
---|
[428] | 211 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
[277] | 212 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
| 213 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
| 214 | KEY post_id (post_id) |
---|
| 215 | ) TYPE=MyISAM"; |
---|
| 216 | $db->queryF( $queries ) ; |
---|
| 217 | $msgs[] = "$views_table table of XPressME was made."; |
---|
[428] | 218 | } else { |
---|
| 219 | if (!is_found_table_column($views_table,'blog_id')){ |
---|
| 220 | $queries ="ALTER TABLE $views_table ADD blog_id bigint(20) FIRST"; |
---|
| 221 | $db->queryF( $queries ) ; |
---|
| 222 | $msgs[] = "$views_table ADD blog_id ."; |
---|
| 223 | } |
---|
[488] | 224 | |
---|
| 225 | // The table is repaired. |
---|
| 226 | $non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1"; |
---|
| 227 | $non_blogid_res = $db->query($non_blogid_sql, 0, 0); |
---|
| 228 | while($row = $db->fetchArray($non_blogid_res)){ |
---|
| 229 | $total_view = $row['post_views']; |
---|
| 230 | $post_id = $row['post_id']; |
---|
| 231 | $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"; |
---|
| 232 | $new_blogid_res = $db->query($new_blogid_sql, 0, 0); |
---|
| 233 | if ($db->getRowsNum($new_blogid_res) > 0){ |
---|
| 234 | $new_row = $db->fetchArray($new_blogid_res); |
---|
| 235 | $total_view = $total_view + $new_row['post_views_sum']; |
---|
| 236 | $del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1"; |
---|
| 237 | $db->queryF( $del_sql ) ; |
---|
| 238 | } |
---|
| 239 | $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)"; |
---|
| 240 | $db->queryF( $update_sql ) ; |
---|
| 241 | } |
---|
[277] | 242 | } |
---|
| 243 | |
---|
| 244 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
| 245 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
| 246 | $queries ="CREATE TABLE $d3forum_link ( |
---|
| 247 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
| 248 | post_id int(10) unsigned NOT NULL default '0' , |
---|
| 249 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
| 250 | KEY post_id (post_id) |
---|
| 251 | )TYPE=MyISAM"; |
---|
| 252 | $db->queryF( $queries ) ; |
---|
| 253 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
| 257 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
| 258 | $queries ="CREATE TABLE $group_role ( |
---|
| 259 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
| 260 | name varchar(50) NOT NULL default '' , |
---|
| 261 | description text NOT NULL default '', |
---|
| 262 | group_type varchar(50) NOT NULL default '' , |
---|
| 263 | role varchar(20) NOT NULL default '' , |
---|
| 264 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
| 265 | KEY groupid (groupid) |
---|
| 266 | )TYPE=MyISAM"; |
---|
| 267 | $db->queryF( $queries ) ; |
---|
| 268 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
| 269 | $db->queryF( $sql ) ; |
---|
| 270 | $msgs[] = "$group_role table of XPressME was made."; |
---|
| 271 | } |
---|
| 272 | |
---|
[352] | 273 | if (! enhanced_table_check($mydirname,'notify_reserve')){ |
---|
| 274 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
| 275 | $queries ="CREATE TABLE $notify_reserve ( |
---|
| 276 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
| 277 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
| 278 | category text NOT NULL default '', |
---|
| 279 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
| 280 | event varchar(20) NOT NULL default '', |
---|
| 281 | extra_tags_arry longtext NOT NULL default '' , |
---|
| 282 | user_list_arry longtext NOT NULL default '' , |
---|
| 283 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
| 284 | omit_user_id varchar(20) NOT NULL default '' , |
---|
| 285 | KEY notify_reserve_id (notify_reserve_id) |
---|
| 286 | )TYPE=MyISAM"; |
---|
| 287 | $db->queryF( $queries ) ; |
---|
| 288 | $msgs[] = "$notify_reserve table of XPressME was made."; |
---|
| 289 | } |
---|
[277] | 290 | return $msgs; |
---|
| 291 | } |
---|
| 292 | endif; |
---|
| 293 | |
---|
[1] | 294 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
| 295 | function enhanced_table_check($mydirname,$table_name){ |
---|
| 296 | global $xoopsModule; |
---|
| 297 | |
---|
| 298 | $xoopsDB =& Database::getInstance(); |
---|
| 299 | if ($mydirname == 'wordpress'){ |
---|
| 300 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
| 301 | } else { |
---|
| 302 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
| 303 | } |
---|
| 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 | |
---|
[428] | 319 | if( ! function_exists( 'is_found_table_column' ) ) : |
---|
| 320 | function is_found_table_column($table,$column){ |
---|
| 321 | global $xoopsModule; |
---|
| 322 | $xoopsDB =& Database::getInstance(); |
---|
[151] | 323 | |
---|
[428] | 324 | $sql = "DESCRIBE $table $column"; |
---|
| 325 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 326 | if ($res === false){ |
---|
| 327 | return false; |
---|
| 328 | } else { |
---|
| 329 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
| 330 | return true; |
---|
| 331 | else |
---|
| 332 | return false; |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | endif; |
---|
[151] | 336 | |
---|
[428] | 337 | |
---|
[1] | 338 | ?> |
---|