WordPress.org

Plugin Directory

Changeset 326449


Ignore:
Timestamp:
12/27/10 20:12:46 (3 years ago)
Author:
MrWiblog
Message:

1.1.3 (2010/12/27)

  • Added [bestinviters] shortcode
  • Added [myinviter] shortcode
  • Fixed bugs with database collation which led to empty reports
  • Made support for different versions of WordPress more robust
  • Added support for invitation codes, so people can register without being invited as long as they have a valid code
  • Added reports for invitation codes
Location:
wordpress-mu-secure-invites/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wordpress-mu-secure-invites/trunk/readme.txt

    r307135 r326449  
    55Requires at least: 2.7 
    66Tested up to: 3.0.1 
    7 Stable tag: 1.1.2 
     7Stable tag: 1.1.3 
    88 
    99Secure Invites is a Wordpress plugin that allows you to only allow invited people to sign up. 
     
    2222* Set the message to show if someone tries to sign up with no valid invitation 
    2323* Turn off security on signup form, allowing anyone to sign up (this does not affect the ability to invite people) 
    24 - Show an invitation form on the dashboard 
     24* Show an invitation form on the dashboard 
     25* Show best inviters on your site with a shortcode 
     26* Set any number of special codes with which people can sign up without being invited 
     27* View reports on the number of people who have signed up with each code 
    2528 
    2629This plugin is based on the invitation plugin by kt (Gord) from http://www.ikazoku.com. 
     
    3841As an administrator you can now select multiple invitations and delete them. This is much better than the one-at-a-time deletion method in previous versions. 
    3942 
    40 = Shortcode = 
    41  
    42 By using the [inviteform] shortcode you can place an invitation form on any post or page. 
     43= Shortcodes = 
     44 
     45There are three shortcodes available: 
     46 
     471) By using the [inviteform] shortcode you can place an invitation form on any post or page. 
     48 
     492) Using [bestinviters] will show a list of the top 6 inviters by points, with the points they have currently got. 
     50 
     513) Using [myinviter] will show the diplay name for the person who invited the current user. Using [myinviter id="123"] will show the display name for the person who invited the user with ID 123. 
    4352 
    4453= Automatic BuddyPress theme integration = 
     
    117126== Changelog == 
    118127 
     128= 1.1.3 (2010/12/27) = 
     129 
     130* Added [bestinviters] shortcode 
     131* Added [myinviter] shortcode 
     132* Fixed bugs with database collation which led to empty reports 
     133* Made support for different versions of WordPress more robust 
     134* Added support for invitation codes, so people can register without being invited as long as they have a valid code 
     135* Added reports for invitation codes 
     136 
    119137= 1.1.2 (2010/11/02) = 
    120138 
  • wordpress-mu-secure-invites/trunk/secure_invite.php

    r307135 r326449  
    33Plugin Name: Secure Invites 
    44Description: Stops public signup on your Wordpress MultiSite or BuddyPress site, but allows existing users to email and invite their friend to join your blog community. This plugin is based on a plugin by kt (Gord), from http://www.ikazoku.com. 
    5 Version: 1.1.2 
     5Version: 1.1.3 
    66Author: Chris Taylor 
    77Author URI: http://www.stillbreathing.co.uk 
    88Plugin URI: http://www.stillbreathing.co.uk/wordpress/wordpress-mu-secure-invites/ 
    9 Date: 2010-11-02 
     9Date: 2010-12-27 
    1010*/ 
     11 
     12function secure_invite_version() { 
     13    return "1.1.3"; 
     14} 
    1115 
    1216// when the admin menu is built 
     
    2125// add shortcodes 
    2226// [inviteform] 
    23 add_shortcode('inviteform', 'secure_invite_shortcode'); 
     27add_shortcode('inviteform', 'secure_invite_form_shortcode'); 
     28// [myinviter] or [myinviter id="123"] 
     29add_shortcode('myinviter', 'secure_invite_myinviter_shortcode'); 
     30// [bestinviters] 
     31add_shortcode('bestinviters', 'secure_invite_bestinviters_shortcode'); 
    2432 
    2533// when a user is registered 
     
    5159 
    5260// add the form to a post or page using a shortcode 
    53 function secure_invite_shortcode($atts, $content="") { 
     61function secure_invite_form_shortcode($atts, $content="") { 
    5462    return secure_invite_form($success='Thanks, your invitation has been sent', $error='Sorry, your invitation could not be sent. Perhaps this email address is already registered.', true); 
     63} 
     64 
     65// show the details of the inviter of the current user 
     66function secure_invite_myinviter_shortcode($atts, $content="") { 
     67    extract(shortcode_atts(array( 
     68        'id' => null 
     69    ), $atts)); 
     70    if ($id == null) { 
     71        global $current_user; 
     72        $email = $current_user->user_email; 
     73    } else { 
     74        $user = get_userdata($id); 
     75        $email = $user->user_email; 
     76    } 
     77    if ($email) { 
     78        global $wpdb; 
     79        $sql = $wpdb->prepare("select u.display_name from {$wpdb->users} u inner join " . secure_invite_prefix() . "invitations i on i.user_id = u.id where i.invited_email = %s;", $email); 
     80        return $wpdb->get_var($sql); 
     81    } 
     82} 
     83 
     84function secure_invite_bestinviters_shortcode($atts, $content="") { 
     85    $best_inviters = secure_inviters_get_best_by_points(); 
     86    if ($best_inviters && count($best_inviters) > 0) { 
     87        $o = "<ul>\n"; 
     88        foreach($best_inviters as $best_inviter) { 
     89            $o .= "<li>" . $best_inviter->display_name . ": " . $best_inviter->secure_invite_points . "</li>"; 
     90        } 
     91        $o .= "</ul>"; 
     92        return $o; 
     93    } 
     94    return ""; 
     95} 
     96 
     97// get the link to the admin page 
     98function secure_invite_page_link() { 
     99    $wpmums = "wpmu-admin"; 
     100    if (version_compare(get_bloginfo('version'), "3") >= 0) { 
     101        $wpmums = "ms-admin"; 
     102        if ( !defined( 'WP_ALLOW_MULTISITE' ) || !WP_ALLOW_MULTISITE) { 
     103            $wpmums = "options-general"; 
     104        } 
     105    } 
     106    return $wpmums; 
     107} 
     108 
     109// get the base prefix 
     110function secure_invite_prefix() { 
     111    global $wpdb; 
     112    if ( !empty( $wpdb->base_prefix ) ) return $wpdb->base_prefix; 
     113    return $wpdb->prefix; 
    55114} 
    56115 
     
    181240// check secure pages 
    182241function secure_invite_check_secure_page() { 
     242    session_start(); 
     243    // set the invite code 
     244    if (isset($_POST["invite_code"])) { 
     245        $_SESSION["invite_code"] = trim($_POST["invite_code"]); 
     246        header("Location: " . $_SERVER['REQUEST_URI']); 
     247        exit(); 
     248    } 
     249 
    183250    // when wp-signup.php or another restricted page is requested, and open signup is disabled 
    184251    if (secure_invite_is_restricted_page() && stripslashes( get_site_option("secure_invite_open_signup", "0") ) != "1") { 
     
    188255        $valid = false; 
    189256 
    190         // check the email address is a valid invitation, or the uer is logged in 
     257        // check the email address is a valid invitation, or a valid code has been given, or the user is logged in 
    191258        if ( 
    192259            (isset($_GET["email"]) && secure_invites_is_valid_email($_GET["email"])) 
    193260            || 
    194261            (isset($_POST["user_email"]) && secure_invites_is_valid_email(trim(@$_POST["user_email"]))) 
     262            || 
     263            (isset($_SESSION["invite_code"]) && secure_invites_is_valid_code(trim(@$_SESSION["invite_code"]))) 
    195264            || 
    196265            ((function_exists("is_user_logged_in") && is_user_logged_in()) || (isset($current_user) && $current_user->ID != "")) 
     
    202271            } 
    203272        } 
     273         
     274        // Originally from Giovanni Gonzalez <giova@cal.berkeley.edu> 
     275        // Check the list of invitation codes defined in the Security Settings 
     276        $invitation_code_message = ""; 
     277        $site_invite_codes = explode("\n",get_site_option('secure_invite_invitation_codes')); 
     278        if (is_array($site_invite_codes) && count($site_invite_codes) > 0 && $site_invite_codes[0] != "") { 
     279            $invitation_code_message = "</p> 
     280            <p>" . __('Or enter an invitation code below:', 'secure_invite') . '</p> 
     281            <form action="' . $_SERVER['REQUEST_URI'] . '" method="post"> 
     282                <p><input type="text" name="invite_code" /> 
     283                <button type="submit">' . __("Register code", "secure_invite") . '</button></p> 
     284            </form> 
     285            <p>' . __("Contact the site administrator if you have any problems.", "secure_invite"); 
     286            for ( $i = 1; $i <= count($site_invite_codes); $i++ ) { 
     287                if ( trim(@$_POST['invitecode']) == trim($site_invite_codes[$i - 1]) ) { 
     288                    echo "VALID: ".$_POST['invitecode']." = ".$site_invite_codes[$i - 1]; 
     289                    $valid = true; 
     290                }    
     291            } 
     292        } 
    204293 
    205294        // if the signup request is not valid 
     
    209298            if ($secure_invite_no_invite_message == "") { $secure_invite_no_invite_message = secure_invite_default_setting("secure_invite_no_invite_message"); } 
    210299            // stop processing 
    211             wp_die($secure_invite_no_invite_message); 
     300            wp_die($secure_invite_no_invite_message . $invitation_code_message, __("Invitation required", "secure_invite")); 
    212301            exit(); 
    213302        } 
     
    221310    $user = get_userdata($user_id); 
    222311    $email = $user->user_email; 
     312     
     313    // save the invite code, if one is set 
     314    if ($_SESSION["invite_code"] != ""){ 
     315        update_user_meta($user_id, "secure_invite_invitation_code", $_SESSION["invite_code"]); 
     316    } 
    223317     
    224318    // check if this is an invited email address 
     
    230324        // increase the level 1 inviter points by 5 
    231325        $points_1 = (int)secure_invite_get_user_meta($inviterid_1, "secure_invite_points"); 
    232         update_usermeta($inviterid_1, "secure_invite_points", ($points_1+5)); 
     326        update_user_meta($inviterid_1, "secure_invite_points", ($points_1+5)); 
    233327        // get the inviter 1 email 
    234328        $inviter_1 = get_userdata($inviterid_1); 
     
    243337            // increase the level 2 inviter points by 2 
    244338            $points_2 = (int)secure_invite_get_user_meta($inviterid_2, "secure_invite_points"); 
    245             update_usermeta($inviterid_2, "secure_invite_points", ($points_2+2)); 
     339            update_user_meta($inviterid_2, "secure_invite_points", ($points_2+2)); 
    246340            // get the inviter 2 email 
    247341            $inviter_2 = get_userdata($inviterid_2); 
     
    256350                // increase the level 3 inviter points by 1 
    257351                $points_3 = (int)secure_invite_get_user_meta($inviterid_3, "secure_invite_points"); 
    258                 update_usermeta($inviterid_3, "secure_invite_points", ($points_3+1)); 
     352                update_user_meta($inviterid_3, "secure_invite_points", ($points_3+1)); 
    259353                 
    260354            } 
    261355        } 
    262356    } 
     357    return $user_id; 
    263358} 
    264359 
     
    266361function secure_invite_get_inviter_id($email) { 
    267362    global $wpdb; 
    268     $sql = $wpdb->prepare("select user_id from ".$wpdb->base_prefix."invitations where invited_email = '%s';", $email); 
     363    $sql = $wpdb->prepare("select user_id from ".secure_invite_prefix()."invitations where invited_email = '%s';", $email); 
    269364    return $wpdb->get_var($sql); 
    270365} 
     
    272367// check if this is a restricted page 
    273368function secure_invite_is_restricted_page() { 
     369    $uri = $_SERVER["REQUEST_URI"]; 
    274370    $secure_invite_signup_page = stripslashes( get_site_option("secure_invite_signup_page") ); 
    275371    if ( $secure_invite_signup_page == "" ) { $secure_invite_signup_page = secure_invite_default_setting("secure_invite_signup_page"); } 
     
    277373        $pages = explode( ",", $secure_invite_signup_page ); 
    278374        foreach( $pages as $page ) { 
    279             if ( strpos( $_SERVER["REQUEST_URI"], $page ) !== false ) { 
     375            if ( strpos( $uri, $page ) !== false ) { 
    280376                return true; 
    281377            } 
    282378        } 
    283379    } else { 
    284         if ( strpos( $_SERVER["REQUEST_URI"], $secure_invite_signup_page ) !== false ) { 
     380        if ( strpos( $uri, $secure_invite_signup_page ) !== false ) { 
    285381            return true; 
    286382        } 
    287383    } 
    288384    return false; 
     385} 
     386 
     387// check a code is valid 
     388function secure_invites_is_valid_code($code) { 
     389    $valid = false; 
     390    $site_invite_codes = explode("\n",get_site_option('secure_invite_invitation_codes')); 
     391    if (is_array($site_invite_codes) && count($site_invite_codes) > 0 && $site_invite_codes[0] != "") { 
     392        for ( $i = 1; $i <= count($site_invite_codes); $i++ ) { 
     393            if ( trim(@$code) == trim($site_invite_codes[$i - 1]) ) { 
     394                $valid = true; 
     395            }    
     396        } 
     397    } 
     398    return $valid; 
    289399} 
    290400 
     
    300410        } 
    301411        global $wpdb; 
    302         $sql = $wpdb->prepare("select count(id) from ".$wpdb->base_prefix."invitations where invited_email = '%s' and UNIX_TIMESTAMP(datestamp) > %d;", $email, (time()-($timelimit*60*60*24))); 
     412        $sql = $wpdb->prepare("select count(id) from ".secure_invite_prefix()."invitations where invited_email = '%s' and UNIX_TIMESTAMP(datestamp) > %d;", $email, (time()-($timelimit*60*60*24))); 
    303413        $invites = $wpdb->get_var($sql); 
    304414         
     
    374484        secure_invite_bulk_invite(); 
    375485     
     486    } else if (@$_GET["view"] == "top") { 
     487     
     488        echo ' 
     489        <div class="wrap"> 
     490        '; 
     491        secure_invite_wp_plugin_standard_header( "GBP", "Secure invites", "Chris Taylor", "chris@stillbreathing.co.uk", "http://wordpress.org/extend/plugins/wordpress-mu-secure-invites/" ); 
     492        echo ' 
     493        <h2>' . __("Secure invites admin", "secure_invite") . ' 
     494        <span style="float:right"> 
     495            <a href="' . secure_invite_page_link(). '.php?page=secure_invite_list&amp;view=settings" class="button">' . __("Settings", "secure_invite") . '</a> 
     496            <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
     497            <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
     498        </h2> 
     499        '; 
     500     
     501        secure_invite_by_points(100); 
     502         
     503        echo ' 
     504        </div> 
     505        '; 
     506     
     507    } else if (@$_GET["view"] == "debug") { 
     508     
     509        global $wpdb; 
     510     
     511        $version = $wpdb->get_var("SELECT VERSION();"); 
     512     
     513        echo ' 
     514        <div class="wrap"> 
     515        <h2>Secure invite debug</h2> 
     516        <p>MySQL version: ' . $version . '</p> 
     517        <p>PHP version: ' . phpversion() . '</p> 
     518        <p>Secure Invite version: ' . secure_invite_version() . '</p> 
     519        <p>secure_invite_preset: ' . get_site_option("secure_invite_preset") . '</p> 
     520        <p>secure_invite_days_after_joining: ' . get_site_option("secure_invite_days_after_joining") . '</p> 
     521        <p>secure_invite_signup_page: ' . get_site_option("secure_invite_signup_page") . '</p> 
     522        <p>secure_invite_registration_page: ' . get_site_option("secure_invite_registration_page") . '</p> 
     523        <p>secure_invite_no_invite_message: ' . get_site_option("secure_invite_no_invite_message") . '</p> 
     524        <p>secure_invite_signup_time_limit: ' . get_site_option("secure_invite_signup_time_limit") . '</p> 
     525        <p>secure_invite_default_message: ' . get_site_option("secure_invite_default_message") . '</p> 
     526        <p>secure_invite_open_signup: ' . get_site_option("secure_invite_open_signup") . '</p> 
     527        <p>secure_invite_invite_limit: ' . get_site_option("secure_invite_invite_limit") . '</p> 
     528        <p>secure_invite_show_admin_link: ' . get_site_option("secure_invite_show_admin_link") . '</p> 
     529        <p>secure_invite_invitation_codes: ' . get_site_option("secure_invite_invitation_codes") . '</p> 
     530        <p> 
     531        <textarea cols="60" rows="12" style="width:100%">id,user_id,invited_email,datestamp'; 
     532        $sql = "select id, user_id, invited_email, datestamp from ".secure_invite_prefix()."invitations order by id;"; 
     533        $rows = $wpdb->get_results($sql); 
     534        if ($rows) { 
     535            foreach($rows as $row) { 
     536                echo "\n" . $row->id . "," . $row->user_id . "," . $row->invited_email . "," . $row->datestamp;  
     537            } 
     538        } 
     539        echo '</textarea> 
     540        </p> 
     541        </div> 
     542        '; 
     543     
    376544    } 
    377545     
    378546    secure_invite_wp_plugin_standard_footer( "GBP", "Secure invites", "Chris Taylor", "chris@stillbreathing.co.uk", "http://wordpress.org/extend/plugins/wordpress-mu-secure-invites/" ); 
    379     echo '</div>'; 
    380547} 
    381548 
     
    420587 
    421588    if ($name == "secure_invite_buddypress_theme_actions") { return "bp_members_directory_member_types"; } 
     589     
     590    if ($name == "secure_invite_invitation_codes") { return ""; } 
    422591 
    423592} 
     
    438607        $values["secure_invite_invite_limit"] = secure_invite_default_setting("secure_invite_invite_limit"); 
    439608        $values["secure_invite_show_admin_link"] = secure_invite_default_setting("secure_invite_show_admin_link"); 
     609        $values["secure_invite_invitation_codes"] = secure_invite_default_setting("secure_invite_invitation_codes"); 
    440610         
    441611        // preset 1 
     
    485655    update_site_option("secure_invite_invite_limit", trim($values["secure_invite_invite_limit"])); 
    486656    update_site_option("secure_invite_show_admin_link", trim($values["secure_invite_show_admin_link"])); 
     657    update_site_option("secure_invite_invitation_codes", trim($values["secure_invite_invitation_codes"])); 
    487658    if (isset($values["secure_invite_buddypress_theme_actions"])) { 
    488659        $vals = implode(",", $values["secure_invite_buddypress_theme_actions"]); 
     
    505676    } 
    506677     
    507     $wpmums = "wpmu-admin"; 
    508     if (version_compare(get_bloginfo('version'), "3") >= 0) { 
    509         $wpmums = "ms-admin"; 
    510         if ( !defined( 'WP_ALLOW_MULTISITE' ) || !WP_ALLOW_MULTISITE) { 
    511             $wpmums = "options-general"; 
    512         } 
    513     } 
    514      
    515678    $secure_invite_preset = stripslashes( get_site_option("secure_invite_preset") ); 
    516679 
     
    520683    $secure_invite_open_signup = stripslashes( get_site_option("secure_invite_open_signup", "0") ); 
    521684    $open_signup = ""; 
    522     if ($secure_invite_open_signup == "1") { $open_signup = ' checked="checked"'; } 
     685    if ($secure_invite_open_signup == "1") { $open_signup = ' selected="selected"'; } 
    523686     
    524687    $secure_invite_signup_page = stripslashes( get_site_option("secure_invite_signup_page") ); 
     
    546709    if ($secure_invite_buddypress_theme_actions == "") { $secure_invite_buddypress_theme_actions = secure_invite_default_setting("secure_invite_buddypress_theme_actions"); } 
    547710    $secure_invite_buddypress_theme_actions = $secure_invite_buddypress_theme_actions . ","; 
     711     
     712    $secure_invite_invitation_codes = stripslashes( get_site_option("secure_invite_invitation_codes") ); 
    548713 
    549714    echo '<div class="wrap"> 
    550715    <h2>' . __("Invitation settings", "secure_invite") . '   
    551716    <span style="float:right"> 
    552         <a href="' . $wpmums . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> 
    553         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
    554         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
     717        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> 
     718        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
     719        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
    555720    </h2> 
    556721    '; 
     
    558723    echo ' 
    559724    <h3>' . __("Settings presets", "secure_invite") . '</h3> 
    560     <form action="' . $wpmums . '.php?page=secure_invite_list&amp;view=settings" method="post"> 
     725    <form action="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=settings" method="post"> 
    561726    <ul> 
    562727        <li><input type="radio" name="secure_invite_preset" id="secure_invite_preset_1" value="1"'; 
     
    584749    <h3>' . __("Custom settings", "secure_invite") . '</h3> 
    585750    <p>' . __("Use custom settings for secure invitations here.", "secure_invite") . '</p> 
    586     <form action="' . $wpmums . '.php?page=secure_invite_list&amp;view=settings" method="post"> 
     751    <form action="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=settings" method="post"> 
    587752    <fieldset> 
    588753     
     
    591756    <option value="yes"'; 
    592757    if ($secure_invite_show_admin_link == "yes"){ echo ' selected="selected"'; } 
    593     echo '">'.__("Yes", "secure_invite").'</option> 
     758    echo '>'.__("Yes", "secure_invite").'</option> 
    594759    <option value="no"'; 
    595760    if ($secure_invite_show_admin_link == "no"){ echo ' selected="selected"'; } 
    596     echo '">'.__("No", "secure_invite").'</option> 
     761    echo '>'.__("No", "secure_invite").'</option> 
    597762    </select> <span class="description">' . __("Show the invite link in the admin area for normal users", "secure_invite") . '</span></p> 
    598763     
     
    603768     
    604769    <p><label for="secure_invite_invite_limit" style="float:left;width:30%;">' . __("Maximum number of invites per person", "secure_invite") . '</label> 
    605     <input type="text" name="secure_invite_invite_limit" id="secure_invite_invite_limit" value="'.$secure_invite_invite_limit.'" style="width:10%" /> <span class="description">' . __('How many invites can each user send (<a href="' . $wpmums . '.php?page=secure_invite_list&view=users">override this for particular users here</a>)? (set as 0 or blank for unlimited)', "secure_invite") . '</span></p> 
     770    <input type="text" name="secure_invite_invite_limit" id="secure_invite_invite_limit" value="'.$secure_invite_invite_limit.'" style="width:10%" /> <span class="description">' . __('How many invites can each user send (<a href="' . secure_invite_page_link(). '.php?page=secure_invite_list&amp;view=users">override this for particular users here</a>)? (set as 0 or blank for unlimited)', "secure_invite") . '</span></p> 
    606771     
    607772    <h3 style="padding-top:2em">' . __( "Security settings", "secure_invite" ) . '</h3> 
    608773     
    609774    <p><label for="secure_invite_open_signup" style="float:left;width:30%;">' . __("Open signup", "secure_invite") . '</label> 
    610     <input type="checkbox" name="secure_invite_open_signup" id="secure_invite_open_signup"' . $open_signup . ' value="1" /> <span class="description">' . __("Allow anyone to sign up? This disables the security on the signup page", "secure_invite") . '</span></p> 
     775    <select name="secure_invite_open_signup" id="secure_invite_open_signup"> 
     776        <option value="0">' . __("No", "secure_invite") . '</option> 
     777        <option value="1"' . $open_signup . '>' . __("Yes", "secure_invite"). '</option> 
     778        </select> <span class="description">' . __("Allow anyone to sign up? This disables the security on the signup page", "secure_invite") . '</span></p> 
    611779     
    612780    <p><label for="secure_invite_signup_page" style="float:left;width:30%;">' . __("Signup page", "secure_invite") . '</label> 
     
    622790    <p><label for="secure_invite_signup_time_limit" style="float:left;width:30%;">' . __("Time limit for signups (days)", "secure_invite") . '</label> 
    623791    <input type="text" name="secure_invite_signup_time_limit" id="secure_invite_signup_time_limit" value="'.$secure_invite_signup_time_limit.'" style="width:10%" /> <span class="description">' . __("How many days would you like an invitation to be open for?", "secure_invite") . '</span></p> 
     792     
     793    <h3 style="padding-top:2em">' . __( "Invitation codes", "secure_invite" ) . '</h3> 
     794    <p>' . __("Allow people to sign up to your site using a special code. The code they sign up with will be stored so you can see which codes are most effective. Add one code per line.", "secure_invite") . '</p> 
     795    <p><label for="secure_invite_invitation_codes" style="float:left;width:30%;">' . __("Invitation codes (one per line)", "secure_invite") . '</label> 
     796    <textarea name="secure_invite_invitation_codes" id="secure_invite_invitation_codes" style="width:99%" rows="4" cols="30">'.$secure_invite_invitation_codes.'</textarea></p> 
    624797     
    625798    <h3 style="padding-top:2em">' . __( "Message settings", "secure_invite" ) . '</h3> 
     
    636809        <li><code>[timeout]</code> ' . __("where you want the number of days this invitation is valid to appear", "secure_invite") . '</li> 
    637810    </ul> 
    638     <p><label for="secure_invite_default_message" style="float:left;width:30%;>"' . __("Default message for invites", "secure_invite") . '</label> 
     811    <p><label for="secure_invite_default_message" style="float:left;width:30%;">' . __("Default message for invites", "secure_invite") . '</label> 
    639812    <textarea name="secure_invite_default_message" id="secure_invite_default_message" style="width:99%" rows="12" cols="30">'.$secure_invite_default_message.'</textarea></p> 
    640813    '; 
     
    737910        secure_invite_send_bulk($_POST["invite-emails"], $_POST["invite-personalmessage"]); 
    738911    } 
     912     
     913    $site_name = stripslashes( get_site_option("site_name") ); 
     914    if ( $site_name == "" ){ $site_name = stripslashes( get_option( "blogname" ) ); } 
    739915 
    740916    echo '<div class="wrap"> 
    741917    <h2>' . __("Bulk invite", "secure_invite") . '   
    742918    <span style="float:right"> 
    743         <a href="' . $wpmums . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> 
    744         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
    745         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
     919        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> 
     920        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
     921        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
    746922    </h2> 
    747923    '; 
     
    749925    echo ' 
    750926    <form action="options-general.php?page=secure_invite_list&amp;view=bulk" method="post"> 
    751     <p>' . __("Add email addresses, one per line. You can also add names and email addresses using CSV formatting. Each line should be like this: <em>Invitee name,invitee@email.com</em>", "secure_invite") . '</p> 
     927    <p>' . __("Add email addresses, one per line. You can also add names and email addresses using CSV formatting. Each line should be like this:<br /><em>Invitee name,invitee@email.com</em>", "secure_invite") . '</p> 
    752928    <p style="clear:both"> 
    753929        <label for="emails" style="display:block">' . __("Emails", "secure_invite") . '</label> 
     
    763939    </p> 
    764940    </form> 
     941    </div> 
    765942    '; 
    766943} 
     
    770947    global $wpdb; 
    771948     
    772     $wpmums = "wpmu-admin"; 
    773     if (version_compare(get_bloginfo('version'), "3") >= 0) { 
    774         $wpmums = "ms-admin"; 
    775         if ( !defined( 'WP_ALLOW_MULTISITE' ) || !WP_ALLOW_MULTISITE) { 
    776             $wpmums = "options-general"; 
    777         } 
    778     } 
    779      
    780949    echo '<div class="wrap"> 
    781950    <h2>' . __("User invitation settings", "secure_invite") . ' 
    782     <span style="float:right"><a href="' . $wpmums . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> | <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=settings" class="button">' . __("Settings", "secure_invite") . '</a></span> 
     951    <span style="float:right"> 
     952        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list" class="button">' . __("Invitation list", "secure_invite") . '</a> 
     953        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
     954        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=settings" class="button">' . __("Settings", "secure_invite") . '</a></span> 
    783955    </h2>'; 
    784956 
     
    794966                    (select count(i.invited_email) 
    795967                    from " . $wpdb->base_prefix . "invitations i 
    796                     inner join " . $wpdb->users . " s on s.user_email = i.invited_email 
     968                    inner join " . $wpdb->users . " s on CONVERT(s.user_email using utf8) = CONVERT(i.invited_email using utf8) 
    797969                    where i.user_id = u.ID) as signups, 
    798970                    (select count(invited_email) from " . $wpdb->base_prefix . "invitations 
     
    825997                    echo ' 
    826998                    <tr> 
    827                         <td><a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_login . '</a></td> 
    828                         <td><a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_nicename . '</a></td> 
    829                         <td><a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->display_name . '</a></td> 
    830                         <td><a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_email . '</a></td> 
     999                        <td><a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_login . '</a></td> 
     1000                        <td><a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_nicename . '</a></td> 
     1001                        <td><a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->display_name . '</a></td> 
     1002                        <td><a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $user->ID . '">' . $user->user_email . '</a></td> 
    8311003                        <td>' . $user->invitations . '</td> 
    8321004                        <td>' . $user->signups . '</td> 
     
    8511023                $can = "yes"; 
    8521024            } 
    853             update_usermeta($_GET["id"], "secure_invite_user_can_invite", $can); 
    854             update_usermeta($_GET["id"], "secure_invite_user_invite_limit", "_" .$_POST["secure_invite_user_invite_limit"]); 
     1025            update_user_meta($_GET["id"], "secure_invite_user_can_invite", $can); 
     1026            update_user_meta($_GET["id"], "secure_invite_user_invite_limit", "_" .$_POST["secure_invite_user_invite_limit"]); 
    8551027         
    8561028            echo ' 
     
    8631035     
    8641036    // get a user 
    865     if (@$_GET && is_array($_GET) && $_GET["id"] != "") 
     1037    if (@$_GET && is_array($_GET) && @$_GET["id"] != "") 
    8661038    { 
    8671039         
     
    8781050         
    8791051        $remaining = secure_invite_user_invites_remaining($user->ID); 
     1052        $remaining_header = ""; 
    8801053        if ($remaining != "") { 
    881             $remaining = "<p>" . $remaining . "</p>"; 
    882         } 
     1054            $remaining_header = "<th>" . __("Remaining invites", "secure_invite") . "</th>"; 
     1055        } 
     1056         
     1057        // get the details for this user 
     1058        $sent = secure_invite_user_sent_invites($user->ID); 
     1059        $accepted = (int)secure_invite_user_accepted_invites($user->ID); 
     1060        $rate = round((($accepted / $sent) * 100), 1); 
     1061        $points = (int)secure_invite_get_user_meta($user->ID, "secure_invite_points"); 
    8831062         
    8841063        echo ' 
     1064        <p>' . __("Username", "secure_invite") . ': ' . $user->user_login . ' (<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>)</p> 
     1065        <table class="widefat"> 
     1066        <thead> 
     1067        <tr> 
     1068            <th>' . __("Invites sent", "secure_invite") . '</th> 
     1069            <th>' . __("Invites accepted", "secure_invite") . '</th> 
     1070            <th>' . __("Acceptance rate", "secure_invite") . '</th> 
     1071            ' . $remaining_header . ' 
     1072            <th>' . __("Invite points", "secure_invite") . '</th> 
     1073        </tr> 
     1074        </thead> 
     1075        <tbody> 
     1076        <tr> 
     1077            <td>' . $sent . '</td> 
     1078            <td>' . $accepted . '</td> 
     1079            <td>' . $rate . '%</td> 
     1080            ' . $remaining . ' 
     1081            <td>' . $points . '</td> 
     1082        </tr> 
     1083        </tbody> 
     1084        </table> 
    8851085        <h3>' . __("Set invite settings for this user", "secure_invite") . '</h3> 
    886         <p>' . __("Username", "secure_invite") . ': ' . $user->user_login . '</p> 
    887         <p>' . __("Invites sent", "secure_invite") . ': ' . secure_invite_user_sent_invites($user->ID) . '</p> 
    888         ' . $remaining . ' 
    889         <p>' . __("Invites accepted", "secure_invite") . ': ' . (int)secure_invite_user_accepted_invites($user->ID) . '</p> 
    890         <p>' . __("Invite points", "secure_invite") . ': ' . (int)secure_invite_get_user_meta($user->ID, "secure_invite_points") . '</p> 
    891         <form action="' . $wpmums . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $_GET["id"] . '" method="post"> 
     1086        <form action="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users&amp;id=' . $_GET["id"] . '" method="post"> 
    8921087        <fieldset> 
    8931088        <p><label for="secure_invite_user_can_invite" style="float:left;width:15%;">' . __("Can invite", "secure_invite") . '</label> 
     
    9041099    echo '<h3>' .  __("Search users", "secure_invite") . '</h3> 
    9051100    <p>' . __("Search for a user to override their invitation settings.", "secure_invite") . '</p> 
    906     <form action="' . $wpmums . '.php?page=secure_invite_list&amp;view=users" method="post"> 
     1101    <form action="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users" method="post"> 
    9071102    <fieldset> 
    9081103    <p><label for="secure_invite_search_users" style="float:left;width:15%;">' . __("Search users", "secure_invite") . '</label> 
     
    9221117            (select count(i2.invited_email) 
    9231118            from ".$wpdb->base_prefix."invitations i2 
    924             inner join ".$wpdb->users." u2 on u2.user_email = i2.invited_email 
     1119            inner join ".$wpdb->users." u2 on CONVERT(u2.user_email USING utf8) = CONVERT(i2.invited_email using utf8) 
    9251120            where year(i2.datestamp) = year(i.datestamp) 
    9261121            and month(i2.datestamp) = month(i.datestamp)) as signups 
     
    9481143    <tbody> 
    9491144    '; 
     1145    $alt = ''; 
    9501146    foreach ($invites_per_month as $invite_month) 
    9511147    { 
     
    9801176            (select count(i2.invited_email) 
    9811177            from ".$wpdb->base_prefix."invitations i2 
    982             inner join ".$wpdb->users." u2 on u2.user_email = i2.invited_email 
     1178            inner join ".$wpdb->users." u2 on CONVERT(u2.user_email USING utf8) = CONVERT(i2.invited_email USING utf8) 
    9831179            where i2.user_id = i.user_id) as signups 
    9841180            from ".$wpdb->base_prefix."invitations i 
    9851181            inner join ".$wpdb->base_prefix."users u on u.id = i.user_id 
    9861182            group by i.user_id 
    987             order by count(i.invited_email) desc 
     1183            order by signups desc 
    9881184            limit 0, " . (int)$limit . ";"; 
    9891185    $best_inviters = $wpdb->get_results($sql); 
     
    10061202    <tbody> 
    10071203    '; 
     1204    $alt = ''; 
    10081205    foreach ($best_inviters as $best_inviter) 
    10091206    { 
     
    10331230function secure_invite_list_page() { 
    10341231    global $wpdb; 
    1035      
    1036     $wpmums = "wpmu-admin"; 
    1037     if (version_compare(get_bloginfo('version'), "3") >= 0) { 
    1038         $wpmums = "ms-admin"; 
    1039         if ( !defined( 'WP_ALLOW_MULTISITE' ) || !WP_ALLOW_MULTISITE) { 
    1040             $wpmums = "options-general"; 
    1041         } 
    1042     } 
    10431232 
    10441233    echo ' 
     
    10491238    <h2>' . __("Secure invites admin", "secure_invite") . ' 
    10501239    <span style="float:right"> 
    1051         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=settings" class="button">' . __("Settings", "secure_invite") . '</a> 
    1052         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
    1053         <a href="' . $wpmums . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
     1240        <a href="' . secure_invite_page_link(). '.php?page=secure_invite_list&amp;view=settings" class="button">' . __("Settings", "secure_invite") . '</a> 
     1241        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=bulk" class="button">' . __("Bulk invite", "secure_invite") . '</a> 
     1242        <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;view=users" class="button">' . __("Special users", "secure_invite") . '</a></span> 
    10541243    </h2> 
    10551244    '; 
     
    10591248    { 
    10601249        if (isset($_GET["delete"]) && $_GET["delete"] != "") { 
    1061             $sql = "delete from ".$wpdb->base_prefix."invitations 
    1062                     where invited_email = '" . str_replace(" ", "+", urldecode($wpdb->escape($_GET["delete"]))) . "';"; 
     1250            $sql = "delete from ".secure_invite_prefix()."invitations 
     1251                    where invited_email = '" . $wpdb->escape( str_replace(" ", "+", urldecode($wpdb->escape($_GET["delete"]))) ) . "';"; 
    10631252            if ($wpdb->query($sql)) { 
    10641253                echo '<div id="message" class="updated fade"><p><strong>' . __("The invitation for this email address has been deleted", "secure_invite") . '</strong></p></div>'; 
     
    10681257        } else { 
    10691258            $emails = str_replace(" ", "+", urldecode(implode("','", $_POST["delete"]))); 
    1070             $sql = "delete from ".$wpdb->base_prefix."invitations 
    1071                     where invited_email in ('" . $emails . "');"; 
     1259            $sql = "delete from ".secure_invite_prefix()."invitations 
     1260                    where invited_email in ('" . $wpdb->escape( $emails ) . "');"; 
    10721261            if ($wpdb->query($sql)) { 
    10731262                echo '<div id="message" class="updated fade"><p><strong>' . __("The selected invitations have been deleted", "secure_invite") . '</strong></p></div>'; 
     
    10871276    secure_invite_by_inviter(); 
    10881277     
    1089     // get the best inviters by points 
    1090     $sql = "select u.user_nicename, 
    1091             CAST(m.secure_invite_points AS SIGNED) as secure_invite_points 
    1092             from ".$wpdb->users." u 
    1093             inner join ".$wpdb->usermeta." m on m.user_id = u.ID and m.meta_key = 'secure_invite_points' 
    1094             order by CAST(m.secure_invite_points AS SIGNED) desc 
    1095             limit 0, 6;"; 
    1096     $best_inviters = $wpdb->get_results($sql); 
    1097     $best_inviters_num = count($best_inviters);  
    1098     if ($best_inviters && $best_inviters_num > 0) 
    1099     { 
    1100     echo ' 
    1101     <div style="float:right;width:45%"> 
    1102     <h3>' . __("Best inviters by points", "secure_invite") . '</h3> 
    1103     <table summary="'.__("Best inviters by points", "secure_invite").'" class="widefat"> 
    1104     <thead> 
    1105     <tr> 
    1106         <th>'.__("Name", "secure_invite").'</th> 
    1107         <th>'.__("Points", "secure_invite").'</th> 
    1108     </tr> 
    1109     </thead> 
    1110     <tbody> 
    1111     '; 
    1112     foreach ($best_inviters as $best_inviter) 
    1113     { 
    1114         if ($alt == '') { $alt = ' class="alternate"'; } else { $alt = ''; } 
    1115         echo ' 
    1116         <tr'.$alt.'> 
    1117             <td>'.__($best_inviter->user_nicename).'</td> 
    1118             <td>'.__($best_inviter->secure_invite_points).'</td> 
    1119         </tr> 
    1120         '; 
    1121     } 
    1122     echo ' 
    1123     </tbody> 
    1124     </table> 
     1278    // show best inviters by points 
     1279    secure_invite_by_points( 6, "float:left;width:75%;" ); 
     1280     
     1281    // show best codes by signups 
     1282    secure_invite_signups_by_code( "float:right;width:20%;" ); 
     1283             
     1284    // show the invitation list 
     1285    secure_invite_invite_list(); 
     1286     
     1287    echo ' 
    11251288    </div> 
    11261289    '; 
    1127     } 
    1128              
     1290} 
     1291 
     1292// show the list of invites 
     1293function secure_invite_invite_list() { 
     1294 
     1295    global $wpdb; 
     1296     
    11291297    // get the page 
    11301298    $page = @(int)$_GET["p"]; 
     
    11381306    // get the invites 
    11391307    $sql = $wpdb->prepare("select SQL_CALC_FOUND_ROWS i.user_id, i.invited_email, UNIX_TIMESTAMP(i.datestamp) as datestamp, u.user_nicename as inviter, l.user_nicename as signed_up 
    1140             from ".$wpdb->base_prefix."invitations i 
     1308            from ".secure_invite_prefix()."invitations i 
    11411309            inner join ".$wpdb->users." u on u.id = i.user_id 
    1142             left outer join ".$wpdb->users." l on l.user_email = i.invited_email 
     1310            left outer join ".$wpdb->users." l on CONVERT(l.user_email USING utf8) = CONVERT(i.invited_email USING utf8) 
    11431311            order by i.datestamp desc 
    11441312            limit %d, 50", $start); 
     
    11681336                '; 
    11691337                } else { 
    1170                     echo '<li style="display: inline;"><a href="' . $wpmums . '-admin.php?page=secure_invite_list&amp;p='.$i.'">'.$i.'</a></li> 
     1338                    echo '<li style="display: inline;"><a href="' . secure_invite_page_link() . '-admin.php?page=secure_invite_list&amp;p='.$i.'">'.$i.'</a></li> 
    11711339                '; 
    11721340                } 
     
    11751343            '; 
    11761344        } 
    1177         echo '<form action="' . $wpmums . '.php?page=secure_invite_list" method="post"> 
     1345        echo '<form action="' . secure_invite_page_link() . '.php?page=secure_invite_list" method="post"> 
    11781346        <table summary="'.__("Invitations sent by site users", "secure_invite").'" class="widefat"> 
    11791347        <thead> 
     
    12001368            echo ' 
    12011369            <td> 
    1202                 <a href="' . $wpmums . '.php?page=secure_invite_list&amp;delete='.urlencode($invite->invited_email).'">' . __("Delete", "secure_invite") . '</a> 
     1370                <a href="' . secure_invite_page_link() . '.php?page=secure_invite_list&amp;delete='.urlencode($invite->invited_email).'">' . __("Delete", "secure_invite") . '</a> 
    12031371                <input type="checkbox" name="delete[]" value="'.urlencode($invite->invited_email).'" /> 
    12041372            </td> 
     
    12301398                '; 
    12311399                } else { 
    1232                     echo '<li style="display: inline;"><a href="' . $wpmums . '-admin.php?page=secure_invite_list&amp;p='.$i.'">'.$i.'</a></li> 
     1400                    echo '<li style="display: inline;"><a href="' . secure_invite_page_link() . '-admin.php?page=secure_invite_list&amp;p='.$i.'">'.$i.'</a></li> 
    12331401                '; 
    12341402                } 
     
    12401408        echo '<p>' . __("No invitations sent yet.", "secure_invite") . '</p>'; 
    12411409    } 
     1410 
     1411} 
     1412 
     1413// get the best inviters by points 
     1414function secure_inviters_get_best_by_points($limit=6) { 
     1415    global $wpdb; 
     1416     
     1417    // get the best inviters by points 
     1418    $sql = $wpdb->prepare( "select u.user_nicename, u.display_name, 
     1419            u.ID as user_id, 
     1420            CAST(m.meta_value AS SIGNED) as secure_invite_points, 
     1421            (select count(user_id) from ".secure_invite_prefix()."invitations where user_id = u.ID) as sent, 
     1422            (select count(u2.id) from ".$wpdb->users." u2 inner join ".secure_invite_prefix()."invitations i on CONVERT(i.invited_email USING utf8) = CONVERT(u2.user_email USING utf8) where i.user_id = u.ID) as accepted 
     1423            from ".$wpdb->users." u 
     1424            inner join ".$wpdb->usermeta." m on m.user_id = u.ID and m.meta_key = 'secure_invite_points' 
     1425            order by CAST(m.meta_value AS SIGNED) desc 
     1426            limit 0, %d;", $limit ); 
     1427    $best_inviters = $wpdb->get_results($sql); 
     1428    return $best_inviters; 
     1429} 
     1430 
     1431// show the best inviters by points 
     1432function secure_invite_by_points( $limit = 6, $style = "" ) { 
     1433 
     1434    $best_inviters = secure_inviters_get_best_by_points($limit); 
     1435    $best_inviters_num = count($best_inviters);  
     1436    echo ' 
     1437    <div style="' . $style . '"> 
     1438    <h3 style="clear:both">' . __("Best inviters by points", "secure_invite") . '</h3> 
     1439    '; 
     1440    if ($best_inviters && $best_inviters_num > 0) 
     1441    { 
     1442    echo ' 
     1443    <table summary="'.__("Best inviters by points", "secure_invite").'" class="widefat"> 
     1444    <thead> 
     1445    <tr> 
     1446        <th>'.__("Name", "secure_invite").'</th> 
     1447        <th>'.__("Invites Sent", "secure_invite").'</th> 
     1448        <th>'.__("Invites Accepted", "secure_invite").'</th> 
     1449        <th>'.__("Acceptance Rate", "secure_invite").'</th> 
     1450        <th>'.__("Invite Points", "secure_invite").'</th> 
     1451    </tr> 
     1452    </thead> 
     1453    <tbody> 
     1454    '; 
     1455    $alt = ''; 
     1456    foreach ($best_inviters as $best_inviter) 
     1457    { 
     1458        $rate = round((($best_inviter->accepted / $best_inviter->sent) * 100), 1); 
     1459        if ($alt == '') { $alt = ' class="alternate"'; } else { $alt = ''; } 
     1460        echo ' 
     1461        <tr'.$alt.'> 
     1462            <td>'.$best_inviter->user_nicename.'</td> 
     1463            <td>'.$best_inviter->sent.'</td> 
     1464            <td>'.$best_inviter->accepted.'</td> 
     1465            <td>'.$rate.'%</td> 
     1466            <td>'.$best_inviter->secure_invite_points.'</td> 
     1467        </tr> 
     1468        '; 
     1469    } 
     1470    echo ' 
     1471    </tbody> 
     1472    </table> 
     1473    '; 
     1474    if ( $limit < 100 ) { 
     1475    echo ' 
     1476    <p><a href="?page=secure_invite_list&amp;view=top">' . __( "View top 100 inviters by points", "secure_invite" ) . '</a></p> 
     1477    '; 
     1478    } 
     1479    } else { 
     1480    echo ' 
     1481    <p>' . __("No inviters with points yet", "secure_invite") . '</p> 
     1482    '; 
     1483    } 
     1484    echo ' 
     1485    </div> 
     1486    '; 
     1487 
     1488} 
     1489 
     1490// get the signups by code 
     1491function secure_inviters_get_signups_by_code() { 
     1492    global $wpdb; 
     1493     
     1494    // get the best inviters by points 
     1495    $sql = $wpdb->prepare( "select count(u.ID) as signups, 
     1496            m.meta_value as code 
     1497            from ".$wpdb->users." u 
     1498            inner join ".$wpdb->usermeta." m on m.user_id = u.ID and m.meta_key = 'secure_invite_invitation_code' 
     1499            group by m.meta_value 
     1500            order by count(u.ID) desc;" ); 
     1501    $best_codes = $wpdb->get_results($sql); 
     1502    return $best_codes; 
     1503} 
     1504 
     1505// show the number of signups by code 
     1506function secure_invite_signups_by_code( $style = "" ) { 
     1507 
     1508    $best_codes = secure_inviters_get_signups_by_code(); 
     1509    $best_codes_num = count($best_codes);    
     1510    echo ' 
     1511    <div style="' . $style . '"> 
     1512    <h3 style="clear:both">' . __("Best codes by signups", "secure_invite") . '</h3> 
     1513    '; 
     1514    if ($best_codes && $best_codes_num > 0) 
     1515    { 
     1516    echo ' 
     1517    <table summary="'.__("Best codes by signups", "secure_invite").'" class="widefat"> 
     1518    <thead> 
     1519    <tr> 
     1520        <th>'.__("Code", "secure_invite").'</th> 
     1521        <th>'.__("Signups", "secure_invite").'</th> 
     1522    </tr> 
     1523    </thead> 
     1524    <tbody> 
     1525    '; 
     1526    $alt = ''; 
     1527    foreach ($best_codes as $best_code) 
     1528    { 
     1529        if ($alt == '') { $alt = ' class="alternate"'; } else { $alt = ''; } 
     1530        echo ' 
     1531        <tr'.$alt.'> 
     1532            <td>'.$best_code->code.'</td> 
     1533            <td>'.$best_code->signups.'</td> 
     1534        </tr> 
     1535        '; 
     1536    } 
     1537    echo ' 
     1538    </tbody> 
     1539    </table> 
     1540    '; 
     1541    } else { 
     1542    echo ' 
     1543    <p>' . __("No signups using codes yet", "secure_invite") . '</p> 
     1544    '; 
     1545    } 
     1546    echo ' 
     1547    </div> 
     1548    '; 
     1549 
    12421550} 
    12431551 
     
    12461554    global $wpdb; 
    12471555    // if the invitations table does not exist 
    1248     $sql = "select count(id) from ".$wpdb->base_prefix."invitations;"; 
     1556    $sql = "select count(id) from ".secure_invite_prefix()."invitations;"; 
    12491557    $exists = $wpdb->get_var($sql); 
    12501558    if($exists == "") 
     
    12531561        // include the file with the required database manipulation functions 
    12541562        // create the table 
    1255         $sql = "CREATE TABLE ".$wpdb->base_prefix."invitations ( 
     1563        $sql = "CREATE TABLE ".secure_invite_prefix()."invitations ( 
    12561564id mediumint(9) NOT NULL AUTO_INCREMENT, 
    12571565user_id mediumint(9), 
     
    15071815    global $wpdb, $current_user; 
    15081816    if ($userid == 0) { $userid = $current_user->id; } 
    1509     return $wpdb->get_var($wpdb->prepare("select count(user_id) from ".$wpdb->base_prefix."invitations where user_id = %d", $userid)); 
     1817    return $wpdb->get_var($wpdb->prepare("select count(user_id) from ".secure_invite_prefix()."invitations where user_id = %d", $userid)); 
    15101818} 
    15111819 
    15121820// get the number of invites this user has sent which have resulted in a non-spam, non-deleted signup 
    1513 function secure_invite_user_accepted_invites() { 
     1821function secure_invite_user_accepted_invites( $userid = 0 ) { 
    15141822    global $wpdb, $current_user; 
    15151823    if ($userid == 0) { $userid = $current_user->id; } 
    1516     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)); 
     1824    return $wpdb->get_var($wpdb->prepare("select count(u.id) from ".$wpdb->users." u inner join ".secure_invite_prefix()."invitations i on CONVERT(i.invited_email USING utf8) = CONVERT(u.user_email USING utf8) where u.user_status = 0 and i.user_id = %d", $userid)); 
    15171825} 
    15181826 
     
    15501858        } 
    15511859    } 
    1552     $sql = $wpdb->prepare("select count(invited_email) from ".$wpdb->base_prefix."invitations where invited_email = %s", $email ); 
     1860    $sql = $wpdb->prepare("select count(invited_email) from ".secure_invite_prefix()."invitations where invited_email = %s", $email ); 
    15531861    $found_emails = $wpdb->get_var( $sql ); 
    15541862    $already_invited = false; 
     
    15791887             
    15801888            // save the invitation  
    1581             $sql = $wpdb->prepare("insert into ".$wpdb->base_prefix."invitations 
     1889            $sql = $wpdb->prepare("insert into ".secure_invite_prefix()."invitations 
    15821890        (user_id, invited_email, datestamp) 
    15831891        values 
Note: See TracChangeset for help on using the changeset viewer.