' . __("Thanks, your invitation has been sent", "secure_invite") . '
' . __("You must supply a valid email address. Please try again.", "secure_invite") . '
'.__('The settings have been updated', "secure_invite").'
' . __("Use custom settings for secure invitations here.", "secure_invite") . '
' . __("Username", "secure_invite") . ' | ' . __("Nice name", "secure_invite") . ' | ' . __("Display name", "secure_invite") . ' | ' . __("Email", "secure_invite") . ' | ' . __("Invites sent", "secure_invite") . ' | ' . __("Resulting signups", "secure_invite") . ' |
---|---|---|---|---|---|
' . $user->user_login . ' | ' . $user->user_nicename . ' | ' . $user->display_name . ' | ' . $user->user_email . ' | ' . $user->invitations . ' | ' . $user->signups . ' |
' . __("No users found, please try again", "secure_invite") . '
' . __("The settings for this user have been saved", "secure_invite") . '
" . $remaining . "
"; } echo '' . __("Username", "secure_invite") . ': ' . $user->user_login . '
' . __("Invites sent", "secure_invite") . ': ' . secure_invite_user_sent_invites($user->ID) . '
' . $remaining . '' . __("Invites accepted", "secure_invite") . ': ' . (int)secure_invite_user_accepted_invites($user->ID) . '
' . __("Invite points", "secure_invite") . ': ' . (int)get_usermeta($user->ID, "secure_invite_points") . '
'; } echo '' . __("Search for a user to override their invitation settings.", "secure_invite") . '
' . __("The invitation for this email address has been deleted", "secure_invite") . '
' . __("The invitation for this email address could not be deleted", "secure_invite") . '
' . __("The selected invitations have been deleted", "secure_invite") . '
' . __("The selected invitations could not be deleted", "secure_invite") . '
'.__("Month", "secure_invite").' | '.__("Invites sent", "secure_invite").' | '.__("Resulting signups", "secure_invite").' |
---|---|---|
'.__(date("F Y", $invite_month->date)).' | '.__($invite_month->invites).' | '.__($invite_month->signups).' |
'.__("No invitations sent yet", "secure_invite").'
'; } echo ''.__("Name", "secure_invite").' | '.__("Invites sent", "secure_invite").' | '.__("Resulting signups", "secure_invite").' |
---|---|---|
'.__($best_inviter->user_nicename).' | '.__($best_inviter->invites).' | '.__($best_inviter->signups).' |
'.__("No invitations sent yet", "secure_invite").'
'; } echo ''.__("Name", "secure_invite").' | '.__("Points", "secure_invite").' |
---|---|
'.__($best_inviter->user_nicename).' | '.__($best_inviter->secure_invite_points).' |
' . __("No invitations sent yet.", "secure_invite") . '
'; } } // check the invites table exists function secure_invite_check_table() { global $wpdb; // if the invitations table does not exist $sql = "select count(id) from ".$wpdb->base_prefix."invitations;"; $exists = $wpdb->get_var($sql); if($exists == "") { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); // include the file with the required database manipulation functions // create the table $sql = "CREATE TABLE ".$wpdb->base_prefix."invitations ( id mediumint(9) NOT NULL AUTO_INCREMENT, user_id mediumint(9), invited_email varchar(255), datestamp datetime, PRIMARY KEY (id) );"; dbDelta($sql); } } // show a BuddyPress form function secure_invite_buddypress_form($hidelink = false, $usepost = false) { // if the current user is allowed to send invites if (secure_invite_user_can_invite()) { $name = ""; $email = ""; $message = ""; if ($usepost) { $name = @$_POST["name"]; $email = @$_POST["email"]; $message = @$_POST["personalmessage"]; } $rand = rand(1, 10000); $hide = "_visible"; if (!$hidelink) { $hide = ""; echo ' '; } $qs = ""; if ($_SERVER["QUERY_STRING"] != "") { $qs = "?" . $_SERVER["QUERY_STRING"]; } echo '' . __($success, "secure_invite") . '
'; } else { // show the error message echo '' . __($error, "secure_invite") . '
'; } } $qs = ""; if ($_SERVER["QUERY_STRING"] != "") { $qs = "?" . $_SERVER["QUERY_STRING"]; } // show the form echo ' '; } } // see if a user can send an invite function secure_invite_user_can_invite() { global $wpdb, $current_user; $site_registration = stripslashes( get_site_option( "registration" ) ); // if the current user exists and is logged in if ($current_user && $current_user->id != "") { // if site registration is allowed if ($site_registration == "all" || $site_registration == "user") { // if the user has not been overridden if (get_usermeta($current_user->ID, "secure_invite_user_can_invite") != "no") { // get the date this user was registered $registered = $wpdb->get_var($wpdb->prepare("select UNIX_TIMESTAMP(user_registered) from ".$wpdb->users." where id=%d;", $current_user->id)); // get how many days after registration invites are locked $secure_invite_days_after_joining = (int)stripslashes( get_site_option("secure_invite_days_after_joining") ); if ($secure_invite_days_after_joining == "") { $secure_invite_days_after_joining = 30; } // if the user is not too new, or is a site admin if ($registered < (time() - ($secure_invite_days_after_joining * 24 * 60 * 60)) || is_site_admin()) { // get the total number of invites a user is allowed to send $secure_invite_invite_limit = stripslashes( get_site_option("secure_invite_invite_limit") ); if ($secure_invite_invite_limit == "") { $secure_invite_invite_limit = 0; } // get the limit for this user $user_limit = trim(get_usermeta($current_user->ID, "secure_invite_user_invite_limit"), "_"); if ($user_limit != "") { $secure_invite_invite_limit = (int)$user_limit; } // get the number of invites this user has sent $sent = secure_invite_user_sent_invites(); // if the user has sent less than their limit, or there is no limit if ($sent < $secure_invite_invite_limit || $secure_invite_invite_limit == "" || $secure_invite_invite_limit == 0 || $user_limit == 0) { return true; } else { add_action('admin_head', 'secure_invites_disallowed_limit'); add_action('wp_head', 'secure_invites_disallowed_limit'); return false; } } else { add_action('admin_head', 'secure_invites_disallowed_new'); add_action('wp_head', 'secure_invites_disallowed_new'); return false; } } else { add_action('admin_head', 'secure_invites_disallowed_turnedoff'); add_action('wp_head', 'secure_invites_disallowed_turnedoff'); return false; } } else { add_action('admin_head', 'secure_invites_disallowed_registration'); add_action('wp_head', 'secure_invites_disallowed_registration'); return false; } } else { add_action('admin_head', 'secure_invites_disallowed_login'); add_action('wp_head', 'secure_invites_disallowed_login'); return false; } } // the reasons why people are disallowed from sending invites function secure_invites_disallowed_limit() { echo ''; } function secure_invites_disallowed_new() { echo ''; } function secure_invites_disallowed_registration() { echo ''; } function secure_invites_disallowed_login() { echo ''; } function secure_invites_disallowed_turnedoff() { echo ''; } // get the number of invites this user has sent function secure_invite_user_sent_invites($userid = 0) { global $wpdb, $current_user; if ($userid == 0) { $userid = $current_user->id; } return $wpdb->get_var($wpdb->prepare("select count(user_id) from ".$wpdb->base_prefix."invitations where user_id = %d", $userid)); } // get the number of invites this user has sent which have resulted in a non-spam, non-deleted signup function secure_invite_user_accepted_invites() { global $wpdb, $current_user; if ($userid == 0) { $userid = $current_user->id; } return $wpdb->get_var($wpdb->prepare("select count(u.user_id) from ".$wpdb->users." u inner join ".$wpdb->base_prefix."invitations i on i.invited_email = u.user_email where u.spam = 0 and u.deleted = 0 and i.user_id = %d", $userid)); } // show how many invites this user is allowed to send function secure_invite_user_invites_remaining() { global $current_user; // get the total number of invites a user is allowed to send $secure_invite_invite_limit = stripslashes( get_site_option("secure_invite_invite_limit") ); if ($secure_invite_invite_limit == "") { $secure_invite_invite_limit = secure_invite_default_setting("secure_invite_invite_limit"); } // get the limit for this user $user_limit = trim(get_usermeta($current_user->ID, "secure_invite_user_invite_limit"), "_"); if ($user_limit != "") { $secure_invite_invite_limit = (int)$user_limit; } if ($secure_invite_invite_limit > 0) { // get the number of invites sent $sent = secure_invite_user_sent_invites(); return __("Number of invites left to send:", "secure_invite") . " " . ($secure_invite_invite_limit - $sent); } else { return ""; } } // check if an email address exists function secure_invite_email_exists($email) { if( function_exists('email_exists') ) { return email_exists( trim( $email ) ); } else { global $wpdb; $sql = $wpdb->prepare( "select user_email from " . $wpdb->users . " where user_email = %s;", trim( $email ) ); $saved_email = $wpdb->get_var( $sql ); if ( $saved_email == trim( $email ) ) { return true; } else { return false; } } return false; } // send an invitation function secure_invite_send() { global $current_site, $current_user, $blog_id, $wpdb; // check the user can invite if (secure_invite_user_can_invite()) { // check this email address isn't already registered if ( !secure_invite_email_exists( trim($_POST['invite-email']) ) ) { $usernickname = $current_user->display_name; $to = trim($_POST['invite-email']); $from = $current_user->display_name . ' <' . $current_user->user_email . '>'; $pname = trim($_POST['invite-name']); $site_url = $current_site->domain; $site_name = stripslashes( get_site_option("site_name") ); // save the invitation $sql = $wpdb->prepare("insert into ".$wpdb->base_prefix."invitations (user_id, invited_email, datestamp) values (%d, %s, now());", $current_user->id, $to); $wpdb->print_error(); $query = $wpdb->query($sql); $query_error = mysql_error(); // if the invitation could be saved if ($query) { if(!empty($pname)) { $subject = $pname.', '.$usernickname.' has invited you to join '.$site_name; $message .= "Dear ".$pname.", "; } else { $subject = 'Hi there, '. $usernickname.' has invited you to join '.$site_name; $message .= "Hi there, "; } $secure_invite_signup_time_limit = (int)stripslashes( get_site_option("secure_invite_signup_time_limit") ); if ($secure_invite_signup_time_limit == "") { $secure_invite_signup_time_limit = secure_invite_default_setting("secure_invite_signup_time_limit"); } $secure_invite_signup_page = stripslashes( get_site_option("secure_invite_signup_page") ); if ($secure_invite_signup_page == "") { $secure_invite_signup_page = secure_invite_default_setting("secure_invite_signup_page"); } $secure_invite_registration_page = stripslashes( get_site_option("secure_invite_registration_page") ); if ($secure_invite_registration_page == "") { $secure_invite_registration_page = secure_invite_default_setting("secure_invite_registration_page"); } $secure_invite_default_message = stripslashes( get_site_option("secure_invite_default_message") ); if ($secure_invite_default_message == "") { $secure_invite_default_message = secure_invite_default_setting("secure_invite_default_message"); } $secure_invite_default_message = str_replace("[sitename]", $site_name, $secure_invite_default_message); $secure_invite_default_message = str_replace("[signuplink]", $secure_invite_registration_page . "?" . $to, $secure_invite_default_message); $secure_invite_default_message = str_replace("[name]", $usernickname, $secure_invite_default_message); $secure_invite_default_message = str_replace("[timeout]", $secure_invite_signup_time_limit, $secure_invite_default_message); $message = $message . "\n\n" . stripslashes($_POST['invite-personalmessage']) . "\n\n" . $secure_invite_default_message; $headers = 'From: '. $from . "\r\n" . 'Reply-To: ' . $from; wp_mail($to, $subject, $message, $headers); return true; } else { $headers = 'From: '. $from . "\r\n" . 'Reply-To: ' . $from; wp_mail(stripslashes( get_site_option("admin_email") ), "Secure invite failure for ".$from, "A user just tried to invite someone to join ".$site_name.". The following SQL query could not be completed:\n\n".$sql."\n\nThe error reported was:\n\n".$query_error."\n\nThis is an automatic email sent by the Secure Invites plugin.", $headers); } } } return false; } // add an invitation to the database function secure_invite_admin() { global $current_site, $current_user, $blog_id, $wpdb; $site_url = $current_site->domain; $site_name = stripslashes( get_site_option("site_name") ); // check the invites table exists secure_invite_check_table(); if($_POST['invite-action']=="send") { // if the email is valid if(is_email($_POST['invite-email'])) { // try to send if (secure_invite_send()) { echo ''.__('Your invitation has been successfully sent to', "secure_invite").' '.$_POST['invite-email'].'.
'.__('Your invitation could not be sent to', "secure_invite").' '.$_POST['invite-email'].'. '.__('Perhaps this email address is already registered. Please try again. If it fails more than twice please contact the site administrator.', "secure_invite").'
'.__('Please enter a valid email address', "secure_invite").'
' . __( "Thank you for donating" ) . '
' . sprintf ( __( 'To report bugs please visit %s.' ), $bugs_page, $bugs_page ) . '
'; } if ( $paypal_address != "" && is_email( $paypal_address ) ) { $r .= ' '; } $r .= ''; $r .= '