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 | |
---|
226 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
227 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
228 | $queries ="CREATE TABLE $d3forum_link ( |
---|
229 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
230 | post_id int(10) unsigned NOT NULL default '0' , |
---|
231 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
232 | KEY post_id (post_id) |
---|
233 | )TYPE=MyISAM"; |
---|
234 | $db->queryF( $queries ) ; |
---|
235 | $msgs[] = "$d3forum_link table of XPressME was made."; |
---|
236 | } |
---|
237 | |
---|
238 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
239 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
240 | $queries ="CREATE TABLE $group_role ( |
---|
241 | groupid smallint(5) 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 | } |
---|
254 | |
---|
255 | if (! enhanced_table_check($mydirname,'notify_reserve')){ |
---|
256 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
257 | $queries ="CREATE TABLE $notify_reserve ( |
---|
258 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
259 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
260 | category text NOT NULL default '', |
---|
261 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
262 | event varchar(20) NOT NULL default '', |
---|
263 | extra_tags_arry longtext NOT NULL default '' , |
---|
264 | user_list_arry longtext NOT NULL default '' , |
---|
265 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
266 | omit_user_id varchar(20) NOT NULL default '' , |
---|
267 | KEY notify_reserve_id (notify_reserve_id) |
---|
268 | )TYPE=MyISAM"; |
---|
269 | $db->queryF( $queries ) ; |
---|
270 | $msgs[] = "$notify_reserve table of XPressME was made."; |
---|
271 | } |
---|
272 | return $msgs; |
---|
273 | } |
---|
274 | endif; |
---|
275 | |
---|
276 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
277 | function enhanced_table_check($mydirname,$table_name){ |
---|
278 | global $xoopsModule; |
---|
279 | |
---|
280 | $xoopsDB =& Database::getInstance(); |
---|
281 | if ($mydirname == 'wordpress'){ |
---|
282 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
283 | } else { |
---|
284 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
285 | } |
---|
286 | $db_enhanced = $xpress_prefix . $table_name; |
---|
287 | |
---|
288 | $sql = "show tables like '$db_enhanced'"; |
---|
289 | $res = $xoopsDB->query($sql, 0, 0); |
---|
290 | if ($res === false){ |
---|
291 | return false; |
---|
292 | } else { |
---|
293 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
294 | return true; |
---|
295 | else |
---|
296 | return false; |
---|
297 | } |
---|
298 | } |
---|
299 | endif; |
---|
300 | |
---|
301 | if( ! function_exists( 'is_found_table_column' ) ) : |
---|
302 | function is_found_table_column($table,$column){ |
---|
303 | global $xoopsModule; |
---|
304 | $xoopsDB =& Database::getInstance(); |
---|
305 | |
---|
306 | $sql = "DESCRIBE $table $column"; |
---|
307 | $res = $xoopsDB->queryF($sql, 0, 0); |
---|
308 | if ($res === false){ |
---|
309 | return false; |
---|
310 | } else { |
---|
311 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
312 | return true; |
---|
313 | else |
---|
314 | return false; |
---|
315 | } |
---|
316 | } |
---|
317 | endif; |
---|
318 | |
---|
319 | |
---|
320 | ?> |
---|