'ol', 'container_class' => 'ga-ranking', 'before' => '
  • ', 'after' => '
  • ', 'echo' => 'true', ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); $options = get_option( 'aistear_ga_ranking_options' ); $ga_email = $options[email]; $ga_pass = $options[pass]; $ga_profile_id = $options[profile_id]; $dimensions = array( 'pageTitle', 'pagePath' ); $metrics = array( 'pageviews', 'visits' ); $sort_metric = '-pageviews'; $filter=""; $start = '-'. $options[period] . ' day'; $start_date = date('Y-m-d', strtotime($start)); $end_date = date('Y-m-d', strtotime('-1 day')); $start_index = 1; $max_results = $options[count]; try { $ga = new gapi( $ga_email, $ga_pass ); } catch ( Exception $e ) { if ( is_user_logged_in() ) { echo "

    Authentication Failed

    "; echo "

    " . $e->getMessage() . "

    "; } } if ( !empty($ga) ) { $ga->requestReportData( $ga_profile_id, $dimensions, $metrics, $sort_metric, $filter, $start_date, $end_date, $start_index, $max_results ); $transient_key = 'aistear_ga_ranking_' . $ga_profile_id; $transients = get_transient( $transient_key ); if ( $transients === false ) { $rank = 1; $container_class = esc_attr( $container_class ); $transients = '<' . $container . ' class="' . $container_class . '">'; foreach( $ga->getResults() as $result ) { $sbefore = sprintf( $before, $rank ); $transients .= $sbefore . '' . $result->getPagetitle() . ''. $after; $rank++; } $transients .= ''; set_transient( $transient_key, $transients, 24*60*60 ); } $output = $transients; if (!$echo) { return $output; } echo $output; } } function aistear_ga_ranking_deactivation() { $options = get_option( 'aistear_ga_ranking_options' ); $transient_key = 'aistear_ga_ranking_' . $options[profile_id]; delete_transient( $transient_key ); delete_option( 'aistear_ga_ranking_options' ); } register_deactivation_hook( __FILE__, 'aistear_ga_ranking_deactivation'); /* Widget */ class Aistear_GA_Ranking_WidgetItem extends WP_Widget { function __construct() { $widget_options = array( 'classname' => 'ga-ranking-widget', 'description' => 'Displays the ranking that is based on the data of Google Analytics' ); parent::__construct('aistear_ga_rankig', __('Google Analytics Ranking'), $widget_options); } function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( $title ) { echo $before_title . $title . $after_title; } aistear_ga_ranking(); echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); return $instance; } function form($instance) { $title = esc_attr($instance['title']); ?>