Completed
Push — add/admin-page-package ( b95118 )
by
unknown
26:28 queued 19:26
created

Jetpack_About_Page::submenu_order()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 10
nop 1
dl 0
loc 23
rs 8.9297
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
use Automattic\Jetpack\AdminPage\Page as AdminPage;
9
10
/**
11
 * Disable direct access and execution.
12
 */
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
require_once 'class.jetpack-admin-page.php';
18
19
/**
20
 * Builds the landing page and its menu.
21
 */
22
class Jetpack_About_Page extends Jetpack_Admin_Page {
23
24
	/**
25
	 * Show the settings page only when Jetpack is connected or in dev mode.
26
	 *
27
	 * @var bool If the page should be shown.
28
	 */
29
	protected $dont_show_if_not_active = true;
30
31
	/**
32
	 * Anonymous info about a12s. The method fetch_a8c_data() stores the response from wpcom here.
33
	 *
34
	 * @var array
35
	 */
36
	private $a8c_data = null;
37
38
	/**
39
	 * Add a submenu item to the Jetpack admin menu.
40
	 *
41
	 * @return string
42
	 */
43
	public function get_page_hook() {
44
		// Add the main admin Jetpack menu.
45
		return add_submenu_page(
46
			null,
47
			esc_html__( 'About Jetpack', 'jetpack' ),
48
			'',
49
			'jetpack_admin_page',
50
			'jetpack_about',
51
			array( $this, 'render' )
52
		);
53
54
	}
55
56
	/**
57
	 * Add page action
58
	 *
59
	 * @param string $hook Hook of current page, unused.
60
	 */
61
	public function add_page_actions( $hook ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
62
		// Place the Jetpack menu item on top and others in the order they appear.
63
		add_filter( 'custom_menu_order', '__return_true' );
64
		add_filter( 'menu_order', array( $this, 'submenu_order' ) );
65
		$this->a8c_data = $this->fetch_a8c_data();
66
	}
67
68
	/**
69
	 * Enqueues scripts and styles for the admin page.
70
	 */
71
	public function page_admin_scripts() {
72
		wp_enqueue_style( 'plugin-install' );
73
		wp_enqueue_script( 'plugin-install' );
74
		// required for plugin modal action button functionality.
75
		wp_enqueue_script( 'updates' );
76
		// required for modal popup JS and styling.
77
		wp_enqueue_style( 'thickbox' );
78
		wp_enqueue_script( 'thickbox' );
79
	}
80
81
	/**
82
	 * Load styles for static page.
83
	 */
84
	public function additional_styles() {
85
		Jetpack_Admin_Page::load_wrapper_styles();
86
	}
87
88
	/**
89
	 * Change order of menu item so the About page menu item is below Site Stats.
90
	 *
91
	 * @param array $menu_order List of menu slugs. It's unaffected. This filter is used to reorder the Jetpack submenu items.
92
	 *
93
	 * @return array
94
	 */
95
	public function submenu_order( $menu_order ) {
96
		global $submenu;
97
98
		$stats_key = null;
99
		$about_key = null;
100
101
		foreach ( $submenu['jetpack'] as $index => $menu_item ) {
102
			if ( false !== array_search( 'stats', $menu_item, true ) ) {
103
				$stats_key = $index;
104
			}
105
			if ( false !== array_search( 'jetpack_about', $menu_item, true ) ) {
106
				$about_key = $index;
107
			}
108
		}
109
110
		if ( $stats_key && $about_key ) {
111
			$temp                             = $submenu['jetpack'][ $stats_key ];
112
			$submenu['jetpack'][ $stats_key ] = $submenu['jetpack'][ $about_key ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
113
			$submenu['jetpack'][ $about_key ] = $temp; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
114
		}
115
116
		return $menu_order;
117
	}
118
119
	/**
120
	 * Render the page content
121
	 */
122
	public function page_render() {
123
		?>
124
		<div class="jp-lower">
125
			<div class="jetpack-about__link-back">
126
				<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack' ) ); ?>">
127
					<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>
128
					<?php esc_html_e( 'Back to Jetpack Dashboard', 'jetpack' ); ?>
129
				</a>
130
			</div>
131
			<div class="jetpack-about__main">
132
				<div class="jetpack-about__logo">
133
					<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">
134
					<g>
135
						<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
136
							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
137
							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
138
							s22.122-9.803,22.122-20.614V47.245z"/>
139
						<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
140
							L33.401,54.369h24.72L45.552,30.906z"/>
141
						<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
142
							c13.242,0,18.687-6.116,18.687-16.424V20.012h10.475v32.598C158.342,66.436,149.46,78,128.427,78z"/>
143
						<path d="M216.667,28.727v47.094h-10.475V28.727h-24.386v-8.715h59.245v8.715H216.667z"/>
144
						<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
145
							l22.038,38.296L390.713,63l2.599-4.692l21.786-38.296h14.331v55.81H418.955z"/>
146
						<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
147
							l-12.151,23.464h24.72L484.569,30.906z"/>
148
						<path d="M562.081,28.727v47.094h-10.474V28.727h-24.386v-8.715h59.245v8.715H562.081z"/>
149
						<path d="M638.924,28.727v47.094H628.45V28.727h-24.386v-8.715h59.245v8.715H638.924z"/>
150
						<path d="M689.118,75.821v-50.53c4.19,0,5.866-2.263,5.866-5.28h4.442v55.81H689.118z"/>
151
						<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
152
							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
153
							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
154
							L781.464,35.765z"/>
155
						<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
156
							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"/>
157
					</g>
158
					</svg>
159
				</div>
160
				<div class="jetpack-about__content">
161
					<div class="jetpack-about__images">
162
						<ul class="jetpack-about__gravatars">
163
							<?php $this->display_gravatars(); ?>
164
						</ul>
165
						<p class="meet-the-team">
166
							<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>
167
						</p>
168
					</div>
169
170
					<div class="jetpack-about__text">
171
						<p>
172
							<?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' ); ?>
173
							<a href="https://automattic.com/" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_learn_more">
174
								<?php esc_html_e( 'Learn more about us.', 'jetpack' ); ?>
175
							</a>
176
						</p>
177
						<p>
178
							<?php
179
							echo esc_html(
180
								sprintf(
181
									/* translators: first placeholder is the number of Automattic employees. The second is the number of countries of origin*/
182
									__( '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' ),
183
									$this->a8c_data['a12s'],
184
									$this->a8c_data['countries'],
185
									$this->a8c_data['languages']
186
								)
187
							);
188
							?>
189
						</p>
190
						<p>
191
							<?php esc_html_e( 'We believe in Open Source and the vast majority of our work is available under the GPL.', 'jetpack' ); ?>
192
						</p>
193
						<p>
194
							<?php
195
								// 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().
196
								echo wp_kses(
197
									__( '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' ),
198
									array(
199
										'a' => array(
200
											'href'   => array(),
201
											'class'  => array(),
202
											'target' => array(),
203
											'rel'    => array(),
204
											'data-jptracks-name' => array(),
205
										),
206
									)
207
								);
208
							?>
209
						</p>
210
						<p>
211
							<a href="https://automattic.com/work-with-us" target="_blank" rel="noopener noreferrer" class="jptracks" data-jptracks-name="jetpack_about_work_with_us">
212
								<?php esc_html_e( 'Come work with us', 'jetpack' ); ?>
213
							</a>
214
						</p>
215
					</div>
216
				</div>
217
			</div>
218
219
			<div class="jetpack-about__colophon">
220
				<h3><?php esc_html_e( 'Popular WordPress services by Automattic', 'jetpack' ); ?></h3>
221
				<ul class="jetpack-about__services">
222
				<?php $this->display_plugins(); ?>
223
				</ul>
224
225
				<p class="jetpack-about__services-more">
226
				<?php
227
				echo wp_kses(
228
					__( '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' ),
229
					array(
230
						'a' => array(
231
							'href'               => array(),
232
							'target'             => array(),
233
							'rel'                => array(),
234
							'class'              => array(),
235
							'data-jptracks-name' => array(),
236
						),
237
					)
238
				);
239
				?>
240
														</p>
241
			</div>
242
		</div>
243
		<?php
244
	}
245
246
	/**
247
	 * Add information cards for a8c plugins.
248
	 */
249
	public function display_plugins() {
250
		$plugins_allowedtags = array(
251
			'a'       => array(
252
				'href'   => array(),
253
				'title'  => array(),
254
				'target' => array(),
255
			),
256
			'abbr'    => array( 'title' => array() ),
257
			'acronym' => array( 'title' => array() ),
258
			'code'    => array(),
259
			'pre'     => array(),
260
			'em'      => array(),
261
			'strong'  => array(),
262
			'ul'      => array(),
263
			'ol'      => array(),
264
			'li'      => array(),
265
			'p'       => array(),
266
			'br'      => array(),
267
		);
268
269
		// slugs for plugins we want to display.
270
		$a8c_plugins = $this->a8c_data['featured_plugins'];
271
272
		// need this to access the plugins_api() function.
273
		include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
274
275
		$plugins = array();
276
		foreach ( $a8c_plugins as $slug ) {
277
			$args = array(
278
				'slug'   => $slug,
279
				'fields' => array(
280
					'added'                    => false,
281
					'author'                   => false,
282
					'author_profile'           => false,
283
					'banners'                  => false,
284
					'contributors'             => false,
285
					'donate_link'              => false,
286
					'homepage'                 => false,
287
					'reviews'                  => false,
288
					'screenshots'              => false,
289
					'support_threads'          => false,
290
					'support_threads_resolved' => false,
291
					'sections'                 => false,
292
					'tags'                     => false,
293
					'versions'                 => false,
294
295
					'compatibility'            => true,
296
					'downloaded'               => true,
297
					'downloadlink'             => true,
298
					'icons'                    => true,
299
					'last_updated'             => true,
300
					'num_ratings'              => true,
301
					'rating'                   => true,
302
					'requires'                 => true,
303
					'requires_php'             => true,
304
					'short_description'        => true,
305
					'tested'                   => true,
306
				),
307
			);
308
309
			// should probably add some error checking here too.
310
			$api       = plugins_api( 'plugin_information', $args );
311
			$plugins[] = $api;
312
		}
313
314
		foreach ( $plugins as $plugin ) {
315
			if ( is_object( $plugin ) ) {
316
				$plugin = (array) $plugin;
317
			}
318
319
			$title   = wp_kses( $plugin['name'], $plugins_allowedtags );
320
			$version = wp_kses( $plugin['version'], $plugins_allowedtags );
321
322
			$name = wp_strip_all_tags( $title . ' ' . $version );
323
324
			// Remove any HTML from the description.
325
			$description = wp_strip_all_tags( $plugin['short_description'] );
326
327
			$wp_version = get_bloginfo( 'version' );
328
329
			$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
330
			$compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
331
332
			$action_links = array();
333
334
			// install button.
335
			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
336
				$status = install_plugin_install_status( $plugin );
337
				switch ( $status['status'] ) {
338
					case 'install':
339
						if ( $status['url'] ) {
340
							if ( $compatible_php && $compatible_wp ) {
341
								$action_links[] = sprintf(
342
									'<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>',
343
									esc_attr( $plugin['slug'] ),
344
									esc_url( $status['url'] ),
345
									/* translators: %s: plugin name and version */
346
									esc_attr( sprintf( __( 'Install %s now', 'jetpack' ), $name ) ),
347
									esc_attr( $name ),
348
									esc_html__( 'Install Now', 'jetpack' )
349
								);
350
							} else {
351
								$action_links[] = sprintf(
352
									'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
353
									_x( 'Cannot Install', 'plugin', 'jetpack' )
354
								);
355
							}
356
						}
357
						break;
358
359
					case 'update_available':
360
						if ( $status['url'] ) {
361
							$action_links[] = sprintf(
362
								'<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>',
363
								esc_attr( $status['file'] ),
364
								esc_attr( $plugin['slug'] ),
365
								esc_url( $status['url'] ),
366
								/* translators: %s: plugin name and version */
367
								esc_attr( sprintf( __( 'Update %s now', 'jetpack' ), $name ) ),
368
								esc_attr( $name ),
369
								__( 'Update Now', 'jetpack' )
370
							);
371
						}
372
						break;
373
374
					case 'latest_installed':
375
					case 'newer_installed':
376
						if ( is_plugin_active( $status['file'] ) ) {
377
							$action_links[] = sprintf(
378
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
379
								_x( 'Active', 'plugin', 'jetpack' )
380
							);
381
						} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
382
							$button_text = __( 'Activate', 'jetpack' );
383
							/* translators: %s: plugin name */
384
							$button_label = _x( 'Activate %s', 'plugin', 'jetpack' );
385
							$activate_url = add_query_arg(
386
								array(
387
									'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
388
									'action'   => 'activate',
389
									'plugin'   => $status['file'],
390
								),
391
								network_admin_url( 'plugins.php' )
392
							);
393
394
							if ( is_network_admin() ) {
395
								$button_text = __( 'Network Activate', 'jetpack' );
396
								/* translators: %s: plugin name */
397
								$button_label = _x( 'Network Activate %s', 'plugin', 'jetpack' );
398
								$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
399
							}
400
401
							$action_links[] = sprintf(
402
								'<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>',
403
								esc_url( $activate_url ),
404
								esc_attr( sprintf( $button_label, $plugin['name'] ) ),
405
								esc_attr( $plugin['name'] ),
406
								$button_text
407
							);
408
						} else {
409
							$action_links[] = sprintf(
410
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
411
								_x( 'Installed', 'plugin', 'jetpack' )
412
							);
413
						}
414
						break;
415
				}
416
			}
417
418
			$plugin_install = "plugin-install.php?tab=plugin-information&amp;plugin={$plugin['slug']}&amp;TB_iframe=true&amp;width=600&amp;height=550";
419
			$details_link   = is_multisite()
420
				? network_admin_url( $plugin_install )
421
				: admin_url( $plugin_install );
422
423
			if ( ! empty( $plugin['icons']['svg'] ) ) {
424
				$plugin_icon_url = $plugin['icons']['svg'];
425
			} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
426
				$plugin_icon_url = $plugin['icons']['2x'];
427
			} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
428
				$plugin_icon_url = $plugin['icons']['1x'];
429
			} else {
430
				$plugin_icon_url = $plugin['icons']['default'];
431
			}
432
			?>
433
434
		<li class="jetpack-about__plugin plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
435
			<?php
436
			if ( ! $compatible_php || ! $compatible_wp ) {
437
				echo '<div class="notice inline notice-error notice-alt"><p>';
438
				if ( ! $compatible_php && ! $compatible_wp ) {
439
					esc_html_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.', 'jetpack' );
440
					if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
441
						printf(
442
							/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
443
							' ' . 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 ) ) ),
444
							esc_url( self_admin_url( 'update-core.php' ) ),
445
							esc_url( wp_get_update_php_url() )
446
						);
447
						wp_update_php_annotation();
448 View Code Duplication
					} elseif ( current_user_can( 'update_core' ) ) {
449
						printf(
450
							/* translators: %s: "Update WordPress" screen URL */
451
							' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
452
							esc_url( self_admin_url( 'update-core.php' ) )
453
						);
454
					} elseif ( current_user_can( 'update_php' ) ) {
455
						printf(
456
							/* translators: %s: "Update PHP" page URL */
457
							' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
458
							esc_url( wp_get_update_php_url() )
459
						);
460
						wp_update_php_annotation();
461
					}
462
				} elseif ( ! $compatible_wp ) {
463
					esc_html_e( 'This plugin doesn&#8217;t work with your version of WordPress.', 'jetpack' );
464 View Code Duplication
					if ( current_user_can( 'update_core' ) ) {
465
						printf(
466
							/* translators: %s: "Update WordPress" screen URL */
467
							' ' . wp_kses( __( '<a href="%s">Please update WordPress</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
468
							esc_url( self_admin_url( 'update-core.php' ) )
469
						);
470
					}
471 View Code Duplication
				} elseif ( ! $compatible_php ) {
472
					esc_html_e( 'This plugin doesn&#8217;t work with your version of PHP.', 'jetpack' );
473
					if ( current_user_can( 'update_php' ) ) {
474
						printf(
475
							/* translators: %s: "Update PHP" page URL */
476
							' ' . wp_kses( __( '<a href="%s">Learn more about updating PHP</a>.', 'jetpack' ), array( 'a' => array( 'href' => true ) ) ),
477
							esc_url( wp_get_update_php_url() )
478
						);
479
						wp_update_php_annotation();
480
					}
481
				}
482
				echo '</p></div>';
483
			}
484
			?>
485
486
			<div class="plugin-card-top">
487
				<div class="name column-name">
488
					<h3>
489
						<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'] ); ?>">
490
						<?php echo esc_html( $title ); ?>
491
						<img src="<?php echo esc_url( $plugin_icon_url ); ?>" class="plugin-icon" alt="<?php esc_attr_e( 'Plugin icon', 'jetpack' ); ?>" aria-hidden="true">
492
						</a>
493
					</h3>
494
				</div>
495
				<div class="desc column-description">
496
					<p><?php echo esc_html( $description ); ?></p>
497
				</div>
498
499
				<div class="details-link">
500
					<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>
501
				</div>
502
			</div>
503
504
			<div class="plugin-card-bottom">
505
				<div class="meta">
506
					<?php
507
					wp_star_rating(
508
						array(
509
							'rating' => $plugin['rating'],
510
							'type'   => 'percent',
511
							'number' => $plugin['num_ratings'],
512
						)
513
					);
514
					?>
515
					<span class="num-ratings" aria-hidden="true">(<?php echo esc_html( number_format_i18n( $plugin['num_ratings'] ) ); ?> <?php esc_html_e( 'ratings', 'jetpack' ); ?>)</span>
516
					<div class="downloaded">
517
						<?php
518
						if ( $plugin['active_installs'] >= 1000000 ) {
519
							$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
520
							$active_installs_text     = sprintf(
521
								/* translators: number of millions of installs. */
522
								_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations', 'jetpack' ),
523
								number_format_i18n( $active_installs_millions )
524
							);
525
						} elseif ( 0 === $plugin['active_installs'] ) {
526
							$active_installs_text = _x( 'Less Than 10', 'Active plugin installations', 'jetpack' );
527
						} else {
528
							$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
529
						}
530
						/* translators: number of active installs */
531
						printf( esc_html__( '%s Active Installations', 'jetpack' ), esc_html( $active_installs_text ) );
532
						?>
533
					</div>
534
				</div>
535
536
				<div class="action-links">
537
					<?php
538
					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...
539
						// The var simply collects strings that have already been sanitized.
540
						// phpcs:ignore WordPress.Security.EscapeOutput
541
						echo '<ul class="action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
542
					}
543
					?>
544
				</div>
545
			</div>
546
		</li>
547
			<?php
548
549
		}
550
551
	}
552
553
	/**
554
	 * Fetch anonymous data about A12s from wpcom: total count, number of countries, languages spoken.
555
	 *
556
	 * @since 7.4
557
	 *
558
	 * @return array $data
559
	 */
560
	private function fetch_a8c_data() {
561
		$data = get_transient( 'jetpack_a8c_data' );
562
		if ( false === $data ) {
563
			$data = json_decode(
564
				wp_remote_retrieve_body(
565
					wp_remote_get( 'https://public-api.wordpress.com/wpcom/v2/jetpack-about' )
566
				),
567
				true
568
			);
569
			if ( ! empty( $data ) && is_array( $data ) ) {
570
				set_transient( 'jetpack_a8c_data', $data, DAY_IN_SECONDS );
571
			} else {
572
				// Fallback if everything fails.
573
				$data = array(
574
					'a12s'             => 888,
575
					'countries'        => 69,
576
					'languages'        => 83,
577
					'featured_plugins' => array(
578
						'woocommerce',
579
						'wp-super-cache',
580
						'wp-job-manager',
581
						'co-authors-plus',
582
					),
583
				);
584
			}
585
		}
586
		return $data;
587
	}
588
589
	/**
590
	 * Compile and display a list of avatars for A12s that gave their permission.
591
	 *
592
	 * @since 7.3
593
	 */
594
	public function display_gravatars() {
595
		$hashes = array(
596
			'https://1.gravatar.com/avatar/d2ab03dbab0c97740be75f290a2e3190',
597
			'https://2.gravatar.com/avatar/b0b357b291ac72bc7da81b4d74430fe6',
598
			'https://2.gravatar.com/avatar/9e149207a0e0818abed0edbb1fb2d0bf',
599
			'https://2.gravatar.com/avatar/9f376366854d750124dffe057dda99c9',
600
			'https://1.gravatar.com/avatar/1c75d26ad0d38624f02b15accc1f20cd',
601
			'https://1.gravatar.com/avatar/c510e69d83c7d10be4df64feeff4e46a',
602
			'https://0.gravatar.com/avatar/88ec0dcadea38adf5f30a17e54e9b248',
603
			'https://1.gravatar.com/avatar/bc45834430c5b0936d76e3f468f9ca57',
604
			'https://0.gravatar.com/avatar/032677e4115f3a38dc7785529e8cc4d9',
605
			'https://0.gravatar.com/avatar/72a638c2520ea177976e8eafb201a82f',
606
			'https://0.gravatar.com/avatar/b3618d70c63bbc5cc7caee0beded5ff0',
607
			'https://1.gravatar.com/avatar/4d346581a3340e32cf93703c9ce46bd4',
608
			'https://2.gravatar.com/avatar/9c2f6b95a00dfccfadc6a912a2b859ba',
609
			'https://1.gravatar.com/avatar/1a33e7a69df4f675fcd799edca088ac2',
610
			'https://2.gravatar.com/avatar/d5dc443845c134f365519568d5d80e62',
611
			'https://0.gravatar.com/avatar/c0ccdd53794779bcc07fcae7b79c4d80',
612
		);
613
		$output = '';
614
		foreach ( $hashes as $hash ) {
615
			$output .= '<li><img src="' . esc_url( $hash ) . '?s=150"></li>' . "\n";
616
		}
617
		echo wp_kses(
618
			$output,
619
			array(
620
				'li'  => true,
621
				'img' => array(
622
					'src' => true,
623
				),
624
			)
625
		);
626
	}
627
}
628