function gad_pageviews_sparkline($link_uri)
 {
     if ($this->auth_type == 'oauth') {
         $ga = new GALib('oauth', NULL, $this->oauth_token, $this->oauth_secret, $this->account_id);
     } else {
         $ga = new GALib('client', $this->auth_token, NULL, NULL, $this->account_id);
     }
     $start_date = date('Y-m-d', time() - 60 * 60 * 24 * 30);
     $end_date = date('Y-m-d');
     $data = $ga->daily_uri_pageviews_for_date_period($link_uri, $start_date, $end_date);
     $error_type = gad_request_error_type($ga);
     if ($error_type == 'perm') {
         return '';
     } else {
         if ($error_type == 'retry') {
             $data = $ga->daily_uri_pageviews_for_date_period($link_uri, $start_date, $end_date);
         }
     }
     $minvalue = 999999999;
     $maxvalue = 0;
     $count = 0;
     foreach ($data as $date => $value) {
         if ($minvalue > $value['ga:pageviews']) {
             $minvalue = $value['ga:pageviews'];
         }
         if ($maxvalue < $value['ga:pageviews']) {
             $maxvalue = $value['ga:pageviews'];
         }
         $cvals .= $value['ga:pageviews'] . ($count < sizeof($data) - 1 ? "," : "");
         $count++;
     }
     return '<img width="90" height="30" src="http://chart.apis.google.com/chart?chs=90x30&cht=ls&chf=bg,s,FFFFFF00&chco=0077CC&chd=t:' . $cvals . '&chds=' . $minvalue . ',' . $maxvalue . '"/>';
 }
 function fill_posts_pages_placeholder()
 {
     global $wpdb;
     if (($value = $this->security_check()) !== true) {
         die($value);
     }
     $post_id = intval($_REQUEST['pid']);
     $count = intval($_REQUEST['count']);
     // This is done to reduce the number of requests made at the same time
     if ($count % 2 == 0) {
         usleep(500000);
     }
     if ($count % 4 == 0) {
         usleep(500000);
     }
     if (get_option('gad_auth_token') == 'gad_see_oauth') {
         $ga = new GALib('oauth', NULL, get_option('gad_oauth_token'), get_option('gad_oauth_secret'), get_option('gad_account_id'), get_option('gad_cache_timeout') !== false ? get_option('gad_cache_timeout') : 60);
     } else {
         $ga = new GALib('client', get_option('gad_auth_token'), NULL, NULL, get_option('gad_account_id'), get_option('gad_cache_timeout') !== false ? get_option('gad_cache_timeout') : 60);
     }
     $link_value = get_permalink($post_id);
     $url_data = parse_url($link_value);
     $link_uri = substr($url_data['path'] . (isset($url_data['query']) ? '?' . $url_data['query'] : ''), -20);
     $is_draft = $wpdb->get_var($wpdb->prepare("SELECT count(1) FROM {$wpdb->posts} WHERE post_status = 'draft' AND ID = %d", $post_id));
     if ($link_uri == '' || isset($is_draft) && $is_draft > 0) {
         echo "";
     } else {
         $start_date = date('Y-m-d', time() - 60 * 60 * 24 * 30);
         $end_date = date('Y-m-d');
         $data = $ga->summary_by_partial_uri_for_date_period($link_uri, $start_date, $end_date);
         $error_type = gad_request_error_type($ga);
         if ($error_type == 'perm') {
             die("Could not load data");
         } else {
             if ($error_type == 'retry') {
                 $data = $ga->summary_by_partial_uri_for_date_period($link_uri, $start_date, $end_date);
             }
         }
         $minvalue = 999999999;
         $maxvalue = 0;
         $pageviews = 0;
         $exits = 0;
         $uniques = 0;
         $count = 0;
         foreach ($data as $date => $value) {
             if ($minvalue > $value['ga:pageviews']) {
                 $minvalue = $value['ga:pageviews'];
             }
             if ($maxvalue < $value['ga:pageviews']) {
                 $maxvalue = $value['ga:pageviews'];
             }
             $cvals .= $value['ga:pageviews'] . ($count < sizeof($data) - 1 ? "," : "");
             $count++;
             $pageviews += $value['ga:pageviews'];
             $exits += $value['ga:exits'];
             $uniques += $value['ga:uniquePageviews'];
         }
         $ui = new GADAdminPagesPostsUI();
         $ui->display_posts_pages_custom_column($cvals, $minvalue, $maxvalue, $pageviews, $exits, $uniques);
     }
     die("");
 }
 function populate_goal_data($ga)
 {
     $goal_data_tmp = $ga->goals_for_date_period($this->start_date, $this->end_date, array(get_option('gad_goal_one') !== false, get_option('gad_goal_two') !== false, get_option('gad_goal_three') !== false, get_option('gad_goal_four') !== false));
     $error_type = gad_request_error_type($ga);
     if ($error_type == 'perm') {
         $this->fatal_error = true;
     } else {
         if ($error_type == 'retry') {
             $goal_data_tmp = $ga->goals_for_date_period($this->start_date, $this->end_date, array(get_option('gad_goal_one') !== false, get_option('gad_goal_two') !== false, get_option('gad_goal_three') !== false, get_option('gad_goal_four') !== false));
         }
     }
     $this->goal_data = array();
     foreach ($goal_data_tmp as $gd) {
         if (gad_is_assoc($gd)) {
             foreach ($gd as $gk => $gv) {
                 $this->goal_data[$gk] += $gv;
             }
         }
     }
 }