XPressME Integration Kit

Trac

source: branches/Ver2.1/xpressme_integration_kit/include/oninstall.php @ 397

Last change on this file since 397 was 397, checked in by toemon, 15 years ago

WPMU2.8にてユーザテーブルを含むグローバルテーブルがインストールされないバグを修正 Fixes #221 (thx threm)

File size: 12.2 KB
Line 
1<?php
2$mydirpath = dirname(dirname(__FILE__));
3$mydirname = basename($mydirpath);
4$lang = @$GLOBALS["xoopsConfig"]['language'];
5global $wp_db_version,$wp_rewrite;
6include_once $mydirpath .'/wp-includes/version.php' ;
7
8// language file (modinfo.php)
9
10if( 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
17eval( ' function xoops_module_install_'.$mydirname.'( $module ) { return xpress_oninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ;
18
19
20if( ! function_exists( 'xpress_oninstall_base' ) ) :
21function 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                $ret = array() ;
32        } else {
33                if( ! is_array( $ret ) ) $ret = array() ;
34        }
35
36        $db =& Database::getInstance() ;
37        $mid = $module->getVar('mid') ;
38
39//xpress
40        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query;
41        global $xoops_config;
42               
43        define("WP_INSTALLING", true);
44        define('WP_FIRST_INSTALL', true); // For WPMU2.8
45       
46        $site_url= XOOPS_URL."/modules/".$mydirname;
47        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
48        $path = $mydirpath . '/';
49        $site_name = ucfirst($mydirname) . ' ' . _MI_XP2_NAME;
50       
51// install WordPress
52        if (file_exists($path . 'wp-load.php')) {
53                require_once $path . 'wp-load.php';
54        } else {
55                require_once $path . 'wp-config.php';
56        }
57        include_once($mydirpath . '/wp-admin/upgrade-functions.php');
58        wp_cache_flush();
59        make_db_current_silent();
60        $ret[] = "The data base of wordpress was made by prefix $table_prefix.";
61       
62        $option_desc = __('WordPress web address');
63        $wpdb->query("INSERT INTO $wpdb->options (blog_id, option_name,option_value, autoload) VALUES ('0', 'siteurl','$site_url', 'yes')");   
64        $wpdb->query("INSERT INTO $wpdb->options (blog_id, option_name,option_value, autoload) VALUES ('0', 'home','$site_url', 'yes')");
65
66        populate_options();
67        populate_roles();
68       
69// create XPressME table
70        $xp_prefix = $mydirname;
71        if ($xp_prefix == 'wordpress'){
72                $xp_prefix = 'wp';
73        }
74        $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
75
76        $charset_collate = '';
77        if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
78                if ( ! empty($wpdb->charset) )
79                        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
80                if ( ! empty($wpdb->collate) )
81                        $charset_collate .= " COLLATE $wpdb->collate";
82        }
83        $views_queries ="CREATE TABLE $views_table (
84                post_id bigint(20) unsigned NOT NULL default '0',
85                post_views bigint(20) unsigned NOT NULL default '0',
86                KEY post_id (post_id)
87                )$charset_collate;";
88
89        dbDelta($views_queries);
90        $ret[] = "$views_table table of XPressME was made.";
91
92       
93        $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
94        $views_queries ="CREATE TABLE $d3forum_link (
95                comment_ID bigint(20) unsigned NOT NULL default '0',
96                post_id int(10) unsigned NOT NULL default '0' ,
97                wp_post_ID bigint(20) unsigned NOT NULL default '0',
98                KEY post_id (post_id)
99                )$charset_collate;";
100        dbDelta($views_queries);
101        $ret[] = "$d3forum_link table of XPressME was made.";
102       
103        $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
104        $views_queries ="CREATE TABLE $group_role (
105                groupid smallint(5) unsigned NOT NULL default '0',
106                name varchar(50)  NOT NULL default '' ,
107                description text  NOT NULL default '',
108                group_type varchar(50)  NOT NULL default '' ,
109                role varchar(20)  NOT NULL default '' ,
110                login_all smallint(5) unsigned NOT NULL default '0' ,
111                KEY groupid (groupid)
112                )$charset_collate;";
113        dbDelta($views_queries);
114        $ret[] = "$group_role table of XPressME was made.";
115       
116        $notify_reserve = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_notify_reserve' ;
117        $queries ="CREATE TABLE $notify_reserve (
118                notify_reserve_id bigint(20) NOT NULL AUTO_INCREMENT ,
119                notify_reserve_status varchar(20)  NOT NULL default '' ,
120                category text  NOT NULL default '',
121                item_id bigint(20) unsigned NOT NULL default '0',
122                event varchar(20) NOT NULL default '',
123                extra_tags_arry longtext NOT NULL default '' ,
124                user_list_arry longtext NOT NULL default '' ,
125                module_id smallint(5) unsigned NOT NULL default '0' ,
126                omit_user_id varchar(20) NOT NULL default '' ,
127                KEY notify_reserve_id (notify_reserve_id)
128                )TYPE=MyISAM";
129        dbDelta($queries);
130        $ret[] = "$notify_reserve table of XPressME was made.";
131
132        $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
133        $wpdb->query($sql);
134       
135// make templates
136        include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
137        $t_mess = xpress_templates_make($mid,$mydirname);
138       
139// Admin User Data write
140        // Change uid field
141        $wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'");
142        $user_name = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uname"):'admin';
143        $email = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("email"):'foo@exsample.com';
144        $pass_md5 = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("pass"):'';
145       
146        if (!function_exists('username_exists')){
147                require_once($mydirpath . '/wp-includes/registration-functions.php');
148        }
149        $user_id = username_exists($user_name);
150        if ( !$user_id ) {
151                $random_password = 'admin';
152                if (!$xoops_config->is_wpmu){
153                        $user_id = wp_create_user($user_name, $random_password, $email);
154                } else {
155                        $user_id = wpmu_create_user($user_name, $random_password, $email);
156                }
157        } else {
158                $random_password = __('User already exists.  Password inherited.');
159        }
160
161        $user = new WP_User($user_id);
162        $user->set_role('administrator');
163        'User ' . $user_name . ' of the administrator was made.';
164        // over write xoops md5 password
165        $sql = "UPDATE $wpdb->users SET user_pass ='$pass_md5' WHERE ID = $user_id";
166        $wpdb->query($sql);
167        $ret[] = 'The password of XOOPS was copied.';
168       
169       
170// Set Default data
171        if (!$xoops_config->is_wpmu){   // for WordPress
172                // make WordPress Default data 
173                if (function_exists('wp_install_defaults')){
174                        wp_install_defaults($user_id);
175                } else {
176                        wp_install_old_defaults($user_id);
177                }
178               
179                $ret[] = 'The first sample post & comment was written.';
180               
181                // Rewrite Option for Xpress
182                        if (WPLANG == 'ja_EUC') {
183                                $setup_charset = 'EUC-JP';
184                        } elseif(WPLANG == 'ja_SJIS') {
185                                $setup_charset = 'Shift_JIS';
186                        } else {
187                                $setup_charset = 'UTF-8';
188                        }
189                        update_option("blog_charset", $setup_charset);
190
191                        update_option('blogname', $site_name );
192                        update_option('blogdescription', 'WordPress for XOOPS');
193                        update_option("admin_email", $GLOBALS["xoopsConfig"]['adminmail']);
194                        update_option("ping_sites", "http://rpc.pingomatic.com/\nhttp://ping.xoopsforge.com/");
195                        update_option("home", $site_url);
196                        update_option("siteurl", $site_url);
197                        update_option("what_to_show", "posts");
198                        update_option('default_pingback_flag', 0);
199                        $ret[] = 'The initial data was written in the data base of wordpress.';
200                       
201                        update_option("template", "xpress_default");
202                        update_option("stylesheet", "xpress_default");
203                        $ret[] = 'The default theme of wordpress was set to xpress_default.';
204                //      update_option('uploads_use_yearmonth_folders', 1);
205                        update_option('upload_path', 'wp-content/uploads');
206                       
207        } else {        // for WordPress MU
208                global $base,$current_site, $dirs, $wpmu_version;
209               
210                $base =  $xoops_config->mu_path_current_site;
211                $domain = $xoops_config->mu_domain_current_site;
212                $admin_email = $GLOBALS["xoopsConfig"]['adminmail'];
213                $admin_user_name = $user_name;
214                $admin_user_id = $user_id;
215                include_once($mydirpath . '/include/xpress_mu_function.php');
216               
217                do_htaccess( $xoops_config->module_path . '/htaccess.dist', $xoops_config->module_path . '/.htaccess', $base, '');
218                xpress_mu_install_defaults($domain,$base,$site_name,$admin_user_id,$admin_user_name,$admin_email);
219        }
220       
221// activate the xpressme plugin
222        require_once dirname( __FILE__ ).'/xpress_active_plugin.php';
223        if (xpress_pulugin_activation('xpressme/xpressme.php')){
224                $ret[] = 'The xpressme plug-in was activated.';
225        }
226
227        $ret = array_merge($ret,$t_mess);
228
229        return true ;
230}
231endif;
232
233if( ! function_exists( 'xpress_message_append_oninstall' ) ) :
234function xpress_message_append_oninstall( &$module_obj , &$log )
235{
236        if( is_array( @$GLOBALS['ret'] ) ) {
237                foreach( $GLOBALS['ret'] as $message ) {
238                        $log->add( strip_tags( $message ) ) ;
239                }
240        }
241
242        // use mLog->addWarning() or mLog->addError() if necessary
243}
244endif;
245
246if( ! function_exists( 'wp_install_old_defaults' ) ) :
247function wp_install_old_defaults($user_id) {
248        global $wpdb;
249
250        // Now drop in some default links
251        $wpdb->query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name) VALUES (1, '".$wpdb->escape(__('Blogroll'))."')");
252        $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/', '');");
253        $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/', '');");
254        $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/', '');");
255        $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/', '');");
256        $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/', '');");
257        $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', '');");
258        $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/', '');");
259
260        // Default category
261        $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', '')");
262
263        // First post
264        $now = date('Y-m-d H:i:s');
265        $now_gmt = gmdate('Y-m-d H:i:s');
266        $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', '', '', '')");
267
268        $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
269
270        // Default comment
271        $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&#039;s comments. There you will have the option to edit or delete them.'))."')");
272
273        // First Page
274
275        $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', '', '', '')");
276}
277endif;
278
279?>
Note: See TracBrowser for help on using the repository browser.