| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Module Name: Jetpack Stats | |
| 3 | + * Module Name: Site Stats | |
| 4 | 4 | * Module Description: Collect valuable traffic stats and insights. |
| 5 | 5 | * Sort Order: 1 |
| 6 | 6 | * Recommendation Order: 2 |
| 7 | 7 | * First Introduced: 1.1 |
| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | * Recommendation Order: 2 |
| 7 | 7 | * First Introduced: 1.1 |
| 8 | 8 | * Requires Connection: Yes |
| 9 | 9 | * Auto Activate: Yes |
| 10 | - * Module Tags: Jetpack Stats, Site Stats, Recommended | |
| 10 | + * Module Tags: Site Stats, Recommended | |
| 11 | 11 | * Feature: Engagement |
| 12 | 12 | * Additional Search Queries: statistics, tracking, analytics, views, traffic, stats |
| 13 | 13 | * |
| 14 | 14 | * @package automattic/jetpack |
| @@ -17,31 +17,18 @@ | ||
| 17 | 17 | use Automattic\Jetpack\Connection\Client; |
| 18 | 18 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 19 | 19 | use Automattic\Jetpack\Connection\XMLRPC_Async_Call; |
| 20 | 20 | use Automattic\Jetpack\Redirect; |
| 21 | -use Automattic\Jetpack\Stats\Main as Stats; | |
| 22 | -use Automattic\Jetpack\Stats\Options as Stats_Options; | |
| 23 | -use Automattic\Jetpack\Stats\Tracking_Pixel as Stats_Tracking_Pixel; | |
| 24 | -use Automattic\Jetpack\Stats\XMLRPC_Provider as Stats_XMLRPC; | |
| 25 | -use Automattic\Jetpack\Stats_Admin\Dashboard as Stats_Dashboard; | |
| 26 | -use Automattic\Jetpack\Stats_Admin\Main as Stats_Main; | |
| 27 | -use Automattic\Jetpack\Stats_Admin\Notices as Stats_Notices; | |
| 28 | -use Automattic\Jetpack\Status\Host; | |
| 21 | +use Automattic\Jetpack\Status; | |
| 29 | 22 | use Automattic\Jetpack\Tracking; |
| 30 | 23 | |
| 31 | -if ( defined( 'STATS_DASHBOARD_SERVER' ) ) { | |
| 24 | +if ( defined( 'STATS_VERSION' ) ) { | |
| 32 | 25 | return; |
| 33 | 26 | } |
| 34 | 27 | |
| 35 | -define( 'STATS_DASHBOARD_SERVER', 'dashboard.wordpress.com' ); | |
| 28 | +define( 'STATS_VERSION', '9' ); | |
| 29 | +defined( 'STATS_DASHBOARD_SERVER' ) || define( 'STATS_DASHBOARD_SERVER', 'dashboard.wordpress.com' ); | |
| 36 | 30 | |
| 37 | -/** | |
| 38 | - * Stats content markers. | |
| 39 | - * Used to test for content vs script when parsing server-generated HTML. | |
| 40 | - */ | |
| 41 | -const STATS_BODY_MARKER = '<div id="statchart"'; | |
| 42 | -const STATS_CONTENT_MARKER = '<div class="gotonewdash">'; | |
| 43 | - | |
| 44 | 31 | add_action( 'jetpack_modules_loaded', 'stats_load' ); |
| 45 | 32 | |
| 46 | 33 | /** |
| 47 | 34 | * Load Stats. |
| @@ -51,12 +38,25 @@ | ||
| 51 | 38 | */ |
| 52 | 39 | function stats_load() { |
| 53 | 40 | Jetpack::enable_module_configurable( __FILE__ ); |
| 54 | 41 | |
| 42 | + // Generate the tracking code after wp() has queried for posts. | |
| 43 | + add_action( 'template_redirect', 'stats_template_redirect', 1 ); | |
| 44 | + | |
| 55 | 45 | add_action( 'wp_head', 'stats_admin_bar_head', 100 ); |
| 56 | 46 | |
| 47 | + add_action( 'wp_head', 'stats_hide_smile_css' ); | |
| 48 | + add_action( 'embed_head', 'stats_hide_smile_css' ); | |
| 49 | + | |
| 57 | 50 | add_action( 'jetpack_admin_menu', 'stats_admin_menu' ); |
| 58 | 51 | |
| 52 | + // Map stats caps. | |
| 53 | + add_filter( 'map_meta_cap', 'stats_map_meta_caps', 10, 3 ); | |
| 54 | + | |
| 55 | + add_action( 'admin_init', 'stats_merged_widget_admin_init' ); | |
| 56 | + | |
| 57 | + add_filter( 'jetpack_xmlrpc_unauthenticated_methods', 'stats_xmlrpc_methods' ); | |
| 58 | + | |
| 59 | 59 | add_filter( 'pre_option_db_version', 'stats_ignore_db_version' ); |
| 60 | 60 | |
| 61 | 61 | // Add an icon to see stats in WordPress.com for a particular post. |
| 62 | 62 | add_action( 'admin_print_styles-edit.php', 'jetpack_stats_load_admin_css' ); |
| @@ -63,10 +63,8 @@ | ||
| 63 | 63 | add_filter( 'manage_posts_columns', 'jetpack_stats_post_table' ); |
| 64 | 64 | add_filter( 'manage_pages_columns', 'jetpack_stats_post_table' ); |
| 65 | 65 | add_action( 'manage_posts_custom_column', 'jetpack_stats_post_table_cell', 10, 2 ); |
| 66 | 66 | add_action( 'manage_pages_custom_column', 'jetpack_stats_post_table_cell', 10, 2 ); |
| 67 | - // Filter for adding the Jetpack plugin version to tracking stats. | |
| 68 | - add_filter( 'stats_array', 'filter_stats_array_add_jp_version' ); | |
| 69 | 67 | |
| 70 | 68 | require_once __DIR__ . '/stats/class-jetpack-stats-upgrade-nudges.php'; |
| 71 | 69 | add_action( 'updating_jetpack_version', array( 'Jetpack_Stats_Upgrade_Nudges', 'unset_nudges_setting' ) ); |
| 72 | 70 | } |
| @@ -71,16 +69,55 @@ | ||
| 71 | 69 | add_action( 'updating_jetpack_version', array( 'Jetpack_Stats_Upgrade_Nudges', 'unset_nudges_setting' ) ); |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | /** |
| 73 | + * Delay conditional for current_user_can to after init. | |
| 74 | + * | |
| 75 | + * @access public | |
| 76 | + * @return void | |
| 77 | + */ | |
| 78 | +function stats_merged_widget_admin_init() { | |
| 79 | + if ( current_user_can( 'view_stats' ) ) { | |
| 80 | + add_action( 'load-index.php', 'stats_enqueue_dashboard_head' ); | |
| 81 | + add_action( 'jetpack_dashboard_widget', 'stats_jetpack_dashboard_widget' ); | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +/** | |
| 86 | + * Enqueue Stats Dashboard | |
| 87 | + * | |
| 88 | + * @access public | |
| 89 | + * @return void | |
| 90 | + */ | |
| 91 | +function stats_enqueue_dashboard_head() { | |
| 92 | + add_action( 'admin_head', 'stats_dashboard_head' ); | |
| 93 | +} | |
| 94 | + | |
| 95 | +/** | |
| 75 | 96 | * Checks if filter is set and dnt is enabled. |
| 76 | 97 | * |
| 77 | - * @deprecated 11.5 | |
| 78 | 98 | * @return bool |
| 79 | 99 | */ |
| 80 | 100 | function jetpack_is_dnt_enabled() { |
| 81 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::jetpack_is_dnt_enabled' ); | |
| 82 | - return Stats::jetpack_is_dnt_enabled(); | |
| 101 | + /** | |
| 102 | + * Filter the option which decides honor DNT or not. | |
| 103 | + * | |
| 104 | + * @module stats | |
| 105 | + * @since 6.1.0 | |
| 106 | + * | |
| 107 | + * @param bool false Honors DNT for clients who don't want to be tracked. Defaults to false. Set to true to enable. | |
| 108 | + */ | |
| 109 | + if ( false === apply_filters( 'jetpack_honor_dnt_header_for_stats', false ) ) { | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + | |
| 113 | + foreach ( $_SERVER as $name => $value ) { | |
| 114 | + if ( 'http_dnt' === strtolower( $name ) && 1 === (int) $value ) { | |
| 115 | + return true; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + return false; | |
| 83 | 120 | } |
| 84 | 121 | |
| 85 | 122 | /** |
| 86 | 123 | * Prevent sparkline img requests being redirected to upgrade.php. |
| @@ -93,9 +130,9 @@ | ||
| 93 | 130 | function stats_ignore_db_version( $version ) { |
| 94 | 131 | if ( |
| 95 | 132 | is_admin() && |
| 96 | 133 | isset( $_GET['page'] ) && 'stats' === $_GET['page'] && // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 97 | - isset( $_GET['chart'] ) && strpos( $_GET['chart'], 'admin-bar-hours' ) === 0 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput | |
| 134 | + isset( $_GET['chart'] ) && strpos( $_GET['chart'], 'admin-bar-hours' ) === 0 // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 98 | 135 | ) { |
| 99 | 136 | global $wp_db_version; |
| 100 | 137 | return $wp_db_version; |
| 101 | 138 | } |
| @@ -104,10 +141,8 @@ | ||
| 104 | 141 | |
| 105 | 142 | /** |
| 106 | 143 | * Maps view_stats cap to read cap as needed. |
| 107 | 144 | * |
| 108 | - * @deprecated 11.5 | |
| 109 | - * | |
| 110 | 145 | * @access public |
| 111 | 146 | * @param mixed $caps Caps. |
| 112 | 147 | * @param mixed $cap Cap. |
| 113 | 148 | * @param mixed $user_id User ID. |
| @@ -113,68 +148,191 @@ | ||
| 113 | 148 | * @param mixed $user_id User ID. |
| 114 | 149 | * @return array Possibly mapped capabilities for meta capability. |
| 115 | 150 | */ |
| 116 | 151 | function stats_map_meta_caps( $caps, $cap, $user_id ) { |
| 117 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::map_meta_caps' ); | |
| 118 | - return Stats::map_meta_caps( $caps, $cap, $user_id ); | |
| 152 | + // Map view_stats to exists. | |
| 153 | + if ( 'view_stats' === $cap ) { | |
| 154 | + $user = new WP_User( $user_id ); | |
| 155 | + $user_role = array_shift( $user->roles ); | |
| 156 | + $stats_roles = stats_get_option( 'roles' ); | |
| 157 | + | |
| 158 | + // Is the users role in the available stats roles? | |
| 159 | + if ( is_array( $stats_roles ) && in_array( $user_role, $stats_roles, true ) ) { | |
| 160 | + $caps = array( 'read' ); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + return $caps; | |
| 119 | 165 | } |
| 120 | 166 | |
| 121 | 167 | /** |
| 122 | 168 | * Stats Template Redirect. |
| 123 | 169 | * |
| 124 | - * @deprecated 11.5 | |
| 125 | 170 | * @access public |
| 126 | 171 | * @return void |
| 127 | 172 | */ |
| 128 | 173 | function stats_template_redirect() { |
| 129 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::template_redirect' ); | |
| 130 | - Stats::template_redirect(); | |
| 174 | + global $current_user; | |
| 175 | + | |
| 176 | + if ( is_feed() || is_robots() || is_trackback() || is_preview() || jetpack_is_dnt_enabled() ) { | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + | |
| 180 | + // Staging Sites should not generate tracking stats. | |
| 181 | + $status = new Status(); | |
| 182 | + if ( $status->is_staging_site() ) { | |
| 183 | + return; | |
| 184 | + } | |
| 185 | + | |
| 186 | + // Should we be counting this user's views? | |
| 187 | + if ( ! empty( $current_user->ID ) ) { | |
| 188 | + $count_roles = stats_get_option( 'count_roles' ); | |
| 189 | + if ( ! is_array( $count_roles ) || ! array_intersect( $current_user->roles, $count_roles ) ) { | |
| 190 | + return; | |
| 191 | + } | |
| 192 | + } | |
| 193 | + | |
| 194 | + add_action( 'wp_footer', 'stats_footer', 101 ); | |
| 195 | + add_action( 'web_stories_print_analytics', 'stats_footer' ); | |
| 196 | + | |
| 131 | 197 | } |
| 132 | 198 | |
| 133 | 199 | /** |
| 134 | 200 | * Stats Build View Data. |
| 135 | 201 | * |
| 136 | - * @deprecated 11.5 | |
| 137 | 202 | * @access public |
| 138 | 203 | * @return array. |
| 139 | 204 | */ |
| 140 | 205 | function stats_build_view_data() { |
| 141 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Tracking_Pixel::build_view_data' ); | |
| 142 | - return Stats_Tracking_Pixel::build_view_data(); | |
| 206 | + global $wp_the_query; | |
| 207 | + | |
| 208 | + $blog = Jetpack_Options::get_option( 'id' ); | |
| 209 | + $tz = get_option( 'gmt_offset' ); | |
| 210 | + $v = 'ext'; | |
| 211 | + $blog_url = wp_parse_url( site_url() ); | |
| 212 | + $srv = $blog_url['host']; | |
| 213 | + $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ); | |
| 214 | + if ( $wp_the_query->is_single || $wp_the_query->is_page || $wp_the_query->is_posts_page ) { | |
| 215 | + // Store and reset the queried_object and queried_object_id | |
| 216 | + // Otherwise, redirect_canonical() will redirect to home_url( '/' ) for show_on_front = page sites where home_url() is not all lowercase. | |
| 217 | + // Repro: | |
| 218 | + // 1. Set home_url = https://ExamPle.com/ | |
| 219 | + // 2. Set show_on_front = page | |
| 220 | + // 3. Set page_on_front = something | |
| 221 | + // 4. Visit https://example.com/ ! | |
| 222 | + $queried_object = isset( $wp_the_query->queried_object ) ? $wp_the_query->queried_object : null; | |
| 223 | + $queried_object_id = isset( $wp_the_query->queried_object_id ) ? $wp_the_query->queried_object_id : null; | |
| 224 | + try { | |
| 225 | + $post_obj = $wp_the_query->get_queried_object(); | |
| 226 | + $post = $post_obj instanceof WP_Post ? $post_obj->ID : '0'; | |
| 227 | + } finally { | |
| 228 | + $wp_the_query->queried_object = $queried_object; | |
| 229 | + $wp_the_query->queried_object_id = $queried_object_id; | |
| 230 | + } | |
| 231 | + } else { | |
| 232 | + $post = '0'; | |
| 233 | + } | |
| 234 | + | |
| 235 | + return compact( 'v', 'j', 'blog', 'post', 'tz', 'srv' ); | |
| 143 | 236 | } |
| 144 | 237 | |
| 145 | 238 | /** |
| 239 | + * Stats Footer. | |
| 240 | + * | |
| 241 | + * @access public | |
| 242 | + * @return void | |
| 243 | + */ | |
| 244 | +function stats_footer() { | |
| 245 | + $data = stats_build_view_data(); | |
| 246 | + if ( Jetpack_AMP_Support::is_amp_request() ) { | |
| 247 | + stats_render_amp_footer( $data ); | |
| 248 | + } else { | |
| 249 | + stats_render_footer( $data ); | |
| 250 | + } | |
| 251 | + | |
| 252 | +} | |
| 253 | + | |
| 254 | +/** | |
| 255 | + * Render the stats footer | |
| 256 | + * | |
| 257 | + * @param array $data Array of data for the JS stats tracker. | |
| 258 | + */ | |
| 259 | +function stats_render_footer( $data ) { | |
| 260 | + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 261 | + // When there is a way to use defer with enqueue, we can move to it and inline the custom data. | |
| 262 | + $script = 'https://stats.wp.com/e-' . gmdate( 'YW' ) . '.js'; | |
| 263 | + $data_stats_array = stats_array( $data ); | |
| 264 | + | |
| 265 | + $stats_footer = <<<END | |
| 266 | +<script src='{$script}' defer></script> | |
| 267 | +<script> | |
| 268 | + _stq = window._stq || []; | |
| 269 | + _stq.push([ 'view', {{$data_stats_array}} ]); | |
| 270 | + _stq.push([ 'clickTrackerInit', '{$data['blog']}', '{$data['post']}' ]); | |
| 271 | +</script> | |
| 272 | + | |
| 273 | +END; | |
| 274 | + // phpcs:enable | |
| 275 | + print $stats_footer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 276 | +} | |
| 277 | + | |
| 278 | +/** | |
| 279 | + * Render the stats footer for AMP output. | |
| 280 | + * | |
| 281 | + * @param array $data Array of data for the JS stats tracker. | |
| 282 | + */ | |
| 283 | +function stats_render_amp_footer( $data ) { | |
| 284 | + $data['host'] = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; // input var ok. | |
| 285 | + $data['rand'] = 'RANDOM'; // AMP placeholder. | |
| 286 | + $data['ref'] = 'DOCUMENT_REFERRER'; // AMP placeholder. | |
| 287 | + $data = array_map( 'rawurlencode', $data ); | |
| 288 | + $pixel_url = add_query_arg( $data, 'https://pixel.wp.com/g.gif' ); | |
| 289 | + | |
| 290 | + ?> | |
| 291 | + <amp-pixel src="<?php echo esc_url( $pixel_url ); ?>"></amp-pixel> | |
| 292 | + <?php | |
| 293 | +} | |
| 294 | + | |
| 295 | +/** | |
| 146 | 296 | * Stats Get Options. |
| 147 | 297 | * |
| 148 | - * @deprecated 11.5 | |
| 149 | - * | |
| 150 | 298 | * @access public |
| 151 | 299 | * @return array. |
| 152 | 300 | */ |
| 153 | 301 | function stats_get_options() { |
| 154 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::get_options' ); | |
| 155 | - return Stats_Options::get_options(); | |
| 302 | + $options = get_option( 'stats_options' ); | |
| 303 | + | |
| 304 | + if ( ! isset( $options['version'] ) || $options['version'] < STATS_VERSION ) { | |
| 305 | + $options = stats_upgrade_options( $options ); | |
| 306 | + } | |
| 307 | + | |
| 308 | + return $options; | |
| 156 | 309 | } |
| 157 | 310 | |
| 158 | 311 | /** |
| 159 | 312 | * Get Stats Options. |
| 160 | 313 | * |
| 161 | - * @deprecated 11.5 | |
| 162 | - * | |
| 163 | 314 | * @access public |
| 164 | 315 | * @param mixed $option Option. |
| 165 | 316 | * @return mixed|null. |
| 166 | 317 | */ |
| 167 | 318 | function stats_get_option( $option ) { |
| 168 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::get_option' ); | |
| 169 | - return Stats_Options::get_option( $option ); | |
| 319 | + $options = stats_get_options(); | |
| 320 | + | |
| 321 | + if ( 'blog_id' === $option ) { | |
| 322 | + return Jetpack_Options::get_option( 'id' ); | |
| 323 | + } | |
| 324 | + | |
| 325 | + if ( isset( $options[ $option ] ) ) { | |
| 326 | + return $options[ $option ]; | |
| 327 | + } | |
| 328 | + | |
| 329 | + return null; | |
| 170 | 330 | } |
| 171 | 331 | |
| 172 | 332 | /** |
| 173 | 333 | * Stats Set Options. |
| 174 | 334 | * |
| 175 | - * @deprecated 11.5 | |
| 176 | - * | |
| 177 | 335 | * @access public |
| 178 | 336 | * @param mixed $option Option. |
| 179 | 337 | * @param mixed $value Value. |
| 180 | 338 | * @return bool. |
| @@ -179,41 +337,95 @@ | ||
| 179 | 337 | * @param mixed $value Value. |
| 180 | 338 | * @return bool. |
| 181 | 339 | */ |
| 182 | 340 | function stats_set_option( $option, $value ) { |
| 183 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::set_option' ); | |
| 184 | - return Stats_Options::set_option( $option, $value ); | |
| 341 | + $options = stats_get_options(); | |
| 342 | + | |
| 343 | + $options[ $option ] = $value; | |
| 344 | + | |
| 345 | + return stats_set_options( $options ); | |
| 185 | 346 | } |
| 186 | 347 | |
| 187 | 348 | /** |
| 188 | 349 | * Stats Set Options. |
| 189 | 350 | * |
| 190 | - * @deprecated 11.5 | |
| 191 | - * | |
| 192 | 351 | * @access public |
| 193 | 352 | * @param mixed $options Options. |
| 194 | 353 | * @return bool |
| 195 | 354 | */ |
| 196 | 355 | function stats_set_options( $options ) { |
| 197 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::set_options' ); | |
| 198 | - return Stats_Options::set_options( $options ); | |
| 356 | + return update_option( 'stats_options', $options ); | |
| 199 | 357 | } |
| 200 | 358 | |
| 201 | 359 | /** |
| 202 | 360 | * Stats Upgrade Options. |
| 203 | 361 | * |
| 204 | - * @deprecated 11.5 | |
| 205 | - * | |
| 206 | 362 | * @access public |
| 207 | 363 | * @param mixed $options Options. |
| 208 | 364 | * @return array|bool |
| 209 | 365 | */ |
| 210 | 366 | function stats_upgrade_options( $options ) { |
| 211 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::upgrade_options' ); | |
| 212 | - return Stats_Options::upgrade_options( $options ); | |
| 367 | + $defaults = array( | |
| 368 | + 'admin_bar' => true, | |
| 369 | + 'roles' => array( 'administrator' ), | |
| 370 | + 'count_roles' => array(), | |
| 371 | + 'blog_id' => Jetpack_Options::get_option( 'id' ), | |
| 372 | + 'do_not_track' => true, // @todo | |
| 373 | + 'hide_smile' => true, | |
| 374 | + ); | |
| 375 | + | |
| 376 | + if ( isset( $options['reg_users'] ) ) { | |
| 377 | + if ( ! function_exists( 'get_editable_roles' ) ) { | |
| 378 | + require_once ABSPATH . 'wp-admin/includes/user.php'; | |
| 379 | + } | |
| 380 | + if ( $options['reg_users'] ) { | |
| 381 | + $options['count_roles'] = array_keys( get_editable_roles() ); | |
| 382 | + } | |
| 383 | + unset( $options['reg_users'] ); | |
| 384 | + } | |
| 385 | + | |
| 386 | + if ( is_array( $options ) && ! empty( $options ) ) { | |
| 387 | + $new_options = array_merge( $defaults, $options ); | |
| 388 | + } else { | |
| 389 | + $new_options = $defaults; | |
| 390 | + } | |
| 391 | + | |
| 392 | + $new_options['version'] = STATS_VERSION; | |
| 393 | + | |
| 394 | + if ( ! stats_set_options( $new_options ) ) { | |
| 395 | + return false; | |
| 396 | + } | |
| 397 | + | |
| 398 | + return $new_options; | |
| 213 | 399 | } |
| 214 | 400 | |
| 215 | 401 | /** |
| 402 | + * Creates the "array" string used as part of the JS tracker. | |
| 403 | + * | |
| 404 | + * @access public | |
| 405 | + * @param array $kvs KVS. | |
| 406 | + * @return string | |
| 407 | + */ | |
| 408 | +function stats_array( $kvs ) { | |
| 409 | + /** | |
| 410 | + * Filter the options added to the JavaScript Stats tracking code. | |
| 411 | + * | |
| 412 | + * @module stats | |
| 413 | + * | |
| 414 | + * @since 1.1.0 | |
| 415 | + * | |
| 416 | + * @param array $kvs Array of options about the site and page you're on. | |
| 417 | + */ | |
| 418 | + $kvs = (array) apply_filters( 'stats_array', $kvs ); | |
| 419 | + $kvs = array_map( 'addslashes', $kvs ); | |
| 420 | + $jskvs = array(); | |
| 421 | + foreach ( $kvs as $k => $v ) { | |
| 422 | + $jskvs[] = "$k:'$v'"; | |
| 423 | + } | |
| 424 | + return join( ',', $jskvs ); | |
| 425 | +} | |
| 426 | + | |
| 427 | +/** | |
| 216 | 428 | * Admin Pages. |
| 217 | 429 | * |
| 218 | 430 | * @access public |
| 219 | 431 | * @return void |
| @@ -223,9 +435,9 @@ | ||
| 223 | 435 | |
| 224 | 436 | // If we're at an old Stats URL, redirect to the new one. |
| 225 | 437 | // Don't even bother with caps, menu_page_url(), etc. Just do it. |
| 226 | 438 | if ( 'index.php' === $pagenow && isset( $_GET['page'] ) && 'stats' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 227 | - $redirect_url = str_replace( array( '/wp-admin/index.php?', '/wp-admin/?' ), '/wp-admin/admin.php?', isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : null ); | |
| 439 | + $redirect_url = str_replace( array( '/wp-admin/index.php?', '/wp-admin/?' ), '/wp-admin/admin.php?', $_SERVER['REQUEST_URI'] ); | |
| 228 | 440 | $relative_pos = strpos( $redirect_url, '/wp-admin/' ); |
| 229 | 441 | if ( false !== $relative_pos ) { |
| 230 | 442 | wp_safe_redirect( admin_url( substr( $redirect_url, $relative_pos + 10 ) ) ); |
| 231 | 443 | exit; |
| @@ -231,29 +443,10 @@ | ||
| 231 | 443 | exit; |
| 232 | 444 | } |
| 233 | 445 | } |
| 234 | 446 | |
| 235 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 236 | - if ( ! ( new Host() )->is_woa_site() && isset( $_GET['enable_new_stats'] ) && '1' === $_GET['enable_new_stats'] ) { | |
| 237 | - // Passing true enables Odyssey Stats. | |
| 238 | - // We're ignorning the return value for now. | |
| 239 | - Stats_Main::update_new_stats_status( true ); | |
| 240 | - } | |
| 241 | - | |
| 242 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 243 | - if ( ( new Host() )->is_woa_site() || ! Stats_Options::get_option( 'enable_odyssey_stats' ) || isset( $_GET['noheader'] ) ) { | |
| 244 | - // Show old Jetpack Stats interface for: | |
| 245 | - // - Atomic sites. | |
| 246 | - // - When the "enable_odyssey_stats" option is disabled. | |
| 247 | - // - When being shown in the adminbar outside of wp-admin. | |
| 248 | - $hook = add_submenu_page( 'jetpack', __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', 'jetpack_admin_ui_stats_report_page_wrapper' ); | |
| 249 | - add_action( "load-$hook", 'stats_reports_load' ); | |
| 250 | - } else { | |
| 251 | - // Enable the new Odyssey Stats experience. | |
| 252 | - $stats_dashboard = new Stats_Dashboard(); | |
| 253 | - $hook = add_submenu_page( 'jetpack', __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', array( $stats_dashboard, 'render' ) ); | |
| 254 | - add_action( "load-$hook", array( $stats_dashboard, 'admin_init' ) ); | |
| 255 | - } | |
| 447 | + $hook = add_submenu_page( 'jetpack', __( 'Site Stats', 'jetpack' ), __( 'Site Stats', 'jetpack' ), 'view_stats', 'stats', 'jetpack_admin_ui_stats_report_page_wrapper' ); | |
| 448 | + add_action( "load-$hook", 'stats_reports_load' ); | |
| 256 | 449 | } |
| 257 | 450 | |
| 258 | 451 | /** |
| 259 | 452 | * Stats Admin Path. |
| @@ -281,58 +474,24 @@ | ||
| 281 | 474 | |
| 282 | 475 | Jetpack_Admin_Page::load_wrapper_styles(); |
| 283 | 476 | add_action( 'admin_print_styles', 'stats_reports_css' ); |
| 284 | 477 | |
| 285 | - if ( ! empty( $_GET['nojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 478 | + if ( isset( $_GET['nojs'] ) && $_GET['nojs'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 286 | 479 | $parsed = wp_parse_url( admin_url() ); |
| 287 | 480 | // Remember user doesn't want JS. |
| 288 | - setcookie( 'stnojs', '1', time() + 172800, $parsed['path'], COOKIE_DOMAIN, is_ssl(), true ); // 2 days. | |
| 481 | + setcookie( 'stnojs', '1', time() + 172800, $parsed['path'] ); // 2 days. | |
| 289 | 482 | } |
| 290 | 483 | |
| 291 | - if ( ! empty( $_COOKIE['stnojs'] ) ) { | |
| 484 | + if ( isset( $_COOKIE['stnojs'] ) && $_COOKIE['stnojs'] ) { | |
| 292 | 485 | // Detect if JS is on. If so, remove cookie so next page load is via JS. |
| 293 | 486 | add_action( 'admin_print_footer_scripts', 'stats_js_remove_stnojs_cookie' ); |
| 294 | 487 | } elseif ( ! isset( $_GET['noheader'] ) && empty( $_GET['nojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 295 | 488 | // Normal page load. Load page content via JS. |
| 296 | 489 | add_action( 'admin_print_footer_scripts', 'stats_js_load_page_via_ajax' ); |
| 297 | - add_action( 'admin_print_footer_scripts', 'stats_script_dismiss_nudge_handler' ); | |
| 298 | 490 | } |
| 299 | 491 | } |
| 300 | 492 | |
| 301 | 493 | /** |
| 302 | - * JavaScript to dismiss the Odyssey nudge. | |
| 303 | - * | |
| 304 | - * @access public | |
| 305 | - * @return void | |
| 306 | - */ | |
| 307 | -function stats_script_dismiss_nudge_handler() { | |
| 308 | - ?> | |
| 309 | - <script type="text/javascript"> | |
| 310 | - function stats_odyssey_dismiss_nudge() { | |
| 311 | - // Hide the nudge UI, effectively dismissing it. | |
| 312 | - var element = document.getElementById( "stats-odyssey-nudge-main" ); | |
| 313 | - element.classList.toggle( "is-hidden" ); | |
| 314 | - // Send an AJAX request. | |
| 315 | - // Note we can provide a 'postponed_for' parameter to set the delay. | |
| 316 | - // Without a parameter it defaults to 30 days which is what we want here. | |
| 317 | - let nonce = <?php echo wp_json_encode( wp_create_nonce( 'wp_rest' ) ); ?>; | |
| 318 | - let url = <?php echo wp_json_encode( rest_url( '/jetpack/v4/stats-app/stats/notices' ) ); ?>; | |
| 319 | - let data = { | |
| 320 | - id: 'opt_in_new_stats', | |
| 321 | - status: 'postponed', | |
| 322 | - }; | |
| 323 | - jQuery.ajax({ | |
| 324 | - type: "POST", | |
| 325 | - url: url, | |
| 326 | - data: data, | |
| 327 | - headers: { "x-wp-nonce": nonce }, | |
| 328 | - }); | |
| 329 | - } | |
| 330 | - </script> | |
| 331 | - <?php | |
| 332 | -} | |
| 333 | - | |
| 334 | -/** | |
| 335 | 494 | * Stats Reports CSS. |
| 336 | 495 | * |
| 337 | 496 | * @access public |
| 338 | 497 | * @return void |
| @@ -348,9 +507,9 @@ | ||
| 348 | 507 | |
| 349 | 508 | #stats-loading-wrap p { |
| 350 | 509 | text-align: center; |
| 351 | 510 | font-size: 2em; |
| 352 | - margin-bottom: 3em; | |
| 511 | + margin: 7.5em 15px 0 0; | |
| 353 | 512 | height: 64px; |
| 354 | 513 | line-height: 64px; |
| 355 | 514 | } |
| 356 | 515 | </style> |
| @@ -385,11 +544,9 @@ | ||
| 385 | 544 | <script type="text/javascript"> |
| 386 | 545 | /* <![CDATA[ */ |
| 387 | 546 | if ( -1 == document.location.href.indexOf( 'noheader' ) ) { |
| 388 | 547 | jQuery( function( $ ) { |
| 389 | - const loadStatsUrl = new URL( document.location.href ); | |
| 390 | - loadStatsUrl.searchParams.append( 'noheader', 1 ); | |
| 391 | - $.get( loadStatsUrl.toString(), function( responseText ) { | |
| 548 | + $.get( document.location.href + '&noheader', function( responseText ) { | |
| 392 | 549 | $( '#stats-loading-wrap' ).replaceWith( responseText ); |
| 393 | 550 | $( '#jp-stats-wrap' )[0].dispatchEvent( new Event( 'stats-loaded' ) ); |
| 394 | 551 | } ); |
| 395 | 552 | } ); |
| @@ -407,8 +564,9 @@ | ||
| 407 | 564 | Jetpack_Admin_Page::wrap_ui( 'stats_reports_page', array( 'is-wide' => true ) ); |
| 408 | 565 | } else { |
| 409 | 566 | stats_reports_page(); |
| 410 | 567 | } |
| 568 | + | |
| 411 | 569 | } |
| 412 | 570 | |
| 413 | 571 | /** |
| 414 | 572 | * Stats Report Page. |
| @@ -416,13 +574,15 @@ | ||
| 416 | 574 | * @access public |
| 417 | 575 | * @param bool $main_chart_only (default: false) Main Chart Only. |
| 418 | 576 | */ |
| 419 | 577 | function stats_reports_page( $main_chart_only = false ) { |
| 578 | + | |
| 420 | 579 | if ( isset( $_GET['dashboard'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 421 | 580 | return stats_dashboard_widget_content(); |
| 422 | 581 | } |
| 423 | 582 | |
| 424 | - $blog_id = Stats_Options::get_option( 'blog_id' ); | |
| 583 | + $blog_id = stats_get_option( 'blog_id' ); | |
| 584 | + $stats_url = Redirect::get_url( 'calypso-stats' ); | |
| 425 | 585 | |
| 426 | 586 | if ( ! $main_chart_only && ! isset( $_GET['noheader'] ) && empty( $_GET['nojs'] ) && empty( $_COOKIE['stnojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 427 | 587 | $nojs_url = add_query_arg( 'nojs', '1' ); |
| 428 | 588 | $http = is_ssl() ? 'https' : 'http'; |
| @@ -430,9 +590,9 @@ | ||
| 430 | 590 | ?> |
| 431 | 591 | |
| 432 | 592 | <div id="jp-stats-wrap"> |
| 433 | 593 | <div class="wrap"> |
| 434 | - <h1><?php esc_html_e( 'Jetpack Stats', 'jetpack' ); ?> | |
| 594 | + <h2><?php esc_html_e( 'Site Stats', 'jetpack' ); ?> | |
| 435 | 595 | <?php |
| 436 | 596 | if ( current_user_can( 'jetpack_manage_modules' ) ) : |
| 437 | 597 | $i18n_headers = jetpack_get_module_i18n( 'stats' ); |
| 438 | 598 | ?> |
| @@ -460,10 +620,11 @@ | ||
| 460 | 620 | </h2> |
| 461 | 621 | </div> |
| 462 | 622 | <div id="stats-loading-wrap" class="wrap"> |
| 463 | 623 | <p class="hide-if-no-js"><img width="32" height="32" alt="<?php esc_attr_e( 'Loading…', 'jetpack' ); ?>" src="<?php echo esc_url( $static_url ); ?>" /></p> |
| 464 | - <p class="hide-if-js"><?php esc_html_e( 'Jetpack Stats work better with JavaScript enabled.', 'jetpack' ); ?><br /> | |
| 465 | - <a href="<?php echo esc_url( $nojs_url ); ?>"><?php esc_html_e( 'View Jetpack Stats without JavaScript', 'jetpack' ); ?></a>.</p> | |
| 624 | + <p style="font-size: 11pt; margin: 0;"><a href="<?php echo esc_url( $stats_url ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'View stats on WordPress.com right now', 'jetpack' ); ?></a></p> | |
| 625 | + <p class="hide-if-js"><?php esc_html_e( 'Your Site Stats work better with JavaScript enabled.', 'jetpack' ); ?><br /> | |
| 626 | + <a href="<?php echo esc_url( $nojs_url ); ?>"><?php esc_html_e( 'View Site Stats without JavaScript', 'jetpack' ); ?></a>.</p> | |
| 466 | 627 | </div> |
| 467 | 628 | </div> |
| 468 | 629 | <?php |
| 469 | 630 | return; |
| @@ -468,9 +629,9 @@ | ||
| 468 | 629 | <?php |
| 469 | 630 | return; |
| 470 | 631 | } |
| 471 | 632 | |
| 472 | - $day = isset( $_GET['day'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_GET['day'] ) ? $_GET['day'] : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput | |
| 633 | + $day = isset( $_GET['day'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_GET['day'] ) ? $_GET['day'] : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 473 | 634 | $q = array( |
| 474 | 635 | 'noheader' => 'true', |
| 475 | 636 | 'proxy' => '', |
| 476 | 637 | 'page' => 'stats', |
| @@ -501,37 +662,35 @@ | ||
| 501 | 662 | 'blog_subscribers' => 'int', |
| 502 | 663 | 'comment_subscribers' => null, |
| 503 | 664 | 'type' => array( 'wpcom', 'email', 'pending' ), |
| 504 | 665 | 'pagenum' => 'int', |
| 505 | - 'masterbar' => null, | |
| 506 | 666 | ); |
| 507 | 667 | foreach ( $args as $var => $vals ) { |
| 508 | 668 | if ( ! isset( $_REQUEST[ $var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 509 | 669 | continue; |
| 510 | 670 | } |
| 511 | - $val = wp_unslash( $_REQUEST[ $var ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 512 | 671 | if ( is_array( $vals ) ) { |
| 513 | - if ( in_array( $val, $vals, true ) ) { | |
| 514 | - $q[ $var ] = $val; | |
| 672 | + if ( in_array( $_REQUEST[ $var ], $vals, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 673 | + $q[ $var ] = $_REQUEST[ $var ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 515 | 674 | } |
| 516 | 675 | } elseif ( 'int' === $vals ) { |
| 517 | - $q[ $var ] = (int) $val; | |
| 676 | + $q[ $var ] = (int) $_REQUEST[ $var ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 518 | 677 | } elseif ( 'date' === $vals ) { |
| 519 | - if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $val ) ) { | |
| 520 | - $q[ $var ] = $val; | |
| 678 | + if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_REQUEST[ $var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 679 | + $q[ $var ] = $_REQUEST[ $var ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 521 | 680 | } |
| 522 | 681 | } elseif ( null === $vals ) { |
| 523 | 682 | $q[ $var ] = ''; |
| 524 | 683 | } elseif ( 'data' === $vals ) { |
| 525 | - if ( 'index.php' === substr( $val, 0, 9 ) ) { | |
| 526 | - $q[ $var ] = $val; | |
| 684 | + if ( 'index.php' === substr( $_REQUEST[ $var ], 0, 9 ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 685 | + $q[ $var ] = $_REQUEST[ $var ];// phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 527 | 686 | } |
| 528 | 687 | } |
| 529 | 688 | } |
| 530 | 689 | |
| 531 | 690 | if ( isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 532 | - if ( preg_match( '/^[a-z0-9-]+$/', $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput | |
| 533 | - $chart = sanitize_title( $_GET['chart'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput | |
| 691 | + if ( preg_match( '/^[a-z0-9-]+$/', $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 692 | + $chart = sanitize_title( $_GET['chart'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 534 | 693 | $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$chart}.php"; |
| 535 | 694 | } |
| 536 | 695 | } else { |
| 537 | 696 | $url = 'https://' . STATS_DASHBOARD_SERVER . '/wp-admin/index.php'; |
| @@ -560,17 +719,9 @@ | ||
| 560 | 719 | $body = stats_convert_post_titles( $get['body'] ); |
| 561 | 720 | $body = stats_convert_chart_urls( $body ); |
| 562 | 721 | $body = stats_convert_image_urls( $body ); |
| 563 | 722 | $body = stats_convert_admin_urls( $body ); |
| 564 | - | |
| 565 | - // The response can contain either the content to display OR | |
| 566 | - // the scripts for the chart UI. The following calls inspect the | |
| 567 | - // response, insert the Odyssey nudge as needed, and make sure | |
| 568 | - // everything is output correctly. | |
| 569 | - stats_print_header_section( $body ); | |
| 570 | - stats_print_odyssey_nudge( $body ); | |
| 571 | - stats_print_content_section( $body ); | |
| 572 | - stats_print_chart_scripts( $body ); | |
| 723 | + echo $body; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 573 | 724 | } |
| 574 | 725 | |
| 575 | 726 | if ( isset( $_GET['page'] ) && 'stats' === $_GET['page'] && ! isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 576 | 727 | $tracking = new Tracking(); |
| @@ -582,230 +733,8 @@ | ||
| 582 | 733 | } |
| 583 | 734 | } |
| 584 | 735 | |
| 585 | 736 | /** |
| 586 | - * Legacy Stats: Print Header Section | |
| 587 | - * | |
| 588 | - * @access public | |
| 589 | - * @param mixed $html HTML. | |
| 590 | - * @return void | |
| 591 | - */ | |
| 592 | -function stats_print_header_section( $html ) { | |
| 593 | - $header = stats_parse_header_section( $html ); | |
| 594 | - if ( $header !== '' ) { | |
| 595 | - echo $header; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 596 | - } | |
| 597 | -} | |
| 598 | - | |
| 599 | -/** | |
| 600 | - * Legacy Stats: Print Content Section | |
| 601 | - * | |
| 602 | - * @access public | |
| 603 | - * @param mixed $html HTML. | |
| 604 | - * @return void | |
| 605 | - */ | |
| 606 | -function stats_print_content_section( $html ) { | |
| 607 | - $content = stats_parse_content_section( $html ); | |
| 608 | - if ( $content !== '' ) { | |
| 609 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 610 | - } | |
| 611 | -} | |
| 612 | - | |
| 613 | -/** | |
| 614 | - * Legacy Stats: Print Chart Scripts | |
| 615 | - * | |
| 616 | - * @access public | |
| 617 | - * @param mixed $html HTML. | |
| 618 | - * @return void | |
| 619 | - */ | |
| 620 | -function stats_print_chart_scripts( $html ) { | |
| 621 | - if ( is_chart_scripts( $html ) ) { | |
| 622 | - echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 623 | - } | |
| 624 | -} | |
| 625 | - | |
| 626 | -/** | |
| 627 | - * Legacy Stats: Test for presence of chart scripts | |
| 628 | - * | |
| 629 | - * @access public | |
| 630 | - * @param mixed $html Input HTML that may or may not include the chart scripts. | |
| 631 | - * @return bool | |
| 632 | - */ | |
| 633 | -function is_chart_scripts( $html ) { | |
| 634 | - $pos = strpos( $html, STATS_CONTENT_MARKER ); | |
| 635 | - return $pos === false; | |
| 636 | -} | |
| 637 | - | |
| 638 | -/** | |
| 639 | - * Legacy Stats: Parse Header Section | |
| 640 | - * | |
| 641 | - * Returns the section of the content up to and including the date header. | |
| 642 | - * | |
| 643 | - * @access public | |
| 644 | - * @param mixed $html HTML. | |
| 645 | - * @return string | |
| 646 | - */ | |
| 647 | -function stats_parse_header_section( $html ) { | |
| 648 | - $head = strstr( $html, STATS_CONTENT_MARKER, true ); | |
| 649 | - // Enforce a string result instead of string|false. | |
| 650 | - if ( $head === false ) { | |
| 651 | - return ''; | |
| 652 | - } | |
| 653 | - return $head; | |
| 654 | -} | |
| 655 | - | |
| 656 | -/** | |
| 657 | - * Legacy Stats: Print Content Section | |
| 658 | - * | |
| 659 | - * Returns the section of the content excluding the date header. | |
| 660 | - * | |
| 661 | - * @access public | |
| 662 | - * @param mixed $html HTML. | |
| 663 | - * @return string | |
| 664 | - */ | |
| 665 | -function stats_parse_content_section( $html ) { | |
| 666 | - $body = strstr( $html, STATS_BODY_MARKER ); | |
| 667 | - // Enforce a string result instead of string|false. | |
| 668 | - if ( $body === false ) { | |
| 669 | - return ''; | |
| 670 | - } | |
| 671 | - return $body; | |
| 672 | -} | |
| 673 | - | |
| 674 | -/** | |
| 675 | - * Legacy Stats: Determine if we need to show the Odyssey upgrade nudge. | |
| 676 | - * | |
| 677 | - * @access public | |
| 678 | - * @return boolean | |
| 679 | - */ | |
| 680 | -function stats_should_show_odyssey_nudge() { | |
| 681 | - $stats_notices = ( new Stats_Notices() )->get_notices_to_show(); | |
| 682 | - return isset( $stats_notices[ Stats_Notices::OPT_IN_NEW_STATS_NOTICE_ID ] ) | |
| 683 | - && $stats_notices[ Stats_Notices::OPT_IN_NEW_STATS_NOTICE_ID ]; | |
| 684 | -} | |
| 685 | - | |
| 686 | -/** | |
| 687 | - * Legacy Stats: Print the Odyssey upgrade nudge. | |
| 688 | - * | |
| 689 | - * @access public | |
| 690 | - * @param mixed $html HTML. | |
| 691 | - * @return void | |
| 692 | - */ | |
| 693 | -function stats_print_odyssey_nudge( $html ) { | |
| 694 | - if ( ! stats_should_show_odyssey_nudge() ) { | |
| 695 | - return; | |
| 696 | - } | |
| 697 | - $pos = strpos( $html, STATS_CONTENT_MARKER ); | |
| 698 | - if ( $pos === false ) { | |
| 699 | - return; | |
| 700 | - } | |
| 701 | - $learn_url = Redirect::get_url( 'jetpack-stats-learn-more' ); | |
| 702 | - $redirect_url = admin_url( 'admin.php?page=stats&enable_new_stats=1' ); | |
| 703 | - ?> | |
| 704 | - <style> | |
| 705 | - .stats-odyssey-notice { | |
| 706 | - display: flex; | |
| 707 | - font-size: var( --font-body ); | |
| 708 | - | |
| 709 | - border: 1px solid var( --jp-gray-5 ); | |
| 710 | - border-left-color: var( --jp-black ); | |
| 711 | - border-left-width: 6px; | |
| 712 | - border-radius: 4px; | |
| 713 | - | |
| 714 | - margin-top: 24px; | |
| 715 | - background: white; | |
| 716 | - position: relative; | |
| 717 | - } | |
| 718 | - .stats-odyssey-notice--content { | |
| 719 | - padding: 24px 0 24px 30px; | |
| 720 | - font-size: 2em; | |
| 721 | - width: 100%; | |
| 722 | - } | |
| 723 | - .stats-odyssey-notice--content-header { | |
| 724 | - font-size: 24px; | |
| 725 | - line-height: 32px; | |
| 726 | - margin: 0; | |
| 727 | - margin-bottom: 8px; | |
| 728 | - } | |
| 729 | - .stats-odyssey-notice--content-text { | |
| 730 | - font-size: 16px; | |
| 731 | - margin: 0; | |
| 732 | - } | |
| 733 | - .stats-odyssey-notice--image-container { | |
| 734 | - background-image: url("/wp-content/plugins/jetpack/images/odyssey-upgrade/background.png"), url("/wp-content/plugins/jetpack/images/odyssey-upgrade/gradient.png"); | |
| 735 | - background-size: cover; | |
| 736 | - padding-right: 28px; | |
| 737 | - width: 100%; | |
| 738 | - } | |
| 739 | - .stats-odyssey-notice--close-button { | |
| 740 | - position: absolute; | |
| 741 | - top: 1rem; | |
| 742 | - right: 1rem; | |
| 743 | - background-color: transparent; | |
| 744 | - border: none; | |
| 745 | - cursor: pointer; | |
| 746 | - } | |
| 747 | - .stats-odyssey-notice--action-bar { | |
| 748 | - display: flex; | |
| 749 | - align-items: center; | |
| 750 | - margin-top: 24px; | |
| 751 | - } | |
| 752 | - .stats-odyssey-notice--primary-button { | |
| 753 | - margin-right: 18px; | |
| 754 | - padding-left: 20px; | |
| 755 | - padding-right: 20px; | |
| 756 | - font-size: 16px; | |
| 757 | - border-color: black; | |
| 758 | - background-color: black; | |
| 759 | - } | |
| 760 | - .stats-odyssey-notice--primary-button:hover { | |
| 761 | - border-color: #3c434a; | |
| 762 | - background-color: #3c434a; | |
| 763 | - } | |
| 764 | - .is-primary-link { | |
| 765 | - color: white; | |
| 766 | - text-decoration: none; | |
| 767 | - } | |
| 768 | - .is-primary-link:active { | |
| 769 | - color: white; | |
| 770 | - } | |
| 771 | - .is-primary-link:focus { | |
| 772 | - color: white; | |
| 773 | - box-shadow: none; | |
| 774 | - outline: none; | |
| 775 | - } | |
| 776 | - .is-primary-link:hover { | |
| 777 | - color: white; | |
| 778 | - } | |
| 779 | - .is-secondary-link { | |
| 780 | - color: black; | |
| 781 | - font-size: var( --font-body ); | |
| 782 | - } | |
| 783 | - .is-secondary-link:hover { | |
| 784 | - color: black; | |
| 785 | - } | |
| 786 | - .is-hidden { | |
| 787 | - display: none; | |
| 788 | - } | |
| 789 | - </style> | |
| 790 | - <div id="stats-odyssey-nudge-main" class="stats-odyssey-notice"> | |
| 791 | - <div class="stats-odyssey-notice--content"> | |
| 792 | - <h2 class="stats-odyssey-notice--content-header"><?php esc_html_e( 'Explore the new Jetpack Stats', 'jetpack' ); ?></h2> | |
| 793 | - <p class="stats-odyssey-notice--content-text"><?php esc_html_e( "We've added new stats and insights in a more modern and mobile friendly experience to help you grow your site.", 'jetpack' ); ?></p> | |
| 794 | - <div class="stats-odyssey-notice--action-bar"> | |
| 795 | - <button class="dops-button stats-odyssey-notice--primary-button"> | |
| 796 | - <a class="is-primary-link" href="<?php echo esc_url( $redirect_url ); ?>"><?php esc_html_e( 'Switch to new Stats', 'jetpack' ); ?></a> | |
| 797 | - </button> | |
| 798 | - <a class="is-secondary-link" href="<?php echo esc_url( $learn_url ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Learn about Stats', 'jetpack' ); ?> <svg xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle;" viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg></a> | |
| 799 | - </div> | |
| 800 | - </div> | |
| 801 | - <div class="stats-odyssey-notice--image-container"></div> | |
| 802 | - <button class="stats-odyssey-notice--close-button" onclick="stats_odyssey_dismiss_nudge()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button> | |
| 803 | - </div> | |
| 804 | - <?php | |
| 805 | -} | |
| 806 | - | |
| 807 | -/** | |
| 808 | 737 | * Stats Convert Admin Urls. |
| 809 | 738 | * |
| 810 | 739 | * @access public |
| 811 | 740 | * @param mixed $html HTML. |
| @@ -902,18 +831,20 @@ | ||
| 902 | 831 | return $matches[0]; |
| 903 | 832 | } |
| 904 | 833 | |
| 905 | 834 | /** |
| 906 | - * CSS to hide the tracking pixel smiley. | |
| 907 | - * It is now hidden for everyone (used to be visible if you had set the hide_smile option). | |
| 835 | + * Stats Hide Smile. | |
| 908 | 836 | * |
| 909 | 837 | * @access public |
| 910 | 838 | * @return void |
| 911 | 839 | */ |
| 912 | 840 | function stats_hide_smile_css() { |
| 913 | - ?> | |
| 914 | -<style>img#wpstats{display:none}</style> | |
| 915 | - <?php | |
| 841 | + $options = stats_get_options(); | |
| 842 | + if ( isset( $options['hide_smile'] ) && $options['hide_smile'] ) { | |
| 843 | + ?> | |
| 844 | +<style type='text/css'>img#wpstats{display:none}</style> | |
| 845 | + <?php | |
| 846 | + } | |
| 916 | 847 | } |
| 917 | 848 | |
| 918 | 849 | /** |
| 919 | 850 | * Stats Admin Bar Head. |
| @@ -921,9 +852,9 @@ | ||
| 921 | 852 | * @access public |
| 922 | 853 | * @return void |
| 923 | 854 | */ |
| 924 | 855 | function stats_admin_bar_head() { |
| 925 | - if ( ! Stats_Options::get_option( 'admin_bar' ) ) { | |
| 856 | + if ( ! stats_get_option( 'admin_bar' ) ) { | |
| 926 | 857 | return; |
| 927 | 858 | } |
| 928 | 859 | |
| 929 | 860 | if ( ! current_user_can( 'view_stats' ) ) { |
| @@ -965,46 +896,45 @@ | ||
| 965 | 896 | <?php |
| 966 | 897 | } |
| 967 | 898 | |
| 968 | 899 | /** |
| 969 | - * Gets the image source of the given stats chart. | |
| 900 | + * Stats AdminBar. | |
| 970 | 901 | * |
| 971 | - * @param string $chart Name of the chart. | |
| 972 | - * @param array $args Extra list of argument to use in the image source. | |
| 973 | - * @return string An image source. | |
| 902 | + * @access public | |
| 903 | + * @param mixed $wp_admin_bar WPAdminBar. | |
| 904 | + * @return void | |
| 974 | 905 | */ |
| 975 | -function stats_get_image_chart_src( $chart, $args = array() ) { | |
| 976 | - $url = add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ); | |
| 906 | +function stats_admin_bar_menu( &$wp_admin_bar ) { | |
| 907 | + $url = add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ); // no menu_page_url() blog-side. | |
| 977 | 908 | |
| 978 | - return add_query_arg( | |
| 979 | - array_merge( | |
| 909 | + $img_src = esc_attr( | |
| 910 | + add_query_arg( | |
| 980 | 911 | array( |
| 981 | 912 | 'noheader' => '', |
| 982 | 913 | 'proxy' => '', |
| 983 | - 'chart' => $chart, | |
| 914 | + 'chart' => 'admin-bar-hours-scale', | |
| 984 | 915 | ), |
| 985 | - $args | |
| 986 | - ), | |
| 987 | - $url | |
| 916 | + $url | |
| 917 | + ) | |
| 988 | 918 | ); |
| 989 | -} | |
| 919 | + $img_src_2x = esc_attr( | |
| 920 | + add_query_arg( | |
| 921 | + array( | |
| 922 | + 'noheader' => '', | |
| 923 | + 'proxy' => '', | |
| 924 | + 'chart' => 'admin-bar-hours-scale-2x', | |
| 925 | + ), | |
| 926 | + $url | |
| 927 | + ) | |
| 928 | + ); | |
| 990 | 929 | |
| 991 | -/** | |
| 992 | - * Stats AdminBar. | |
| 993 | - * | |
| 994 | - * @access public | |
| 995 | - * @param mixed $wp_admin_bar WPAdminBar. | |
| 996 | - * @return void | |
| 997 | - */ | |
| 998 | -function stats_admin_bar_menu( &$wp_admin_bar ) { | |
| 999 | - $img_src = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale' ) ); | |
| 1000 | - $img_src_2x = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale-2x' ) ); | |
| 1001 | - $alt = esc_attr( __( 'Stats', 'jetpack' ) ); | |
| 1002 | - $title = esc_attr( __( 'Views over 48 hours. Click for more Jetpack Stats.', 'jetpack' ) ); | |
| 930 | + $alt = esc_attr( __( 'Stats', 'jetpack' ) ); | |
| 1003 | 931 | |
| 932 | + $title = esc_attr( __( 'Views over 48 hours. Click for more Site Stats.', 'jetpack' ) ); | |
| 933 | + | |
| 1004 | 934 | $menu = array( |
| 1005 | 935 | 'id' => 'stats', |
| 1006 | - 'href' => add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ), // no menu_page_url() blog-side. | |
| 936 | + 'href' => $url, | |
| 1007 | 937 | 'title' => "<div><img src='$img_src' srcset='$img_src 1x, $img_src_2x 2x' width='112' height='24' alt='$alt' title='$title'></div>", |
| 1008 | 938 | ); |
| 1009 | 939 | |
| 1010 | 940 | $wp_admin_bar->add_menu( $menu ); |
| @@ -1021,9 +951,9 @@ | ||
| 1021 | 951 | * |
| 1022 | 952 | * @deprecated since 10.3. |
| 1023 | 953 | */ |
| 1024 | 954 | function stats_update_blog() { |
| 1025 | - _deprecated_function( __METHOD__, 'jetpack-10.3' ); | |
| 955 | + deprecated_function( __METHOD__, 'jetpack-10.3' ); | |
| 1026 | 956 | XMLRPC_Async_Call::add_call( 'jetpack.updateBlog', 0, stats_get_blog() ); |
| 1027 | 957 | } |
| 1028 | 958 | |
| 1029 | 959 | /** |
| @@ -1028,23 +958,73 @@ | ||
| 1028 | 958 | |
| 1029 | 959 | /** |
| 1030 | 960 | * Stats Get Blog. |
| 1031 | 961 | * |
| 1032 | - * @deprecated 11.5 | |
| 962 | + * @access public | |
| 963 | + * @return string | |
| 964 | + */ | |
| 965 | +function stats_get_blog() { | |
| 966 | + $home = wp_parse_url( trailingslashit( get_option( 'home' ) ) ); | |
| 967 | + $blog = array( | |
| 968 | + 'host' => $home['host'], | |
| 969 | + 'path' => $home['path'], | |
| 970 | + 'blogname' => get_option( 'blogname' ), | |
| 971 | + 'blogdescription' => get_option( 'blogdescription' ), | |
| 972 | + 'siteurl' => get_option( 'siteurl' ), | |
| 973 | + 'gmt_offset' => get_option( 'gmt_offset' ), | |
| 974 | + 'timezone_string' => get_option( 'timezone_string' ), | |
| 975 | + 'stats_version' => STATS_VERSION, | |
| 976 | + 'stats_api' => 'jetpack', | |
| 977 | + 'page_on_front' => get_option( 'page_on_front' ), | |
| 978 | + 'permalink_structure' => get_option( 'permalink_structure' ), | |
| 979 | + 'category_base' => get_option( 'category_base' ), | |
| 980 | + 'tag_base' => get_option( 'tag_base' ), | |
| 981 | + ); | |
| 982 | + $blog = array_merge( stats_get_options(), $blog ); | |
| 983 | + unset( $blog['roles'], $blog['blog_id'] ); | |
| 984 | + return stats_esc_html_deep( $blog ); | |
| 985 | +} | |
| 986 | + | |
| 987 | +/** | |
| 988 | + * Modified from stripslashes_deep() | |
| 1033 | 989 | * |
| 1034 | 990 | * @access public |
| 991 | + * @param mixed $value Value. | |
| 1035 | 992 | * @return string |
| 1036 | 993 | */ |
| 1037 | -function stats_get_blog() { | |
| 1038 | - _deprecated_function( __METHOD__, 'jetpack-11.5' ); | |
| 1039 | - return Stats_XMLRPC::init()->get_blog(); | |
| 994 | +function stats_esc_html_deep( $value ) { | |
| 995 | + if ( is_array( $value ) ) { | |
| 996 | + $value = array_map( 'stats_esc_html_deep', $value ); | |
| 997 | + } elseif ( is_object( $value ) ) { | |
| 998 | + $vars = get_object_vars( $value ); | |
| 999 | + foreach ( $vars as $key => $data ) { | |
| 1000 | + $value->{$key} = stats_esc_html_deep( $data ); | |
| 1001 | + } | |
| 1002 | + } elseif ( is_string( $value ) ) { | |
| 1003 | + $value = esc_html( $value ); | |
| 1004 | + } | |
| 1005 | + | |
| 1006 | + return $value; | |
| 1040 | 1007 | } |
| 1041 | 1008 | |
| 1042 | 1009 | /** |
| 1010 | + * Stats xmlrpc_methods function. | |
| 1011 | + * | |
| 1012 | + * @access public | |
| 1013 | + * @param mixed $methods Methods. | |
| 1014 | + * @return array | |
| 1015 | + */ | |
| 1016 | +function stats_xmlrpc_methods( $methods ) { | |
| 1017 | + $my_methods = array( | |
| 1018 | + 'jetpack.getBlog' => 'stats_get_blog', | |
| 1019 | + ); | |
| 1020 | + | |
| 1021 | + return array_merge( $methods, $my_methods ); | |
| 1022 | +} | |
| 1023 | + | |
| 1024 | +/** | |
| 1043 | 1025 | * Stats Dashboard Widget Options. |
| 1044 | 1026 | * |
| 1045 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1046 | - * | |
| 1047 | 1027 | * @access public |
| 1048 | 1028 | * @return array |
| 1049 | 1029 | */ |
| 1050 | 1030 | function stats_dashboard_widget_options() { |
| @@ -1065,21 +1045,18 @@ | ||
| 1065 | 1045 | unset( $options[ $key ] ); |
| 1066 | 1046 | } |
| 1067 | 1047 | } |
| 1068 | 1048 | |
| 1069 | - return array_merge( $defaults, $options ); | |
| 1049 | + return array_merge( $defaults, $options ); | |
| 1070 | 1050 | } |
| 1071 | 1051 | |
| 1072 | 1052 | /** |
| 1073 | 1053 | * Stats Dashboard Widget Control. |
| 1074 | 1054 | * |
| 1075 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1076 | - * | |
| 1077 | 1055 | * @access public |
| 1078 | 1056 | * @return void |
| 1079 | 1057 | */ |
| 1080 | 1058 | function stats_dashboard_widget_control() { |
| 1081 | - stats_dashboard_widget_controls_handle_submission(); | |
| 1082 | 1059 | $periods = array( |
| 1083 | 1060 | '1' => __( 'day', 'jetpack' ), |
| 1084 | 1061 | '7' => __( 'week', 'jetpack' ), |
| 1085 | 1062 | '31' => __( 'month', 'jetpack' ), |
| @@ -1090,56 +1067,28 @@ | ||
| 1090 | 1067 | '31' => __( 'the past month', 'jetpack' ), |
| 1091 | 1068 | '90' => __( 'the past quarter', 'jetpack' ), |
| 1092 | 1069 | '365' => __( 'the past year', 'jetpack' ), |
| 1093 | 1070 | ); |
| 1094 | - stats_dashboard_widget_controls_html( $intervals, $periods, stats_dashboard_widget_options() ); | |
| 1095 | -} | |
| 1096 | - | |
| 1097 | -/** | |
| 1098 | - * Handle widget controls form submission. | |
| 1099 | - * | |
| 1100 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1101 | - * | |
| 1102 | - * @access public | |
| 1103 | - * @return void | |
| 1104 | - */ | |
| 1105 | -function stats_dashboard_widget_controls_handle_submission() { | |
| 1106 | - $options = stats_dashboard_widget_options(); | |
| 1107 | - $defaults = array( | |
| 1071 | + $defaults = array( | |
| 1108 | 1072 | 'top' => 1, |
| 1109 | 1073 | 'search' => 7, |
| 1110 | 1074 | ); |
| 1111 | 1075 | |
| 1112 | - // Check if the correct form was submitted. | |
| 1113 | - if ( isset( $_POST['stats_id'] ) && 'dashboard_stats' === $_POST['stats_id'] ) { | |
| 1114 | - // Perform nonce verification. | |
| 1115 | - if ( | |
| 1116 | - isset( $_POST['dashboard-widget-nonce'] ) && | |
| 1117 | - wp_verify_nonce( filter_var( wp_unslash( $_POST['dashboard-widget-nonce'] ) ), 'edit-dashboard-widget_dashboard_stats' ) | |
| 1118 | - ) { | |
| 1119 | - // Update options. | |
| 1120 | - $options['chart'] = isset( $_POST['chart'] ) ? (int) $_POST['chart'] : 1; | |
| 1121 | - foreach ( array( 'top', 'search' ) as $key ) { | |
| 1122 | - $options[ $key ] = isset( $_POST[ $key ] ) ? (int) $_POST[ $key ] : $defaults[ $key ]; | |
| 1076 | + $options = stats_dashboard_widget_options(); | |
| 1077 | + | |
| 1078 | + if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['widget_id'] ) && 'dashboard_stats' === $_POST['widget_id'] ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 1079 | + if ( isset( $periods[ $_POST['chart'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 1080 | + $options['chart'] = $_POST['chart']; // phpcs:ignore WordPress.Security.NonceVerification | |
| 1081 | + } | |
| 1082 | + foreach ( array( 'top', 'search' ) as $key ) { | |
| 1083 | + if ( isset( $intervals[ $_POST[ $key ] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 1084 | + $options[ $key ] = $_POST[ $key ]; // phpcs:ignore WordPress.Security.NonceVerification | |
| 1085 | + } else { | |
| 1086 | + $options[ $key ] = $defaults[ $key ]; | |
| 1123 | 1087 | } |
| 1124 | - update_option( 'stats_dashboard_widget', $options ); | |
| 1125 | 1088 | } |
| 1089 | + update_option( 'stats_dashboard_widget', $options ); | |
| 1126 | 1090 | } |
| 1127 | -} | |
| 1128 | - | |
| 1129 | -/** | |
| 1130 | - * Output HTML for widget controls. | |
| 1131 | - * | |
| 1132 | - * @param array $intervals Array of intervals. | |
| 1133 | - * @param array $periods Array of periods. | |
| 1134 | - * @param array $options Array of options. | |
| 1135 | - * | |
| 1136 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1137 | - * | |
| 1138 | - * @access public | |
| 1139 | - * @return void | |
| 1140 | - */ | |
| 1141 | -function stats_dashboard_widget_controls_html( $intervals, $periods, $options ) { | |
| 1142 | 1091 | ?> |
| 1143 | 1092 | <p> |
| 1144 | 1093 | <label for="chart"><?php esc_html_e( 'Chart stats by', 'jetpack' ); ?></label> |
| 1145 | 1094 | <select id="chart" name="chart"> |
| @@ -1183,10 +1132,8 @@ | ||
| 1183 | 1132 | |
| 1184 | 1133 | /** |
| 1185 | 1134 | * Jetpack Stats Dashboard Widget. |
| 1186 | 1135 | * |
| 1187 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1188 | - * | |
| 1189 | 1136 | * @access public |
| 1190 | 1137 | * @return void |
| 1191 | 1138 | */ |
| 1192 | 1139 | function stats_jetpack_dashboard_widget() { |
| @@ -1193,9 +1140,9 @@ | ||
| 1193 | 1140 | ?> |
| 1194 | 1141 | <form id="stats_dashboard_widget_control" action="<?php echo esc_url( admin_url() ); ?>" method="post"> |
| 1195 | 1142 | <?php stats_dashboard_widget_control(); ?> |
| 1196 | 1143 | <?php wp_nonce_field( 'edit-dashboard-widget_dashboard_stats', 'dashboard-widget-nonce' ); ?> |
| 1197 | - <input type="hidden" name="stats_id" value="dashboard_stats" /> | |
| 1144 | + <input type="hidden" name="widget_id" value="dashboard_stats" /> | |
| 1198 | 1145 | <?php submit_button( __( 'Submit', 'jetpack' ) ); ?> |
| 1199 | 1146 | </form> |
| 1200 | 1147 | <button type="button" class="handlediv js-toggle-stats_dashboard_widget_control" aria-expanded="true"> |
| 1201 | 1148 | <span class="screen-reader-text"><?php esc_html_e( 'Configure', 'jetpack' ); ?></span> |
| @@ -1200,9 +1147,9 @@ | ||
| 1200 | 1147 | <button type="button" class="handlediv js-toggle-stats_dashboard_widget_control" aria-expanded="true"> |
| 1201 | 1148 | <span class="screen-reader-text"><?php esc_html_e( 'Configure', 'jetpack' ); ?></span> |
| 1202 | 1149 | <span class="toggle-indicator" aria-hidden="true"></span> |
| 1203 | 1150 | </button> |
| 1204 | - <div id="dashboard_stats" class="is-loading"> | |
| 1151 | + <div id="dashboard_stats"> | |
| 1205 | 1152 | <div class="inside"> |
| 1206 | 1153 | <div style="height: 250px;"></div> |
| 1207 | 1154 | </div> |
| 1208 | 1155 | </div> |
| @@ -1209,18 +1156,73 @@ | ||
| 1209 | 1156 | <?php |
| 1210 | 1157 | } |
| 1211 | 1158 | |
| 1212 | 1159 | /** |
| 1160 | + * JavaScript and CSS for dashboard widget. | |
| 1161 | + * | |
| 1162 | + * @access public | |
| 1163 | + * @return void | |
| 1164 | + */ | |
| 1165 | +function stats_dashboard_head() { | |
| 1166 | + ?> | |
| 1167 | +<script type="text/javascript"> | |
| 1168 | +/* <![CDATA[ */ | |
| 1169 | +jQuery( function($) { | |
| 1170 | + var dashStats = jQuery( '#dashboard_stats div.inside' ); | |
| 1171 | + | |
| 1172 | + if ( dashStats.find( '.dashboard-widget-control-form' ).length ) { | |
| 1173 | + return; | |
| 1174 | + } | |
| 1175 | + | |
| 1176 | + if ( ! dashStats.length ) { | |
| 1177 | + dashStats = jQuery( '#dashboard_stats div.dashboard-widget-content' ); | |
| 1178 | + var h = parseInt( dashStats.parent().height() ) - parseInt( dashStats.prev().height() ); | |
| 1179 | + var args = 'width=' + dashStats.width() + '&height=' + h.toString(); | |
| 1180 | + } else { | |
| 1181 | + if ( jQuery('#dashboard_stats' ).hasClass('postbox') ) { | |
| 1182 | + var args = 'width=' + ( dashStats.prev().width() * 2 ).toString(); | |
| 1183 | + } else { | |
| 1184 | + var args = 'width=' + ( dashStats.width() * 2 ).toString(); | |
| 1185 | + } | |
| 1186 | + } | |
| 1187 | + | |
| 1188 | + dashStats | |
| 1189 | + .not( '.dashboard-widget-control' ) | |
| 1190 | + .load( 'admin.php?page=stats&noheader&dashboard&' + args ); | |
| 1191 | + | |
| 1192 | + jQuery( window ).one( 'resize', function() { | |
| 1193 | + jQuery( '#stat-chart' ).css( 'width', 'auto' ); | |
| 1194 | + } ); | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + // Widget settings toggle container. | |
| 1198 | + var toggle = $( '.js-toggle-stats_dashboard_widget_control' ); | |
| 1199 | + | |
| 1200 | + // Move the toggle in the widget header. | |
| 1201 | + toggle.appendTo( '#jetpack_summary_widget .handle-actions' ); | |
| 1202 | + | |
| 1203 | + // Toggle settings when clicking on it. | |
| 1204 | + toggle.show().click( function( e ) { | |
| 1205 | + e.preventDefault(); | |
| 1206 | + e.stopImmediatePropagation(); | |
| 1207 | + $( this ).parent().toggleClass( 'controlVisible' ); | |
| 1208 | + $( '#stats_dashboard_widget_control' ).slideToggle(); | |
| 1209 | + } ); | |
| 1210 | +} ); | |
| 1211 | +/* ]]> */ | |
| 1212 | +</script> | |
| 1213 | + <?php | |
| 1214 | +} | |
| 1215 | + | |
| 1216 | +/** | |
| 1213 | 1217 | * Stats Dashboard Widget Content. |
| 1214 | 1218 | * |
| 1215 | - * TODO: This should be moved into class-jetpack-stats-dashboard-widget.php. | |
| 1216 | - * | |
| 1217 | 1219 | * @access public |
| 1218 | 1220 | * @return void |
| 1219 | 1221 | */ |
| 1220 | 1222 | function stats_dashboard_widget_content() { |
| 1221 | - $width = isset( $_GET['width'] ) ? intval( $_GET['width'] ) / 2 : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1222 | - $height = isset( $_GET['height'] ) ? intval( $_GET['height'] ) - 36 : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1223 | + $width = isset( $_GET['width'] ) ? (int) ( $_GET['width'] / 2 ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1224 | + $height = isset( $_GET['height'] ) ? (int) $_GET['height'] - 36 : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1223 | 1225 | if ( ! $width || $width < 250 ) { |
| 1224 | 1226 | $width = 370; |
| 1225 | 1227 | } |
| 1226 | 1228 | if ( ! $height || $height < 230 ) { |
| @@ -1227,9 +1229,9 @@ | ||
| 1227 | 1229 | $height = 180; |
| 1228 | 1230 | } |
| 1229 | 1231 | |
| 1230 | 1232 | $_width = $width - 5; |
| 1231 | - $_height = $height - 5; | |
| 1233 | + $_height = $height - ( $GLOBALS['is_winIE'] ? 16 : 5 ); // Hack! @todo Remove WordPress 5.8 is minimum. IE should be fully deprecated. | |
| 1232 | 1234 | |
| 1233 | 1235 | $options = stats_dashboard_widget_options(); |
| 1234 | 1236 | $blog_id = Jetpack_Options::get_option( 'id' ); |
| 1235 | 1237 | |
| @@ -1268,9 +1270,9 @@ | ||
| 1268 | 1270 | $post_ids = array(); |
| 1269 | 1271 | |
| 1270 | 1272 | $csv_end_date = current_time( 'Y-m-d' ); |
| 1271 | 1273 | $csv_args = array( |
| 1272 | - 'top' => "&limit=6&end=$csv_end_date", | |
| 1274 | + 'top' => "&limit=8&end=$csv_end_date", | |
| 1273 | 1275 | 'search' => "&limit=5&end=$csv_end_date", |
| 1274 | 1276 | ); |
| 1275 | 1277 | |
| 1276 | 1278 | $top_posts = stats_get_csv( 'postviews', "days=$options[top]$csv_args[top]" ); |
| @@ -1282,9 +1284,9 @@ | ||
| 1282 | 1284 | $post_ids[] = $post['post_id']; |
| 1283 | 1285 | } |
| 1284 | 1286 | |
| 1285 | 1287 | // Cache. |
| 1286 | - get_posts( array( 'include' => implode( ',', array_unique( $post_ids ) ) ) ); | |
| 1288 | + get_posts( array( 'include' => join( ',', array_unique( $post_ids ) ) ) ); | |
| 1287 | 1289 | |
| 1288 | 1290 | $searches = array(); |
| 1289 | 1291 | $search_terms = stats_get_csv( 'searchterms', "days=$options[search]$csv_args[search]" ); |
| 1290 | 1292 | foreach ( $search_terms as $search_term ) { |
| @@ -1295,73 +1297,73 @@ | ||
| 1295 | 1297 | } |
| 1296 | 1298 | |
| 1297 | 1299 | ?> |
| 1298 | 1300 | <div id="stats-info"> |
| 1299 | - <div id="stats-info-container"> | |
| 1300 | - <div class="stats-info-header"> | |
| 1301 | - <h2><?php esc_html_e( 'Highlights', 'jetpack' ); ?></h2> | |
| 1302 | - <div class="stats-info-header-right"> | |
| 1303 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=stats' ) ); ?>" class="button button-primary"> | |
| 1304 | - <?php esc_html_e( 'View detailed stats', 'jetpack' ); ?> | |
| 1305 | - </a> | |
| 1306 | - </div> | |
| 1307 | - </div> | |
| 1308 | - <div class="stats-info-content"> | |
| 1309 | - <div id="top-posts" class="stats-section"> | |
| 1310 | - <div class="stats-section-inner"> | |
| 1311 | - <h3 class="heading"><?php esc_html_e( 'Top Posts', 'jetpack' ); ?></h3> | |
| 1312 | - <?php | |
| 1313 | - if ( empty( $top_posts ) ) { | |
| 1314 | - ?> | |
| 1315 | - <p class="nothing"><?php esc_html_e( 'Sorry, nothing to report.', 'jetpack' ); ?></p> | |
| 1316 | - <?php | |
| 1317 | - } else { | |
| 1318 | - foreach ( $top_posts as $post ) { | |
| 1319 | - if ( ! get_post( $post['post_id'] ) ) { | |
| 1320 | - continue; | |
| 1321 | - } | |
| 1322 | - ?> | |
| 1323 | - <p> | |
| 1324 | - <?php | |
| 1325 | - printf( | |
| 1326 | - esc_html( | |
| 1327 | - /* Translators: Stats dashboard widget Post list with view count: "Post Title 1 View (or Views if plural)". */ | |
| 1328 | - _n( '%1$s %2$s View', '%1$s %2$s Views', $post['views'], 'jetpack' ) | |
| 1329 | - ), | |
| 1330 | - '<a href="' . esc_url( get_permalink( $post['post_id'] ) ) . '">' . esc_html( get_the_title( $post['post_id'] ) ) . '</a>', | |
| 1331 | - esc_html( number_format_i18n( $post['views'] ) ) | |
| 1332 | - ); | |
| 1333 | - ?> | |
| 1334 | - </p> | |
| 1335 | - <?php | |
| 1336 | - } | |
| 1301 | + <div id="top-posts" class='stats-section'> | |
| 1302 | + <div class="stats-section-inner"> | |
| 1303 | + <h3 class="heading"><?php esc_html_e( 'Top Posts', 'jetpack' ); ?></h3> | |
| 1304 | + <?php | |
| 1305 | + if ( empty( $top_posts ) ) { | |
| 1306 | + ?> | |
| 1307 | + <p class="nothing"><?php esc_html_e( 'Sorry, nothing to report.', 'jetpack' ); ?></p> | |
| 1308 | + <?php | |
| 1309 | + } else { | |
| 1310 | + foreach ( $top_posts as $post ) { | |
| 1311 | + if ( ! get_post( $post['post_id'] ) ) { | |
| 1312 | + continue; | |
| 1337 | 1313 | } |
| 1338 | 1314 | ?> |
| 1339 | - </div> | |
| 1340 | - </div> | |
| 1341 | - <div id="top-search" class="stats-section"> | |
| 1342 | - <div class="stats-section-inner"> | |
| 1343 | - <h3 class="heading"><?php esc_html_e( 'Top Searches', 'jetpack' ); ?></h3> | |
| 1315 | + <p> | |
| 1344 | 1316 | <?php |
| 1345 | - if ( empty( $searches ) ) { | |
| 1346 | - ?> | |
| 1347 | - <p class="nothing"><?php esc_html_e( 'Sorry, nothing to report.', 'jetpack' ); ?></p> | |
| 1348 | - <?php | |
| 1349 | - } else { | |
| 1350 | - foreach ( $searches as $search_term_item ) { | |
| 1351 | - printf( | |
| 1352 | - '<p>%s</p>', | |
| 1353 | - esc_html( $search_term_item ) | |
| 1354 | - ); | |
| 1355 | - } | |
| 1356 | - } | |
| 1317 | + printf( | |
| 1318 | + esc_html( | |
| 1319 | + /* Translators: Stats dashboard widget Post list with view count: "Post Title 1 View (or Views if plural)". */ | |
| 1320 | + _n( '%1$s %2$s View', '%1$s %2$s Views', $post['views'], 'jetpack' ) | |
| 1321 | + ), | |
| 1322 | + '<a href="' . esc_url( get_permalink( $post['post_id'] ) ) . '">' . esc_html( get_the_title( $post['post_id'] ) ) . '</a>', | |
| 1323 | + esc_html( number_format_i18n( $post['views'] ) ) | |
| 1324 | + ); | |
| 1357 | 1325 | ?> |
| 1358 | - </div> | |
| 1359 | - </div> | |
| 1326 | + </p> | |
| 1327 | + <?php | |
| 1328 | + } | |
| 1329 | + } | |
| 1330 | + ?> | |
| 1360 | 1331 | </div> |
| 1361 | 1332 | </div> |
| 1333 | + <div id="top-search" class='stats-section'> | |
| 1334 | + <div class="stats-section-inner"> | |
| 1335 | + <h3 class="heading"><?php esc_html_e( 'Top Searches', 'jetpack' ); ?></h3> | |
| 1336 | + <?php | |
| 1337 | + if ( empty( $searches ) ) { | |
| 1338 | + ?> | |
| 1339 | + <p class="nothing"><?php esc_html_e( 'Sorry, nothing to report.', 'jetpack' ); ?></p> | |
| 1340 | + <?php | |
| 1341 | + } else { | |
| 1342 | + foreach ( $searches as $search_term_item ) { | |
| 1343 | + printf( | |
| 1344 | + '<p>%s</p>', | |
| 1345 | + esc_html( $search_term_item ) | |
| 1346 | + ); | |
| 1347 | + } | |
| 1348 | + } | |
| 1349 | + ?> | |
| 1350 | + </div> | |
| 1351 | + </div> | |
| 1362 | 1352 | </div> |
| 1353 | +<div class="clear"></div> | |
| 1354 | +<div class="stats-view-all"> | |
| 1363 | 1355 | <?php |
| 1356 | + $stats_day_url = Redirect::get_url( 'calypso-stats-day' ); | |
| 1357 | + printf( | |
| 1358 | + '<a class="button" target="_blank" rel="noopener noreferrer" href="%1$s">%2$s</a>', | |
| 1359 | + esc_url( $stats_day_url ), | |
| 1360 | + esc_html__( 'View all stats', 'jetpack' ) | |
| 1361 | + ); | |
| 1362 | + ?> | |
| 1363 | +</div> | |
| 1364 | +<div class="clear"></div> | |
| 1365 | + <?php | |
| 1364 | 1366 | exit; |
| 1365 | 1367 | } |
| 1366 | 1368 | |
| 1367 | 1369 | /** |
| @@ -1378,11 +1380,11 @@ | ||
| 1378 | 1380 | $error = md5( wp_json_encode( compact( 'get', 'url' ) ) ); |
| 1379 | 1381 | Jetpack::state( $state_name, $error ); |
| 1380 | 1382 | if ( $error !== $previous_error ) { |
| 1381 | 1383 | ?> |
| 1382 | - <div class="wrap"> | |
| 1383 | - <p><?php esc_html_e( 'We were unable to get your stats just now. Please reload this page to try again.', 'jetpack' ); ?></p> | |
| 1384 | - </div> | |
| 1384 | + <div class="wrap"> | |
| 1385 | + <p><?php esc_html_e( 'We were unable to get your stats just now. Please reload this page to try again.', 'jetpack' ); ?></p> | |
| 1386 | + </div> | |
| 1385 | 1387 | <?php |
| 1386 | 1388 | return; |
| 1387 | 1389 | } |
| 1388 | 1390 | ?> |
| @@ -1387,39 +1389,43 @@ | ||
| 1387 | 1389 | } |
| 1388 | 1390 | ?> |
| 1389 | 1391 | <div class="wrap"> |
| 1390 | 1392 | <p> |
| 1391 | - <?php | |
| 1392 | - printf( | |
| 1393 | - /* translators: placeholder is an a href for a support site. */ | |
| 1394 | - esc_html__( 'We were unable to get your stats just now. Please reload this page to try again. If this error persists, please contact %1$s. In your report, please include the information below.', 'jetpack' ), | |
| 1395 | - sprintf( | |
| 1396 | - '<a href="https://support.wordpress.com/contact/?jetpack=needs-service">%s</a>', | |
| 1397 | - esc_html__( 'Jetpack Support', 'jetpack' ) | |
| 1398 | - ) | |
| 1399 | - ); | |
| 1400 | - ?> | |
| 1401 | - </p> | |
| 1402 | - <pre class="stats-widget-error"> | |
| 1403 | - User Agent: "<?php echo isset( $_SERVER['HTTP_USER_AGENT'] ) ? esc_html( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>" | |
| 1404 | - Page URL: "http<?php echo ( is_ssl() ? 's' : '' ) . '://' . esc_html( ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : '' ) . ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>" | |
| 1405 | - API URL: "<?php echo esc_url( $url ); ?>" | |
| 1406 | - <?php | |
| 1407 | - if ( is_wp_error( $get ) ) { | |
| 1408 | - foreach ( $get->get_error_codes() as $code ) { | |
| 1409 | - foreach ( $get->get_error_messages( $code ) as $message ) { | |
| 1410 | - print esc_html( $code ) . ': "' . esc_html( $message ) . '"'; | |
| 1411 | - } | |
| 1393 | + <?php | |
| 1394 | + printf( | |
| 1395 | + /* translators: placeholder is an a href for a support site. */ | |
| 1396 | + esc_html__( 'We were unable to get your stats just now. Please reload this page to try again. If this error persists, please contact %1$s. In your report, please include the information below.', 'jetpack' ), | |
| 1397 | + sprintf( | |
| 1398 | + '<a href="https://support.wordpress.com/contact/?jetpack=needs-service">%s</a>', | |
| 1399 | + esc_html__( 'Jetpack Support', 'jetpack' ) | |
| 1400 | + ) | |
| 1401 | + ); | |
| 1402 | + ?> | |
| 1403 | + </p> | |
| 1404 | + <pre> | |
| 1405 | + User Agent: "<?php echo esc_html( $_SERVER['HTTP_USER_AGENT'] ); ?>" | |
| 1406 | + Page URL: "http<?php echo ( is_ssl() ? 's' : '' ) . '://' . esc_html( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); ?>" | |
| 1407 | + API URL: "<?php echo esc_url( $url ); ?>" | |
| 1408 | + <?php | |
| 1409 | + if ( is_wp_error( $get ) ) { | |
| 1410 | + foreach ( $get->get_error_codes() as $code ) { | |
| 1411 | + foreach ( $get->get_error_messages( $code ) as $message ) { | |
| 1412 | + ?> | |
| 1413 | + <?php print esc_html( $code ) . ': "' . esc_html( $message ) . '"'; ?> | |
| 1414 | + | |
| 1415 | + <?php | |
| 1412 | 1416 | } |
| 1413 | - } else { | |
| 1414 | - $get_code = wp_remote_retrieve_response_code( $get ); | |
| 1415 | - $content_length = strlen( wp_remote_retrieve_body( $get ) ); | |
| 1416 | - ?> | |
| 1417 | - Response code: "<?php print esc_html( $get_code ); ?>" | |
| 1418 | - Content length: "<?php print esc_html( $content_length ); ?>" | |
| 1419 | - <?php | |
| 1420 | 1417 | } |
| 1418 | + } else { | |
| 1419 | + $get_code = wp_remote_retrieve_response_code( $get ); | |
| 1420 | + $content_length = strlen( wp_remote_retrieve_body( $get ) ); | |
| 1421 | 1421 | ?> |
| 1422 | +Response code: "<?php print esc_html( $get_code ); ?>" | |
| 1423 | +Content length: "<?php print esc_html( $content_length ); ?>" | |
| 1424 | + | |
| 1425 | + <?php | |
| 1426 | + } | |
| 1427 | + ?> | |
| 1422 | 1428 | </pre> |
| 1423 | 1429 | </div> |
| 1424 | 1430 | <?php |
| 1425 | 1431 | } |
| @@ -1563,9 +1569,9 @@ | ||
| 1563 | 1569 | * @return string |
| 1564 | 1570 | */ |
| 1565 | 1571 | function jetpack_stats_api_path( $resource = '' ) { |
| 1566 | 1572 | $resource = ltrim( $resource, '/' ); |
| 1567 | - return sprintf( '/sites/%d/stats/%s', Stats_Options::get_option( 'blog_id' ), $resource ); | |
| 1573 | + return sprintf( '/sites/%d/stats/%s', stats_get_option( 'blog_id' ), $resource ); | |
| 1568 | 1574 | } |
| 1569 | 1575 | |
| 1570 | 1576 | /** |
| 1571 | 1577 | * Fetches stats data from the REST API. Caches locally for 5 minutes. |
| @@ -1571,15 +1577,13 @@ | ||
| 1571 | 1577 | * Fetches stats data from the REST API. Caches locally for 5 minutes. |
| 1572 | 1578 | * |
| 1573 | 1579 | * @link: https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/stats/ |
| 1574 | 1580 | * @access public |
| 1575 | - * @deprecated 11.5 Use WPCOM_Stats available methodsinstead. | |
| 1576 | 1581 | * @param array $args (default: array()) The args that are passed to the endpoint. |
| 1577 | 1582 | * @param string $resource (default: '') Optional sub-endpoint following /stats/. |
| 1578 | 1583 | * @return array|WP_Error. |
| 1579 | 1584 | */ |
| 1580 | 1585 | function stats_get_from_restapi( $args = array(), $resource = '' ) { |
| 1581 | - _deprecated_function( __METHOD__, 'jetpack-11.5', 'Please checkout the methods available in Automattic\Jetpack\Stats\WPCOM_Stats' ); | |
| 1582 | 1586 | $endpoint = jetpack_stats_api_path( $resource ); |
| 1583 | 1587 | $api_version = '1.1'; |
| 1584 | 1588 | $args = wp_parse_args( $args, array() ); |
| 1585 | 1589 | $cache_key = md5( implode( '|', array( $endpoint, $api_version, wp_json_encode( $args ) ) ) ); |
| @@ -1648,22 +1652,13 @@ | ||
| 1648 | 1652 | // Adds a stats link on the edit posts page. |
| 1649 | 1653 | if ( ! current_user_can( 'view_stats' ) || ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ) { |
| 1650 | 1654 | return $columns; |
| 1651 | 1655 | } |
| 1652 | - | |
| 1653 | 1656 | // Array-Fu to add before comments. |
| 1654 | 1657 | $pos = array_search( 'comments', array_keys( $columns ), true ); |
| 1655 | - | |
| 1656 | - // Fallback to the last position if the post type does not support comments. | |
| 1657 | 1658 | if ( ! is_int( $pos ) ) { |
| 1658 | - $pos = count( $columns ); | |
| 1659 | - } | |
| 1660 | - | |
| 1661 | - // Final fallback, if the array was malformed by another plugin for example. | |
| 1662 | - if ( ! is_int( $pos ) ) { | |
| 1663 | 1659 | return $columns; |
| 1664 | 1660 | } |
| 1665 | - | |
| 1666 | 1661 | $chunks = array_chunk( $columns, $pos, true ); |
| 1667 | 1662 | $chunks[0]['stats'] = esc_html__( 'Stats', 'jetpack' ); |
| 1668 | 1663 | |
| 1669 | 1664 | return call_user_func_array( 'array_merge', $chunks ); |
| @@ -1669,9 +1664,9 @@ | ||
| 1669 | 1664 | return call_user_func_array( 'array_merge', $chunks ); |
| 1670 | 1665 | } |
| 1671 | 1666 | |
| 1672 | 1667 | /** |
| 1673 | - * Set content for cell with link to an entry's stats in Odyssey Stats. | |
| 1668 | + * Set content for cell with link to an entry's stats in WordPress.com. | |
| 1674 | 1669 | * |
| 1675 | 1670 | * @param string $column The name of the column to display. |
| 1676 | 1671 | * @param int $post_id The current post ID. |
| 1677 | 1672 | * |
| @@ -1686,51 +1681,18 @@ | ||
| 1686 | 1681 | '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', |
| 1687 | 1682 | esc_html__( 'No stats', 'jetpack' ) |
| 1688 | 1683 | ); |
| 1689 | 1684 | } else { |
| 1690 | - $stats_post_url = ! ( new Host() )->is_woa_site() && Stats_Options::get_option( 'enable_odyssey_stats' ) | |
| 1691 | - ? admin_url( sprintf( 'admin.php?page=stats#!/stats/post/%d/%d', $post_id, Jetpack_Options::get_option( 'id', 0 ) ) ) | |
| 1692 | - : Redirect::get_url( | |
| 1685 | + $stats_post_url = Redirect::get_url( | |
| 1693 | 1686 | 'calypso-stats-post', |
| 1694 | 1687 | array( |
| 1695 | 1688 | 'path' => $post_id, |
| 1696 | 1689 | ) |
| 1697 | 1690 | ); |
| 1698 | - | |
| 1699 | 1691 | printf( |
| 1700 | 1692 | '<a href="%s" title="%s" class="dashicons dashicons-chart-bar" target="_blank"></a>', |
| 1701 | 1693 | esc_url( $stats_post_url ), |
| 1702 | - esc_html__( 'View stats for this post', 'jetpack' ) | |
| 1694 | + esc_html__( 'View stats for this post in WordPress.com', 'jetpack' ) | |
| 1703 | 1695 | ); |
| 1704 | 1696 | } |
| 1705 | 1697 | } |
| 1706 | -} | |
| 1707 | - | |
| 1708 | -/** | |
| 1709 | - * Add the Jetpack plugin version to the stats tracking data. | |
| 1710 | - * | |
| 1711 | - * @param array $kvs The stats array in key values. | |
| 1712 | - * @return array | |
| 1713 | - */ | |
| 1714 | -function filter_stats_array_add_jp_version( $kvs ) { | |
| 1715 | - $kvs['j'] = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ); | |
| 1716 | - | |
| 1717 | - return $kvs; | |
| 1718 | -} | |
| 1719 | - | |
| 1720 | -/** | |
| 1721 | - * Convert stats array to object after sanity checking the array is valid. | |
| 1722 | - * | |
| 1723 | - * @param array $stats_array The stats array. | |
| 1724 | - * @return WP_Error|Object|null | |
| 1725 | - */ | |
| 1726 | -function convert_stats_array_to_object( $stats_array ) { | |
| 1727 | - | |
| 1728 | - if ( is_wp_error( $stats_array ) ) { | |
| 1729 | - return $stats_array; | |
| 1730 | - } | |
| 1731 | - $encoded_array = wp_json_encode( $stats_array ); | |
| 1732 | - if ( ! $encoded_array ) { | |
| 1733 | - return new WP_Error( 'stats_encoding_error', 'Failed to encode stats array' ); | |
| 1734 | - } | |
| 1735 | - return json_decode( $encoded_array ); | |
| 1736 | 1698 | } |