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 | $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpress_message_append_onupdate' ) ; |
---|
18 | $msgs = array() ; |
---|
19 | } else { |
---|
20 | if( ! is_array( $msgs ) ) $msgs = array() ; |
---|
21 | } |
---|
22 | |
---|
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 | global $xoops_db; |
---|
30 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; |
---|
31 | $path = $mydirpath . '/'; |
---|
32 | |
---|
33 | |
---|
34 | //Site_url and home of an optional table are repaired. |
---|
35 | $site_url= XOOPS_URL."/modules/".$mydirname; |
---|
36 | xpress_put_siteurl($mydirname,$site_url); |
---|
37 | $home = get_xpress_option($mydirname,'home'); |
---|
38 | $home_check = 'home option is right'; |
---|
39 | if (strcmp($site_url,$home) !== 0 ){ |
---|
40 | if (!@fclose(@fopen($home . '/xoops_version.php', "r"))){ |
---|
41 | xpress_put_home($mydirname,$site_url); |
---|
42 | $home_check = 'Change home option $home to $site_url'; |
---|
43 | } |
---|
44 | } |
---|
45 | $msgs[] = $home_check; |
---|
46 | // XPressME orignal table update |
---|
47 | $t_mess = xpress_table_make($module , $mydirname); |
---|
48 | $msgs = array_merge($msgs,$t_mess); |
---|
49 | |
---|
50 | // make templates |
---|
51 | include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; |
---|
52 | $mod_version = $module->getVar('version') ; |
---|
53 | |
---|
54 | $t_mess = xpress_clean_templates_file($mydirname,$mod_version); |
---|
55 | $msgs = array_merge($msgs,$t_mess); |
---|
56 | |
---|
57 | $t_mess = xpress_templates_make($mid,$mydirname); |
---|
58 | $msgs = array_merge($msgs,$t_mess); |
---|
59 | |
---|
60 | // The activation processing of the XPressME plugin is omitted. |
---|
61 | // Because the XPressME plugin is done with wp-config in activation |
---|
62 | |
---|
63 | /* activate the xpressme plugin */ |
---|
64 | // require_once dirname( __FILE__ ).'/xpress_active_plugin.php'; |
---|
65 | // if (xpress_pulugin_activation('xpressme/xpressme.php')){ |
---|
66 | // $msgs[] = 'The xpressme plug-in was activated.'; |
---|
67 | // } |
---|
68 | |
---|
69 | return true ; |
---|
70 | } |
---|
71 | endif; |
---|
72 | |
---|
73 | if( ! function_exists( 'xpress_put_siteurl' ) ) : |
---|
74 | function xpress_put_siteurl($mydirname,$url){ |
---|
75 | global $xoopsModule,$xoopsDB; |
---|
76 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
77 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
78 | |
---|
79 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'"; |
---|
80 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
81 | } |
---|
82 | endif; |
---|
83 | |
---|
84 | if( ! function_exists( 'xpress_put_home' ) ) : |
---|
85 | function xpress_put_home($mydirname,$url){ |
---|
86 | global $xoopsModule,$xoopsDB; |
---|
87 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
88 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
89 | |
---|
90 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'"; |
---|
91 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
92 | } |
---|
93 | endif; |
---|
94 | |
---|
95 | if( ! function_exists( 'get_xpress_option' ) ) { |
---|
96 | function get_xpress_option($mydirname,$option_name){ |
---|
97 | global $xoopsModule,$xoopsDB; |
---|
98 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
99 | $option_table = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
100 | |
---|
101 | $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'"; |
---|
102 | |
---|
103 | $result = $xoopsDB->query($sql, 0, 0); |
---|
104 | if ($xoopsDB->getRowsNum($result) > 0){ |
---|
105 | $row = $xoopsDB->fetchArray($result); |
---|
106 | return $row['option_value']; |
---|
107 | } |
---|
108 | return 0; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
113 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
114 | { |
---|
115 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
116 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
117 | $log->add( strip_tags( $message ) ) ; |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
122 | } |
---|
123 | endif; |
---|
124 | |
---|
125 | if( ! function_exists( 'get_db_version' ) ) : |
---|
126 | function get_db_version($mydirname){ |
---|
127 | global $xoopsModule,$xoopsDB; |
---|
128 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
129 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
130 | |
---|
131 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
132 | $res = $xoopsDB->query($sql, 0, 0); |
---|
133 | if ($res === false){ |
---|
134 | return false; |
---|
135 | } else { |
---|
136 | $row = $xoopsDB->fetchArray($res); |
---|
137 | return $row['option_value']; |
---|
138 | } |
---|
139 | } |
---|
140 | endif; |
---|
141 | |
---|
142 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
143 | function xpress_block_check($mydirname){ |
---|
144 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
145 | |
---|
146 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
147 | |
---|
148 | if ( !$xoops_block_check->is_admin() ) |
---|
149 | { |
---|
150 | $cont = 'Block Check Pass'; |
---|
151 | return cont; |
---|
152 | } |
---|
153 | |
---|
154 | switch ( $xoops_block_check->get_op() ) |
---|
155 | { |
---|
156 | case "remove_block": |
---|
157 | $cont = $xoops_block_check->remove_block(); |
---|
158 | break; |
---|
159 | |
---|
160 | default: |
---|
161 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
162 | break; |
---|
163 | } |
---|
164 | return $cont; |
---|
165 | } |
---|
166 | endif; |
---|
167 | |
---|
168 | if( ! function_exists( 'xpress_table_make' ) ) : |
---|
169 | function xpress_table_make($module, $mydirname) |
---|
170 | { |
---|
171 | global $xoopsDB; |
---|
172 | $mid = $module->getVar('mid') ; |
---|
173 | |
---|
174 | // XPressME orignal table update |
---|
175 | $xp_prefix = preg_replace('/wordpress/','wp',$mydirname); |
---|
176 | $msgs = array(); |
---|
177 | |
---|
178 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
179 | if (! enhanced_table_check($mydirname,'views')){ |
---|
180 | $queries ="CREATE TABLE $views_table ( |
---|
181 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
182 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
183 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
184 | KEY post_id (post_id) |
---|
185 | ) TYPE=MyISAM"; |
---|
186 | $xoopsDB->queryF( $queries ) ; |
---|
187 | $msgs[] = "$views_table table of XPressME was made."; |
---|
188 | } else { |
---|
189 | if (!is_found_table_column($views_table,'blog_id')){ |
---|
190 | $queries ="ALTER TABLE $views_table ADD blog_id bigint(20) FIRST"; |
---|
191 | $xoopsDB->queryF( $queries ) ; |
---|
192 | $msgs[] = "$views_table ADD blog_id ."; |
---|
193 | } |
---|
194 | |
---|
195 | // The table is repaired. |
---|
196 | $non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1"; |
---|
197 | $non_blogid_res = $xoopsDB->query($non_blogid_sql, 0, 0); |
---|
198 | while($row = $xoopsDB->fetchArray($non_blogid_res)){ |
---|
199 | $total_view = $row['post_views']; |
---|
200 | $post_id = $row['post_id']; |
---|
201 | $new_blogid_sql ="SELECT SUM(post_views) as post_views_sum FROM $views_table WHERE post_id = $post_id AND blog_id = 1 GROUP BY post_id"; |
---|
202 | $new_blogid_res = $xoopsDB->query($new_blogid_sql, 0, 0); |
---|
203 | if ($xoopsDB->getRowsNum($new_blogid_res) > 0){ |
---|
204 | $new_row = $xoopsDB->fetchArray($new_blogid_res); |
---|
205 | $total_view = $total_view + $new_row['post_views_sum']; |
---|
206 | $del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1"; |
---|
207 | $xoopsDB->queryF( $del_sql ) ; |
---|
208 | } |
---|
209 | $update_sql = "UPDATE $views_table SET post_views = $total_view , blog_id = 1 WHERE post_id = $post_id AND (blog_id IS NULL OR blog_id < 1)"; |
---|
210 | $xoopsDB->queryF( $update_sql ) ; |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
215 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
216 | $queries ="CREATE TABLE $d3forum_link ( |
---|
217 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
218 | post_id int(10) unsigned NOT NULL default '0' , |
---|
219 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
220 | forum_id bigint(20) unsigned NOT NULL default '0', |
---|
221 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
222 | KEY post_id (post_id) |
---|
223 | )TYPE=MyISAM"; |
---|
224 | $xoopsDB->queryF( $queries ) ; |
---|
225 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
226 | } else { |
---|
227 | if (!is_found_table_column($d3forum_link,'forum_id')){ |
---|
228 | $queries ="ALTER TABLE $d3forum_link ADD forum_id bigint(20) unsigned NOT NULL default '0' AFTER wp_post_ID"; |
---|
229 | $xoopsDB->queryF( $queries ) ; |
---|
230 | $msgs[] = "$d3forum_link ADD forum_id ."; |
---|
231 | // The table is repaired. |
---|
232 | // $update_sql = "UPDATE $d3forum_link SET forum_id = 1 WHERE(forum_id IS NULL OR forum_id < 1)"; |
---|
233 | // $xoopsDB->queryF( $update_sql ) ; |
---|
234 | } |
---|
235 | if (!is_found_table_column($d3forum_link,'blog_id')){ |
---|
236 | $queries ="ALTER TABLE $d3forum_link ADD blog_id bigint(20) unsigned NOT NULL default '0' AFTER forum_id"; |
---|
237 | $xoopsDB->queryF( $queries ) ; |
---|
238 | $msgs[] = "$d3forum_link ADD blog_id ."; |
---|
239 | // The table is repaired. |
---|
240 | $update_sql = "UPDATE $d3forum_link SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)"; |
---|
241 | $xoopsDB->queryF( $update_sql ) ; |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
246 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
247 | $queries ="CREATE TABLE $group_role ( |
---|
248 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
249 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
250 | name varchar(50) NOT NULL default '' , |
---|
251 | description text NOT NULL default '', |
---|
252 | group_type varchar(50) NOT NULL default '' , |
---|
253 | role varchar(20) NOT NULL default '' , |
---|
254 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
255 | KEY groupid (groupid) |
---|
256 | )TYPE=MyISAM"; |
---|
257 | $xoopsDB->queryF( $queries ) ; |
---|
258 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
259 | $xoopsDB->queryF( $sql ) ; |
---|
260 | $msgs[] = "$group_role table of XPressME was made."; |
---|
261 | } else { |
---|
262 | if (!is_found_table_column($group_role,'blog_id')){ |
---|
263 | $queries ="ALTER TABLE $group_role ADD blog_id bigint(20) AFTER groupid"; |
---|
264 | $xoopsDB->queryF( $queries ) ; |
---|
265 | $msgs[] = "$group_role ADD blog_id ."; |
---|
266 | } |
---|
267 | // The table is repaired. |
---|
268 | $update_sql = "UPDATE $group_role SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)"; |
---|
269 | $xoopsDB->queryF( $update_sql ) ; |
---|
270 | } |
---|
271 | |
---|
272 | if (! enhanced_table_check($mydirname,'notify_reserve')){ |
---|
273 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
274 | $queries ="CREATE TABLE $notify_reserve ( |
---|
275 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
276 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
277 | category text NOT NULL default '', |
---|
278 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
279 | event varchar(20) NOT NULL default '', |
---|
280 | extra_tags_arry longtext NOT NULL default '' , |
---|
281 | user_list_arry longtext NOT NULL default '' , |
---|
282 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
283 | omit_user_id varchar(20) NOT NULL default '' , |
---|
284 | KEY notify_reserve_id (notify_reserve_id) |
---|
285 | )TYPE=MyISAM"; |
---|
286 | $xoopsDB->queryF( $queries ) ; |
---|
287 | $msgs[] = "$notify_reserve table of XPressME was made."; |
---|
288 | } |
---|
289 | return $msgs; |
---|
290 | } |
---|
291 | endif; |
---|
292 | |
---|
293 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
294 | function enhanced_table_check($mydirname,$table_name){ |
---|
295 | global $xoopsModule,$xoopsDB; |
---|
296 | |
---|
297 | $xpress_prefix = $xoopsDB->prefix(preg_replace('/wordpress/','wp',$mydirname) . '_'); |
---|
298 | $db_enhanced = $xpress_prefix . $table_name; |
---|
299 | |
---|
300 | $sql = "show tables like '$db_enhanced'"; |
---|
301 | $res = $xoopsDB->query($sql, 0, 0); |
---|
302 | if ($res === false){ |
---|
303 | return false; |
---|
304 | } else { |
---|
305 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
306 | return true; |
---|
307 | else |
---|
308 | return false; |
---|
309 | } |
---|
310 | } |
---|
311 | endif; |
---|
312 | |
---|
313 | if( ! function_exists( 'is_found_table_column' ) ) : |
---|
314 | function is_found_table_column($table,$column){ |
---|
315 | global $xoopsModule,$xoopsDB; |
---|
316 | |
---|
317 | $sql = "DESCRIBE $table $column"; |
---|
318 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
319 | if ($res === false){ |
---|
320 | return false; |
---|
321 | } else { |
---|
322 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
323 | return true; |
---|
324 | else |
---|
325 | return false; |
---|
326 | } |
---|
327 | } |
---|
328 | endif; |
---|
329 | |
---|
330 | |
---|
331 | ?> |
---|