/**
  * Widget.
  */
 function widget($args = array())
 {
     if (is_array($args)) {
         extract($args, EXTR_SKIP);
     }
     echo $before_widget . $before_title . $widget_name . $after_title;
     $form = new WPSDAdminConfigForm();
     if ($form->getWpsdWidgetOverview()) {
         $result = wpsd_read_cache();
         echo '<!-- WP-Stats-Dashboard - START General Stats -->';
         if (defined('WPSD_PLUGIN_URL')) {
             echo '<div align="center" id="wpsd-loading"> <img src="' . WPSD_PLUGIN_URL . '/resources/images/ajax-loader.gif" alt="' . __('loading', 'wpsd') . '" width="24" height="24" /></div>';
             echo '<div id="wpsd-stats-ranking"></div>';
         } else {
             _e('WPSD_PLUGIN_URL not defined', 'wpsd');
         }
         // Get domain.
         $domain_url = get_bloginfo('url');
         // Get shortened url.
         $s = get_option('wpsd_bitly_s');
         if ('' != $s) {
             $domain_url = $s;
         }
         echo '<br/><input type="button" value="' . __('Reload', 'wpsd') . '" class="button-primary" id="btn_wpsd_reload_2" />';
         echo '<!-- WP-Stats-Dashboard - STOP General Stats-->';
     } else {
         _e('Widget disabled check', 'wpsd');
         echo ' <a href="' . wpsd_get_settings_url() . '" title="wp-stats-dashboard settings" target="_self">' . __('settings', 'wpsd') . '</a>';
     }
     echo $after_widget;
 }
 /**
  * Widget.
  */
 function widget($args = array())
 {
     if (is_array($args)) {
         extract($args, EXTR_SKIP);
     }
     echo $before_widget . $before_title . $widget_name . $after_title;
     $form = new WPSDAdminConfigForm();
     if ($form->getWpsdWidgetTrends()) {
         $dao = new WPSDTrendsDao();
         $factory = new WPSDStatsFactory();
         $trends_type = $form->getWpsdTrendsType();
         if (null == $trends_type) {
             $trends_type = $factory->pagerank;
         }
         $rows = $dao->getStats($trends_type);
         $data = array();
         if (is_array($rows)) {
             foreach ($rows as $row) {
                 $data[$row->wpsd_trends_date] = $row->wpsd_trends_stats;
             }
         }
         // Default is pagerank.
         $this->render_admin('admin_trend', array('set' => $data, 'label' => 'days', 'form' => $form));
     } else {
         _e('Widget disabled check', 'wpsd');
         echo ' <a href="' . wpsd_get_settings_url() . '" title="wp-stats-dashboard settings" target="_self">' . __('settings', 'wpsd') . '</a>';
     }
     echo $after_widget;
 }
 /**
  * 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;
 }
$cache_path = wpsd_get_cache_path();
$un = get_option('wpsd_un');
$pw = get_option('wpsd_pw');
$user = wp_get_current_user();
// stats are only for administrators.
if (($user->caps['administrator'] || wpsd_has_access()) && '' != $un && '' != $pw && file_exists($cache_path) && is_writable($cache_path)) {
    ?>

	<div id="wpsd_chart_container">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
	</div>
		
<?php 
} else {
    ?>

<?php 
    _e('check', 'wpsd');
    ?>
 <a href="<?php 
    echo wpsd_get_settings_url();
    ?>
" title="wp-stats-dashboard settings" target="_self"><?php 
    _e('settings', 'wpsd');
    ?>
</a>

<?php 
}