diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-07-19 16:47:50 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-07-19 16:47:50 +0000 |
| commit | 4dcf1b98ef1f7ea9fbaeffda363ed11c105c6fb2 (patch) | |
| tree | 8d76dab67710303807a31e78a9a6da798db4a2c4 | |
| parent | 2d4088706f1e0c2e31260ffdacf378ec1323c0ce (diff) | |
| download | wordpress-mu-4dcf1b98ef1f7ea9fbaeffda363ed11c105c6fb2.tar.gz wordpress-mu-4dcf1b98ef1f7ea9fbaeffda363ed11c105c6fb2.tar.xz wordpress-mu-4dcf1b98ef1f7ea9fbaeffda363ed11c105c6fb2.zip | |
Added user invites. WIP.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@48 7be80a69-a1ef-0310-a953-fb0f7c49ff36
| -rw-r--r-- | wp-inst/wp-admin/invites.php | 109 | ||||
| -rw-r--r-- | wp-inst/wp-admin/menu.php | 6 | ||||
| -rw-r--r-- | wp-inst/wp-content/mu-plugins/invites.php | 97 |
3 files changed, 195 insertions, 17 deletions
diff --git a/wp-inst/wp-admin/invites.php b/wp-inst/wp-admin/invites.php new file mode 100644 index 0000000..c2323b4 --- /dev/null +++ b/wp-inst/wp-admin/invites.php @@ -0,0 +1,109 @@ +<?php +require_once('admin.php'); + +$title = __('Invites'); +$parent_file = 'edit.php'; + +if( $_POST[ 'action' ] == 'send' ) { + $invites_left = get_usermeta( $user_ID, 'invites_left' ); + if( $invites_left != false ) { + if( $_POST[ 'email' ] != '' && is_email( $_POST[ 'email' ] ) ) { + $msg = get_site_settings( "invites_default_message" ); + $subject = get_site_settings( "invites_default_subject" ); + $from = $cache_userdata[ $user_ID ]->user_email; + + if( $msg == '' ) { + $msg = +"Dear FIRSTNAME LASTNAME, +--------------------------------------------- +PERSONALMESSAGE +--------------------------------------------- +You have been invited to open a free WordPress weblog. + +To accept this invitation and register for your weblog, visit +REGURL +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)."; + update_site_settings( "invites_default_message", $msg ); + } + + if( $subject == '' ) { + $subject = "FIRSTNAME, USERNAME has invited you to use WordPress"; + update_site_settings( "invites_default_subject", $subject ); + } + + $msg = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $msg ); + $msg = str_replace( "LASTNAME", $_POST[ 'lname' ], $msg ); + $msg = str_replace( "PERSONALMESSAGE", $_POST[ 'personalmessage' ], $msg ); + $msg = str_replace( "\\r\\n", "\n", stripslashes( str_replace( "REGURL", get_site_settings( "siteurl" ) . "/invite/".md5( $_POST[ 'email' ] ), $msg ) ) ); + + $subject = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $subject ); + if( $cache_userdata[ $user_ID ]->display_name != '' ) { + $username = $cache_userdata[ $user_ID ]->display_name; + } elseif( $cache_userdata[ $user_ID ]->first_name != '' ) { + $username = $cache_userdata[ $user_ID ]->first_name; + } elseif( $cache_userdata[ $user_ID ]->nickname != '' ) { + $username = $cache_userdata[ $user_ID ]->nickname; + } else { + $username = __( 'Someone' ); + } + $subject = str_replace( "USERNAME", ucfirst( $username ), $subject ); + + $email = $wpdb->escape( $_POST[ 'email' ] ); + $query = "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', 'invite' , '".md5( strtolower( $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' , '$user_ID')"; + $wpdb->query( $query ); + mail( $_POST[ 'email' ], $subject, $msg, "From: $from" ); + $invites_left = $invites_left - 1; + update_usermeta( $user_ID, "invites_left", $invites_left ); + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=sent&to=" . urlencode( $email ) ); + exit; + } + } +} elseif( $_POST[ 'personalmessage' ] == '' ) { + $_POST[ 'personalmessage' ] = "I've been using WordPress and thought you might like to try it out. Here's an invitation to create an account."; +} + +include('admin-header.php'); +if (isset($_GET['result'] ) == 'sent' ) { + ?><div class="updated"><p><strong><?php echo sprintf( __("Invite Sent to %s."), $wpdb->escape( $_GET[ 'to' ] ) ) ?></strong></p></div><?php +} +?> + +<div class="wrap"> + <h2><?php _e('Invites') ?></h2> + <form name="form1" method="post" action="invites.php"> + <input type="hidden" name="action" value="send" /> + <fieldset class="options"> + <legend><?php _e('Send Invite To') ?></legend> + <table width="100%" cellspacing="2" cellpadding="5" class="editform"> + <tr valign="top"> + <th width="33%" scope="row"><?php _e('First Name:') ?></th> + <td><input name="fname" type="text" id="fname" value="<?php echo stripslashes( $_POST[ 'fname' ] ) ?>" size="40" /></td> + </tr> + <tr valign="top"> + <th width="33%" scope="row"><?php _e('Last Name:') ?></th> + <td><input name="lname" type="text" id="lname" value="<?php echo stripslashes( $_POST[ 'lname' ] ) ?>" size="40" /></td> + </tr> + <tr valign="top"> + <th width="33%" scope="row"><?php _e('Email:') ?></th> + <td><input name="email" type="text" id="email" value="<?php echo stripslashes( $_POST[ 'email' ] ) ?>" size="40" /></td> + </tr> + <tr valign="top"> + <th width="33%" scope="row"><?php _e('Personal Message:') ?></th> + <td><textarea rows="5" cols="40" name="personalmessage" tabindex="5" id="defaultmessage"><?php echo stripslashes( $_POST[ 'personalmessage' ] ) ?></textarea></td> + </tr> + </table> + </fieldset> + <p class="submit"> + <input type="submit" name="Submit" value="<?php _e('Send Invite') ?> »" /> + </p> + </form> +</div> +<?php include("admin-footer.php") ?> diff --git a/wp-inst/wp-admin/menu.php b/wp-inst/wp-admin/menu.php index 4d14087..c84301b 100644 --- a/wp-inst/wp-admin/menu.php +++ b/wp-inst/wp-admin/menu.php @@ -26,6 +26,12 @@ $submenu['edit.php'][20] = array(__('Comments'), 'edit_posts', 'edit-comments.ph $awaiting_mod = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); $submenu['edit.php'][25] = array(sprintf(__("Awaiting Moderation (%s)"), $awaiting_mod), 'edit_posts', 'moderation.php'); $submenu['edit.php'][30] = array(__('Files'), 'edit_files', 'templates.php'); +$invites_left = get_usermeta( $user_ID, 'invites_left' ); +if( $invites_left == '' ) { + $invites_left = get_site_settings( 'invites_per_user' ); + update_usermeta( $user_ID, "invites_left", $invites_left ); +} +$submenu['edit.php'][35] = array(sprintf(__("Invites (%s)"), $invites_left ), 'edit_posts', 'invites.php'); // TODO: put somewhere else. $submenu['link-manager.php'][5] = array(__('Manage Links'), 'manage_links', 'link-manager.php'); $submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-add.php'); diff --git a/wp-inst/wp-content/mu-plugins/invites.php b/wp-inst/wp-content/mu-plugins/invites.php index ceb7301..3498dba 100644 --- a/wp-inst/wp-content/mu-plugins/invites.php +++ b/wp-inst/wp-content/mu-plugins/invites.php @@ -30,6 +30,25 @@ add_action('newblogheader', 'invites_check_user_hash'); function invites_admin_send_email() { global $wpdb; + $msg = get_site_settings( "invites_default_message" ); + if( $msg == '' ) { + $msg = "Dear FIRSTNAME LASTNAME, +--------------------------------------------- +PERSONALMESSAGE +--------------------------------------------- +You have been invited to open a free WordPress weblog. + +To accept this invitation and register for your weblog, visit +REGURL +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)."; + update_site_settings( "invites_default_message", $msg ); + } if( $_GET[ 'action' ] == 'invite' ) { if( is_email( $_POST[ 'email' ] ) ) { $email = $wpdb->escape( $_POST[ 'email' ] ); @@ -39,23 +58,7 @@ function invites_admin_send_email() { $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). -"; + $msg = str_replace( "REGURL", get_settings( "siteurl" ) . "/invite/".md5( $email ), $msg ); mail( $_POST[ 'email' ], "Your WordPress.com Invitation", $msg, "From: WordPress.com <donotreply@".get_settings( "siteurl" ).">" ); header( "Location: wpmu-admin.php?result=invitesent" ); die(); @@ -121,4 +124,64 @@ function invites_cleanup_db( $val ) { } } add_action('newblogfinished', 'invites_cleanup_db'); + +/* admin functions: + Configure invites: sig, number per user, default message + */ + +add_action('admin_menu', 'admin_menu'); +add_action('admin_footer', 'admin_footer'); + +function admin_menu() { + $pfile = basename(dirname(__FILE__)) . '/' . basename(__FILE__); + /* + $invites_left = get_option( "invites_left" ); + if( $invites_left == '' ) { + $invites_left = 5; + update_site_settings( "invites_per_user", $invites_left ); + update_option( "invites_left", $invites_left ); + } + */ + + add_submenu_page('wpmu-admin.php', 'Invites', 'Invites', 0, $pfile, 'invites_admin_content'); +} + +function admin_footer() { +} + +function invites_admin_content() { + global $wpdb; + + switch( $_GET[ 'action' ] ) { + case "updateinvitedefaults": + update_site_settings( "invites_per_user", $wpdb->escape( $_GET[ 'invites_per_user' ] ) ); + update_site_settings( "invites_default_message", $wpdb->escape( $_GET[ 'invites_default_message' ] ) ); + update_site_settings( "invites_default_subject", $wpdb->escape( $_GET[ 'invites_default_subject' ] ) ); + break; + case "": + break; + default: + break; + } + $invites_per_user = get_site_settings( "invites_per_user" ); + if( $invites_per_user == '' ) { + $invites_per_user = 5; + update_site_settings( "invites_per_user", $invites_per_user ); + } + ?> + <div class='wrap'> + <h2>Invite Options</h2> + <form method='GET'> + <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>"/> + <input type='hidden' name='action' value='updateinvitedefaults'> + <table> + <tr><td valign='top'>Invites Per User:</td><td><input type='text' size='2' maxlength='2' name='invites_per_user' value='<?php echo $invites_per_user ?>'></td></tr> + <tr><td valign='top'>Default Subject:</td><td><input type='text' size='70' maxlength='90' name='invites_default_subject' value='<?php echo get_site_settings( "invites_default_subject" ) ?>'></td></tr> + <tr><td valign='top'>Default Message:</td><td><textarea rows="9" cols="70" name="invites_default_message" tabindex="5" id="defaultmessage"><?php echo str_replace( "\\r\\n", "\n", stripslashes( get_site_settings( 'invites_default_message' ) ) ) ?></textarea></td></tr> + <tr><td valign='top' colspan='2'><input type='submit'></td></tr> + </table> + </form> + </div> + <?php +} ?> |
