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 | |
---|
12 | global $msgs ; // TODO :-D |
---|
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' ) ; |
---|
17 | $msgs = array() ; |
---|
18 | } else { |
---|
19 | if( ! is_array( $msgs ) ) $msgs = array() ; |
---|
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' ) ) { |
---|
39 | wp_upgrade(); |
---|
40 | } else { |
---|
41 | wp_cache_flush(); |
---|
42 | make_db_current_silent(); |
---|
43 | upgrade_all(); |
---|
44 | wp_cache_flush(); |
---|
45 | } |
---|
46 | $msgs[] = 'Upgrade Wordpress Database Ver.' . get_db_version($mydirname) .' to' . $wp_db_version; |
---|
47 | } |
---|
48 | |
---|
49 | /* activate the tag plugin */ |
---|
50 | $plugin_current = "xpressme/xpressme.php"; |
---|
51 | update_option('active_plugins', array($plugin_current)); |
---|
52 | include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current); |
---|
53 | do_action('activate_'.$plugin_current); |
---|
54 | $msgs[] = 'The xpressme plug-in was activated.'; |
---|
55 | |
---|
56 | |
---|
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); |
---|
81 | $msgs[] = "$views_table table of XPressME was made."; |
---|
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); |
---|
106 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
107 | } |
---|
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 | } |
---|
122 | |
---|
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 '' , |
---|
130 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
131 | KEY groupid (groupid) |
---|
132 | )$charset_collate;"; |
---|
133 | dbDelta($views_queries); |
---|
134 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
135 | $wpdb->query($sql); |
---|
136 | $msgs[] = "$group_role table of XPressME was made."; |
---|
137 | } |
---|
138 | if ( xpress_block_check($mydirname)) { |
---|
139 | $msgs[] = '<span style="color:#ff0000;">Block Check OK</span>'; |
---|
140 | } else { |
---|
141 | $msgs[] = "Block Check NG. You need Repar Block on This Mobule 'Block Check' Menu"; |
---|
142 | } |
---|
143 | |
---|
144 | // make templates |
---|
145 | include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; |
---|
146 | $t_mess = xpress_templates_make($mid,$mydirname); |
---|
147 | |
---|
148 | $msgs = array_merge($msgs,$t_mess); |
---|
149 | |
---|
150 | return true ; |
---|
151 | } |
---|
152 | endif; |
---|
153 | |
---|
154 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
155 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
156 | { |
---|
157 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
158 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
159 | $log->add( strip_tags( $message ) ) ; |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
164 | } |
---|
165 | endif; |
---|
166 | |
---|
167 | if( ! function_exists( 'get_db_version' ) ) : |
---|
168 | function get_db_version($mydirname){ |
---|
169 | global $xoopsModule; |
---|
170 | $wp_prefix = $mydirname; |
---|
171 | if ($wp_prefix == 'wordpress'){ |
---|
172 | $wp_prefix = 'wp'; |
---|
173 | } |
---|
174 | $xoopsDB =& Database::getInstance(); |
---|
175 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
176 | |
---|
177 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
178 | $res = $xoopsDB->query($sql, 0, 0); |
---|
179 | if ($res === false){ |
---|
180 | return false; |
---|
181 | } else { |
---|
182 | $row = $xoopsDB->fetchArray($res); |
---|
183 | return $row['option_value']; |
---|
184 | } |
---|
185 | } |
---|
186 | endif; |
---|
187 | |
---|
188 | |
---|
189 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
190 | function enhanced_table_check($mydirname,$table_name){ |
---|
191 | global $xoopsModule; |
---|
192 | |
---|
193 | $xoopsDB =& Database::getInstance(); |
---|
194 | if ($mydirname == 'wordpress'){ |
---|
195 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
196 | } else { |
---|
197 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
198 | } |
---|
199 | $db_enhanced = $xpress_prefix . $table_name; |
---|
200 | |
---|
201 | $sql = "show tables like '$db_enhanced'"; |
---|
202 | $res = $xoopsDB->query($sql, 0, 0); |
---|
203 | if ($res === false){ |
---|
204 | return false; |
---|
205 | } else { |
---|
206 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
207 | return true; |
---|
208 | else |
---|
209 | return false; |
---|
210 | } |
---|
211 | } |
---|
212 | endif; |
---|
213 | |
---|
214 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
215 | function xpress_block_check($mydirname){ |
---|
216 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
217 | |
---|
218 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
219 | |
---|
220 | if ( !$xoops_block_check->is_admin() ) |
---|
221 | { |
---|
222 | $cont = 'Block Check Pass'; |
---|
223 | return cont; |
---|
224 | } |
---|
225 | |
---|
226 | switch ( $xoops_block_check->get_op() ) |
---|
227 | { |
---|
228 | case "remove_block": |
---|
229 | $cont = $xoops_block_check->remove_block(); |
---|
230 | break; |
---|
231 | |
---|
232 | default: |
---|
233 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
234 | break; |
---|
235 | } |
---|
236 | return $cont; |
---|
237 | } |
---|
238 | endif; |
---|
239 | |
---|
240 | |
---|
241 | ?> |
---|