root/tags/1.3/wp-signup.php

Revision 1141, 16.5 kB (checked in by donncha, 1 year ago)

Make a radio button of the privacy option

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