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