Exemplo n.º 1
0
 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 . '"/>';
 }
Exemplo n.º 2
0
 function admin_handle_other_options($info_message = '')
 {
     if (isset($_POST['SubmitOptions'])) {
         if (function_exists('current_user_can') && !current_user_can('manage_options')) {
             die(__('Cheatin&#8217; uh?'));
         }
         @SimpleFileCache::clearCache();
         if (isset($_POST['ga_forget_pass'])) {
             delete_option('gad_login_pass');
         }
         if (isset($_POST['ga_forget_all'])) {
             delete_option('gad_oauth_token');
             delete_option('gad_oauth_secret');
             delete_option('gad_account_id');
             delete_option('gad_display_level');
             delete_option('gad_cache_timeout');
             delete_option('gad_goal_one');
             delete_option('gad_goal_two');
             delete_option('gad_goal_three');
             delete_option('gad_goal_four');
             delete_option('gad_login_email');
             delete_option('gad_login_pass');
             delete_option('gad_auth_token');
             delete_option('gad_disable_post_stats');
             $this->admin_plugin_options('Everything Reset');
             return;
         }
         delete_option('gad_account_id');
         add_option('gad_account_id', $_POST['ga_account_id']);
         if (isset($_POST['ga_forget_auth'])) {
             delete_option('gad_oauth_token');
             delete_option('gad_oauth_secret');
             delete_option('gad_auth_token');
             $this->admin_plugin_options('Auth Reset');
             return;
         }
         if (isset($_POST['ga_display_level'])) {
             delete_option('gad_display_level');
             if ($_POST['ga_display_level'] != '') {
                 add_option('gad_display_level', $_POST['ga_display_level']);
             }
         }
         if (isset($_POST['ga_disable_post_stats'])) {
             add_option('gad_disable_post_stats', 'true');
         } else {
             delete_option('gad_disable_post_stats');
         }
         if (isset($_POST['ga_cache_timeout'])) {
             delete_option('gad_cache_timeout');
             if ($_POST['ga_cache_timeout'] != '') {
                 add_option('gad_cache_timeout', $_POST['ga_cache_timeout']);
             }
         }
         delete_option('gad_goal_one');
         delete_option('gad_goal_two');
         delete_option('gad_goal_three');
         delete_option('gad_goal_four');
         if (isset($_POST['ga_goal_one'])) {
             if ($_POST['ga_goal_one'] != '') {
                 add_option('gad_goal_one', $_POST['ga_goal_one']);
             }
         }
         if (isset($_POST['ga_goal_two'])) {
             if ($_POST['ga_goal_two'] != '') {
                 add_option('gad_goal_two', $_POST['ga_goal_two']);
             }
         }
         if (isset($_POST['ga_goal_three'])) {
             if ($_POST['ga_goal_three'] != '') {
                 add_option('gad_goal_three', $_POST['ga_goal_three']);
             }
         }
         if (isset($_POST['ga_goal_four'])) {
             if ($_POST['ga_goal_four'] != '') {
                 add_option('gad_goal_four', $_POST['ga_goal_four']);
             }
         }
         $info_message = 'Options Saved';
     }
     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_cache_timeout') !== false ? get_option('gad_cache_timeout') : 60);
     } else {
         $ga = new GALib('client', get_option('gad_auth_token'), NULL, NULL, '', get_option('gad_cache_timeout') !== false ? get_option('gad_cache_timeout') : 60);
     }
     $account_hash = $ga->account_query();
     if ($ga->isError()) {
         if ($ga->isAuthError()) {
             delete_option('gad_auth_token');
             // this is removed so login will happen again
             $this->admin_plugin_options();
             return;
         } else {
             $ui = new GADAdminOptionsUI();
             $ui->error_message = 'Error gathering analytics data from Google: ' . strip_tags($ga->getErrorMessage());
             $ui->display_admin_halting_error();
             return;
         }
     }
     $ui = new GADAdminOptionsUI();
     $ui->info_message = $info_message;
     $ui->error_message = '';
     $ui->display_admin_handle_other_options($account_hash);
 }
 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("");
 }
Exemplo n.º 4
0
    function widget($args, $instance)
    {
        $cache = wp_cache_get('widget_recent_posts', 'widget');
        $show_popular = class_exists('GADWidgetData') && $instance['show-popular'];
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($args['widget_id'])) {
            $args['widget_id'] = $this->id;
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
        if (empty($instance['number']) || !($number = absint($instance['number']))) {
            $number = 10;
        }
        $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
        if ($r->have_posts()) {
            if ($show_popular) {
                $blog_details = get_blog_details(get_current_blog_id());
                $path = str_replace('/cms', '', $blog_details->path);
                $start_date = date('Y-m-d', strtotime('-1 week', time()));
                $end_date = date('Y-m-d', time());
                $login = new GADWidgetData();
                if ($login->auth_type == 'oauth') {
                    $ga = new GALib('oauth', NULL, $login->oauth_token, $login->oauth_secret, $login->account_id);
                } else {
                    $ga = new GALib('client', $login->auth_token, NULL, NULL, $login->account_id);
                }
                $wp_posts = array();
                $pop_posts = $ga->pages_for_date_period($start_date, $end_date, $number + 1);
                foreach ($pop_posts as $index => $post) {
                    if ($post['value'] == $path) {
                        unset($pop_posts[$index]);
                    } else {
                        $wp_post = get_page_by_path(basename($post['value']), OBJECT, 'post');
                        if (isset($wp_post) && !in_array($wp_post, $wp_posts)) {
                            $wp_posts[] = $wp_post;
                            $wp_post_views[$wp_post->ID] = $post['children']['children']['ga:pageviews'];
                        }
                    }
                }
                $pop_posts = array_slice($wp_posts, 0, $number);
                // the first, most popular page, is always /news/ (the homepage)
            }
            ?>
		<?php 
            echo $before_widget;
            ?>

      <?php 
            if ($show_popular) {
                ?>
    <ul id="news-tab-nav" data-tabs="toggle" tab-index="0">
        <li class="selected"><a class="recent-popular-widget" href="#tab-popular" title="Most popular">Most Popular</a></li>
        <li><a class="recent-popular-widget" href="#tab-recent" title="Most recent">Recent</a></li>
    </ul>
      <?php 
            } else {
                ?>
        <?php 
                echo $before_title . $title . $after_title;
                ?>
      <?php 
            }
            ?>
    
    <ul id="tab-recent" tab-index="0" class="recent-posts" <?php 
            if ($show_popular) {
                ?>
 style="display:none;" <?php 
            }
            ?>
>
		<?php 
            while ($r->have_posts()) {
                $r->the_post();
                ?>
      <li>
        <?php 
                if (has_post_thumbnail()) {
                    ?>
        <a class="widget-thumbnail" href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                    ?>
">
          <?php 
                    the_post_thumbnail('thumbnail');
                    ?>
        </a>
        <?php 
                }
                ?>
        <span>
	        <a class="widget-link" href="<?php 
                the_permalink();
                ?>
" title="<?php 
                echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                ?>
">
	          <?php 
                if (get_the_title()) {
                    the_title();
                } else {
                    the_ID();
                }
                ?>
	        </a>
	        <p> <small><?php 
                echo human_time_diff(get_the_time('U'), current_time('timestamp'));
                ?>
 ago</small> </p>
        </span>
      </li>
		<?php 
            }
            ?>
      <?php 
            if (array_key_exists('show-more-link', $instance) && $instance['show-more-link']) {
                ?>
        <li>
        <?php 
                $page = get_option('page_for_posts') ? get_option('page_for_posts') : 1;
                ?>
        <a class="more" href="<?php 
                echo get_permalink($page);
                ?>
" title="Go to blog page">More</a>
        </li>
      <?php 
            }
            ?>
		</ul>


    <?php 
            wp_reset_postdata();
            ?>

    <?php 
            if ($show_popular) {
                ?>

    <ul id="tab-popular" class="popular-posts" tab-index="0">

      <?php 
                foreach ($pop_posts as $post) {
                    ?>
          <li>
            <?php 
                    if (get_the_post_thumbnail($post->ID)) {
                        ?>
            <a class="widget-thumbnail" href="<?php 
                        echo get_permalink($post->ID);
                        ?>
" title="<?php 
                        echo esc_attr($post->post_title);
                        ?>
">
              <?php 
                        echo get_the_post_thumbnail($post->ID, 'thumbnail');
                        ?>
            </a>
            <?php 
                    }
                    ?>
            <a class="widget-link" href="<?php 
                    echo get_permalink($post->ID);
                    ?>
" title="<?php 
                    echo esc_attr($post->post_title);
                    ?>
">
              <?php 
                    echo $post->post_title;
                    ?>
            </a>
            <p><small><?php 
                    echo $wp_post_views[$post->ID];
                    ?>
 views</small></p>
          </li>

      <?php 
                }
                ?>
    </ul>

    <?php 
            }
            ?>

		<?php 
            echo $after_widget;
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_recent_posts', $cache, 'widget');
    }