Exemple #1
0
function stats_dashboard_widget_content()
{
    if (!isset($_GET['width']) || !($width = (int) ($_GET['width'] / 2)) || $width < 250) {
        $width = 370;
    }
    if (!isset($_GET['height']) || !($height = (int) $_GET['height'] - 36) || $height < 230) {
        $height = 180;
    }
    $_width = $width - 5;
    $_height = $height - ($GLOBALS['is_winIE'] ? 16 : 5);
    // hack!
    $options = stats_dashboard_widget_options();
    $blog_id = Jetpack_Options::get_option('id');
    $q = array('noheader' => 'true', 'proxy' => '', 'blog' => $blog_id, 'page' => 'stats', 'chart' => '', 'unit' => $options['chart'], 'color' => get_user_option('admin_color'), 'width' => $_width, 'height' => $_height, 'ssl' => is_ssl(), 'j' => sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION));
    $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php";
    $url = add_query_arg($q, $url);
    $method = 'GET';
    $timeout = 90;
    $user_id = JETPACK_MASTER_USER;
    $get = Jetpack_Client::remote_request(compact('url', 'method', 'timeout', 'user_id'));
    $get_code = wp_remote_retrieve_response_code($get);
    if (is_wp_error($get) || 2 != intval($get_code / 100) && 304 != $get_code || empty($get['body'])) {
        stats_print_wp_remote_error($get, $url);
    } else {
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        echo $body;
    }
    $post_ids = array();
    $csv_end_date = date('Y-m-d', current_time('timestamp'));
    $csv_args = array('top' => "&limit=8&end={$csv_end_date}", 'search' => "&limit=5&end={$csv_end_date}");
    /* translators: Stats dashboard widget postviews list: "$post_title $views Views" */
    $printf = __('%1$s %2$s Views', 'jetpack');
    foreach ($top_posts = stats_get_csv('postviews', "days={$options['top']}{$csv_args['top']}") as $i => $post) {
        if ($post['post_id'] == 0) {
            unset($top_posts[$i]);
            continue;
        }
        $post_ids[] = $post['post_id'];
    }
    // cache
    get_posts(array('include' => join(',', array_unique($post_ids))));
    $searches = array();
    foreach ($search_terms = stats_get_csv('searchterms', "days={$options['search']}{$csv_args['search']}") as $search_term) {
        if ($search_term['searchterm'] == 'encrypted_search_terms') {
            continue;
        }
        $searches[] = esc_html($search_term['searchterm']);
    }
    ?>
<a class="button" href="admin.php?page=stats"><?php 
    _e('View All', 'jetpack');
    ?>
</a>
<div id="stats-info">
	<div id="top-posts" class='stats-section'>
		<div class="stats-section-inner">
		<h3 class="heading"><?php 
    _e('Top Posts', 'jetpack');
    ?>
</h3>
		<?php 
    if (empty($top_posts)) {
        ?>
			<p class="nothing"><?php 
        _e('Sorry, nothing to report.', 'jetpack');
        ?>
</p>
			<?php 
    } else {
        foreach ($top_posts as $post) {
            if (!get_post($post['post_id'])) {
                continue;
            }
            ?>
				<p><?php 
            printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
            ?>
</p>
				<?php 
        }
    }
    ?>
		</div>
	</div>
	<div id="top-search" class='stats-section'>
		<div class="stats-section-inner">
		<h3 class="heading"><?php 
    _e('Top Searches', 'jetpack');
    ?>
</h3>
		<?php 
    if (empty($searches)) {
        ?>
			<p class="nothing"><?php 
        _e('Sorry, nothing to report.', 'jetpack');
        ?>
</p>
			<?php 
    } else {
        ?>
			<p><?php 
        echo join(',&nbsp; ', $searches);
        ?>
</p>
			<?php 
    }
    ?>
		</div>
	</div>
</div>
<div class="clear"></div>
<?php 
    exit;
}
Exemple #2
0
function stats_dashboard_widget_content()
{
    $blog_id = stats_get_option('blog_id');
    if (!($width = (int) ($_GET['width'] / 2)) || $width < 250) {
        $width = 370;
    }
    if (!($height = (int) $_GET['height'] - 36) || $height < 230) {
        $height = 230;
    }
    $_width = $width - 5;
    $_height = $height - ($GLOBALS['is_winIE'] ? 16 : 5);
    // hack!
    $options = stats_dashboard_widget_options();
    $q = array('noheader' => 'true', 'proxy' => '', 'page' => 'stats', 'blog' => $blog_id, 'key' => stats_get_api_key(), 'chart' => '', 'unit' => $options['chart'], 'width' => $_width, 'height' => $_height);
    $url = 'http://dashboard.wordpress.com/wp-admin/index.php';
    $url = add_query_arg($q, $url);
    $get = wp_remote_get($url, array('timeout' => 300));
    if (is_wp_error($get) || empty($get['body'])) {
        $http = $_SERVER['HTTPS'] ? 'https' : 'http';
        $src = clean_url("{$http}://dashboard.wordpress.com/wp-admin/index.php?page=estats&blog={$blog_id}&noheader=true&chart&unit={$options['chart']}&width={$_width}&height={$_height}");
        echo "<iframe id='stats-graph' class='stats-section' frameborder='0' style='width: {$width}px; height: {$height}px; overflow: hidden' src='{$src}'></iframe>";
    } else {
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_swf_urls($body);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        echo $body;
    }
    $post_ids = array();
    if (version_compare('2.7-z', $GLOBALS['wp_version'], '<=')) {
        $csv_args = array('top' => '&limit=8', 'active' => '&limit=5', 'search' => '&limit=5');
        /* translators: Stats dashboard widget postviews list: "$post_title $views Views" */
        $printf = __('%1$s %2$s Views', 'stats');
    } else {
        $csv_args = array('top' => '', 'active' => '', 'search' => '');
        /* translators: Stats dashboard widget postviews list: "$post_title, $views Views" */
        $printf = __('%1$s, %2$s views', 'stats');
    }
    foreach ($top_posts = stats_get_csv('postviews', "days={$options['top']}{$csv_args['top']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    foreach ($active_posts = stats_get_csv('postviews', "days={$options['active']}{$csv_args['active']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    // cache
    get_posts(array('include' => join(',', array_unique($post_ids))));
    $searches = array();
    foreach ($search_terms = stats_get_csv('searchterms', "days={$options['search']}{$csv_args['search']}") as $search_term) {
        $searches[] = esc_html($search_term['searchterm']);
    }
    ?>
<div id="stats-info">
	<div id="top-posts" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Posts', 'stats');
    ?>
</h4>
		<?php 
    foreach ($top_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
	<div id="top-search" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Searches', 'stats');
    ?>
</h4>
		<p><?php 
    echo join(',&nbsp; ', $searches);
    ?>
</p>
		</div>
	</div>
	<div id="active" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Most Active', 'stats');
    ?>
</h4>
		<?php 
    foreach ($active_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
</div>
<br class="clear" />
<p class="textright">
	<a class="button" href="index.php?page=stats"><?php 
    _e('View All', 'stats');
    ?>
</a>
</p>
<?php 
    exit;
}