Completed
Push — add/about-page ( dea97d...f467d5 )
by
unknown
06:46
created

Jetpack_About_Page::display_gravatars()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 8
nop 0
dl 0
loc 40
rs 8.3466
c 0
b 0
f 0
1
<?php
2
/**
3
 * Disable direct access and execution.
4
 */
5
if ( ! defined( 'ABSPATH' ) ) {
6
	exit;
7
}
8
9
include_once( 'class.jetpack-admin-page.php' );
10
11
// Builds the landing page and its menu
12
class Jetpack_About_Page extends Jetpack_Admin_Page {
13
14
	// Show the settings page only when Jetpack is connected or in dev mode
15
	protected $dont_show_if_not_active = true;
16
17
	/**
18
	 * Add a submenu item to the Jetpack admin menu.
19
	 *
20
	 * @return string
21
	 */
22
	function get_page_hook() {
23
		// Add the main admin Jetpack menu
24
		return add_submenu_page(
25
			'jetpack',
26
			esc_html__( 'About Jetpack', 'jetpack' ),
27
			esc_html__( 'About Jetpack', 'jetpack' ),
28
			'jetpack_admin_page',
29
			'jetpack_about',
30
			array( $this, 'render' )
31
		);
32
	}
33
34
	function add_page_actions( $hook ) {
35
		// Place the Jetpack menu item on top and others in the order they appear
36
		add_filter( 'custom_menu_order', '__return_true' );
37
		add_filter( 'menu_order',        array( $this, 'submenu_order' ) );
38
	}
39
40
	function page_admin_scripts() {
41
		wp_enqueue_style( 'plugin-install' );
42
		wp_enqueue_script( 'plugin-install' );
43
		// required for plugin modal action button functionality
44
		wp_enqueue_script( 'updates' );
45
		// required for modal popup JS and styling
46
		wp_enqueue_style( 'thickbox' );
47
		wp_enqueue_script( 'thickbox' );
48
	}
49
50
	/**
51
	 * Load styles for static page.
52
	 */
53
	function additional_styles() {
54
		Jetpack_Admin_Page::load_wrapper_styles();
55
	}
56
57
	/**
58
	 * Render the page with a common top and bottom part, and page specific content
59
	 */
60
	function render() {
61
		Jetpack_Admin_Page::wrap_ui( array( $this, 'page_render' ), array( 'show-nav' => false ) );
62
	}
63
64
	/**
65
	 * Change order of menu item so the About page menu item is below Site Stats.
66
	 *
67
	 * @param array $menu_order List of menu slugs. It's unaffected. This filter is used to reorder the Jetpack submenu items.
68
	 *
69
	 * @return array
70
	 */
71
	function submenu_order( $menu_order ) {
72
		global $submenu;
73
74
		$stats_key = null;
75
		$about_key = null;
76
77
		foreach ( $submenu['jetpack'] as $index => $menu_item ) {
78
			if ( false !== array_search( 'stats', $menu_item ) ) {
79
				$stats_key = $index;
80
			}
81
			if ( false !== array_search( 'jetpack_about', $menu_item ) ) {
82
				$about_key = $index;
83
			}
84
		}
85
86
		if ( $stats_key && $about_key ) {
87
			$temp = $submenu['jetpack'][ $stats_key ];
88
			$submenu['jetpack'][ $stats_key ] = $submenu['jetpack'][ $about_key ];
89
			$submenu['jetpack'][ $about_key ] = $temp;
90
		}
91
92
		return $menu_order;
93
	}
94
95
	/**
96
	 * Render the page content
97
	 */
98
	function page_render() {
99
		?>
100
		<div class="jp-lower">
101
			<div class="jetpack-about__link-back">
102
				<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack' ) ); ?>">
103
					<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>
104
					<?php esc_html_e( 'Back to Jetpack Dashboard', 'jetpack' ); ?>
105
				</a>
106
			</div>
107
			<div class="jetpack-about__main">
108
				<div class="jetpack-about__logo">
109
					<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"
110
						 viewBox="0 0 800 96" style="enable-background:new 0 0 800 96;" xml:space="preserve">
111
					<g>
112
						<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
113
							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
114
							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
115
							s22.122-9.803,22.122-20.614V47.245z"/>
116
						<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
117
							L33.401,54.369h24.72L45.552,30.906z"/>
118
						<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
119
							c13.242,0,18.687-6.116,18.687-16.424V20.012h10.475v32.598C158.342,66.436,149.46,78,128.427,78z"/>
120
						<path d="M216.667,28.727v47.094h-10.475V28.727h-24.386v-8.715h59.245v8.715H216.667z"/>
121
						<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
122
							l22.038,38.296L390.713,63l2.599-4.692l21.786-38.296h14.331v55.81H418.955z"/>
123
						<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
124
							l-12.151,23.464h24.72L484.569,30.906z"/>
125
						<path d="M562.081,28.727v47.094h-10.474V28.727h-24.386v-8.715h59.245v8.715H562.081z"/>
126
						<path d="M638.924,28.727v47.094H628.45V28.727h-24.386v-8.715h59.245v8.715H638.924z"/>
127
						<path d="M689.118,75.821v-50.53c4.19,0,5.866-2.263,5.866-5.28h4.442v55.81H689.118z"/>
128
						<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
129
							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
130
							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
131
							L781.464,35.765z"/>
132
						<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
133
							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"/>
134
					</g>
135
					</svg>
136
				</div>
137
				<div class="jetpack-about__content">
138
					<div class="jetpack-about__images">
139
						<ul class="jetpack-about__gravatars">
140
							<?php $this->display_gravatars(); ?>
141
						</ul>
142
						<p class="meet-the-team">
143
							<a href="https://automattic.com/about/" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_meet_the_team"><?php esc_html_e( 'Meet the Automattic team', 'jetpack' ); ?></a>
144
						</p>
145
					</div>
146
147
					<div class="jetpack-about__text">
148
						<p>
149
							<?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' ); ?>
150
							<a href="https://automattic.com/" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_learn_more">
151
								<?php esc_html_e( 'Learn more about us.', 'jetpack' ); ?>
152
							</a>
153
						</p>
154
						<p>
155
							<?php esc_html_e( 'We’re a distributed company with 864 Automatticians in 68 countries speaking 84 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' ); ?>
156
						</p>
157
						<p>
158
							<?php esc_html_e( 'We believe in Open Source and the vast majority of our work is available under the GPL.', 'jetpack' ); ?>
159
						</p>
160
						<p>
161
							<?php
162
								// 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()
163
								echo wp_kses( __( 'We strive to live by the <a href="https://automattic.com/creed/" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_creed">Automattic Creed</a>.', 'jetpack' ), array( 'a' => array( 'href' => array(), 'class' => array(), 'target' => array(), 'data-jptracks-name' => array() ) ) ); ?>
164
						</p>
165
						<p>
166
							<a href="https://automattic.com/jobs" target="_blank"  class="jptracks" data-jptracks-name="jetpack_about_work_with_us">
167
								<?php esc_html_e( 'Come work with us', 'jetpack' ); ?>
168
							</a>
169
						</p>
170
					</div>
171
				</div>
172
			</div>
173
174
			<div class="jetpack-about__colophon">
175
				<h3><?php esc_html_e( 'Popular WordPress services by Automattic', 'jetpack' ); ?></h3>
176
				<ul class="jetpack-about__services">
177
				<?php $this->display_plugins(); ?>
178
				</ul>
179
180
				<p class="jetpack-about__services-more"><?php echo wp_kses( __( 'For even more of our WordPress plugins, please <a href="https://profiles.wordpress.org/automattic/#content-plugins" target="_blank" class="jptracks" data-jptracks-name="jetpack_about_wporg_profile">take a look at our WordPress.org profile</a>.', 'jetpack' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'class' => array(), 'data-jptracks-name' => array() ) ) ); ?></p>
181
			</div>
182
		</div>
183
		<?php
184
	}
185
186
	function display_plugins() {
187
		$plugins_allowedtags = array(
188
			'a'       => array(
189
				'href'   => array(),
190
				'title'  => array(),
191
				'target' => array(),
192
			),
193
			'abbr'    => array( 'title' => array() ),
194
			'acronym' => array( 'title' => array() ),
195
			'code'    => array(),
196
			'pre'     => array(),
197
			'em'      => array(),
198
			'strong'  => array(),
199
			'ul'      => array(),
200
			'ol'      => array(),
201
			'li'      => array(),
202
			'p'       => array(),
203
			'br'      => array(),
204
		);
205
206
		// slugs for plugins we want to display
207
		$a8c_plugins = array(
208
			'akismet',
209
			'wp-super-cache',
210
			'vaultpress',
211
			'polldaddy',
212
		);
213
214
		// need this to access the plugins_api() function
215
		include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
216
217
		foreach ( $a8c_plugins as $slug ){
218
			$args = array(
219
				'slug'	=> $slug,
220
				'fields'	=> array(
221
					'added'						=> false,
222
					'author'						=> false,
223
					'author_profile'				=> false,
224
					'banners'					=> false,
225
					'contributors'				=> false,
226
					'donate_link'				=> false,
227
					'homepage'					=> false,
228
					'reviews'					=> false,
229
					'screenshots'				=> false,
230
					'support_threads'			=> false,
231
					'support_threads_resolved'	=> false,
232
					'sections'					=> false,
233
					'tags'						=> false,
234
					'versions'					=> false,
235
236
					'compatibility'				=> true,
237
					'downloaded'					=> true,
238
					'downloadlink'				=> true,
239
					'icons'						=> true,
240
					'last_updated'				=> true,
241
					'num_ratings'				=> true,
242
					'rating'						=> true,
243
					'requires'					=> true,
244
					'requires_php'				=> true,
245
					'short_description'			=> true,
246
					'tested'						=> true,
247
				),
248
			);
249
250
			// should probably add some error checking here too
251
			$api = plugins_api( 'plugin_information', $args );
252
			$plugins[] = $api;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$plugins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $plugins = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
253
		}
254
255
		foreach ( $plugins as $plugin ) {
0 ignored issues
show
Bug introduced by
The variable $plugins does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
256
			if ( is_object( $plugin ) ) {
257
				$plugin = (array) $plugin;
258
			}
259
260
			$title = wp_kses( $plugin['name'], $plugins_allowedtags );
261
			$version     = wp_kses( $plugin['version'], $plugins_allowedtags );
262
263
			$name = strip_tags( $title . ' ' . $version );
264
265
			// Remove any HTML from the description.
266
			$description = strip_tags( $plugin['short_description'] );
267
268
			$wp_version = get_bloginfo( 'version' );
269
270
			$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
271
			$tested_wp      = ( empty( $plugin['tested'] ) || version_compare( $wp_version, $plugin['tested'], '<=' ) );
0 ignored issues
show
Unused Code introduced by
$tested_wp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
272
			$compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
273
274
			$action_links = array();
275
276
			// install button
277
			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
278
				$status = install_plugin_install_status( $plugin );
279
				switch ( $status['status'] ) {
280
					case 'install':
281 View Code Duplication
						if ( $status['url'] ) {
282
							if ( $compatible_php && $compatible_wp ) {
283
								$action_links[] = sprintf(
284
									'<a class="install-now button jptracks" data-slug="%s" href="%s" aria-label="%s" data-name="%s" data-jptracks-name="jetpack_about_install_button" data-jptracks-prop="%s">%s</a>',
285
									esc_attr( $plugin['slug'] ),
286
									esc_url( $status['url'] ),
287
									/* translators: %s: plugin name and version */
288
									esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
289
									esc_attr( $name ),
290
									esc_attr( $name ),
291
									__( 'Install Now' )
292
								);
293
							} else {
294
								$action_links[] = sprintf(
295
									'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
296
									_x( 'Cannot Install', 'plugin' )
297
								);
298
							}
299
						}
300
						break;
301
302
					case 'update_available':
303 View Code Duplication
						if ( $status['url'] ) {
304
							$action_links[] = sprintf(
305
								'<a class="update-now button aria-button-if-js jptracks" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s" data-jptracks-name="jetpack_about_update_button" data-jptracks-prop="%s">%s</a>',
306
								esc_attr( $status['file'] ),
307
								esc_attr( $plugin['slug'] ),
308
								esc_url( $status['url'] ),
309
								/* translators: %s: plugin name and version */
310
								esc_attr( sprintf( __( 'Update %s now' ), $name ) ),
311
								esc_attr( $name ),
312
								esc_attr( $name ),
313
								__( 'Update Now' )
314
							);
315
						}
316
						break;
317
318
					case 'latest_installed':
319
					case 'newer_installed':
320
						if ( is_plugin_active( $status['file'] ) ) {
321
							$action_links[] = sprintf(
322
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
323
								_x( 'Active', 'plugin' )
324
							);
325
						} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
326
							$button_text = __( 'Activate' );
327
							/* translators: %s: plugin name */
328
							$button_label = _x( 'Activate %s', 'plugin' );
329
							$activate_url = add_query_arg(
330
								array(
331
									'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
332
									'action'   => 'activate',
333
									'plugin'   => $status['file'],
334
								),
335
								network_admin_url( 'plugins.php' )
336
							);
337
338
							if ( is_network_admin() ) {
339
								$button_text = __( 'Network Activate' );
340
								/* translators: %s: plugin name */
341
								$button_label = _x( 'Network Activate %s', 'plugin' );
342
								$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
343
							}
344
345
							$action_links[] = sprintf(
346
								'<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>',
347
								esc_url( $activate_url ),
348
								esc_attr( sprintf( $button_label, $plugin['name'] ) ),
349
								esc_attr( $plugin['name'] ),
350
								$button_text
351
							);
352
						} else {
353
							$action_links[] = sprintf(
354
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
355
								_x( 'Installed', 'plugin' )
356
							);
357
						}
358
						break;
359
				}
360
			}
361
362
			$details_link = self_admin_url(
363
				'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
364
				'&amp;TB_iframe=true&amp;width=600&amp;height=550'
365
			);
366
367
			if ( ! empty( $plugin['icons']['svg'] ) ) {
368
				$plugin_icon_url = $plugin['icons']['svg'];
369
			} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
370
				$plugin_icon_url = $plugin['icons']['2x'];
371
			} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
372
				$plugin_icon_url = $plugin['icons']['1x'];
373
			} else {
374
				$plugin_icon_url = $plugin['icons']['default'];
375
			}
376
?>
377
378
		<li class="jetpack-about__plugin plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
379
			<?php
380
			if ( ! $compatible_php || ! $compatible_wp ) {
381
				echo '<div class="notice inline notice-error notice-alt"><p>';
382
				if ( ! $compatible_php && ! $compatible_wp ) {
383
					_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.' );
384
					if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
385
						printf(
386
							/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
387
							' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
388
							self_admin_url( 'update-core.php' ),
389
							esc_url( wp_get_update_php_url() )
390
						);
391
						wp_update_php_annotation();
392
					} elseif ( current_user_can( 'update_core' ) ) {
393
						printf(
394
							/* translators: %s: "Update WordPress" screen URL */
395
							' ' . __( '<a href="%s">Please update WordPress</a>.' ),
396
							self_admin_url( 'update-core.php' )
397
						);
398 View Code Duplication
					} elseif ( current_user_can( 'update_php' ) ) {
399
						printf(
400
							/* translators: %s: "Update PHP" page URL */
401
							' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
402
							esc_url( wp_get_update_php_url() )
403
						);
404
						wp_update_php_annotation();
405
					}
406
				} elseif ( ! $compatible_wp ) {
407
					_e( 'This plugin doesn&#8217;t work with your version of WordPress.' );
408
					if ( current_user_can( 'update_core' ) ) {
409
						printf(
410
							/* translators: %s: "Update WordPress" screen URL */
411
							' ' . __( '<a href="%s">Please update WordPress</a>.' ),
412
							self_admin_url( 'update-core.php' )
413
						);
414
					}
415 View Code Duplication
				} elseif ( ! $compatible_php ) {
416
					_e( 'This plugin doesn&#8217;t work with your version of PHP.' );
417
					if ( current_user_can( 'update_php' ) ) {
418
						printf(
419
							/* translators: %s: "Update PHP" page URL */
420
							' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
421
							esc_url( wp_get_update_php_url() )
422
						);
423
						wp_update_php_annotation();
424
					}
425
				}
426
				echo '</p></div>';
427
			}
428
			?>
429
430
			<div class="plugin-card-top">
431
				<div class="name column-name">
432
					<h3>
433
						<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'] ); ?>">
434
						<?php echo $title; ?>
435
						<img src="<?php echo esc_attr( $plugin_icon_url ); ?>" class="plugin-icon" alt="">
436
						</a>
437
					</h3>
438
				</div>
439
				<div class="desc column-description">
440
					<p><?php echo $description; ?></p>
441
				</div>
442
443
				<div class="details-link">
444
					<a class="jptracks thickbox open-plugin-details-modal" href="<?php echo $details_link; ?>" data-jptracks-name="jetpack_about_plugin_details_modal" data-jptracks-prop="<?php echo esc_attr( $plugin['slug'] ); ?>"><?php _e( 'More Details', 'jetpack' ); ?></a>
445
				</div>
446
			</div>
447
448
			<div class="plugin-card-bottom">
449
				<div class="meta">
450
					<?php
451
					wp_star_rating(
452
						array(
453
							'rating' => $plugin['rating'],
454
							'type'   => 'percent',
455
							'number' => $plugin['num_ratings'],
456
						)
457
					);
458
					?>
459
					<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?> <?php esc_html_e( 'ratings', 'jetpack' ); ?>)</span>
460
					<div class="downloaded">
461
						<?php
462
						if ( $plugin['active_installs'] >= 1000000 ) {
463
							$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
464
							$active_installs_text     = sprintf(
465
								_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
466
								number_format_i18n( $active_installs_millions )
467
							);
468
						} elseif ( 0 == $plugin['active_installs'] ) {
469
							$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
470
						} else {
471
							$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
472
						}
473
						printf( __( '%s Active Installations' ), $active_installs_text );
474
						?>
475
					</div>
476
				</div>
477
478
				<div class="action-links">
479
					<?php
480
					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...
481
						echo '<ul class="action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
482
					}
483
					?>
484
				</div>
485
			</div>
486
		</li>
487
			<?php
488
489
		}
490
491
	}
492
493
	/**
494
	 * Fetch Gravatar hashes for public A12s from wpcom and display them as a list.
495
	 */
496
	function display_gravatars() {
497
		if ( false === ( $hashes = get_transient( 'a12s_hashes' ) ) ) {
498
			$response = json_decode( wp_remote_retrieve_body(
499
					wp_remote_get( 'https://public-api.wordpress.com/wpcom/v2/a11n-gravatar-hashes' )
500
			) );
501
			if ( ! empty( $response ) && is_array( $response ) ) {
502
				$hashes = array();
503
				foreach ( $response as $hash ) {
504
					$hashes[] = "https://2.gravatar.com/avatar/$hash";
505
				}
506
				if ( ! empty( $hashes ) ) {
507
					set_transient( 'a12s_hashes', $hashes, DAY_IN_SECONDS );
508
				} else {
509
					$hashes = array(
510
						'https://2.gravatar.com/avatar/5ef318426c941cbef6db5342c1356231',
511
						'https://0.gravatar.com/avatar/07adca4279691873f594d48dd7c657e1',
512
						'https://2.gravatar.com/avatar/b0b357b291ac72bc7da81b4d74430fe6',
513
						'https://1.gravatar.com/avatar/ab1f64abf81653d5a60d78a86a26bec1',
514
						'https://2.gravatar.com/avatar/eecc887dff6e1e42103590c76f215d87',
515
						'https://0.gravatar.com/avatar/987da1e668e6eb5cde64b52a477764ec',
516
						'https://1.gravatar.com/avatar/4ac90c7bc18ab89a243e6ca93bda983a',
517
						'https://1.gravatar.com/avatar/4d346581a3340e32cf93703c9ce46bd4',
518
						'https://1.gravatar.com/avatar/78c17142720e599ad7919c541124749e',
519
						'https://0.gravatar.com/avatar/9f376366854d750124dffe057dda99c9',
520
						'https://1.gravatar.com/avatar/1a33e7a69df4f675fcd799edca088ac2',
521
						'https://0.gravatar.com/avatar/30cf08c478da339285e39b5e8feb6a3f',
522
						'https://1.gravatar.com/avatar/d212b7b6c54f0ccb2c848d23440b33ba',
523
						'https://0.gravatar.com/avatar/c0ccdd53794779bcc07fcae7b79c4d80',
524
						'https://2.gravatar.com/avatar/8e6e7e85e416fd569d0f821f6fbc4c2f',
525
						'https://2.gravatar.com/avatar/ebdbd8f65be345e43b11e4487e9fc445',
526
					);
527
				}
528
			}
529
		}
530
		$output = '';
531
		foreach ( $hashes as $hash ) {
532
			$output .= '<li><img src="' . $hash . '?s=150"></li>' . "\n";
533
		}
534
		echo $output;
535
	}
536
537
}
538