XPressME Integration Kit

Trac

source: trunk/include/xpress_mu_function.php @ 228

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

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

File size: 11.7 KB
Line 
1<?php
2if( ! function_exists( 'xpress_mu_install_defaults' ) ) :
3function xpress_mu_install_defaults($domain,$base,$site_name,$admin_user_id,$admin_user_name,$admin_email){
4                global $xoops_config,$wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query;
5               
6                // set up MU site tables
7                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'site_name', '" . $site_name . "')" );
8                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_email', '".$admin_email."')" );
9                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_user_id', '". $admin_user_id ."')" );
10                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'registration', 'none')" );
11                $wpdb->query( "INSERT INTO ".$wpdb->site." ( id, domain, path ) VALUES ( NULL, '$domain', '$base' )" );
12                $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (1, 'Uncategorized', 'uncategorized', NOW())" );
13                $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (2, 'Blogroll', 'blogroll', NOW())" );
14                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'upload_filetypes', 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf' )" );
15                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'blog_upload_space', '10' )" );
16                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'fileupload_maxk', '1500' )" );
17                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'site_admins', '" . serialize( array( $admin_user_name ) ) . "' )" );
18                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'allowedthemes', '" . serialize( array( 'classic' => 1, 'default' => 1, 'xpress_default' => 1 ) ) . "' )" );
19                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'illegal_names', '" . serialize( array(  "www", "web", "root", "admin", "main", "invite", "administrator" ) ) . "' )" );
20                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'welcome_email', 'Dear User,
21
22Your new $site_name blog has been successfully set up at:
23BLOG_URL
24
25You can log in to the administrator account with the following information:
26Username: USERNAME
27Password: PASSWORD
28Login Here: BLOG_URLwp-login.php
29
30We hope you enjoy your new blog.
31Thanks!
32
33--The Team @ SITE_NAME')" );
34
35                $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'first_post', 'Welcome to <a href=\"$site_url\">$site_name</a>. This is your first post. Edit or delete it, then start blogging!' )" );
36                $weblog_title = $site_name;
37
38
39                $current_site->domain = $domain;
40                $current_site->path = $base;
41                $current_site->site_name = $site_name;
42
43                update_blog_option( 1, 'template', 'xpress_mu_home');
44                update_blog_option( 1, 'stylesheet', 'xpress_mu_home');
45               
46                mu_create_blog( $domain, $base, $weblog_title, $user_id, array( 'blog_public' => 1, 'public' => 1 ) );
47}
48endif;
49
50if( ! function_exists( 'do_htaccess' ) ) :
51function do_htaccess( $oldfilename, $newfilename, $base, $url ) {
52        // remove ending slash from $base and $url
53        $htaccess = '';
54        if( substr($base, -1 ) == '/') {
55                $base = substr($base, 0, -1);
56        }
57
58        if( substr($url, -1 ) == '/') {
59                $url = substr($url, 0, -1);
60        }
61        $err = '';
62        if( is_file( $oldfilename ) ) {
63                $fp = @fopen( $oldfilename, "r" );
64                if( $fp ) {
65                        while( !feof( $fp ) )
66                        {
67                                $htaccess .= fgets( $fp, 4096 );
68                        }
69                        fclose( $fp );
70                        $htaccess = str_replace( "BASE", $base, $htaccess );
71                        if( touch( $newfilename ) ) {
72                                $fp = fopen( $newfilename, "w" );
73                                if( $fp ) {
74                                        fwrite( $fp, $htaccess );
75                                        fclose( $fp );
76                                } else {
77                                        $err = "could not open $newfilename for writing";
78                                }
79                        } else {
80                                $err = "could not open $newfilename for writing";
81                        }
82                } else {
83                        $err = "could not open $oldfilename for reading";
84                }
85        } else {
86                $err = "$oldfilename not found";
87        }
88
89        if( $err != '' ) {
90                print "<h2>Warning!</h2>";
91                print "<p><strong>There was a problem creating the .htaccess file.</strong> </p>";
92                print "<p style='color: #900'>Error: ";
93                if( $err == "could not open $newfilename for writing" ) {
94                        print "Could Not Write To $newfilename.";
95                } elseif( $err == "could not open $oldfilename for reading" ) {
96                        print "I could not read from $oldfilename. ";
97                } elseif( $err == "$oldfilename not found" ) {
98                        print "The file, $oldfilename, is missing.";
99                }
100                print "</p>";
101                filestats( $err );
102
103                print "<p>Please ensure that the webserver can write to this directory.</p>";
104                print "<p>If you use Cpanel then read <a href='http://mu.wordpress.org/forums/topic.php?id=99'>this post</a>. Cpanel creates files that I need to overwrite and you have to fix that.</p>";
105                print "<p>If all else fails then you'll have to create it by hand:";
106                print "<ul>
107                        <li> Download htaccess.dist to your computer and open it in your favourite text editor.</li>
108                        <li> Replace the following text:
109                        <ul>
110                        <li>BASE by '$base'</li>
111                        <li>HOST by '$url'</li>
112                        </ul>
113                        </li>
114                        <li> Rename htaccess.dist to .htaccess and upload it back to the same directory.</li>
115                        </ul>";
116                die( "Installation Aborted!" );
117        }
118}
119endif;
120
121// this function is used to change wpmu_create_blog()
122// wpmu_create_blog() of wp_includes/wpmu_functions.php has the bug
123// when install_blog_defaults is called.
124if( ! function_exists( 'mu_create_blog' ) ) :
125function mu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
126        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query;
127        global $xoops_config;
128        global $base,$current_site, $dirs, $wpmu_version;
129
130        if(!is_object($wp_rewrite)){
131                $wp_rewrite   =& new WP_Rewrite();
132        }
133       
134        $domain = preg_replace( "/\s+/", '', sanitize_user( $domain, true ) );
135        if( constant( 'VHOST' ) == 'yes' )
136                $domain = str_replace( '@', '', $domain );
137        $title = strip_tags( $title );
138        $user_id = (int) $user_id;
139
140        if( empty($path) )
141                $path = '/';
142
143        // Check if the domain has been used already. We should return an error message.
144        if ( domain_exists($domain, $path, $site_id) )
145                return new WP_Error('blog_taken', __('Blog already exists.'));
146
147        if ( !defined("WP_INSTALLING") )
148                define( "WP_INSTALLING", true );
149
150        if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
151                return new WP_Error('insert_blog', __('Could not create blog.'));
152
153        switch_to_blog($blog_id);
154
155        install_blog($blog_id, $title);
156
157        install_mu_blog_defaults($blog_id, $user_id);
158
159        add_user_to_blog($blog_id, $user_id, 'administrator');
160
161        if ( is_array($meta) ) foreach ($meta as $key => $value) {
162                if( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' ) {
163                        update_blog_status( $blog_id, $key, $value );
164                } else {
165                        update_option( $key, $value );
166                }
167        }
168
169        add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
170
171        update_option( 'blog_public', $meta['public'] );
172
173        if(get_usermeta( $user_id, 'primary_blog' ) == 1 )
174                update_usermeta( $user_id, 'primary_blog', $blog_id );
175
176
177        restore_current_blog();
178
179        do_action( 'wpmu_new_blog', $blog_id, $user_id );
180
181        return $blog_id;
182}
183endif;
184
185// this function is used to change install_blog_defaults()
186// When install_blog_defaults is called, $wp_rewrite is not object.
187if( ! function_exists( 'install_mu_blog_defaults' ) ) :
188function install_mu_blog_defaults($blog_id, $user_id) {
189        global $wpdb, $wp_rewrite, $current_site, $table_prefix;
190        if(!is_object($wp_rewrite)){
191                $wp_rewrite   =& new WP_Rewrite();
192        }
193
194        $wpdb->suppress_errors();
195
196        // Cast for security
197        $user_id = (int) $user_id;
198        $blog_id = (int) $blog_id;
199
200        // Default links
201        $wpdb->insert( $wpdb->links,  array('link_url' => 'http://wordpress.com/', 'link_name' => 'WordPress.com', 'link_category' => '1356', 'link_owner' => $user_id, 'link_rss' => 'http://wordpress.com/feed/') );
202        $wpdb->insert( $wpdb->links,  array('link_url' => 'http://wordpress.org/', 'link_name' => 'WordPress.org', 'link_category' => '1356', 'link_owner' => $user_id, 'link_rss' => 'http://wordpress.org/development/feed/') );
203        $wpdb->insert( $wpdb->term_relationships, array('object_id' => 1, 'term_taxonomy_id' => 2));
204        $wpdb->insert( $wpdb->term_relationships, array('object_id' => 2, 'term_taxonomy_id' => 2));
205
206        // First post
207        $now = date('Y-m-d H:i:s');
208        $now_gmt = gmdate('Y-m-d H:i:s');
209        $first_post = get_site_option( 'first_post' );
210        if( $first_post == false ) {
211                $first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
212        }
213        $first_post = str_replace( "SITE_URL", clean_url("http://" . $current_site->domain . $current_site->path), $first_post );
214        $first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
215        $wpdb->insert( $wpdb->posts, array(
216                'post_author' => $user_id,
217                'post_date' => $now,
218                'post_date_gmt' => $now_gmt,
219                'post_content' => stripslashes( $first_post ),
220                'post_excerpt' => '',
221                'post_title' => __('Hello world!'),
222                'post_category' => 0,
223                'post_name' => __('hello-world'),
224                'post_modified' => $now,
225                'post_modified_gmt' => $now_gmt,
226                'comment_count' => 1
227        ) );   
228        $wpdb->insert( $wpdb->term_relationships, array('object_id' => 1, 'term_taxonomy_id' => 1));
229        update_option( "post_count", 1 );
230
231        // First page
232        $wpdb->insert( $wpdb->posts, array(
233                'post_author' => $user_id,
234                'post_date' => $now,
235                'post_date_gmt' => $now_gmt,
236                'post_content' => __('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.'),
237                'post_excerpt' => '',
238                'post_title' => __('About'),
239                'post_category' => 0,
240                'post_name' => __('about'),
241                'post_modified' => $now,
242                'post_modified_gmt' => $now_gmt,
243                'post_status' => 'publish',
244                'post_type' => 'page',
245                'to_ping' => '',
246                'pinged' => '',
247                'post_content_filtered' => ''
248        ) );
249       
250        // Flush rules to pick up the new page.
251        $wp_rewrite->init();
252        $wp_rewrite->flush_rules();
253
254        // Default comment
255        $wpdb->insert( $wpdb->comments, array(
256                'comment_post_ID' => '1',
257                'comment_author' => __('Mr WordPress'),
258                'comment_author_email' => '',
259                'comment_author_url' => 'http://' . $current_site->domain . $current_site->path,
260                'comment_author_IP' => '127.0.0.1',
261                'comment_date' => $now,
262                'comment_date_gmt' => $now_gmt,
263                'comment_content' => __("Hi, this is a comment.<br />To delete a comment, just log in, and view the posts' comments, there you will have the option to edit or delete them.")
264        ) );
265       
266        $user = new WP_User($user_id);
267        $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
268
269        // Remove all perms except for the login user.
270        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') );
271        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') );
272       
273        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
274        if ( !is_site_admin( $user->user_login ) && $user_id != 1 )
275                $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix.'1_capabilities') );
276
277        $wpdb->suppress_errors( false );
278}
279endif;
280
281?>
Note: See TracBrowser for help on using the repository browser.