/** * wp_ajax_wpsd_load_authors function. * * @access public * @return void */ function wp_ajax_wpsd_load_authors() { global $wpdb; $form = new WPSDAdminConfigForm(); if (!$form->getWpsdWidgetAuthors()) { _e('Widget disabled check', 'wpsd'); echo ' <a href="' . wpsd_get_settings_url() . '" title="wp-stats-dashboard settings" target="_self">' . __('settings', 'wpsd') . '</a>'; die; } $results = $wpdb->get_results("\r\n\t\t\tSELECT COUNT(*) as c, post_author as user_id\r\n\t\t\tFROM {$wpdb->posts} WHERE post_status = 'publish'\r\n\t\t\tGROUP BY post_author\r\n\t\t\tORDER BY c DESC\r\n\t\t\tLIMIT 5"); if (null != $results && is_array($results)) { print '<style>table.wpsd_top5_authors { width:100%; } </style>'; echo '<table class="wpsd_top5_authors">'; printf('<thead><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr></thead>', __('Rank', 'wpsd'), __('WPSD Score', 'wpsd'), __('Author', 'wpsd'), __('Post Count', 'wpsd'), __('Comments Received', 'wpsd'), __('Comments Placed', 'wpsd'), __('Klout Score', 'wpsd'), __('Twitter Ratio', 'wpsd')); echo '<tbody>'; $list = array(); foreach ($results as $r) { if (null == $r->user_id) { continue; } $metrics = new WPSDUserMetrics($r->user_id); $avatar = get_avatar($r->user_id, 32); $user_data = get_userdata($r->user_id); $author = sprintf('<a href="%s">%s <br/> <span>%s</span></a>', 'user-edit.php?user_id=' . $r->user_id, $avatar, $user_data->user_login); $wpsd_score = $metrics->getWpsdScore(); $list[$wpsd_score] = array('metrics' => $metrics, 'avatar' => $avatar, 'user_data' => $user_data, 'author' => $author); } ksort($list, SORT_NUMERIC); $list = array_reverse($list); $i = 0; foreach ($list as $item) { $metrics = $item['metrics']; $avatar = $item['avatar']; $user_data = $item['user_data']; $author = $item['author']; if ($i % 2 == 0) { echo '<tr>'; } else { echo '<tr class="highlight">'; } $this->render_admin('admin_user_metrics', array('metrics' => $metrics, 'author' => $author, 'rank' => $i + 1)); echo '</tr>'; $i++; } echo '</tbody>'; echo '</table>'; } else { _e('No authors found with comments placed', 'wpsd'); } die; }