XPressME Integration Kit

Trac

source: trunk/include/oninstall.php @ 210

Last change on this file since 210 was 210, checked in by toemon, 16 years ago

WordPressMUをインストールするための変更

File size: 7.4 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.";
113
[80]114        $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
115        $wpdb->query($sql);
[89]116       
[210]117// make templates
[102]118        include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
119        $t_mess = xpress_templates_make($mid,$mydirname);
[210]120       
121// Admin User Data write
122        // Change uid field
123        $wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'");
124        $user_name = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uname"):'admin';
125        $email = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("email"):'foo@exsample.com';
126        $pass_md5 = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("pass"):'';
127       
128        $user_id = username_exists($user_name);
129        if ( !$user_id ) {
130                $random_password = 'admin';
131                if (!$xoops_config->is_wpmu){
132                        $user_id = wp_create_user($user_name, $random_password, $email);
133                } else {
134                        $user_id = wpmu_create_user($user_name, $random_password, $email);
135                }
136        } else {
137                $random_password = __('User already exists.  Password inherited.');
138        }
139
140        $user = new WP_User($user_id);
141        $user->set_role('administrator');
142        'User ' . $user_name . ' of the administrator was made.';
143        // over write xoops md5 password
144        $sql = "UPDATE $wpdb->users SET user_pass ='$pass_md5' WHERE ID = $user_id";
145        $wpdb->query($sql);
146        $ret[] = 'The password of XOOPS was copied.';
147       
148       
149// Set Default data
150        if (!$xoops_config->is_wpmu){   // for WordPress
151                // make WordPress Default data 
152                wp_install_defaults($user_id);
153                $ret[] = 'The first sample post & comment was written.';
154               
155                // Rewrite Option for Xpress
156                //      update_option("blog_charset", wp_blog_charset());
157                        update_option('blogname', $site_name );
158                        update_option('blogdescription', 'WordPress for XOOPS');
159                        update_option("admin_email", $GLOBALS["xoopsConfig"]['adminmail']);
160                        update_option("ping_sites", "http://rpc.pingomatic.com/\nhttp://ping.xoopsforge.com/");
161                        update_option("home", $site_url);
162                        update_option("siteurl", $site_url);
163                        update_option("what_to_show", "posts");
164                        update_option('default_pingback_flag', 0);
165                        $ret[] = 'The initial data was written in the data base of wordpress.';
166                       
167                        update_option("template", "xpress_default");
168                        update_option("stylesheet", "xpress_default");
169                        $ret[] = 'The default theme of wordpress was set to xpress_default.';
170                //      update_option('uploads_use_yearmonth_folders', 1);
171                        update_option('upload_path', 'wp-content/uploads');
172                       
173        } else {        // for WordPress MU
174                global $base,$current_site, $dirs, $wpmu_version;
175               
176                $base =  $xoops_config->mu_path_current_site;
177                $domain = $xoops_config->mu_domain_current_site;
178                $admin_email = $GLOBALS["xoopsConfig"]['adminmail'];
179                $admin_user_name = $user_name;
180                $admin_user_id = $user_id;
181                include_once($mydirpath . '/include/xpress_mu_function.php');
182               
183                do_htaccess( $xoops_config->module_path . '/htaccess.dist', $xoops_config->module_path . '/.htaccess', $base, '');
184                xpress_mu_install_defaults($domain,$base,$site_name,$admin_user_id,$admin_user_name,$admin_email);
185        }
186       
187// activate the xpressme plugin
188        require_once dirname( __FILE__ ).'/xpress_active_plugin.php';
189        if (xpress_pulugin_activation('xpressme/xpressme.php')){
190                $ret[] = 'The xpressme plug-in was activated.';
191        }
192
[102]193        $ret = array_merge($ret,$t_mess);
[1]194
195        return true ;
196}
197endif;
198
199if( ! function_exists( 'xpress_message_append_oninstall' ) ) :
200function xpress_message_append_oninstall( &$module_obj , &$log )
201{
202        if( is_array( @$GLOBALS['ret'] ) ) {
203                foreach( $GLOBALS['ret'] as $message ) {
204                        $log->add( strip_tags( $message ) ) ;
205                }
206        }
207
208        // use mLog->addWarning() or mLog->addError() if necessary
209}
210endif;
211
212?>
Note: See TracBrowser for help on using the repository browser.