Completed
Push — start/7.4-changelog ( b9f2cf...cfa140 )
by Jeremy
49:24 queued 39:50
created

Jetpack_About_Page::fetch_a8c_data()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class for the Jetpack About Page within the wp-admin.
4
 *
5
 * @package Jetpack
6
 */
7
8
/**
9
 * Disable direct access and execution.
10
 */
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
require_once 'class.jetpack-admin-page.php';
16
17
/**
18
 * Builds the landing page and its menu.
19
 */
20
class Jetpack_About_Page extends Jetpack_Admin_Page {
21
22
	/**
23
	 * Show the settings page only when Jetpack is connected or in dev mode.
24
	 *
25
	 * @var bool If the page should be shown.
26
	 */
27
	protected $dont_show_if_not_active = true;
28
29
	/**
30
	 * Anonymous info about a12s. The method fetch_a8c_data() stores the response from wpcom here.
31
	 *
32
	 * @var array
33
	 */
34
	private $a8c_data = null;
35
36
	/**
37
	 * Add a submenu item to the Jetpack admin menu.
38
	 *
39
	 * @return string
40
	 */
41
	public function get_page_hook() {
42
		// Add the main admin Jetpack menu.
43
		return add_submenu_page(
44
			null,
45
			esc_html__( 'About Jetpack', 'jetpack' ),
46
			'',
47
			'jetpack_admin_page',
48
			'jetpack_about',
49
			array( $this, 'render' )
50
		);
51
	}
52
53
	/**
54
	 * Add page action
55
	 *
56
	 * @param string $hook Hook of current page, unused.
57
	 */
58
	public function add_page_actions( $hook ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
59
		// Place the Jetpack menu item on top and others in the order they appear.
60
		add_filter( 'custom_menu_order', '__return_true' );
61
		add_filter( 'menu_order', array( $this, 'submenu_order' ) );
62
		$this->a8c_data = $this->fetch_a8c_data();
63
	}
64
65
	/**
66
	 * Enqueues scripts and styles for the admin page.
67
	 */
68
	public function page_admin_scripts() {
69
		wp_enqueue_style( 'plugin-install' );
70
		wp_enqueue_script( 'plugin-install' );
71
		// required for plugin modal action button functionality.
72
		wp_enqueue_script( 'updates' );
73
		// required for modal popup JS and styling.
74
		wp_enqueue_style( 'thickbox' );
75
		wp_enqueue_script( 'thickbox' );
76
	}
77
78
	/**
79
	 * Load styles for static page.
80
	 */
81
	public function additional_styles() {
82
		Jetpack_Admin_Page::load_wrapper_styles();
83
	}
84
85
	/**
86
	 * Render the page with a common top and bottom part, and page specific content
87
	 */
88
	public function render() {
89
		Jetpack_Admin_Page::wrap_ui( array( $this, 'page_render' ), array( 'show-nav' => false ) );
90
	}
91
92
	/**
93
	 * Change order of menu item so the About page menu item is below Site Stats.
94
	 *
95
	 * @param array $menu_order List of menu slugs. It's unaffected. This filter is used to reorder the Jetpack submenu items.
96
	 *
97
	 * @return array
98
	 */
99
	public function submenu_order( $menu_order ) {
100
		global $submenu;
101
102
		$stats_key = null;
103
		$about_key = null;
104
105
		foreach ( $submenu['jetpack'] as $index => $menu_item ) {
106
			if ( false !== array_search( 'stats', $menu_item, true ) ) {
107
				$stats_key = $index;
108
			}
109
			if ( false !== array_search( 'jetpack_about', $menu_item, true ) ) {
110
				$about_key = $index;
111
			}
112
		}
113
114
		if ( $stats_key && $about_key ) {
115
			$temp                             = $submenu['jetpack'][ $stats_key ];
116
			$submenu['jetpack'][ $stats_key ] = $submenu['jetpack'][ $about_key ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
117
			$submenu['jetpack'][ $about_key ] = $temp; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
118
		}
119
120
		return $menu_order;
121
	}
122
123
	/**
124
	 * Render the page content
125
	 */
126
	public function page_render() {
127
		?>
128
		<div class="jp-lower">
129
			<div class="jetpack-about__link-back">
130
				<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack' ) ); ?>">
131
					<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></g></svg>
132
					<?php esc_html_e( 'Back to Jetpack Dashboard', 'jetpack' ); ?>
133
				</a>
134
			</div>
135
			<div class="jetpack-about__main">
136
				<div class="jetpack-about__logo">
137
					<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 800 96" style="enable-background:new 0 0 800 96;" xml:space="preserve">
138
					<g>
139
						<path style="fill: #39c;" d="M292.922,78c-19.777,0-32.598-14.245-32.598-29.078V47.08c0-15.086,12.821-29.08,32.598-29.08
140
							c19.861,0,32.682,13.994,32.682,29.08v1.843C325.604,63.755,312.783,78,292.922,78z M315.044,47.245
141
							c0-10.808-7.877-20.447-22.122-20.447s-22.04,9.639-22.04,20.447v1.341c0,10.811,7.795,20.614,22.04,20.614
142
							s22.122-9.803,22.122-20.614V47.245z"/>
143
						<path d="M69.602,75.821l-7.374-13.826H29.463l-7.124,13.826H11.277l30.167-55.81h8.715l30.671,55.81H69.602z M45.552,30.906
144
							L33.401,54.369h24.72L45.552,30.906z"/>
145
						<path d="M128.427,78c-20.028,0-29.329-10.894-29.329-25.391V20.012h10.391v32.765c0,10.308,6.788,16.424,19.692,16.424
146
							c13.242,0,18.687-6.116,18.687-16.424V20.012h10.475v32.598C158.342,66.436,149.46,78,128.427,78z"/>
147
						<path d="M216.667,28.727v47.094h-10.475V28.727h-24.386v-8.715h59.245v8.715H216.667z"/>
148
						<path d="M418.955,75.821V31.659l-2.766,4.861l-23.379,39.301h-5.112L364.569,36.52l-2.765-4.861v44.162h-10.224v-55.81h14.497
149
							l22.038,38.296L390.713,63l2.599-4.692l21.786-38.296h14.331v55.81H418.955z"/>
150
						<path d="M508.619,75.821l-7.374-13.826H468.48l-7.123,13.826h-11.061l30.167-55.81h8.715l30.669,55.81H508.619z M484.569,30.906
151
							l-12.151,23.464h24.72L484.569,30.906z"/>
152
						<path d="M562.081,28.727v47.094h-10.474V28.727h-24.386v-8.715h59.245v8.715H562.081z"/>
153
						<path d="M638.924,28.727v47.094H628.45V28.727h-24.386v-8.715h59.245v8.715H638.924z"/>
154
						<path d="M689.118,75.821v-50.53c4.19,0,5.866-2.263,5.866-5.28h4.442v55.81H689.118z"/>
155
						<path d="M781.464,35.765c-5.028-4.609-12.402-8.967-22.374-8.967c-14.916,0-23.296,10.225-23.296,20.867v1.089
156
							c0,10.558,8.464,20.445,24.05,20.445c9.303,0,17.012-4.441,21.872-8.965L788,66.854C781.883,72.887,771.492,78,759.174,78
157
							c-21.118,0-33.939-13.743-33.939-28.828v-1.843c0-15.084,13.993-29.329,34.44-29.329c11.816,0,22.541,4.944,28.324,11.146
158
							L781.464,35.765z"/>
159
						<path d="M299.82,37.417c1.889,1.218,2.418,3.749,1.192,5.648l-9.553,14.797c-1.226,1.901-3.752,2.452-5.637,1.234l0,0
160
							c-1.886-1.22-2.421-3.745-1.192-5.647l9.553-14.797C295.41,36.753,297.935,36.201,299.82,37.417L299.82,37.417z"/>
161
					</g>
162
					</svg>
163
				</div>
164
				<div class="jetpack-about__content">
165
					<div class="jetpack-about__images">
166
						<ul class="jetpack-about__gravatars">
167
							<?php $this->display_gravatars(); ?>
168
						</ul>
169
						<p class="meet-the-team">
170
							<a href="https://automattic.com/about/" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_meet_the_team"><?php esc_html_e( 'Meet the Automattic team', 'jetpack' ); ?></a>
171
						</p>
172
					</div>
173
174
					<div class="jetpack-about__text">
175
						<p>
176
							<?php esc_html_e( 'We are the people behind WordPress.com, WooCommerce, Jetpack, Simplenote, Longreads, VaultPress, Akismet, Gravatar, Crowdsignal, Cloudup, and more. We believe in making the web a better place.', 'jetpack' ); ?>
177
							<a href="https://automattic.com/" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_learn_more">
178
								<?php esc_html_e( 'Learn more about us.', 'jetpack' ); ?>
179
							</a>
180
						</p>
181
						<p>
182
							<?php
183
							echo esc_html(
184
								sprintf(
185
									/* translators: first placeholder is the number of Automattic employees. The second is the number of countries of origin*/
186
									__( 'We’re a distributed company with over %1$s Automatticians in more than %2$s countries speaking at least %3$s different languages. Our common goal is to democratize publishing so that anyone with a story can tell it, regardless of income, gender, politics, language, or where they live in the world.', 'jetpack' ),
187
									$this->a8c_data['a12s'],
188
									$this->a8c_data['countries'],
189
									$this->a8c_data['languages']
190
								)
191
							);
192
							?>
193
						</p>
194
						<p>
195
							<?php esc_html_e( 'We believe in Open Source and the vast majority of our work is available under the GPL.', 'jetpack' ); ?>
196
						</p>
197
						<p>
198
							<?php
199
								// Maybe use printf() because we'll want to escape the string but still allow for the link, so we can't use esc_html_e().
200
								echo wp_kses(
201
									__( 'We strive to live by the <a href="https://automattic.com/creed/" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_creed" rel="noopener noreferrer">Automattic Creed</a>.', 'jetpack' ),
202
									array(
203
										'a' => array(
204
											'href'   => array(),
205
											'class'  => array(),
206
											'target' => array(),
207
											'rel'    => array(),
208
											'data-jptracks-name' => array(),
209
										),
210
									)
211
								);
212
							?>
213
						</p>
214
						<p>
215
							<a href="https://automattic.com/work-with-us" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_work_with_us">
216
								<?php esc_html_e( 'Come work with us', 'jetpack' ); ?>
217
							</a>
218
						</p>
219
					</div>
220
				</div>
221
			</div>
222
223
			<div class="jetpack-about__colophon">
224
				<h3><?php esc_html_e( 'Popular WordPress services by Automattic', 'jetpack' ); ?></h3>
225
				<ul class="jetpack-about__services">
226
				<?php $this->display_plugins(); ?>
227
				</ul>
228
229
				<p class="jetpack-about__services-more">
230
				<?php
231
				echo wp_kses(
232
					__( 'For even more of our WordPress plugins, please <a href="https://profiles.wordpress.org/automattic/#content-plugins" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_wporg_profile">take a look at our WordPress.org profile</a>.', 'jetpack' ),
233
					array(
234
						'a' => array(
235
							'href'               => array(),
236
							'target'             => array(),
237
							'rel'                => array(),
238
							'class'              => array(),
239
							'data-jptracks-name' => array(),
240
						),
241
					)
242
				);
243
				?>
244
														</p>
245
			</div>
246
		</div>
247
		<?php
248
	}
249
250
	/**
251
	 * Add information cards for a8c plugins.
252
	 */
253
	public function display_plugins() {
254
		$plugins_allowedtags = array(
255
			'a'       => array(
256
				'href'   => array(),
257
				'title'  => array(),
258
				'target' => array(),
259
			),
260
			'abbr'    => array( 'title' => array() ),
261
			'acronym' => array( 'title' => array() ),
262
			'code'    => array(),
263
			'pre'     => array(),
264
			'em'      => array(),
265
			'strong'  => array(),
266
			'ul'      => array(),
267
			'ol'      => array(),
268
			'li'      => array(),
269
			'p'       => array(),
270
			'br'      => array(),
271
		);
272
273
		// slugs for plugins we want to display.
274
		$a8c_plugins = $this->a8c_data['featured_plugins'];
275
276
		// need this to access the plugins_api() function.
277
		include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
278
279
		$plugins = array();
280
		foreach ( $a8c_plugins as $slug ) {
281
			$args = array(
282
				'slug'   => $slug,
283
				'fields' => array(
284
					'added'                    => false,
285
					'author'                   => false,
286
					'author_profile'           => false,
287
					'banners'                  => false,
288
					'contributors'             => false,
289
					'donate_link'              => false,
290
					'homepage'                 => false,
291
					'reviews'                  => false,
292
					'screenshots'              => false,
293
					'support_threads'          => false,
294
					'support_threads_resolved' => false,
295
					'sections'                 => false,
296
					'tags'                     => false,
297
					'versions'                 => false,
298
299
					'compatibility'            => true,
300
					'downloaded'               => true,
301
					'downloadlink'             => true,
302
					'icons'                    => true,
303
					'last_updated'             => true,
304
					'num_ratings'              => true,
305
					'rating'                   => true,
306
					'requires'                 => true,
307
					'requires_php'             => true,
308
					'short_description'        => true,
309
					'tested'                   => true,
310
				),
311
			);
312
313
			// should probably add some error checking here too.
314
			$api       = plugins_api( 'plugin_information', $args );
315
			$plugins[] = $api;
316
		}
317
318
		foreach ( $plugins as $plugin ) {
319
			if ( is_object( $plugin ) ) {
320
				$plugin = (array) $plugin;
321
			}
322
323
			$title   = wp_kses( $plugin['name'], $plugins_allowedtags );
324
			$version = wp_kses( $plugin['version'], $plugins_allowedtags );
325
326
			$name = wp_strip_all_tags( $title . ' ' . $version );
327
328
			// Remove any HTML from the description.
329
			$description = wp_strip_all_tags( $plugin['short_description'] );
330
331
			$wp_version = get_bloginfo( 'version' );
332
333
			$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
334
			$compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
335
336
			$action_links = array();
337
338
			// install button.
339
			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
340
				$status = install_plugin_install_status( $plugin );
341
				switch ( $status['status'] ) {
342
					case 'install':
343
						if ( $status['url'] ) {
344
							if ( $compatible_php && $compatible_wp ) {
345
								$action_links[] = sprintf(
346
									'<a class="install-now button jptracks" data-slug="%1$s" href="%2$s" aria-label="%3$s" data-name="%4$s" data-jptracks-name="jetpack_about_install_button" data-jptracks-prop="%4$s">%5$s</a>',
347
									esc_attr( $plugin['slug'] ),
348
									esc_url( $status['url'] ),
349
									/* translators: %s: plugin name and version */
350
									esc_attr( sprintf( __( 'Install %s now', 'jetpack' ), $name ) ),
351
									esc_attr( $name ),
352
									esc_html__( 'Install Now', 'jetpack' )
353
								);
354
							} else {
355
								$action_links[] = sprintf(
356
									'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
357
									_x( 'Cannot Install', 'plugin', 'jetpack' )
358
								);
359
							}
360
						}
361
						break;
362
363
					case 'update_available':
364
						if ( $status['url'] ) {
365
							$action_links[] = sprintf(
366
								'<a class="update-now button aria-button-if-js jptracks" data-plugin="%1$s" data-slug="%2$s" href="%3$s" aria-label="%4$s" data-name="%5$s" data-jptracks-name="jetpack_about_update_button" data-jptracks-prop="%5$s">%6$s</a>',
367
								esc_attr( $status['file'] ),
368
								esc_attr( $plugin['slug'] ),
369
								esc_url( $status['url'] ),
370
								/* translators: %s: plugin name and version */
371
								esc_attr( sprintf( __( 'Update %s now', 'jetpack' ), $name ) ),
372
								esc_attr( $name ),
373
								__( 'Update Now', 'jetpack' )
374
							);
375
						}
376
						break;
377
378
					case 'latest_installed':
379
					case 'newer_installed':
380
						if ( is_plugin_active( $status['file'] ) ) {
381
							$action_links[] = sprintf(
382
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
383
								_x( 'Active', 'plugin', 'jetpack' )
384
							);
385
						} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
386
							$button_text = __( 'Activate', 'jetpack' );
387
							/* translators: %s: plugin name */
388
							$button_label = _x( 'Activate %s', 'plugin', 'jetpack' );
389
							$activate_url = add_query_arg(
390
								array(
391
									'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
392
									'action'   => 'activate',
393
									'plugin'   => $status['file'],
394
								),
395
								network_admin_url( 'plugins.php' )
396
							);
397
398
							if ( is_network_admin() ) {
399
								$button_text = __( 'Network Activate', 'jetpack' );
400
								/* translators: %s: plugin name */
401
								$button_label = _x( 'Network Activate %s', 'plugin', 'jetpack' );
402
								$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
403
							}
404
405
							$action_links[] = sprintf(
406
								'<a href="%1$s" class="button activate-now" aria-label="%2$s" data-jptracks-name="jetpack_about_activate_button" data-jptracks-prop="%3$s">%4$s</a>',
407
								esc_url( $activate_url ),
408
								esc_attr( sprintf( $button_label, $plugin['name'] ) ),
409
								esc_attr( $plugin['name'] ),
410
								$button_text
411
							);
412
						} else {
413
							$action_links[] = sprintf(
414
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
415
								_x( 'Installed', 'plugin', 'jetpack' )
416
							);
417
						}
418
						break;
419
				}
420
			}
421
422
			$plugin_install = "plugin-install.php?tab=plugin-information&amp;plugin={$plugin['slug']}&amp;TB_iframe=true&amp;width=600&amp;height=550";
423
			$details_link   = is_multisite()
424
				? network_admin_url( $plugin_install )
425
				: admin_url( $plugin_install );
426
427
			if ( ! empty( $plugin['icons']['svg'] ) ) {
428
				$plugin_icon_url = $plugin['icons']['svg'];
429
			} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
430
				$plugin_icon_url = $plugin['icons']['2x'];
431
			} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
432
				$plugin_icon_url = $plugin['icons']['1x'];
433
			} else {
434
				$plugin_icon_url = $plugin['icons']['default'];
435
			}
436
			?>
437
438
		<li class="jetpack-about__plugin plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
439
			<?php
440
			if ( ! $compatible_php || ! $compatible_wp ) {
441
				echo '<div class="notice inline notice-error notice-alt"><p>';
442
				if ( ! $compatible_php && ! $compatible_wp ) {
443
					esc_html_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.', 'jetpack' );
444
					if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
445
						printf(
446
							/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
447
							' ' . wp_kses( __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
448
							esc_url( self_admin_url( 'update-core.php' ) ),
449
							esc_url( wp_get_update_php_url() )
450
						);
451
						wp_update_php_annotation();
452 View Code Duplication
					} elseif ( current_user_can( 'update_core' ) ) {
453
						printf(
454
							/* translators: %s: "Update WordPress" screen URL */
455
							' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
456
							esc_url( self_admin_url( 'update-core.php' ) )
457
						);
458
					} elseif ( current_user_can( 'update_php' ) ) {
459
						printf(
460
							/* translators: %s: "Update PHP" page URL */
461
							' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
462
							esc_url( wp_get_update_php_url() )
463
						);
464
						wp_update_php_annotation();
465
					}
466
				} elseif ( ! $compatible_wp ) {
467
					esc_html_e( 'This plugin doesn&#8217;t work with your version of WordPress.', 'jetpack' );
468 View Code Duplication
					if ( current_user_can( 'update_core' ) ) {
469
						printf(
470
							/* translators: %s: "Update WordPress" screen URL */
471
							' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
472
							esc_url( self_admin_url( 'update-core.php' ) )
473
						);
474
					}
475 View Code Duplication
				} elseif ( ! $compatible_php ) {
476
					esc_html_e( 'This plugin doesn&#8217;t work with your version of PHP.', 'jetpack' );
477
					if ( current_user_can( 'update_php' ) ) {
478
						printf(
479
							/* translators: %s: "Update PHP" page URL */
480
							' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
481
							esc_url( wp_get_update_php_url() )
482
						);
483
						wp_update_php_annotation();
484
					}
485
				}
486
				echo '</p></div>';
487
			}
488
			?>
489
490
			<div class="plugin-card-top">
491
				<div class="name column-name">
492
					<h3>
493
						<a href="<?php echo esc_url( $details_link ); ?>" class="jptracks thickbox open-plugin-details-modal" data-jptracks-name="jetpack_about_plugin_modal" data-jptracks-prop="<?php echo esc_attr( $plugin['slug'] ); ?>">
494
						<?php echo esc_html( $title ); ?>
495
						<img src="<?php echo esc_url( $plugin_icon_url ); ?>" class="plugin-icon" alt="<?php esc_attr_e( 'Plugin icon', 'jetpack' ); ?>" aria-hidden="true">
496
						</a>
497
					</h3>
498
				</div>
499
				<div class="desc column-description">
500
					<p><?php echo esc_html( $description ); ?></p>
501
				</div>
502
503
				<div class="details-link">
504
					<a class="jptracks thickbox open-plugin-details-modal" href="<?php echo esc_url( $details_link ); ?>" data-jptracks-name="jetpack_about_plugin_details_modal" data-jptracks-prop="<?php echo esc_attr( $plugin['slug'] ); ?>"><?php esc_html_e( 'More Details', 'jetpack' ); ?></a>
505
				</div>
506
			</div>
507
508
			<div class="plugin-card-bottom">
509
				<div class="meta">
510
					<?php
511
					wp_star_rating(
512
						array(
513
							'rating' => $plugin['rating'],
514
							'type'   => 'percent',
515
							'number' => $plugin['num_ratings'],
516
						)
517
					);
518
					?>
519
					<span class="num-ratings" aria-hidden="true">(<?php echo esc_html( number_format_i18n( $plugin['num_ratings'] ) ); ?> <?php esc_html_e( 'ratings', 'jetpack' ); ?>)</span>
520
					<div class="downloaded">
521
						<?php
522
						if ( $plugin['active_installs'] >= 1000000 ) {
523
							$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
524
							$active_installs_text     = sprintf(
525
								/* translators: number of millions of installs. */
526
								_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations', 'jetpack' ),
527
								number_format_i18n( $active_installs_millions )
528
							);
529
						} elseif ( 0 === $plugin['active_installs'] ) {
530
							$active_installs_text = _x( 'Less Than 10', 'Active plugin installations', 'jetpack' );
531
						} else {
532
							$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
533
						}
534
						/* translators: number of active installs */
535
						printf( esc_html__( '%s Active Installations', 'jetpack' ), esc_html( $active_installs_text ) );
536
						?>
537
					</div>
538
				</div>
539
540
				<div class="action-links">
541
					<?php
542
					if ( $action_links ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $action_links of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
543
						// The var simply collects strings that have already been sanitized.
544
						// phpcs:ignore WordPress.Security.EscapeOutput
545
						echo '<ul class="action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
546
					}
547
					?>
548
				</div>
549
			</div>
550
		</li>
551
			<?php
552
553
		}
554
555
	}
556
557
	/**
558
	 * Fetch anonymous data about A12s from wpcom: total count, number of countries, languages spoken.
559
	 *
560
	 * @since 7.4
561
	 *
562
	 * @return array $data
563
	 */
564
	private function fetch_a8c_data() {
565
		$data = get_transient( 'jetpack_a8c_data' );
566
		if ( false === $data ) {
567
			$data = json_decode(
568
				wp_remote_retrieve_body(
569
					wp_remote_get( 'https://public-api.wordpress.com/wpcom/v2/jetpack-about' )
570
				),
571
				true
572
			);
573
			if ( ! empty( $data ) && is_array( $data ) ) {
574
				set_transient( 'jetpack_a8c_data', $data, DAY_IN_SECONDS );
575
			} else {
576
				// Fallback if everything fails.
577
				$data = array(
578
					'a12s'             => 888,
579
					'countries'        => 69,
580
					'languages'        => 83,
581
					'featured_plugins' => array(
582
						'woocommerce',
583
						'wp-super-cache',
584
						'wp-job-manager',
585
						'co-authors-plus',
586
					),
587
				);
588
			}
589
		}
590
		return $data;
591
	}
592
593
	/**
594
	 * Compile and display a list of avatars for A12s that gave their permission.
595
	 *
596
	 * @since 7.3
597
	 */
598
	public function display_gravatars() {
599
		$hashes = array(
600
			'https://1.gravatar.com/avatar/d2ab03dbab0c97740be75f290a2e3190',
601
			'https://2.gravatar.com/avatar/b0b357b291ac72bc7da81b4d74430fe6',
602
			'https://2.gravatar.com/avatar/9e149207a0e0818abed0edbb1fb2d0bf',
603
			'https://2.gravatar.com/avatar/9f376366854d750124dffe057dda99c9',
604
			'https://1.gravatar.com/avatar/1c75d26ad0d38624f02b15accc1f20cd',
605
			'https://1.gravatar.com/avatar/c510e69d83c7d10be4df64feeff4e46a',
606
			'https://0.gravatar.com/avatar/88ec0dcadea38adf5f30a17e54e9b248',
607
			'https://1.gravatar.com/avatar/bc45834430c5b0936d76e3f468f9ca57',
608
			'https://0.gravatar.com/avatar/032677e4115f3a38dc7785529e8cc4d9',
609
			'https://0.gravatar.com/avatar/72a638c2520ea177976e8eafb201a82f',
610
			'https://0.gravatar.com/avatar/b3618d70c63bbc5cc7caee0beded5ff0',
611
			'https://1.gravatar.com/avatar/4d346581a3340e32cf93703c9ce46bd4',
612
			'https://2.gravatar.com/avatar/9c2f6b95a00dfccfadc6a912a2b859ba',
613
			'https://1.gravatar.com/avatar/1a33e7a69df4f675fcd799edca088ac2',
614
			'https://2.gravatar.com/avatar/d5dc443845c134f365519568d5d80e62',
615
			'https://0.gravatar.com/avatar/c0ccdd53794779bcc07fcae7b79c4d80',
616
		);
617
		$output = '';
618
		foreach ( $hashes as $hash ) {
619
			$output .= '<li><img src="' . esc_url( $hash ) . '?s=150"></li>' . "\n";
620
		}
621
		echo wp_kses(
622
			$output,
623
			array(
624
				'li'  => true,
625
				'img' => array(
626
					'src' => true,
627
				),
628
			)
629
		);
630
	}
631
}
632