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