示例#1
0
function stats_reports_page()
{
    if (isset($_GET['dashboard'])) {
        return stats_dashboard_widget_content();
    }
    if (!isset($_GET['noheader']) && empty($_GET['nojs']) && empty($_COOKIE['stnojs'])) {
        $nojs_url = add_query_arg('nojs', '1');
        if ('classic' != ($color = get_user_option('admin_color'))) {
            $color = 'fresh';
        }
        $http = is_ssl() ? 'https' : 'http';
        // Loading message
        // No JS fallback message
        ?>
<style type="text/css">
@media only screen and (-moz-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) {
	img.wpcom-loading-64 { width: 32px; height: 32px; }
}
</style>
<div id="stats-loading-wrap" class="wrap">
<p class="hide-if-no-js"><img class="wpcom-loading-64" alt="<?php 
        esc_attr_e('Loading&hellip;', 'jetpack');
        ?>
" src="<?php 
        echo esc_url("{$http}://" . STATS_DASHBOARD_SERVER . "/i/loading/{$color}-64.gif");
        ?>
" /></p>
<p class="hide-if-js"><?php 
        esc_html_e('Your Site Stats work better with Javascript enabled.', 'jetpack');
        ?>
<br />
<a href="<?php 
        echo esc_url($nojs_url);
        ?>
"><?php 
        esc_html_e('View Site Stats without Javascript', 'jetpack');
        ?>
</a>.</p>
</div>
<?php 
        return;
    }
    $blog_id = stats_get_option('blog_id');
    $day = isset($_GET['day']) && preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_GET['day']) ? $_GET['day'] : false;
    $q = array('noheader' => 'true', 'proxy' => '', 'page' => 'stats', 'day' => $day, 'blog' => $blog_id, 'charset' => get_option('blog_charset'), 'color' => get_user_option('admin_color'), 'ssl' => is_ssl(), 'j' => sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION));
    $args = array('view' => array('referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table'), 'numdays' => 'int', 'day' => 'date', 'unit' => array(1, 7, 31, 'human'), 'humanize' => array('true'), 'num' => 'int', 'summarize' => null, 'post' => 'int', 'width' => 'int', 'height' => 'int', 'data' => 'data', 'blog_subscribers' => 'int', 'comment_subscribers' => null, 'type' => array('wpcom', 'email', 'pending'), 'pagenum' => 'int');
    foreach ($args as $var => $vals) {
        if (!isset($_REQUEST[$var])) {
            continue;
        }
        if (is_array($vals)) {
            if (in_array($_REQUEST[$var], $vals)) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == 'int') {
            $q[$var] = intval($_REQUEST[$var]);
        } elseif ($vals == 'date') {
            if (preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_REQUEST[$var])) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == null) {
            $q[$var] = '';
        } elseif ($vals == 'data') {
            if (substr($_REQUEST[$var], 0, 9) == 'index.php') {
                $q[$var] = $_REQUEST[$var];
            }
        }
    }
    if (isset($_REQUEST['chart'])) {
        if (preg_match('/^[a-z0-9-]+$/', $_REQUEST['chart'])) {
            $url = 'http://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$_GET['chart']}.php";
        }
    } else {
        $url = 'http://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php";
    }
    $url = add_query_arg($q, $url);
    $method = 'GET';
    $timeout = 90;
    $user_id = JETPACK_MASTER_USER;
    // means send the wp.com user_id
    $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 {
        if (!empty($get['headers']['content-type'])) {
            $type = $get['headers']['content-type'];
            if (substr($type, 0, 5) == 'image') {
                $img = $get['body'];
                header('Content-Type: ' . $type);
                header('Content-Length: ' . strlen($img));
                echo $img;
                die;
            }
        }
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        $body = stats_convert_admin_urls($body);
        echo $body;
    }
    if (isset($_GET['noheader'])) {
        die;
    }
}
示例#2
0
function stats_reports_page($main_chart_only = false)
{
    if (isset($_GET['dashboard'])) {
        return stats_dashboard_widget_content();
    }
    $blog_id = stats_get_option('blog_id');
    $domain = Jetpack::build_raw_urls(get_home_url());
    if (!$main_chart_only && !isset($_GET['noheader']) && empty($_GET['nojs']) && empty($_COOKIE['stnojs'])) {
        $nojs_url = add_query_arg('nojs', '1');
        $http = is_ssl() ? 'https' : 'http';
        // Loading message
        // No JS fallback message
        ?>
<div class="wrap">
	<h2><?php 
        esc_html_e('Site Stats', 'jetpack');
        ?>
 <?php 
        if (current_user_can('jetpack_manage_modules')) {
            ?>
<a style="font-size:13px;" href="<?php 
            echo esc_url(admin_url('admin.php?page=jetpack&configure=stats'));
            ?>
"><?php 
            esc_html_e('Configure', 'jetpack');
            ?>
</a><?php 
        }
        ?>
</h2>
</div>
<div id="stats-loading-wrap" class="wrap">
<p class="hide-if-no-js"><img width="32" height="32" alt="<?php 
        esc_attr_e('Loading&hellip;', 'jetpack');
        ?>
" src="<?php 
        echo esc_url(apply_filters('jetpack_static_url', "{$http}://en.wordpress.com/i/loading/loading-64.gif"));
        ?>
" /></p>
<p style="font-size: 11pt; margin: 0;"><a href="https://wordpress.com/stats/<?php 
        echo $domain;
        ?>
" target="_blank"><?php 
        esc_html_e('View stats on WordPress.com right now', 'jetpack');
        ?>
</a></p>
<p class="hide-if-js"><?php 
        esc_html_e('Your Site Stats work better with JavaScript enabled.', 'jetpack');
        ?>
<br />
<a href="<?php 
        echo esc_url($nojs_url);
        ?>
"><?php 
        esc_html_e('View Site Stats without JavaScript', 'jetpack');
        ?>
</a>.</p>
</div>
<?php 
        return;
    }
    $day = isset($_GET['day']) && preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_GET['day']) ? $_GET['day'] : false;
    $q = array('noheader' => 'true', 'proxy' => '', 'page' => 'stats', 'day' => $day, 'blog' => $blog_id, 'charset' => get_option('blog_charset'), 'color' => get_user_option('admin_color'), 'ssl' => is_ssl(), 'j' => sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION));
    if (get_locale() !== 'en_US') {
        $q['jp_lang'] = get_locale();
    }
    // Only show the main chart, without extra header data, or metaboxes.
    $q['main_chart_only'] = $main_chart_only;
    $args = array('view' => array('referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table'), 'numdays' => 'int', 'day' => 'date', 'unit' => array(1, 7, 31, 'human'), 'humanize' => array('true'), 'num' => 'int', 'summarize' => null, 'post' => 'int', 'width' => 'int', 'height' => 'int', 'data' => 'data', 'blog_subscribers' => 'int', 'comment_subscribers' => null, 'type' => array('wpcom', 'email', 'pending'), 'pagenum' => 'int');
    foreach ($args as $var => $vals) {
        if (!isset($_REQUEST[$var])) {
            continue;
        }
        if (is_array($vals)) {
            if (in_array($_REQUEST[$var], $vals)) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == 'int') {
            $q[$var] = intval($_REQUEST[$var]);
        } elseif ($vals == 'date') {
            if (preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_REQUEST[$var])) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == null) {
            $q[$var] = '';
        } elseif ($vals == 'data') {
            if (substr($_REQUEST[$var], 0, 9) == 'index.php') {
                $q[$var] = $_REQUEST[$var];
            }
        }
    }
    if (isset($_GET['chart'])) {
        if (preg_match('/^[a-z0-9-]+$/', $_GET['chart'])) {
            $chart = sanitize_title($_GET['chart']);
            $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$chart}.php";
        }
    } else {
        $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php";
    }
    $url = add_query_arg($q, $url);
    $method = 'GET';
    $timeout = 90;
    $user_id = JETPACK_MASTER_USER;
    // means send the wp.com user_id
    $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 {
        if (!empty($get['headers']['content-type'])) {
            $type = $get['headers']['content-type'];
            if (substr($type, 0, 5) == 'image') {
                $img = $get['body'];
                header('Content-Type: ' . $type);
                header('Content-Length: ' . strlen($img));
                echo $img;
                die;
            }
        }
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        $body = stats_convert_admin_urls($body);
        echo $body;
    }
    if (isset($_GET['page']) && 'stats' === $_GET['page'] && !isset($_GET['chart'])) {
        JetpackTracking::record_user_event('wpa_page_view', array('path' => 'old_stats'));
    }
    if (isset($_GET['noheader'])) {
        die;
    }
}
示例#3
0
function stats_reports_page()
{
    if (isset($_GET['dashboard'])) {
        return stats_dashboard_widget_content();
    }
    $blog_id = stats_get_option('blog_id');
    $day = isset($_GET['day']) && preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_GET['day']) ? $_GET['day'] : false;
    $q = array('noheader' => 'true', 'proxy' => '', 'page' => 'stats', 'day' => $day, 'blog' => $blog_id, 'charset' => get_option('blog_charset'), 'color' => get_user_option('admin_color'), 'ssl' => is_ssl(), 'j' => JETPACK__API_VERSION);
    $args = array('view' => array('referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table'), 'numdays' => 'int', 'day' => 'date', 'unit' => array(1, 7, 31, 'human'), 'humanize' => array('true'), 'num' => 'int', 'summarize' => null, 'post' => 'int', 'width' => 'int', 'height' => 'int', 'data' => 'data');
    foreach ($args as $var => $vals) {
        if (!isset($_REQUEST[$var])) {
            continue;
        }
        if (is_array($vals)) {
            if (in_array($_REQUEST[$var], $vals)) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == 'int') {
            $q[$var] = intval($_REQUEST[$var]);
        } elseif ($vals == 'date') {
            if (preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_REQUEST[$var])) {
                $q[$var] = $_REQUEST[$var];
            }
        } elseif ($vals == null) {
            $q[$var] = '';
        } elseif ($vals == 'data') {
            if (substr($_REQUEST[$var], 0, 9) == 'index.php') {
                $q[$var] = $_REQUEST[$var];
            }
        }
    }
    if (isset($_REQUEST['chart'])) {
        if (preg_match('/^[a-z0-9-]+$/', $_REQUEST['chart'])) {
            $url = 'http://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$_GET['chart']}.php";
        }
    } else {
        $url = 'http://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php";
    }
    $url = add_query_arg($q, $url);
    $method = 'GET';
    $timeout = 90;
    $user_id = 1;
    // means send the wp.com user_id, not 1
    $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) {
        // @todo nicer looking error
        echo '<p>' . __('We were unable to get your stats just now. Please try again.', 'jetpack') . '</p>';
    } else {
        if (!empty($get['headers']['content-type'])) {
            $type = $get['headers']['content-type'];
            if (substr($type, 0, 5) == 'image') {
                header('Content-Type: ' . $type);
                die($get['body']);
            }
        }
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        $body = stats_convert_admin_urls($body);
        echo $body;
    }
    if (isset($_GET['noheader'])) {
        die;
    }
}