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