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