XPressME Integration Kit

Trac

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

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

グループ権限のMultiBlog対応 Fixes #298

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