root/tags/release-1.0/wp-signup.php

Revision 797, 13.8 kB (checked in by donncha, 2 years ago)

WP Merge - needs testing.

Line 
1 <?php
2
3 define( "WP_INSTALLING", true );
4 require ('wp-config.php');
5
6 require_once( ABSPATH . WPINC . '/registration.php');
7
8 do_action("signup_header");
9 if( $current_blog->domain != $current_site->domain ) {
10     header( "Location: http://" . $current_site->domain . $current_site->path . "wp-signup.php" );
11     die();
12 }
13
14 get_header();
15 ?>
16 <div id="content" class="widecolumn">
17 <style type="text/css">
18 form { margin-top: 2em; }
19 #submit, #blog_title, #user_email {
20     width: 90%;
21     font-size: 24px;
22 }
23 .error {
24     background-color: #f66;
25 }
26 </style>
27 <?php
28 function show_blog_form($blog_id = '', $blog_title = '', $errors = '') {
29     global $current_site;
30     $locale = get_locale();
31
32     // Blog name/Username
33     if ( $errors->get_error_message('blog_id') )
34         print '<tr class="error">';
35     else
36         print '<tr>';
37
38     if( constant( "VHOST" ) == 'no' )
39         echo '<th valign="top">' . __('Blog Name:') . '</th><td>';
40     else
41         echo '<th valign="top">' . __('Blog Domain:') . '</th><td>';
42
43     if ( $errmsg = $errors->get_error_message('blog_id') ) {
44         ?><p><strong><?php echo $errmsg ?></strong></p><?php
45     }
46     if( constant( "VHOST" ) == 'no' ) {
47         print '<span style="font-size: 20px">' . $current_site->domain . $current_site->path . '</span><input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" style="width:40%; text-align: left; font-size: 20px;" /><br />';
48     } else {
49         print '<input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" style="width:40%; text-align: right; font-size: 20px;" /><span style="font-size: 20px">.' . $current_site->domain . $current_site->path . '</span><br />';
50     }
51     if ( !is_user_logged_in() ) {
52         print '(<strong>' . __( 'Your address will be ' );
53         if( constant( "VHOST" ) == 'no' ) {
54             print $current_site->domain . $current_site->path . __( 'blogname' );
55         } else {
56             print __( 'domain.' ) . $current_site->domain . $current_site->path;
57         }
58         print '.</strong>' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' ) . '</td> </tr>';
59     }
60
61     // Blog Title
62     if ( $errors->get_error_message('blog_title')) {
63         print '<tr class="error">';
64     } else {
65         print '<tr>';
66     }
67 ?><th valign="top" width="120"><?php _e('Blog Title:') ?></th><td><?php
68
69     if ( $errmsg = $errors->get_error_message('blog_title') ) {
70 ?><p><strong><?php echo $errmsg ?></strong></p><?php
71     }
72     print '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></td>
73         </tr>';
74 ?>
75 <tr>
76 <th scope="row"  valign="top"><?php _e('Privacy:') ?></th>
77 <td><label><input type="checkbox" name="blog_public" value="1" checked="checked" /> <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.'); ?></label></td>
78 </tr>
79 <?php
80 do_action('signup_blogform');
81 }
82
83 function validate_blog_form() {
84     if ( is_user_logged_in() )
85         $user = wp_get_current_user();
86     else
87         $user = '';
88
89     $result = wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title'], $user);
90
91     return $result;
92 }
93
94 function show_user_form($user_name = '', $user_email = '', $errors = '') {
95     // Blog name/Username
96     if ( $errors->get_error_message('user_name') ) {
97         print '<tr class="error">';
98     } else {
99         print '<tr>';
100     }
101
102     echo '<th valign="top">' . __('Username:') . '</th><td>';
103
104     if ( $errmsg = $errors->get_error_message('user_name') ) {
105         ?><p><strong><?php echo $errmsg ?></strong></p><?php
106     }
107
108     print '<input name="user_name" type="text" id="user_name" value="'.$user_name.'" maxlength="50" style="width:50%; font-size: 30px;" /><br />';
109     _e('(Must be at least 4 characters, letters and numbers only.)'); echo '</td> </tr>';
110
111     // User Email
112     if ( $errors->get_error_message('user_email') ) {
113         print '<tr class="error">';
114     } else {
115         print '<tr>';
116     }
117 ?><th valign="top"><?php _e('Email&nbsp;Address:') ?></th><td><?php
118
119     if ( $errmsg = $errors->get_error_message('user_email') ) {
120 ?><p><strong><?php echo $errmsg ?></strong></p><?php
121     }
122     ?>
123     <input name="user_email" type="text" id="user_email" value="<?php  echo wp_specialchars($user_email, 1) ?>" maxlength="200" /><br /><?php _e('(We&#8217;ll send your password to this address, so <strong>triple-check it</strong>.)') ?></td>
124     </tr>
125     <?php
126     if ( $errmsg = $errors->get_error_message('generic') )
127         print '<tr class="error"> <th colspan="2">'.$errmsg.'</th> </tr>';
128 }
129
130 function validate_user_form() {
131     $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
132
133     return $result;
134 }
135
136 function signup_another_blog($blog_id = '', $blog_title = '', $errors = '') {
137     global $current_user, $wpdb, $domain, $current_site;
138
139     if ( ! is_wp_error($errors) )
140         $errors = new WP_Error();
141
142     // allow definition of default variables
143     $filtered_results = apply_filters('signup_another_blog_init', array('blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors ));
144     $blog_id = $filtered_results['blog_id'];
145     $blog_title = $filtered_results['blog_title'];
146     $errors = $filtered_results['errors'];
147
148     echo '<h2>' . sprintf( __('Get <em>another</em> %s blog in seconds'), $current_site->site_name ) . '</h2>';
149
150     if ( $errors->get_error_code() ) {
151         echo "<p>" . __('There was a problem, please correct the form below and try again.') . "</p>";
152     }
153
154 ?>
155 <p><?php printf(__("Welcome back, %s. By filling out the form below, you can <strong>add another blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly."), $current_user->display_name) ?></p>
156 <?php
157     $blogs = get_blogs_of_user($current_user->ID);
158
159     if ( ! empty($blogs) ) {
160         ?><p><?php _e('Here are the blogs you already have:') ?></p><ul><?php
161         foreach ( $blogs as $blog )
162             echo "<li><a href='http://" . $blog->domain . $blog->path . "'>" . $blog->domain . $blog->path . "</a></li>";
163         ?></ul><?php
164     }
165 ?>
166 <p><?php _e("If you&#8217;re not going to use a great blog domain, leave it for a new user. Now have at it!") ?></p>
167 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
168 <input type="hidden" name="stage" value="gimmeanotherblog">
169 <?php do_action( "signup_hidden_fields" ); ?>
170 <table border="0" width="100%" cellpadding="9">
171 <?php
172     show_blog_form($blog_id, $blog_title, $errors);
173 ?>
174 <tr>
175 <th scope="row"  valign="top">&nbsp;</th>
176 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Create Blog &raquo;') ?>" /></td>
177 </tr>
178 </table>
179 </form>
180 <?php
181 }
182
183 function validate_another_blog_signup() {
184     global $current_user, $blog_id, $blog_title, $errors, $domain, $path;
185
186     $result = validate_blog_form();
187     extract($result);
188
189     if ( $errors->get_error_code() ) {
190         signup_another_blog($blog_id, $blog_title, $errors);
191         return;
192     }
193
194     $public = (int) $_POST['blog_public'];
195     $meta = apply_filters('signup_create_blog_meta', array ('lang_id' => 'en', 'public' => $public));
196
197     wpmu_create_blog($domain, $path, $blog_title, $current_user->id, $meta);
198     confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
199 }
200
201 function confirm_another_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta) {
202 ?>
203 <h2><?php printf(__('%s Is Yours'), $domain.$path ) ?></h2>
204 <p><?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog.  <a href="%3$s">Login</a> as "%4$s" using your existing password.'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?></p>
205 <?php
206     do_action('signup_finished');
207 }
208
209 function signup_user($user_name = '', $user_email = '', $errors = '') {
210     global $current_site;
211
212     if ( ! is_wp_error($errors) )
213         $errors = new WP_Error();
214
215     // allow definition of default variables
216     $filtered_results = apply_filters('signup_user_init', array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ));
217     $user_name = $filtered_results['user_name'];
218     $user_email = $filtered_results['user_email'];
219     $errors = $filtered_results['errors'];
220 ?>
221 <h2><?php printf( __('Get your own %s account in seconds'), $current_site->site_name ) ?></h2>
222 <p>Fill out this one-step form and you'll be blogging seconds later!</p>
223 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
224 <input type="hidden" name="stage" value="validate-user-signup">
225 <?php do_action( "signup_hidden_fields" ); ?>
226 <table border="0" width="100%" cellpadding="9">
227 <?php show_user_form($user_name, $user_email, $errors); ?>
228 <th scope="row"  valign="top">&nbsp;</th>
229 <td>
230 <p>
231 <input id="signupblog" type="radio" name="signup_for" value="blog" checked="checked" />
232 <label for="signupblog"><?php _e('Gimme a blog!') ?></label>
233 <br />
234 <input id="signupuser" type="radio" name="signup_for" value="user" />
235 <label for="signupuser"><?php _e('Just a username, please.') ?></label>
236 </p>
237 </td>
238 </tr>
239 <tr>
240 <th scope="row"  valign="top">&nbsp;</th>
241 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Next &raquo;') ?>" /></td>
242 </tr>
243 </table>
244 </form>
245 <?php
246
247 }
248
249 function validate_user_signup() {
250     $result = validate_user_form();
251     extract($result);
252
253     if ( $errors->get_error_code() ) {
254         signup_user($user_name, $user_email, $errors);
255         return;
256     }
257
258     if ( 'blog' == $_POST['signup_for'] ) {
259         signup_blog($user_name, $user_email);
260         return;
261     }
262
263     wpmu_signup_user($user_name, $user_email);
264
265     confirm_user_signup($user_name, $user_email);
266 }
267
268 function confirm_user_signup($user_name, $user_email) {
269 ?>
270 <h2><?php printf(__('%s Is Your New Username'), $user_name) ?></h2>
271 <p><?php _e('But, before you can start using your new username, <strong>you must activate it</strong>.') ?></p>
272 <p><?php printf(__('Check your inbox at <strong>%1$s</strong> and click the link given.  '),  $user_email) ?></p>
273 <p><?php _e('If you do not activate your username within two days, you will have to sign up again.'); ?></p>
274 <?php
275 }
276
277 function signup_blog($user_name = '', $user_email = '', $blog_id = '', $blog_title = '', $errors = '') {
278     if ( ! is_wp_error($errors) )
279         $errors = new WP_Error();
280
281     // allow definition of default variables
282     $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors ));
283     $user_name = $filtered_results['user_name'];
284     $user_email = $filtered_results['user_email'];
285     $blog_id = $filtered_results['blog_id'];
286     $blog_title = $filtered_results['blog_title'];
287     $errors = $filtered_results['errors'];
288
289     if ( empty($blog_id) )
290         $blog_id = $user_name;
291 ?>
292 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
293 <input type="hidden" name="stage" value="validate-blog-signup">
294 <input type="hidden" name="user_name" value="<?php echo $user_name ?>">
295 <input type="hidden" name="user_email" value="<?php echo $user_email ?>">
296 <?php do_action( "signup_hidden_fields" ); ?>
297 <table border="0" width="100%" cellpadding="9">
298 <?php show_blog_form($blog_id, $blog_title, $errors); ?>
299 <tr>
300 <th scope="row"  valign="top">&nbsp;</th>
301 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Signup &raquo;') ?>" /></td>
302 </tr>
303 </table>
304 </form>
305 <?php
306 }
307
308 function validate_blog_signup() {
309     // Re-validate user info.
310     $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
311     extract($result);
312
313     if ( $errors->get_error_code() ) {
314         signup_user($user_name, $user_email, $errors);
315         return;
316     }
317
318     $result = wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title']);
319     extract($result);
320
321     if ( $errors->get_error_code() ) {
322         signup_blog($user_name, $user_email, $blog_id, $blog_title, $errors);
323         return;
324     }
325
326     $public = (int) $_POST['blog_public'];
327     $meta = array ('lang_id' => 'en', 'public' => $public);
328     $meta = apply_filters( "add_signup_meta", $meta );
329
330     wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
331
332     confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
333 }
334
335 function confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta) {
336 ?>
337 <h2><?php printf(__('%s Is Yours'), $domain.$path) ?></h2>
338 <p><?php _e('But, before you can start using your blog, <strong>you must activate it</strong>.') ?></p>
339 <p><?php printf(__('Check your inbox at <strong>%s</strong> and click the link given.  '),  $user_email) ?></p>
340 <p><?php _e('If you do not activate your blog within two days, you will have to sign up again.'); ?></p>
341 <?php
342     do_action('signup_finished');
343 }
344
345 // Main
346 if( in_array( $_GET[ 'new' ], get_site_option( 'illegal_names' ) ) == true ) {
347     header( "Location: http://{$current_site->domain}{$current_site->path}" );
348     die();
349 }
350 $blog_id = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
351 if( $_POST['blog_public'] != 1 )
352     $_POST['blog_public'] = 0;
353
354 switch ($_POST['stage']) {
355     case 'validate-user-signup' :
356         validate_user_signup();
357         break;
358     case 'validate-blog-signup':
359         validate_blog_signup();
360         break;
361     case 'gimmeanotherblog':
362         validate_another_blog_signup();
363         break;
364     default :
365         $user_email = $_POST[ 'user_email' ];
366         do_action( "preprocess_signup_form" ); // populate the form from invites, elsewhere?
367         if ( is_user_logged_in() )
368             signup_another_blog($blog_id);
369         else
370             signup_user( $blog_id, $user_email );
371
372         if ($blog_id) {
373             if( constant( "VHOST" ) == 'no' )
374                 $newblog = 'http://' . $current_site->domain . $current_site->path . $blog_id . '/';
375             else
376                 $newblog = 'http://' . $blog_id . '.' . $current_site->domain . $current_site->path;
377             printf(__("<p><em>The blog you were looking for, <strong>%s</strong> doesn't exist but you can create it now!</em></p>"), $newblog );
378         }
379         break;
380 }
381 ?>
382 </div>
383
384 <?php get_footer(); ?>
385
Note: See TracBrowser for help on using the browser.