[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' ) ; |
---|
[128] | 17 | $msgs = array() ; |
---|
[1] | 18 | } else { |
---|
[128] | 19 | if( ! is_array( $msgs ) ) $msgs = array() ; |
---|
[1] | 20 | } |
---|
| 21 | |
---|
| 22 | $db =& Database::getInstance() ; |
---|
| 23 | $mid = $module->getVar('mid') ; |
---|
| 24 | |
---|
[208] | 25 | |
---|
| 26 | |
---|
| 27 | //XPressME Update |
---|
| 28 | global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query; |
---|
| 29 | define('WP_INSTALLING', true); |
---|
| 30 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; |
---|
| 31 | $path = $mydirpath . '/'; |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | * xpress_put_siteurl($mydirname,''); |
---|
| 35 | * Call to a member function register() The on a non-object error is evaded. |
---|
| 36 | * It happens by register_widget() that exists in wp-includes/widgets.php. |
---|
| 37 | * The blog is not installed. It is cheating to function wp_maybe_load_widgets(). |
---|
| 38 | * As a result, default-widgets.php is not loaded. |
---|
| 39 | */ |
---|
| 40 | xpress_put_siteurl($mydirname,''); // Site_url is temporarily deleted. |
---|
| 41 | |
---|
| 42 | if (file_exists($path . 'wp-load.php')) { |
---|
| 43 | require_once $path . 'wp-load.php'; |
---|
| 44 | } else { |
---|
| 45 | require_once $path . 'wp-config.php'; |
---|
| 46 | } |
---|
[247] | 47 | // upgrade WordPress |
---|
| 48 | |
---|
| 49 | $site_url= XOOPS_URL."/modules/".$mydirname; |
---|
[258] | 50 | xpress_put_siteurl($mydirname,$site_url); // Site_url is set again. |
---|
[259] | 51 | update_option("home", $site_url); |
---|
[208] | 52 | |
---|
[247] | 53 | require_once($mydirpath . '/wp-admin/upgrade-functions.php'); |
---|
| 54 | |
---|
| 55 | if ( get_db_version($mydirname) != $wp_db_version ){ |
---|
| 56 | if( function_exists( 'wp_upgrade' ) ) { |
---|
| 57 | wp_upgrade(); |
---|
| 58 | } else { |
---|
| 59 | wp_cache_flush(); |
---|
| 60 | make_db_current_silent(); |
---|
| 61 | upgrade_all(); |
---|
| 62 | wp_cache_flush(); |
---|
| 63 | } |
---|
| 64 | $msgs[] = 'Upgrade Wordpress Database Ver.' . get_db_version($mydirname) .' to' . $wp_db_version; |
---|
| 65 | } |
---|
| 66 | |
---|
[208] | 67 | // XPressME orignal table update |
---|
[1] | 68 | if (! enhanced_table_check($mydirname,'views')){ |
---|
| 69 | $xp_prefix = $mydirname; |
---|
| 70 | if ($xp_prefix == 'wordpress'){ |
---|
| 71 | $xp_prefix = 'wp'; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | $charset_collate = ''; |
---|
| 75 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
| 76 | if ( ! empty($wpdb->charset) ) |
---|
| 77 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
| 78 | if ( ! empty($wpdb->collate) ) |
---|
| 79 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
| 80 | } |
---|
| 81 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
| 82 | $views_queries ="CREATE TABLE $views_table ( |
---|
| 83 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
| 84 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
| 85 | KEY post_id (post_id) |
---|
| 86 | )$charset_collate;"; |
---|
| 87 | |
---|
| 88 | dbDelta($views_queries); |
---|
[128] | 89 | $msgs[] = "$views_table table of XPressME was made."; |
---|
[1] | 90 | } |
---|
| 91 | |
---|
| 92 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
| 93 | $xp_prefix = $mydirname; |
---|
| 94 | if ($xp_prefix == 'wordpress'){ |
---|
| 95 | $xp_prefix = 'wp'; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | $charset_collate = ''; |
---|
| 99 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
| 100 | if ( ! empty($wpdb->charset) ) |
---|
| 101 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
| 102 | if ( ! empty($wpdb->collate) ) |
---|
| 103 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
| 107 | $queries ="CREATE TABLE $d3forum_link ( |
---|
| 108 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
| 109 | post_id int(10) unsigned NOT NULL default '0' , |
---|
| 110 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
| 111 | KEY post_id (post_id) |
---|
| 112 | )$charset_collate;"; |
---|
| 113 | dbDelta($queries); |
---|
[128] | 114 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
[1] | 115 | } |
---|
[76] | 116 | |
---|
| 117 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
| 118 | $xp_prefix = $mydirname; |
---|
| 119 | if ($xp_prefix == 'wordpress'){ |
---|
| 120 | $xp_prefix = 'wp'; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | $charset_collate = ''; |
---|
| 124 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
| 125 | if ( ! empty($wpdb->charset) ) |
---|
| 126 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
| 127 | if ( ! empty($wpdb->collate) ) |
---|
| 128 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
| 129 | } |
---|
[1] | 130 | |
---|
[76] | 131 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
| 132 | $views_queries ="CREATE TABLE $group_role ( |
---|
| 133 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
| 134 | name varchar(50) NOT NULL default '' , |
---|
| 135 | description text NOT NULL default '', |
---|
[152] | 136 | group_type varchar(50) NOT NULL default '' , |
---|
[76] | 137 | role varchar(20) NOT NULL default '' , |
---|
[81] | 138 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
[76] | 139 | KEY groupid (groupid) |
---|
| 140 | )$charset_collate;"; |
---|
| 141 | dbDelta($views_queries); |
---|
[80] | 142 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
| 143 | $wpdb->query($sql); |
---|
[128] | 144 | $msgs[] = "$group_role table of XPressME was made."; |
---|
[76] | 145 | } |
---|
[151] | 146 | if ( xpress_block_check($mydirname)) { |
---|
| 147 | $msgs[] = '<span style="color:#ff0000;">Block Check OK</span>'; |
---|
| 148 | } else { |
---|
| 149 | $msgs[] = "Block Check NG. You need Repar Block on This Mobule 'Block Check' Menu"; |
---|
| 150 | } |
---|
| 151 | |
---|
[187] | 152 | // make templates |
---|
[102] | 153 | include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; |
---|
| 154 | $t_mess = xpress_templates_make($mid,$mydirname); |
---|
[151] | 155 | |
---|
[128] | 156 | $msgs = array_merge($msgs,$t_mess); |
---|
[187] | 157 | |
---|
| 158 | |
---|
| 159 | /* activate the xpressme plugin */ |
---|
| 160 | require_once dirname( __FILE__ ).'/xpress_active_plugin.php'; |
---|
| 161 | if (xpress_pulugin_activation('xpressme/xpressme.php')){ |
---|
| 162 | $msgs[] = 'The xpressme plug-in was activated.'; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | // update_option("blog_charset", wp_blog_charset()); |
---|
| 166 | $xpress_version = $module->modinfo['version']; |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|
[1] | 170 | return true ; |
---|
| 171 | } |
---|
| 172 | endif; |
---|
| 173 | |
---|
[187] | 174 | if( ! function_exists( 'xpress_put_siteurl' ) ) : |
---|
| 175 | function xpress_put_siteurl($mydirname,$url){ |
---|
| 176 | global $xoopsModule; |
---|
| 177 | $wp_prefix = $mydirname; |
---|
| 178 | if ($wp_prefix == 'wordpress'){ |
---|
| 179 | $wp_prefix = 'wp'; |
---|
| 180 | } |
---|
| 181 | $xoopsDB =& Database::getInstance(); |
---|
| 182 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 183 | |
---|
| 184 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'"; |
---|
| 185 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
| 186 | } |
---|
| 187 | endif; |
---|
| 188 | |
---|
[1] | 189 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
| 190 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
| 191 | { |
---|
| 192 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
| 193 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
| 194 | $log->add( strip_tags( $message ) ) ; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
| 199 | } |
---|
| 200 | endif; |
---|
| 201 | |
---|
| 202 | if( ! function_exists( 'get_db_version' ) ) : |
---|
| 203 | function get_db_version($mydirname){ |
---|
| 204 | global $xoopsModule; |
---|
| 205 | $wp_prefix = $mydirname; |
---|
| 206 | if ($wp_prefix == 'wordpress'){ |
---|
| 207 | $wp_prefix = 'wp'; |
---|
| 208 | } |
---|
| 209 | $xoopsDB =& Database::getInstance(); |
---|
| 210 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
| 211 | |
---|
| 212 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
| 213 | $res = $xoopsDB->query($sql, 0, 0); |
---|
| 214 | if ($res === false){ |
---|
| 215 | return false; |
---|
| 216 | } else { |
---|
| 217 | $row = $xoopsDB->fetchArray($res); |
---|
| 218 | return $row['option_value']; |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | endif; |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
| 225 | function enhanced_table_check($mydirname,$table_name){ |
---|
| 226 | global $xoopsModule; |
---|
| 227 | |
---|
| 228 | $xoopsDB =& Database::getInstance(); |
---|
| 229 | if ($mydirname == 'wordpress'){ |
---|
| 230 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
| 231 | } else { |
---|
| 232 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
| 233 | } |
---|
| 234 | $db_enhanced = $xpress_prefix . $table_name; |
---|
| 235 | |
---|
| 236 | $sql = "show tables like '$db_enhanced'"; |
---|
| 237 | $res = $xoopsDB->query($sql, 0, 0); |
---|
| 238 | if ($res === false){ |
---|
| 239 | return false; |
---|
| 240 | } else { |
---|
| 241 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
| 242 | return true; |
---|
| 243 | else |
---|
| 244 | return false; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | endif; |
---|
| 248 | |
---|
[151] | 249 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
| 250 | function xpress_block_check($mydirname){ |
---|
| 251 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
| 252 | |
---|
| 253 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
| 254 | |
---|
| 255 | if ( !$xoops_block_check->is_admin() ) |
---|
| 256 | { |
---|
| 257 | $cont = 'Block Check Pass'; |
---|
| 258 | return cont; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | switch ( $xoops_block_check->get_op() ) |
---|
| 262 | { |
---|
| 263 | case "remove_block": |
---|
| 264 | $cont = $xoops_block_check->remove_block(); |
---|
| 265 | break; |
---|
| 266 | |
---|
| 267 | default: |
---|
| 268 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
| 269 | break; |
---|
| 270 | } |
---|
| 271 | return $cont; |
---|
| 272 | } |
---|
| 273 | endif; |
---|
| 274 | |
---|
| 275 | |
---|
[1] | 276 | ?> |
---|