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