XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/oninstall.php @ 352

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

予約投稿、xmlrpc 投稿時のイベント通知問題の修正 fixes #194
イベント通知のデバッグ用の処理追加

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