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