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 = $mydirname; |
---|
84 | if ($wp_prefix == 'wordpress'){ |
---|
85 | $wp_prefix = 'wp'; |
---|
86 | } |
---|
87 | $xoopsDB =& Database::getInstance(); |
---|
88 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
89 | |
---|
90 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'siteurl'"; |
---|
91 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
92 | } |
---|
93 | endif; |
---|
94 | |
---|
95 | if( ! function_exists( 'xpress_put_home' ) ) : |
---|
96 | function xpress_put_home($mydirname,$url){ |
---|
97 | global $xoopsModule; |
---|
98 | $wp_prefix = $mydirname; |
---|
99 | if ($wp_prefix == 'wordpress'){ |
---|
100 | $wp_prefix = 'wp'; |
---|
101 | } |
---|
102 | $xoopsDB =& Database::getInstance(); |
---|
103 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
104 | |
---|
105 | $sql = "UPDATE $db_xpress_option SET option_value = '$url' WHERE option_name = 'home'"; |
---|
106 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
107 | } |
---|
108 | endif; |
---|
109 | |
---|
110 | if( ! function_exists( 'get_xpress_option' ) ) { |
---|
111 | function get_xpress_option($mydirname,$option_name){ |
---|
112 | global $xoopsModule; |
---|
113 | $wp_prefix = $mydirname; |
---|
114 | if ($wp_prefix == 'wordpress'){ |
---|
115 | $wp_prefix = 'wp'; |
---|
116 | } |
---|
117 | $xoopsDB =& Database::getInstance(); |
---|
118 | $option_table = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
119 | |
---|
120 | $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'"; |
---|
121 | |
---|
122 | $result = $xoopsDB->query($sql, 0, 0); |
---|
123 | if ($xoopsDB->getRowsNum($result) > 0){ |
---|
124 | $row = $xoopsDB->fetchArray($result); |
---|
125 | return $row['option_value']; |
---|
126 | } |
---|
127 | return 0; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
132 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
133 | { |
---|
134 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
135 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
136 | $log->add( strip_tags( $message ) ) ; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
141 | } |
---|
142 | endif; |
---|
143 | |
---|
144 | if( ! function_exists( 'get_db_version' ) ) : |
---|
145 | function get_db_version($mydirname){ |
---|
146 | global $xoopsModule; |
---|
147 | $wp_prefix = $mydirname; |
---|
148 | if ($wp_prefix == 'wordpress'){ |
---|
149 | $wp_prefix = 'wp'; |
---|
150 | } |
---|
151 | $xoopsDB =& Database::getInstance(); |
---|
152 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
153 | |
---|
154 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
155 | $res = $xoopsDB->query($sql, 0, 0); |
---|
156 | if ($res === false){ |
---|
157 | return false; |
---|
158 | } else { |
---|
159 | $row = $xoopsDB->fetchArray($res); |
---|
160 | return $row['option_value']; |
---|
161 | } |
---|
162 | } |
---|
163 | endif; |
---|
164 | |
---|
165 | if( ! function_exists( 'xpress_block_check' ) ) : |
---|
166 | function xpress_block_check($mydirname){ |
---|
167 | include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php'); |
---|
168 | |
---|
169 | $xoops_block_check =& xoops_block_check::getInstance(); |
---|
170 | |
---|
171 | if ( !$xoops_block_check->is_admin() ) |
---|
172 | { |
---|
173 | $cont = 'Block Check Pass'; |
---|
174 | return cont; |
---|
175 | } |
---|
176 | |
---|
177 | switch ( $xoops_block_check->get_op() ) |
---|
178 | { |
---|
179 | case "remove_block": |
---|
180 | $cont = $xoops_block_check->remove_block(); |
---|
181 | break; |
---|
182 | |
---|
183 | default: |
---|
184 | $cont = $xoops_block_check->check_blocks($mydirname); |
---|
185 | break; |
---|
186 | } |
---|
187 | return $cont; |
---|
188 | } |
---|
189 | endif; |
---|
190 | |
---|
191 | if( ! function_exists( 'xpress_table_make' ) ) : |
---|
192 | function xpress_table_make($module, $mydirname) |
---|
193 | { |
---|
194 | $xp_prefix = $mydirname; |
---|
195 | if ($xp_prefix == 'wordpress'){ |
---|
196 | $xp_prefix = 'wp'; |
---|
197 | } |
---|
198 | $db =& Database::getInstance() ; |
---|
199 | $mid = $module->getVar('mid') ; |
---|
200 | |
---|
201 | // XPressME orignal table update |
---|
202 | $xp_prefix = $mydirname; |
---|
203 | if ($xp_prefix == 'wordpress'){ |
---|
204 | $xp_prefix = 'wp'; |
---|
205 | } |
---|
206 | $msgs = array(); |
---|
207 | |
---|
208 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
209 | if (! enhanced_table_check($mydirname,'views')){ |
---|
210 | $queries ="CREATE TABLE $views_table ( |
---|
211 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
212 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
213 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
214 | KEY post_id (post_id) |
---|
215 | ) TYPE=MyISAM"; |
---|
216 | $db->queryF( $queries ) ; |
---|
217 | $msgs[] = "$views_table table of XPressME was made."; |
---|
218 | } else { |
---|
219 | if (!is_found_table_column($views_table,'blog_id')){ |
---|
220 | $queries ="ALTER TABLE $views_table ADD blog_id bigint(20) FIRST"; |
---|
221 | $db->queryF( $queries ) ; |
---|
222 | $msgs[] = "$views_table ADD blog_id ."; |
---|
223 | } |
---|
224 | |
---|
225 | // The table is repaired. |
---|
226 | $non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1"; |
---|
227 | $non_blogid_res = $db->query($non_blogid_sql, 0, 0); |
---|
228 | while($row = $db->fetchArray($non_blogid_res)){ |
---|
229 | $total_view = $row['post_views']; |
---|
230 | $post_id = $row['post_id']; |
---|
231 | $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"; |
---|
232 | $new_blogid_res = $db->query($new_blogid_sql, 0, 0); |
---|
233 | if ($db->getRowsNum($new_blogid_res) > 0){ |
---|
234 | $new_row = $db->fetchArray($new_blogid_res); |
---|
235 | $total_view = $total_view + $new_row['post_views_sum']; |
---|
236 | $del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1"; |
---|
237 | $db->queryF( $del_sql ) ; |
---|
238 | } |
---|
239 | $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)"; |
---|
240 | $db->queryF( $update_sql ) ; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
245 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
246 | $queries ="CREATE TABLE $d3forum_link ( |
---|
247 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
248 | post_id int(10) unsigned NOT NULL default '0' , |
---|
249 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
250 | KEY post_id (post_id) |
---|
251 | )TYPE=MyISAM"; |
---|
252 | $db->queryF( $queries ) ; |
---|
253 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
254 | } |
---|
255 | |
---|
256 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
257 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
258 | $queries ="CREATE TABLE $group_role ( |
---|
259 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
260 | blog_id bigint(20) unsigned NOT NULL default '0', |
---|
261 | name varchar(50) NOT NULL default '' , |
---|
262 | description text NOT NULL default '', |
---|
263 | group_type varchar(50) NOT NULL default '' , |
---|
264 | role varchar(20) NOT NULL default '' , |
---|
265 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
266 | KEY groupid (groupid) |
---|
267 | )TYPE=MyISAM"; |
---|
268 | $db->queryF( $queries ) ; |
---|
269 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
270 | $db->queryF( $sql ) ; |
---|
271 | $msgs[] = "$group_role table of XPressME was made."; |
---|
272 | } else { |
---|
273 | if (!is_found_table_column($group_role,'blog_id')){ |
---|
274 | $queries ="ALTER TABLE $group_role ADD blog_id bigint(20) AFTER groupid"; |
---|
275 | $db->queryF( $queries ) ; |
---|
276 | $msgs[] = "$group_role ADD blog_id ."; |
---|
277 | } |
---|
278 | // The table is repaired. |
---|
279 | $update_sql = "UPDATE $group_role SET blog_id = 1 WHERE(blog_id IS NULL OR blog_id < 1)"; |
---|
280 | $db->queryF( $update_sql ) ; |
---|
281 | } |
---|
282 | |
---|
283 | if (! enhanced_table_check($mydirname,'notify_reserve')){ |
---|
284 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
285 | $queries ="CREATE TABLE $notify_reserve ( |
---|
286 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
287 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
288 | category text NOT NULL default '', |
---|
289 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
290 | event varchar(20) NOT NULL default '', |
---|
291 | extra_tags_arry longtext NOT NULL default '' , |
---|
292 | user_list_arry longtext NOT NULL default '' , |
---|
293 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
294 | omit_user_id varchar(20) NOT NULL default '' , |
---|
295 | KEY notify_reserve_id (notify_reserve_id) |
---|
296 | )TYPE=MyISAM"; |
---|
297 | $db->queryF( $queries ) ; |
---|
298 | $msgs[] = "$notify_reserve table of XPressME was made."; |
---|
299 | } |
---|
300 | return $msgs; |
---|
301 | } |
---|
302 | endif; |
---|
303 | |
---|
304 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
305 | function enhanced_table_check($mydirname,$table_name){ |
---|
306 | global $xoopsModule; |
---|
307 | |
---|
308 | $xoopsDB =& Database::getInstance(); |
---|
309 | if ($mydirname == 'wordpress'){ |
---|
310 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
311 | } else { |
---|
312 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
313 | } |
---|
314 | $db_enhanced = $xpress_prefix . $table_name; |
---|
315 | |
---|
316 | $sql = "show tables like '$db_enhanced'"; |
---|
317 | $res = $xoopsDB->query($sql, 0, 0); |
---|
318 | if ($res === false){ |
---|
319 | return false; |
---|
320 | } else { |
---|
321 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
322 | return true; |
---|
323 | else |
---|
324 | return false; |
---|
325 | } |
---|
326 | } |
---|
327 | endif; |
---|
328 | |
---|
329 | if( ! function_exists( 'is_found_table_column' ) ) : |
---|
330 | function is_found_table_column($table,$column){ |
---|
331 | global $xoopsModule; |
---|
332 | $xoopsDB =& Database::getInstance(); |
---|
333 | |
---|
334 | $sql = "DESCRIBE $table $column"; |
---|
335 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
336 | if ($res === false){ |
---|
337 | return false; |
---|
338 | } else { |
---|
339 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
340 | return true; |
---|
341 | else |
---|
342 | return false; |
---|
343 | } |
---|
344 | } |
---|
345 | endif; |
---|
346 | |
---|
347 | |
---|
348 | ?> |
---|