function jetpack_admin_ajax_tracks_callback() { // Check for nonce if (!isset($_REQUEST['tracksNonce']) || !wp_verify_nonce($_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce')) { wp_die('Permissions check failed.'); } if (!isset($_REQUEST['tracksEventName']) || !isset($_REQUEST['tracksEventType'])) { wp_die('No valid event name or type.'); } $tracks_data = array(); if ('click' === $_REQUEST['tracksEventType'] && isset($_REQUEST['tracksEventProp'])) { $tracks_data = array('clicked' => $_REQUEST['tracksEventProp']); } JetpackTracking::record_user_event($_REQUEST['tracksEventName'], $tracks_data); wp_send_json_success(); wp_die(); }
/** * Retrieves a WordPress.com SSO URL with appropriate query parameters or dies. * * @param boolean $reauth Should the user be forced to reauthenticate on WordPress.com? * @param array $args Optional query parameters. * @return string The WordPress.com SSO URL. */ function get_sso_url_or_die($reauth = false, $args = array()) { if (empty($reauth)) { $sso_redirect = $this->build_sso_url($args); } else { self::clear_wpcom_profile_cookies(); $sso_redirect = $this->build_reauth_and_sso_url($args); } // If there was an error retrieving the SSO URL, then error. if (is_wp_error($sso_redirect)) { $error_message = sanitize_text_field(sprintf('%s: %s', $sso_redirect->get_error_code(), $sso_redirect->get_error_message())); JetpackTracking::record_user_event('sso_login_redirect_failed', array('error_message' => $error_message)); wp_die($error_message); } return $sso_redirect; }
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…', '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; } }
function page_render() { $list_table = new Jetpack_Modules_List_Table(); $static_html = @file_get_contents(JETPACK__PLUGIN_DIR . '_inc/build/static.html'); // If static.html isn't there, there's nothing else we can do. if (false === $static_html) { esc_html_e('Error fetching static.html.', 'jetpack'); return; } // We have static.html so let's continue trying to fetch the others $noscript_notice = @file_get_contents(JETPACK__PLUGIN_DIR . '_inc/build/static-noscript-notice.html'); $version_notice = $rest_api_notice = @file_get_contents(JETPACK__PLUGIN_DIR . '_inc/build/static-version-notice.html'); $ie_notice = @file_get_contents(JETPACK__PLUGIN_DIR . '_inc/build/static-ie-notice.html'); $noscript_notice = str_replace('#HEADER_TEXT#', esc_html__('You have JavaScript disabled', 'jetpack'), $noscript_notice); $noscript_notice = str_replace('#TEXT#', esc_html__("Turn on JavaScript to unlock Jetpack's full potential!", 'jetpack'), $noscript_notice); $version_notice = str_replace('#HEADER_TEXT#', esc_html__('You are using an outdated version of WordPress', 'jetpack'), $version_notice); $version_notice = str_replace('#TEXT#', esc_html__("Update WordPress to unlock Jetpack's full potential!", 'jetpack'), $version_notice); $rest_api_notice = str_replace('#HEADER_TEXT#', esc_html(__('WordPress REST API is disabled', 'jetpack')), $rest_api_notice); $rest_api_notice = str_replace('#TEXT#', esc_html(__("Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack')), $rest_api_notice); $ie_notice = str_replace('#HEADER_TEXT#', esc_html__('You are using an unsupported browser version.', 'jetpack'), $ie_notice); $ie_notice = str_replace('#TEXT#', esc_html__("Update your browser to unlock Jetpack's full potential!", 'jetpack'), $ie_notice); ob_start(); $this->admin_page_top(); if ($this->is_wp_version_too_old()) { echo $version_notice; } if (!$this->is_rest_api_enabled()) { echo $rest_api_notice; } echo $noscript_notice; echo $ie_notice; ?> <div class="page-content configure"> <div class="frame top hide-if-no-js"> <div class="wrap"> <div class="manage-left"> <table class="table table-bordered fixed-top"> <thead> <tr> <th class="check-column"><input type="checkbox" class="checkall"></th> <th colspan="2"> <?php $list_table->unprotected_display_tablenav('top'); ?> <span class="filter-search"> <button type="button" class="button">Filter</button> </span> </th> </tr> </thead> </table> </div> </div><!-- /.wrap --> </div><!-- /.frame --> <div class="frame bottom"> <div class="wrap"> <div class="manage-right" style="display: none;"> <div class="bumper"> <form class="navbar-form" role="search"> <input type="hidden" name="page" value="jetpack_modules" /> <?php $list_table->search_box(__('Search', 'jetpack'), 'srch-term'); ?> <p><?php esc_html_e('View:', 'jetpack'); ?> </p> <div class="button-group filter-active"> <button type="button" class="button <?php if (empty($_GET['activated'])) { echo 'active'; } ?> "><?php esc_html_e('All', 'jetpack'); ?> </button> <button type="button" class="button <?php if (!empty($_GET['activated']) && 'true' == $_GET['activated']) { echo 'active'; } ?> " data-filter-by="activated" data-filter-value="true"><?php esc_html_e('Active', 'jetpack'); ?> </button> <button type="button" class="button <?php if (!empty($_GET['activated']) && 'false' == $_GET['activated']) { echo 'active'; } ?> " data-filter-by="activated" data-filter-value="false"><?php esc_html_e('Inactive', 'jetpack'); ?> </button> </div> <p><?php esc_html_e('Sort by:', 'jetpack'); ?> </p> <div class="button-group sort"> <button type="button" class="button <?php if (empty($_GET['sort_by'])) { echo 'active'; } ?> " data-sort-by="name"><?php esc_html_e('Alphabetical', 'jetpack'); ?> </button> <button type="button" class="button <?php if (!empty($_GET['sort_by']) && 'introduced' == $_GET['sort_by']) { echo 'active'; } ?> " data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e('Newest', 'jetpack'); ?> </button> <button type="button" class="button <?php if (!empty($_GET['sort_by']) && 'sort' == $_GET['sort_by']) { echo 'active'; } ?> " data-sort-by="sort"><?php esc_html_e('Popular', 'jetpack'); ?> </button> </div> <p><?php esc_html_e('Show:', 'jetpack'); ?> </p> <?php $list_table->views(); ?> </form> </div> </div> <div class="manage-left" style="width: 100%;"> <form class="jetpack-modules-list-table-form" onsubmit="return false;"> <table class="<?php echo implode(' ', $list_table->get_table_classes()); ?> "> <tbody id="the-list"> <?php $list_table->display_rows_or_placeholder(); ?> </tbody> </table> </form> </div> </div><!-- /.wrap --> </div><!-- /.frame --> </div><!-- /.content --> <?php $this->admin_page_bottom(); $page_content = ob_get_contents(); ob_end_clean(); echo str_replace('<div class="jp-loading-placeholder"><span class="dashicons dashicons-wordpress-alt"></span></div>', $page_content, $static_html); JetpackTracking::record_user_event('wpa_page_view', array('path' => 'old_settings')); }