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 | |
---|
14 | // for Cube 2.1 |
---|
15 | if( defined( 'XOOPS_CUBE_LEGACY' ) ) { |
---|
16 | $root =& XCube_Root::getSingleton(); |
---|
17 | $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', '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 | //XPress TABLE UPGRADE |
---|
27 | global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query; |
---|
28 | define('WP_INSTALLING', true); |
---|
29 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; |
---|
30 | $path = $mydirpath . '/'; |
---|
31 | if (file_exists($path . 'wp-load.php')) { |
---|
32 | require_once $path . 'wp-load.php'; |
---|
33 | } else { |
---|
34 | require_once $path . 'wp-config.php'; |
---|
35 | } |
---|
36 | require_once($mydirpath . '/wp-admin/upgrade-functions.php'); |
---|
37 | |
---|
38 | if ( get_db_version($mydirname) != $wp_db_version ){ |
---|
39 | if( function_exists( 'wp_upgrade' ) ) { |
---|
40 | wp_upgrade(); |
---|
41 | } else { |
---|
42 | wp_cache_flush(); |
---|
43 | make_db_current_silent(); |
---|
44 | upgrade_all(); |
---|
45 | wp_cache_flush(); |
---|
46 | } |
---|
47 | } |
---|
48 | // update_option("blog_charset", wp_blog_charset()); |
---|
49 | $xpress_version = $module->modinfo['version']; |
---|
50 | |
---|
51 | if (! enhanced_table_check($mydirname,'views')){ |
---|
52 | $xp_prefix = $mydirname; |
---|
53 | if ($xp_prefix == 'wordpress'){ |
---|
54 | $xp_prefix = 'wp'; |
---|
55 | } |
---|
56 | |
---|
57 | $charset_collate = ''; |
---|
58 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
59 | if ( ! empty($wpdb->charset) ) |
---|
60 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
61 | if ( ! empty($wpdb->collate) ) |
---|
62 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
63 | } |
---|
64 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
65 | $views_queries ="CREATE TABLE $views_table ( |
---|
66 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
67 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
68 | KEY post_id (post_id) |
---|
69 | )$charset_collate;"; |
---|
70 | |
---|
71 | dbDelta($views_queries); |
---|
72 | } |
---|
73 | |
---|
74 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
75 | $xp_prefix = $mydirname; |
---|
76 | if ($xp_prefix == 'wordpress'){ |
---|
77 | $xp_prefix = 'wp'; |
---|
78 | } |
---|
79 | |
---|
80 | $charset_collate = ''; |
---|
81 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
82 | if ( ! empty($wpdb->charset) ) |
---|
83 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
84 | if ( ! empty($wpdb->collate) ) |
---|
85 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
86 | } |
---|
87 | |
---|
88 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
89 | $queries ="CREATE TABLE $d3forum_link ( |
---|
90 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
91 | post_id int(10) unsigned NOT NULL default '0' , |
---|
92 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
93 | KEY post_id (post_id) |
---|
94 | )$charset_collate;"; |
---|
95 | dbDelta($queries); |
---|
96 | } |
---|
97 | |
---|
98 | clean_template($mydirname,$xpress_version); |
---|
99 | |
---|
100 | // update templates |
---|
101 | // include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates.php' ; |
---|
102 | // $msgs = xpress_update_templates($mid,$mydirname); |
---|
103 | |
---|
104 | return true ; |
---|
105 | } |
---|
106 | endif; |
---|
107 | |
---|
108 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
109 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
110 | { |
---|
111 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
112 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
113 | $log->add( strip_tags( $message ) ) ; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
118 | } |
---|
119 | endif; |
---|
120 | |
---|
121 | if( ! function_exists( 'get_db_version' ) ) : |
---|
122 | function get_db_version($mydirname){ |
---|
123 | global $xoopsModule; |
---|
124 | $wp_prefix = $mydirname; |
---|
125 | if ($wp_prefix == 'wordpress'){ |
---|
126 | $wp_prefix = 'wp'; |
---|
127 | } |
---|
128 | $xoopsDB =& Database::getInstance(); |
---|
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( 'clean_template' ) ) : |
---|
143 | function clean_template($mydirname,$xpress_ver){ |
---|
144 | global $xoopsModule; |
---|
145 | |
---|
146 | $var = floatval($xpress_ver); |
---|
147 | switch ($var){ |
---|
148 | case ($var >= 0.62): |
---|
149 | $temp_file = "'". $mydirname . "_home.html','" . $mydirname. "_index.html','" . $mydirname . "_search.html','" . $mydirname . "_single.html'"; |
---|
150 | break; |
---|
151 | case ($var >= 0.60): |
---|
152 | $temp_file = "'xpress_header.html','xpress_home.html','xpress_index.html','xpress_search.html','xpress_sidebar.html'"; |
---|
153 | break; |
---|
154 | default: |
---|
155 | $temp_file = 'all'; |
---|
156 | } |
---|
157 | |
---|
158 | if ($temp_file != 'all'){ |
---|
159 | $xoopsDB =& Database::getInstance(); |
---|
160 | $db_tplfile = $xoopsDB->prefix('tplfile'); |
---|
161 | $db_tplsource = $xoopsDB->prefix('tplsource'); |
---|
162 | |
---|
163 | $sql = "SELECT * FROM $db_tplfile WHERE tpl_module = '$mydirname' AND NOT tpl_file IN($temp_file)"; |
---|
164 | $res = $xoopsDB->query($sql, 0, 0); |
---|
165 | if ($res === false){ |
---|
166 | return false; |
---|
167 | } else { |
---|
168 | $del_array = ''; |
---|
169 | $i=0; |
---|
170 | while($row = $xoopsDB->fetchArray($res)){ |
---|
171 | if (!empty($del_array)) |
---|
172 | $del_array .= ','; |
---|
173 | $del_array .= $row['tpl_id']; |
---|
174 | } |
---|
175 | if(!empty($del_array)){ |
---|
176 | $del_tplfile = "DELETE FROM $db_tplfile WHERE tpl_id IN ($del_array)"; |
---|
177 | $result = $xoopsDB->query($del_tplfile, 0, 0); |
---|
178 | $del_tplsource = "DELETE FROM $del_tplsource WHERE tpl_id IN ($del_array)"; |
---|
179 | $result = $xoopsDB->query($del_tplfile, 0, 0); |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | endif; |
---|
185 | |
---|
186 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
187 | function enhanced_table_check($mydirname,$table_name){ |
---|
188 | global $xoopsModule; |
---|
189 | |
---|
190 | $xoopsDB =& Database::getInstance(); |
---|
191 | if ($mydirname == 'wordpress'){ |
---|
192 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
193 | } else { |
---|
194 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
195 | } |
---|
196 | $db_enhanced = $xpress_prefix . $table_name; |
---|
197 | |
---|
198 | $sql = "show tables like '$db_enhanced'"; |
---|
199 | $res = $xoopsDB->query($sql, 0, 0); |
---|
200 | if ($res === false){ |
---|
201 | return false; |
---|
202 | } else { |
---|
203 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
204 | return true; |
---|
205 | else |
---|
206 | return false; |
---|
207 | } |
---|
208 | } |
---|
209 | endif; |
---|
210 | |
---|
211 | ?> |
---|