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 | /* activate the tag plugin */ |
---|
49 | $plugin_current = "xpressme/xpressme.php"; |
---|
50 | update_option('active_plugins', array($plugin_current)); |
---|
51 | include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current); |
---|
52 | do_action('activate_'.$plugin_current); |
---|
53 | |
---|
54 | // update_option("blog_charset", wp_blog_charset()); |
---|
55 | $xpress_version = $module->modinfo['version']; |
---|
56 | |
---|
57 | if (! enhanced_table_check($mydirname,'views')){ |
---|
58 | $xp_prefix = $mydirname; |
---|
59 | if ($xp_prefix == 'wordpress'){ |
---|
60 | $xp_prefix = 'wp'; |
---|
61 | } |
---|
62 | |
---|
63 | $charset_collate = ''; |
---|
64 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
65 | if ( ! empty($wpdb->charset) ) |
---|
66 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
67 | if ( ! empty($wpdb->collate) ) |
---|
68 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
69 | } |
---|
70 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
71 | $views_queries ="CREATE TABLE $views_table ( |
---|
72 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
73 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
74 | KEY post_id (post_id) |
---|
75 | )$charset_collate;"; |
---|
76 | |
---|
77 | dbDelta($views_queries); |
---|
78 | } |
---|
79 | |
---|
80 | if (! enhanced_table_check($mydirname,'d3forum_link')){ |
---|
81 | $xp_prefix = $mydirname; |
---|
82 | if ($xp_prefix == 'wordpress'){ |
---|
83 | $xp_prefix = 'wp'; |
---|
84 | } |
---|
85 | |
---|
86 | $charset_collate = ''; |
---|
87 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
88 | if ( ! empty($wpdb->charset) ) |
---|
89 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
90 | if ( ! empty($wpdb->collate) ) |
---|
91 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
92 | } |
---|
93 | |
---|
94 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
95 | $queries ="CREATE TABLE $d3forum_link ( |
---|
96 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
97 | post_id int(10) unsigned NOT NULL default '0' , |
---|
98 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
99 | KEY post_id (post_id) |
---|
100 | )$charset_collate;"; |
---|
101 | dbDelta($queries); |
---|
102 | } |
---|
103 | |
---|
104 | if (! enhanced_table_check($mydirname,'group_role')){ |
---|
105 | $xp_prefix = $mydirname; |
---|
106 | if ($xp_prefix == 'wordpress'){ |
---|
107 | $xp_prefix = 'wp'; |
---|
108 | } |
---|
109 | |
---|
110 | $charset_collate = ''; |
---|
111 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
112 | if ( ! empty($wpdb->charset) ) |
---|
113 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
114 | if ( ! empty($wpdb->collate) ) |
---|
115 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
116 | } |
---|
117 | |
---|
118 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
119 | $views_queries ="CREATE TABLE $group_role ( |
---|
120 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
121 | name varchar(50) NOT NULL default '' , |
---|
122 | description text NOT NULL default '', |
---|
123 | group_type varchar(10) NOT NULL default '' , |
---|
124 | role varchar(20) NOT NULL default '' , |
---|
125 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
126 | KEY groupid (groupid) |
---|
127 | )$charset_collate;"; |
---|
128 | dbDelta($views_queries); |
---|
129 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
130 | $wpdb->query($sql); |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | // TEMPLATES (all templates have been already removed by modulesadmin) |
---|
135 | |
---|
136 | $tplfile_handler =& xoops_gethandler( 'tplfile' ) ; |
---|
137 | $tpl_path = dirname( dirname( __FILE__ ) ).'/templates/source' ; |
---|
138 | if( $handler = @opendir( $tpl_path . '/' ) ) { |
---|
139 | while( ( $file = readdir( $handler ) ) !== false ) { |
---|
140 | if( substr( $file , 0 , 1 ) == '.' ) continue ; |
---|
141 | $file_path = $tpl_path . '/' . $file ; |
---|
142 | if( is_file( $file_path ) ) { |
---|
143 | $mtime = intval( @filemtime( $file_path ) ) ; |
---|
144 | $tplfile =& $tplfile_handler->create() ; |
---|
145 | $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ; |
---|
146 | $tplfile->setVar( 'tpl_refid' , $mid ) ; |
---|
147 | $tplfile->setVar( 'tpl_tplset' , 'default' ) ; |
---|
148 | $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ; |
---|
149 | $tplfile->setVar( 'tpl_desc' , '' , true ) ; |
---|
150 | $tplfile->setVar( 'tpl_module' , $mydirname ) ; |
---|
151 | $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ; |
---|
152 | $tplfile->setVar( 'tpl_lastimported' , 0 ) ; |
---|
153 | $tplfile->setVar( 'tpl_type' , 'block' ) ; |
---|
154 | if( ! $tplfile_handler->insert( $tplfile ) ) { |
---|
155 | $msgs[] = '<span style="color:#flockf0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>'; |
---|
156 | } else { |
---|
157 | $tplid = $tplfile->getVar( 'tpl_id' ) ; |
---|
158 | $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)'; |
---|
159 | // generate compiled file |
---|
160 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; |
---|
161 | include_once XOOPS_ROOT_PATH.'/class/template.php' ; |
---|
162 | if( ! xoops_template_touch( $tplid ) ) { |
---|
163 | $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>'; |
---|
164 | } else { |
---|
165 | $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>'; |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | closedir( $handler ) ; |
---|
171 | } |
---|
172 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; |
---|
173 | include_once XOOPS_ROOT_PATH.'/class/template.php' ; |
---|
174 | xoops_template_clear_module_cache( $mid ) ; |
---|
175 | |
---|
176 | |
---|
177 | return true ; |
---|
178 | } |
---|
179 | endif; |
---|
180 | |
---|
181 | if( ! function_exists( 'xpress_message_append_onupdate' ) ) : |
---|
182 | function xpress_message_append_onupdate( &$module_obj , &$log ) |
---|
183 | { |
---|
184 | if( is_array( @$GLOBALS['msgs'] ) ) { |
---|
185 | foreach( $GLOBALS['msgs'] as $message ) { |
---|
186 | $log->add( strip_tags( $message ) ) ; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
191 | } |
---|
192 | endif; |
---|
193 | |
---|
194 | if( ! function_exists( 'get_db_version' ) ) : |
---|
195 | function get_db_version($mydirname){ |
---|
196 | global $xoopsModule; |
---|
197 | $wp_prefix = $mydirname; |
---|
198 | if ($wp_prefix == 'wordpress'){ |
---|
199 | $wp_prefix = 'wp'; |
---|
200 | } |
---|
201 | $xoopsDB =& Database::getInstance(); |
---|
202 | $db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options'); |
---|
203 | |
---|
204 | $sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'"; |
---|
205 | $res = $xoopsDB->query($sql, 0, 0); |
---|
206 | if ($res === false){ |
---|
207 | return false; |
---|
208 | } else { |
---|
209 | $row = $xoopsDB->fetchArray($res); |
---|
210 | return $row['option_value']; |
---|
211 | } |
---|
212 | } |
---|
213 | endif; |
---|
214 | |
---|
215 | |
---|
216 | if( ! function_exists( 'enhanced_table_check' ) ) : |
---|
217 | function enhanced_table_check($mydirname,$table_name){ |
---|
218 | global $xoopsModule; |
---|
219 | |
---|
220 | $xoopsDB =& Database::getInstance(); |
---|
221 | if ($mydirname == 'wordpress'){ |
---|
222 | $xpress_prefix= $xoopsDB->prefix('wp_'); |
---|
223 | } else { |
---|
224 | $xpress_prefix= $xoopsDB->prefix($mydirname . '_'); |
---|
225 | } |
---|
226 | $db_enhanced = $xpress_prefix . $table_name; |
---|
227 | |
---|
228 | $sql = "show tables like '$db_enhanced'"; |
---|
229 | $res = $xoopsDB->query($sql, 0, 0); |
---|
230 | if ($res === false){ |
---|
231 | return false; |
---|
232 | } else { |
---|
233 | if ($xoopsDB->getRowsNum($res) > 0) |
---|
234 | return true; |
---|
235 | else |
---|
236 | return false; |
---|
237 | } |
---|
238 | } |
---|
239 | endif; |
---|
240 | |
---|
241 | ?> |
---|