/** * Gets posts, based on the params provided * * @package Invite Anyone * @since 0.9 */ function get_posts() { global $wpdb; // $posts is a multidimensional array, containing all different time periods $posts = array(); foreach ($this->time_periods as $tp => $period) { $invite = new Invite_Anyone_Invitation(); // Will be populated out of $this->params. Defaults to none? $args = array('posts_per_page' => '-1', 'status' => 'pending,draft,future,publish,trash'); // Create the date filter if ($tp) { $since = time() - $tp; $this->date_sql = $wpdb->prepare(" AND post_date > %s", date('Y-m-d H:i:s', $since)); add_filter('posts_where_paged', array($this, 'where_filter')); } $invites = $invite->get($args); // Remove the filter if ($tp) { remove_filter('posts_where_paged', array($this, 'where_filter')); } $period['total_count'] = 0; $period['accepted_count'] = 0; $period['total_count_cs'] = 0; $period['accepted_count_cs'] = 0; $period['unique_emails'] = 0; $period['unique_inviters'] = 0; $period['unique_emails'] = array(); $period['unique_inviters'] = array(); if ($invites->have_posts()) { while ($invites->have_posts()) { $invites->the_post(); // Increase the total count $period['total_count']++; $author_key = get_the_author_ID(); // If it's a new sender, add them to $unique_inviters if (!isset($period['unique_inviters'][$author_key])) { $period['unique_inviters'][$author_key] = array('overall' => array('sent' => 0, 'accepted' => 0), 'cloudsponge' => array('sent' => 0, 'accepted' => 0)); } // Bump the inviter's count $period['unique_inviters'][$author_key]['overall']['sent']++; // Is it accepted? $accepted = get_post_meta(get_the_ID(), 'bp_ia_accepted', true); if ($accepted) { // Total accepted count $period['accepted_count']++; // Author's accepted count $period['unique_inviters'][$author_key]['overall']['accepted']++; } // Is it a CloudSponge invite? $is_cloudsponge = get_post_meta(get_the_ID(), 'bp_ia_is_cloudsponge', true); if (__('Yes', 'invite-anyone') == $is_cloudsponge) { $period['total_count_cs']++; // Author count $period['unique_inviters'][$author_key]['cloudsponge']['sent']++; if ($accepted) { // Total accepted count $period['accepted_count_cs']++; // Author's accepted count $period['unique_inviters'][$author_key]['cloudsponge']['accepted']++; } } } } // With all the data tallied, we can come up with some percentages // Overall acceptance rate if ($period['total_count']) { $period['acceptance_rate'] = round($period['accepted_count'] / $period['total_count'] * 100); $period['acceptance_rate'] .= '%'; } else { $period['acceptance_rate'] = __('n/a', 'invite-anyone'); } // CS percentage if ($period['total_count']) { $period['cs_percentage'] = round($period['total_count_cs'] / $period['total_count'] * 100); $period['cs_percentage'] .= '%'; } else { $period['cs_percentage'] = __('n/a', 'invite-anyone'); } // CS acceptance rate if ($period['total_count_cs']) { $period['acceptance_rate_cs'] = round($period['accepted_count_cs'] / $period['total_count_cs'] * 100); $period['acceptance_rate_cs'] .= '%'; } else { $period['acceptance_rate_cs'] = __('n/a', 'invite-anyone'); } // Find the most active user $leader_user_id_pct = 0; $leader_val_pct = 0; $leader_user_id_num = 0; $leader_val_num = 0; $leader_user_id_pct_cs = 0; $leader_val_pct_cs = 0; $leader_user_id_num_cs = 0; $leader_val_num_cs = 0; foreach ($period['unique_inviters'] as $user_id => $u) { // Overall if ($u['overall']['sent']) { if ($u['overall']['sent'] >= $leader_val_num) { $leader_user_id_num = $user_id; $leader_val_num = $u['overall']['sent']; } if ($u['overall']['accepted'] / $u['overall']['sent'] >= $leader_val_pct) { $leader_user_id_pct = $user_id; $leader_val_pct = $u['overall']['accepted'] / $u['overall']['sent'] * 100; } } // CloudSponge if ($u['cloudsponge']['sent']) { if ($u['cloudsponge']['sent'] >= $leader_val_num_cs) { $leader_user_id_num_cs = $user_id; $leader_val_num_cs = $u['cloudsponge']['sent']; } if ($u['cloudsponge']['accepted'] / $u['cloudsponge']['sent'] >= $leader_val_pct_cs) { $leader_user_id_pct_cs = $user_id; $leader_val_pct_cs = $u['cloudsponge']['accepted'] / $u['cloudsponge']['sent'] * 100; } } } $period['top_users']['top_user_num'] = array('user_id' => $leader_user_id_num ? $leader_user_id_num : false, 'sent' => $leader_val_num ? $leader_val_num : false); $period['top_users']['top_user_pct'] = array('user_id' => $leader_user_id_pct ? $leader_user_id_pct : false, 'accepted' => $leader_val_pct ? round($leader_val_pct) . '%' : '-'); $period['top_users']['top_user_num_cs'] = array('user_id' => $leader_user_id_num_cs ? $leader_user_id_num_cs : false, 'sent' => $leader_val_num_cs ? $leader_val_num_cs : false); $period['top_users']['top_user_pct_cs'] = array('user_id' => $leader_user_id_pct_cs ? $leader_user_id_pct_cs : false, 'accepted' => $leader_val_pct_cs ? round($leader_val_pct_cs) . '%' : '-'); // Fetch userlinks foreach ($period['top_users'] as $key => $top_user) { $link = bp_core_get_userlink($top_user['user_id']); $period['top_users'][$key]['user_link'] = $link; } $this->time_periods[$tp] = $period; } }
function invite_anyone_settings_mi_content() { // Load the pagination helper if (!class_exists('BBG_CPT_Pag')) { require_once dirname(__FILE__) . '/../lib/bbg-cpt-pag.php'; } $pagination = new BBG_CPT_Pag(); // Load the sortable helper if (!class_exists('BBG_CPT_Sort')) { require_once dirname(__FILE__) . '/../lib/bbg-cpt-sort.php'; } $cols = array(array('name' => 'author', 'title' => __('Inviter', 'invite-anyone'), 'css_class' => 'ia-inviter'), array('name' => 'ia_invitees', 'title' => __('Invited Email', 'invite-anyone'), 'css_class' => 'ia-invited-email'), array('name' => 'sent', 'title' => __('Sent', 'invite-anyone'), 'css_class' => 'ia-sent', 'default_order' => 'desc', 'posts_column' => 'post_date', 'is_default' => true), array('name' => 'accepted', 'title' => __('Accepted', 'invite-anyone'), 'css_class' => 'ia-accepted', 'default_order' => 'desc'), array('name' => 'cloudsponge', 'title' => __('CloudSponge', 'invite-anyone'), 'css_class' => 'ia-cloudsponge')); $sortable = new BBG_CPT_Sort($cols); $args = array('orderby' => $sortable->get_orderby, 'order' => $sortable->get_order, 'posts_per_page' => $pagination->get_per_page, 'paged' => $pagination->get_paged, 'status' => 'trash,publish,pending,draft,future'); // Get the invites $invite = new Invite_Anyone_Invitation(); $invites = $invite->get($args); // Complete the pagination setup $pagination->setup_query($invites); ?> <?php if ($invites->have_posts()) { ?> <div class="ia-admin-pagination"> <div class="currently-viewing"> <?php $pagination->currently_viewing_text(); ?> </div> <div class="pag-links"> <?php $pagination->paginate_links(); ?> </div> </div> <table class="wp-list-table widefat ia-invite-list"> <thead> <tr> <th scope="col" id="cb" class="check-column"> <input type="checkbox" /> </th> <?php if ($sortable->have_columns()) { while ($sortable->have_columns()) { $sortable->the_column(); ?> <?php $sortable->the_column_th(); ?> <?php } } ?> </tr> </thead> <tbody> <?php while ($invites->have_posts()) { $invites->the_post(); ?> <tr> <th scope="row" class="check-column"> <input type="checkbox" /> </th> <td class="ia-inviter"> <?php echo bp_core_get_userlink(get_the_author_ID()); ?> <div class="row-actions"> <span class="edit"><a href="<?php echo add_query_arg(array('post' => get_the_ID(), 'action' => 'edit'), admin_url('post.php')); ?> "><?php _e('View Invitation', 'invite-anyone'); ?> </a></span> </div> </td> <td class="ia-invited-email"> <?php $emails = wp_get_post_terms(get_the_ID(), invite_anyone_get_invitee_tax_name()); foreach ($emails as $email) { // Before storing taxonomy terms in the db, we replace "+" with ".PLUSSIGN.", so we need to reverse that before displaying the email address. $email_address = str_replace('.PLUSSIGN.', '+', $email->name); echo esc_html($email_address); } ?> </td> <td class="ia-sent"> <?php global $post; $date_invited = invite_anyone_format_date($post->post_date); ?> <?php echo esc_html($date_invited); ?> </td> <td class="ia-accepted"> <?php if ($accepted = get_post_meta(get_the_ID(), 'bp_ia_accepted', true)) { $date_joined = invite_anyone_format_date($accepted); $accepted = true; } else { $date_joined = '-'; $accepted = false; } ?> <?php echo esc_html($date_joined); ?> </td> <td class="ia-cloudsponge"> <?php $is_cloudsponge = get_post_meta(get_the_ID(), 'bp_ia_is_cloudsponge', true); if (!$is_cloudsponge) { $is_cloudsponge = __('(no data)', 'invite-anyone'); } ?> <?php echo esc_html($is_cloudsponge); ?> </td> </tr> <?php } ?> </tbody> </table> <?php if (defined('INVITE_ANYONE_CS_ENABLED') && INVITE_ANYONE_CS_ENABLED) { ?> <p class="description"><strong>Note:</strong> CloudSponge data has only been recorded since Invite Anyone v0.9.</p> <?php } ?> <div class="ia-admin-pagination"> <div class="currently-viewing"> <?php $pagination->currently_viewing_text(); ?> </div> <div class="pag-links"> <?php $pagination->paginate_links(); ?> </div> </div> <?php } else { ?> <p><?php _e('No invitations have been sent yet.', 'invite-anyone'); ?> </p> <?php } ?> <?php }
/** * Was this friendship extended because of a site invite? * * @since 1.2.0 */ public function is_result_of_site_invite($inviter_id, $invitee_email) { $retval = 'No'; if (!class_exists('Invite_Anyone_Invitation')) { return $retval; } // The date_created is updated when the user accepts the invite so this is unreliable. // Probably checking invite_anyone_get_invitations_by_invited_email is better, // Note that "cleared" invites become status = draft. // So invite_anyone_get_invitations_by_invited_email() won't work because it finds only published posts. // Catch a couple of odd cases. $invitee_email = str_replace(' ', '+', $invitee_email); $invitee_email = str_replace('+', '.PLUSSIGN.', $invitee_email); $args = array('inviter_id' => $inviter_id, 'invitee_email' => $invitee_email, 'status' => array('draft', 'publish'), 'posts_per_page' => -1); $invite = new Invite_Anyone_Invitation(); $site_invites = $invite->get($args); // If a connection exists, this will be not empty. if (!empty($site_invites->posts)) { $retval = "Yes"; } return $retval; }
/** * Upgrade for pre-0.9 * * @package Invite Anyone * @since 0.9 */ function upgrade_0_9() { global $wp_query, $post; $args = array('posts_per_page' => '30', 'paged' => '1'); // Get the invites $invite = new Invite_Anyone_Invitation(); $invites = $invite->get($args); // Get the total. We're going to loop through them in an attempt to save memory. $total_invites = $invites->found_posts; unset($invites); unset($args); // WP bug $old_wp_query = $wp_query; $paged = 0; while ($paged * 30 <= $total_invites) { $paged++; $args = array('posts_per_page' => '30', 'paged' => $paged); // Get the invites $invite = new Invite_Anyone_Invitation(); $invites = $invite->get($args); // I don't understand why, but I have to do this to avoid errors. WP bug? $wp_query = $invites; if ($invites->have_posts()) { while ($invites->have_posts()) { $invites->the_post(); // Migrate the accepted data from date_modified to a meta if (!get_post_meta(get_the_ID(), 'bp_ia_accepted', true)) { // When the dates are different, it's been accepted if ($post->post_date != $post->post_modified) { update_post_meta(get_the_ID(), 'bp_ia_accepted', $post->post_modified); } else { // We set this to null so it still comes up in the // meta query update_post_meta(get_the_ID(), 'bp_ia_accepted', ''); } } } } unset($invites); unset($args); } // WP bug $wp_query = $old_wp_query; }