diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-07-12 13:21:19 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-07-12 13:21:19 +0000 |
commit | 95aaacaa0dfab3cfaf51709f7026cbc17478bbc5 (patch) | |
tree | 2a71051bedeb1f84c26c51cfa35e3a5434e61a70 | |
parent | 0a08b806615f3bdd5ca1546c4ab0e25dc3d201f1 (diff) | |
download | wordpress-mu-95aaacaa0dfab3cfaf51709f7026cbc17478bbc5.tar.gz wordpress-mu-95aaacaa0dfab3cfaf51709f7026cbc17478bbc5.tar.xz wordpress-mu-95aaacaa0dfab3cfaf51709f7026cbc17478bbc5.zip |
Added invites plugin.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@6 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r-- | htaccess.dist | 1 | ||||
-rw-r--r-- | wp-inst/wp-content/mu-plugins/invites.php | 124 |
2 files changed, 125 insertions, 0 deletions
diff --git a/htaccess.dist b/htaccess.dist index cf06769..534e06c 100644 --- a/htaccess.dist +++ b/htaccess.dist @@ -55,6 +55,7 @@ RewriteRule ^favicon.ico /wp-inst/favicon.ico [L] RewriteRule ^robots.txt /wp-inst/robots.txt [L] RewriteRule ^wp-newblog.php BASE/wp-inst/wp-newblog.php [L] +RewriteRule ^invite/(.*)/? BASE/wp-inst/wp-newblog.php?u=$1 [L] RewriteRule ^index.php BASE/wp-inst/index.php [L] RewriteRule ^$ BASE/wp-inst/index.php [L] diff --git a/wp-inst/wp-content/mu-plugins/invites.php b/wp-inst/wp-content/mu-plugins/invites.php new file mode 100644 index 0000000..ceb7301 --- /dev/null +++ b/wp-inst/wp-content/mu-plugins/invites.php @@ -0,0 +1,124 @@ +<?php + +$u = ''; +if( $_POST[ 'u' ] ) { + $u = $_POST[ 'u' ]; +} elseif( $_GET[ 'u' ] ) { + $u = $_GET[ 'u' ]; +} +$u = $wpdb->escape( $u ); + +function invites_check_user_hash() { + global $wpdb, $u; + if( $u == '' ) { + header( "Location: ".get_settings( "siteurl" ) ); + die( ); + } else { + $query = "SELECT meta_value + FROM ".$wpdb->usermeta." + WHERE user_id = '0' + AND meta_key = '".invite."' + AND meta_value = '".$u."'"; + $userhash = $wpdb->get_var( $query ); + if( $userhash == false ) { + header( "Location: ".get_settings( "siteurl" ) ); + die(); + } + } +} +add_action('newblogheader', 'invites_check_user_hash'); + +function invites_admin_send_email() { + global $wpdb; + if( $_GET[ 'action' ] == 'invite' ) { + if( is_email( $_POST[ 'email' ] ) ) { + $email = $wpdb->escape( $_POST[ 'email' ] ); + $query = "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) + VALUES ( NULL, '0', 'invite' , '".md5( $email )."')"; + $wpdb->query( $query ); + $query = "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) + VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_invited_by' , 'admin')"; + $wpdb->query( $query ); + $msg = +"You have been invited to open a free WordPress weblog. + +To accept this invitation and register for your weblog, visit +"; + $msg .= get_settings( "siteurl" ) . "/invite/".md5( $email ); + $msg .= +" + +This invitation can only be used to set up one weblog. + +Regards, +The WordPress Team + +(If clicking the URLs in this message does not work, copy and paste them +into the address bar of your browser). +"; + mail( $_POST[ 'email' ], "Your WordPress.com Invitation", $msg, "From: WordPress.com <donotreply@".get_settings( "siteurl" ).">" ); + header( "Location: wpmu-admin.php?result=invitesent" ); + die(); + } else { + header( "Location: wpmu-admin.php?result=invitenotsent" ); + die(); + } + } +} +add_action('wpmuadminedit', 'invites_admin_send_email'); + +function invites_admin_send_form() { + print "<h2>Invites</h2>"; + ?> + <p>Invite a new user to use this site!</p> + <form action='wpmu-edit.php?action=invite' method='POST'> + Email: <input type='text' value='' name='email' size='40'><br /> + <input type='submit' value='Send Invite'> + </form> + <?php + // must also list stats on current invites and drill down into specifics. +} +add_action('wpmuadmindefaultpage', 'invites_admin_send_form'); + +function invites_admin_result() { + switch( $_GET[ 'result' ] ) { + case "invitesent": + ?><div class="updated"><p><strong><?php _e('Invite Sent.') ?></strong></p></div><?php + break; + case "invitenotsent": + ?><div class="updated"><p><strong><?php _e('Invite Not Sent.') ?></strong></p></div><?php + break; + } +} +add_action('wpmuadminresult', 'invites_admin_result'); + +function invites_add_field() { + global $u; + + echo "<input type='hidden' name='u' value='".$u."'>\n"; +} +add_action('newblogform', 'invites_add_field'); + +function invites_cleanup_db( $val ) { + global $wpdb; + if( isset( $_POST[ 'u' ] ) ) { + $query = "DELETE FROM ".$wpdb->usermeta." + WHERE meta_key = 'invite' + AND meta_value = '".$_POST[ 'u' ]."'"; + $wpdb->query( $query ); + + $query = "SELECT ID + FROM ".$wpdb->users." + WHERE user_login = '".$wpdb->escape( $_POST[ 'weblog_id' ] )."'"; + $id = $wpdb->get_var( $query ); + + if( $id ) { + $query = "UPDATE ".$wpdb->usermeta." + SET user_id = '".$id."' + WHERE meta_key = '".$_POST[ 'u' ]."_invited_by'"; + $wpdb->query( $query ); + } + } +} +add_action('newblogfinished', 'invites_cleanup_db'); +?> |