1 | <?php |
---|
2 | $mydirpath = dirname(dirname(__FILE__)); |
---|
3 | $mydirname = basename($mydirpath); |
---|
4 | $lang = @$GLOBALS["xoopsConfig"]['language']; |
---|
5 | global $wp_db_version,$wp_rewrite; |
---|
6 | include_once $mydirpath .'/wp-includes/version.php' ; |
---|
7 | |
---|
8 | // language file (modinfo.php) |
---|
9 | |
---|
10 | if( file_exists( $mydirpath .'/language/'.$lang.'/modinfo.php' ) ) { |
---|
11 | include_once $mydirpath .'/language/'.$lang.'/modinfo.php' ; |
---|
12 | } else if( file_exists( $mydirpath .'/language/english/modinfo.php' ) ) { |
---|
13 | include_once $mydirpath .'/language/english/modinfo.php' ; |
---|
14 | } |
---|
15 | |
---|
16 | |
---|
17 | eval( ' function xoops_module_install_'.$mydirname.'( $module ) { return xpress_oninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ; |
---|
18 | |
---|
19 | |
---|
20 | if( ! function_exists( 'xpress_oninstall_base' ) ) : |
---|
21 | function xpress_oninstall_base( $module , $mydirname ) |
---|
22 | { |
---|
23 | // transations on module install |
---|
24 | |
---|
25 | global $ret ; // TODO :-D |
---|
26 | |
---|
27 | // for Cube 2.1 |
---|
28 | if( defined( 'XOOPS_CUBE_LEGACY' ) ) { |
---|
29 | $root =& XCube_Root::getSingleton(); |
---|
30 | $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'xpress_message_append_oninstall' ) ; |
---|
31 | $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail' , 'xpress_message_append_oninstall_err' ) ; |
---|
32 | $ret = array() ; |
---|
33 | } else { |
---|
34 | if( ! is_array( $ret ) ) $ret = array() ; |
---|
35 | } |
---|
36 | |
---|
37 | $db =& Database::getInstance() ; |
---|
38 | $mid = $module->getVar('mid') ; |
---|
39 | |
---|
40 | if( defined( 'XOOPS_CUBE_LEGACY' ) ) { |
---|
41 | $ret[] = "********************************* Install Log ********************************<br />"; |
---|
42 | } else { |
---|
43 | $ret[] = '<h4 style="border-bottom: 1px dashed rgb(0, 0, 0); text-align: left; margin-bottom: 0px;">Install Log</h4>'; |
---|
44 | } |
---|
45 | |
---|
46 | //xpress |
---|
47 | global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query; |
---|
48 | global $xoops_config; |
---|
49 | |
---|
50 | define("WP_INSTALLING", true); |
---|
51 | $site_url= XOOPS_URL."/modules/".$mydirname; |
---|
52 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; |
---|
53 | $path = $mydirpath . '/'; |
---|
54 | $site_name = ucfirst($mydirname) . ' ' . _MI_XP2_NAME; |
---|
55 | |
---|
56 | // permission and wordpress files check |
---|
57 | require_once ($path . 'include/pre_check.php'); |
---|
58 | if(! xp_permission_check($mydirname, $mydirpath)){ |
---|
59 | if( ! defined( 'XOOPS_CUBE_LEGACY' ) ) { |
---|
60 | $ret = $GLOBALS["err_log"]; |
---|
61 | $ret[] = "<br /><span style=\"color:#ff0000;\">The uninstallation of the module is executed now. </span><br />"; |
---|
62 | $ret[] = xoops_module_uninstall($mydirname); |
---|
63 | } |
---|
64 | return false; |
---|
65 | } |
---|
66 | |
---|
67 | // install WordPress |
---|
68 | if (file_exists($path . 'wp-load.php')) { |
---|
69 | require_once $path . 'wp-load.php'; |
---|
70 | } else { |
---|
71 | require_once $path . 'wp-config.php'; |
---|
72 | } |
---|
73 | include_once($mydirpath . '/wp-admin/upgrade-functions.php'); |
---|
74 | wp_cache_flush(); |
---|
75 | make_db_current_silent(); |
---|
76 | $ret[] = "The data base of wordpress was made by prefix $table_prefix.<br />"; |
---|
77 | |
---|
78 | $option_desc = __('WordPress web address'); |
---|
79 | $wpdb->query("INSERT INTO $wpdb->options (blog_id, option_name,option_value, autoload) VALUES ('0', 'siteurl','$site_url', 'yes')"); |
---|
80 | $wpdb->query("INSERT INTO $wpdb->options (blog_id, option_name,option_value, autoload) VALUES ('0', 'home','$site_url', 'yes')"); |
---|
81 | |
---|
82 | populate_options(); |
---|
83 | populate_roles(); |
---|
84 | |
---|
85 | // create XPressME table |
---|
86 | $xp_prefix = $mydirname; |
---|
87 | if ($xp_prefix == 'wordpress'){ |
---|
88 | $xp_prefix = 'wp'; |
---|
89 | } |
---|
90 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
91 | |
---|
92 | $charset_collate = ''; |
---|
93 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
94 | if ( ! empty($wpdb->charset) ) |
---|
95 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
96 | if ( ! empty($wpdb->collate) ) |
---|
97 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
98 | } |
---|
99 | $views_queries ="CREATE TABLE $views_table ( |
---|
100 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
101 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
102 | KEY post_id (post_id) |
---|
103 | )$charset_collate;"; |
---|
104 | dbDelta($views_queries); |
---|
105 | $ret[] = "$views_table table of XPressME was made.<br />"; |
---|
106 | |
---|
107 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
108 | $views_queries ="CREATE TABLE $d3forum_link ( |
---|
109 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
110 | post_id int(10) unsigned NOT NULL default '0' , |
---|
111 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
112 | KEY post_id (post_id) |
---|
113 | )$charset_collate;"; |
---|
114 | dbDelta($views_queries); |
---|
115 | $ret[] = "$d3forum_link table of XPressME was made.<br />"; |
---|
116 | |
---|
117 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
118 | $views_queries ="CREATE TABLE $group_role ( |
---|
119 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
120 | name varchar(50) NOT NULL default '' , |
---|
121 | description text NOT NULL default '', |
---|
122 | group_type varchar(50) NOT NULL default '' , |
---|
123 | role varchar(20) NOT NULL default '' , |
---|
124 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
125 | KEY groupid (groupid) |
---|
126 | )$charset_collate;"; |
---|
127 | dbDelta($views_queries); |
---|
128 | $ret[] = "$group_role table of XPressME was made.<br />"; |
---|
129 | |
---|
130 | $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ; |
---|
131 | $queries ="CREATE TABLE $notify_reserve ( |
---|
132 | notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT , |
---|
133 | notify_reserve_status varchar(20) NOT NULL default '' , |
---|
134 | category text NOT NULL default '', |
---|
135 | item_id bigint(20) unsigned NOT NULL default '0', |
---|
136 | event varchar(20) NOT NULL default '', |
---|
137 | extra_tags_arry longtext NOT NULL default '' , |
---|
138 | user_list_arry longtext NOT NULL default '' , |
---|
139 | module_id smallint(5) unsigned NOT NULL default '0' , |
---|
140 | omit_user_id varchar(20) NOT NULL default '' , |
---|
141 | KEY notify_reserve_id (notify_reserve_id) |
---|
142 | )TYPE=MyISAM"; |
---|
143 | dbDelta($queries); |
---|
144 | $ret[] = "$notify_reserve table of XPressME was made.<br />"; |
---|
145 | |
---|
146 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
147 | $wpdb->query($sql); |
---|
148 | |
---|
149 | // make templates |
---|
150 | include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ; |
---|
151 | $t_mess = xpress_templates_make($mid,$mydirname); |
---|
152 | |
---|
153 | // Admin User Data write |
---|
154 | // Change uid field |
---|
155 | $wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'"); |
---|
156 | $user_name = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uname"):'admin'; |
---|
157 | $email = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("email"):'foo@exsample.com'; |
---|
158 | $pass_md5 = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("pass"):''; |
---|
159 | |
---|
160 | if (!function_exists('username_exists')){ |
---|
161 | require_once($mydirpath . '/wp-includes/registration-functions.php'); |
---|
162 | } |
---|
163 | $user_id = username_exists($user_name); |
---|
164 | if ( !$user_id ) { |
---|
165 | $random_password = 'admin'; |
---|
166 | if (!$xoops_config->is_wpmu){ |
---|
167 | $user_id = wp_create_user($user_name, $random_password, $email); |
---|
168 | } else { |
---|
169 | $user_id = wpmu_create_user($user_name, $random_password, $email); |
---|
170 | } |
---|
171 | } else { |
---|
172 | $random_password = __('User already exists. Password inherited.'); |
---|
173 | } |
---|
174 | |
---|
175 | $user = new WP_User($user_id); |
---|
176 | $user->set_role('administrator'); |
---|
177 | 'User ' . $user_name . ' of the administrator was made.'; |
---|
178 | // over write xoops md5 password |
---|
179 | $sql = "UPDATE $wpdb->users SET user_pass ='$pass_md5' WHERE ID = $user_id"; |
---|
180 | $wpdb->query($sql); |
---|
181 | $ret[] = 'The password of XOOPS was copied.<br />'; |
---|
182 | |
---|
183 | |
---|
184 | // Set Default data |
---|
185 | if (!$xoops_config->is_wpmu){ // for WordPress |
---|
186 | // make WordPress Default data |
---|
187 | if (function_exists('wp_install_defaults')){ |
---|
188 | wp_install_defaults($user_id); |
---|
189 | } else { |
---|
190 | wp_install_old_defaults($user_id); |
---|
191 | } |
---|
192 | |
---|
193 | $ret[] = 'The first sample post & comment was written.<br />'; |
---|
194 | |
---|
195 | // Rewrite Option for Xpress |
---|
196 | if (WPLANG == 'ja_EUC') { |
---|
197 | $setup_charset = 'EUC-JP'; |
---|
198 | } elseif(WPLANG == 'ja_SJIS') { |
---|
199 | $setup_charset = 'Shift_JIS'; |
---|
200 | } else { |
---|
201 | $setup_charset = 'UTF-8'; |
---|
202 | } |
---|
203 | update_option("blog_charset", $setup_charset); |
---|
204 | |
---|
205 | update_option('blogname', $site_name ); |
---|
206 | update_option('blogdescription', 'WordPress for XOOPS'); |
---|
207 | update_option("admin_email", $GLOBALS["xoopsConfig"]['adminmail']); |
---|
208 | update_option("ping_sites", "http://rpc.pingomatic.com/\nhttp://ping.xoopsforge.com/"); |
---|
209 | update_option("home", $site_url); |
---|
210 | update_option("siteurl", $site_url); |
---|
211 | update_option("what_to_show", "posts"); |
---|
212 | update_option('default_pingback_flag', 0); |
---|
213 | $ret[] = 'The initial data was written in the data base of wordpress.<br />'; |
---|
214 | |
---|
215 | update_option("template", "xpress_default"); |
---|
216 | update_option("stylesheet", "xpress_default"); |
---|
217 | $ret[] = 'The default theme of wordpress was set to xpress_default.<br />'; |
---|
218 | // update_option('uploads_use_yearmonth_folders', 1); |
---|
219 | update_option('upload_path', 'wp-content/uploads'); |
---|
220 | |
---|
221 | } else { // for WordPress MU |
---|
222 | global $base,$current_site, $dirs, $wpmu_version; |
---|
223 | |
---|
224 | $base = $xoops_config->mu_path_current_site; |
---|
225 | $domain = $xoops_config->mu_domain_current_site; |
---|
226 | $admin_email = $GLOBALS["xoopsConfig"]['adminmail']; |
---|
227 | $admin_user_name = $user_name; |
---|
228 | $admin_user_id = $user_id; |
---|
229 | include_once($mydirpath . '/include/xpress_mu_function.php'); |
---|
230 | |
---|
231 | do_htaccess( $xoops_config->module_path . '/htaccess.dist', $xoops_config->module_path . '/.htaccess', $base, ''); |
---|
232 | xpress_mu_install_defaults($domain,$base,$site_name,$admin_user_id,$admin_user_name,$admin_email); |
---|
233 | } |
---|
234 | |
---|
235 | // activate the xpressme plugin |
---|
236 | require_once dirname( __FILE__ ).'/xpress_active_plugin.php'; |
---|
237 | if (xpress_pulugin_activation('xpressme/xpressme.php')){ |
---|
238 | $ret[] = 'The xpressme plug-in was activated.<br />'; |
---|
239 | } else { |
---|
240 | $GLOBALS["err_log"][] = '<span style="color:#ff0000;">failed in the activation of xpressme plug-in.</span><br />'; |
---|
241 | return false; |
---|
242 | } |
---|
243 | |
---|
244 | $ret = array_merge($ret,$t_mess); |
---|
245 | |
---|
246 | return true ; |
---|
247 | } |
---|
248 | endif; |
---|
249 | |
---|
250 | if( ! function_exists( 'xpress_message_append_oninstall' ) ) : |
---|
251 | function xpress_message_append_oninstall( &$module_obj , &$log ) |
---|
252 | { |
---|
253 | if( is_array( @$GLOBALS['ret'] ) ) { |
---|
254 | foreach( $GLOBALS['ret'] as $message ) { |
---|
255 | $log->add( strip_tags( $message ) ) ; |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
260 | } |
---|
261 | endif; |
---|
262 | |
---|
263 | if( ! function_exists( 'xpress_message_append_oninstall_err' ) ) : |
---|
264 | function xpress_message_append_oninstall_err( &$module_obj , &$log ) |
---|
265 | { |
---|
266 | if( is_array( @$GLOBALS["err_log"] ) ) { |
---|
267 | foreach( $GLOBALS["err_log"] as $message ) { |
---|
268 | $log->add( strip_tags($message)) ; |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
273 | } |
---|
274 | endif; |
---|
275 | |
---|
276 | |
---|
277 | if( ! function_exists( 'wp_install_old_defaults' ) ) : |
---|
278 | function wp_install_old_defaults($user_id) { |
---|
279 | global $wpdb; |
---|
280 | |
---|
281 | // Now drop in some default links |
---|
282 | $wpdb->query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name) VALUES (1, '".$wpdb->escape(__('Blogroll'))."')"); |
---|
283 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://blogs.linux.ie/xeer/', 'Donncha', 1, 'http://blogs.linux.ie/xeer/feed/', '');"); |
---|
284 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 1, 'http://zengun.org/weblog/feed/', '');"); |
---|
285 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 1, 'http://boren.nu/feed/', '');"); |
---|
286 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 1, 'http://xml.photomatt.net/feed/', '');"); |
---|
287 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 1, 'http://zed1.com/journalized/feed/', '');"); |
---|
288 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 1, 'http://www.alexking.org/blog/wp-rss2.php', '');"); |
---|
289 | $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 1, 'http://dougal.gunters.org/feed/', '');"); |
---|
290 | |
---|
291 | // Default category |
---|
292 | $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')"); |
---|
293 | |
---|
294 | // First post |
---|
295 | $now = date('Y-m-d H:i:s'); |
---|
296 | $now_gmt = gmdate('Y-m-d H:i:s'); |
---|
297 | $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')"); |
---|
298 | |
---|
299 | $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" ); |
---|
300 | |
---|
301 | // Default comment |
---|
302 | $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.'))."')"); |
---|
303 | |
---|
304 | // First Page |
---|
305 | |
---|
306 | $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static', '', '', '')"); |
---|
307 | } |
---|
308 | endif; |
---|
309 | ?> |
---|