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