Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
79.34% covered (warning)
79.34%
215 / 271
71.43% covered (warning)
71.43%
5 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Sitemap_Stylist
79.93% covered (warning)
79.93%
215 / 269
71.43% covered (warning)
71.43%
5 / 7
11.98
0.00% covered (danger)
0.00%
0 / 1
 sitemap_css
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
3
 sanitize_with_links
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 sitemap_xsl
100.00% covered (success)
100.00%
44 / 44
100.00% covered (success)
100.00%
1 / 1
1
 sitemap_index_xsl
95.92% covered (success)
95.92%
47 / 49
0.00% covered (danger)
0.00%
0 / 1
2
 image_sitemap_xsl
100.00% covered (success)
100.00%
48 / 48
100.00% covered (success)
100.00%
1 / 1
1
 video_sitemap_xsl
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 1
2
 news_sitemap_xsl
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
1 / 1
1
 sitemap_xsl_css
n/a
0 / 0
n/a
0 / 0
1
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2/**
3 * Build the CSS and legacy XSL stylesheets used to present sitemaps.
4 *
5 * @package automattic/jetpack
6 * @since 4.8.0
7 */
8
9if ( ! defined( 'ABSPATH' ) ) {
10    exit( 0 );
11}
12
13/**
14 * Builds the browser stylesheets required by Jetpack_Sitemap_Manager.
15 *
16 * @since 4.8.0
17 */
18class Jetpack_Sitemap_Stylist {
19
20    /**
21     * Provide a localized browser presentation without transforming the XML.
22     *
23     * @since $$next-version$$
24     * @return string CSS stylesheet.
25     */
26    public static function sitemap_css() {
27        $labels = array(
28            'title'       => __( 'XML Sitemap', 'jetpack' ),
29            'index-title' => __( 'XML Sitemap Index', 'jetpack' ),
30            'description' => __( 'This sitemap is generated by Jetpack for search engines. URLs are plain text; copy a URL to open it in your browser.', 'jetpack' ),
31            'url'         => __( 'URL', 'jetpack' ),
32            'lastmod'     => __( 'Last Modified', 'jetpack' ),
33            'image'       => __( 'Image', 'jetpack' ),
34            'video'       => __( 'Video', 'jetpack' ),
35            'video-title' => __( 'Video Title', 'jetpack' ),
36            'news-title'  => __( 'News Title', 'jetpack' ),
37            'published'   => __( 'Publication Date', 'jetpack' ),
38            'footer'      => __( 'Additional sitemap metadata remains available in the XML source.', 'jetpack' ),
39        );
40        // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Read the bundled local stylesheet.
41        $css = file_get_contents( __DIR__ . '/sitemap.css' ) . "\n:root {\n";
42        foreach ( $labels as $key => $label ) {
43            $label = str_replace( array( '\\', '"', "\r", "\n", "\f" ), array( '\\\\', '\\"', ' ', ' ', ' ' ), $label );
44            $css  .= '--jetpack-sitemap-' . $key . ': "' . $label . '";' . "\n";
45        }
46        return $css . 'direction: ' . ( is_rtl() ? 'rtl' : 'ltr' ) . ";\n}\n";
47    }
48
49    /**
50     * Convert named entities, strip all HTML except anchor tags,
51     * and interpolate with vsprintf. This is a helper function
52     * for all the internationalized UI strings in this class
53     * which have to include URLs.
54     *
55     * Note that $url_array should be indexed by integers like so:
56     *
57     * array(
58     *   1 => 'example.com',
59     *   2 => 'example.org',
60     * );
61     *
62     * Then '%1$s' in the format string will substitute 'example.com'
63     * and '%2$s' will substitute 'example.org'.
64     *
65     * @access private
66     * @since 4.8.0
67     * @link https://php.net/manual/en/function.vsprintf.php Format string documentation.
68     *
69     * @param string $format A vsprintf-style format string to be sanitized.
70     * @param array  $url_array The string substitution array to be passed to vsprintf.
71     *
72     * @return string The sanitized string.
73     */
74    private static function sanitize_with_links( $format, $url_array ) {
75        return vsprintf(
76            wp_kses(
77                ent2ncr( $format ),
78                array(
79                    'a' => array(
80                        'href'  => true,
81                        'title' => true,
82                    ),
83                )
84            ),
85            $url_array
86        );
87    }
88
89    /**
90     * Returns the xsl of a sitemap xml file as a string.
91     *
92     * @access public
93     * @since 4.8.0
94     *
95     * @return string The contents of the xsl file.
96     */
97    public static function sitemap_xsl() {
98        $title          = esc_html( ent2ncr( __( 'XML Sitemap', 'jetpack' ) ) );
99        $header_url     = esc_html( ent2ncr( __( 'URL', 'jetpack' ) ) );
100        $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
101
102        $description = self::sanitize_with_links(
103            /* translators: %1$s: jetpack.com URL. %2$s: google.com URL. %3$s: bing.com URL. */
104            __(
105                'This is an XML Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
106                'jetpack'
107            ),
108            array(
109                1 => 'https://jetpack.com/',
110                2 => 'https://www.google.com/',
111                3 => 'https://www.bing.com/',
112            )
113        );
114
115        $more_info = self::sanitize_with_links(
116            /* translators: %1$s: sitemaps.org URL. */
117            __(
118                'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
119                'jetpack'
120            ),
121            array(
122                1 => 'https://sitemaps.org',
123            )
124        );
125
126        $generated_by = self::sanitize_with_links(
127            /* translators: %s: jetpack.com URL. */
128            __(
129                'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
130                'jetpack'
131            ),
132            array(
133                1 => 'https://jetpack.com',
134            )
135        );
136
137        $css = self::sitemap_xsl_css();
138
139        return <<<XSL
140<?xml version='1.0' encoding='UTF-8'?>
141<xsl:stylesheet version='2.0'
142    xmlns:html='http://www.w3.org/TR/REC-html40'
143    xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
144    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
145<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
146<xsl:template match="/">
147<html xmlns="http://www.w3.org/1999/xhtml">
148<head>
149    <title>$title</title>
150    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
151    <style type='text/css'>
152$css
153    </style>
154</head>
155<body>
156    <div id='description'>
157        <h1>$title</h1>
158        <p>$description</p>
159        <p>$more_info</p>
160    </div>
161    <div id='content'>
162        <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
163        <table>
164            <tr>
165                <th>#</th>
166                <th>$header_url</th>
167                <th>$header_lastmod</th>
168            </tr>
169            <xsl:for-each select="sitemap:urlset/sitemap:url">
170                <tr>
171                    <xsl:choose>
172                        <xsl:when test='position() mod 2 != 1'>
173                            <xsl:attribute name="class">odd</xsl:attribute>
174                        </xsl:when>
175                    </xsl:choose>
176                    <td>
177                        <xsl:value-of select = "position()" />
178                    </td>
179                    <td>
180                        <xsl:variable name='itemURL'>
181                            <xsl:value-of select='sitemap:loc'/>
182                        </xsl:variable>
183                        <a href='{\$itemURL}'>
184                            <xsl:value-of select='sitemap:loc'/>
185                        </a>
186                    </td>
187                    <td>
188                        <xsl:value-of select='sitemap:lastmod'/>
189                    </td>
190                </tr>
191            </xsl:for-each>
192        </table>
193    </div>
194    <div id='footer'>
195        <p>$generated_by</p>
196    </div>
197</body>
198</html>
199</xsl:template>
200</xsl:stylesheet>\n
201XSL;
202    }
203
204    /**
205     * Returns the xsl of a sitemap index xml file as a string.
206     *
207     * @access public
208     * @since 4.8.0
209     *
210     * @return string The contents of the xsl file.
211     */
212    public static function sitemap_index_xsl() {
213        $title          = esc_html( ent2ncr( __( 'XML Sitemap Index', 'jetpack' ) ) );
214        $header_url     = esc_html( ent2ncr( __( 'Sitemap URL', 'jetpack' ) ) );
215        $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
216
217        $description = self::sanitize_with_links(
218            /* translators: %1$s: jetpack.com URL. %2$s: google.com URL. %3$s: bing.com URL. */
219            __(
220                'This is an XML Sitemap Index generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
221                'jetpack'
222            ),
223            array(
224                1 => 'https://jetpack.com/',
225                2 => 'https://www.google.com/',
226                3 => 'https://www.bing.com/',
227            )
228        );
229
230        if ( current_user_can( 'manage_options' ) ) {
231            $next = human_time_diff( wp_next_scheduled( 'jp_sitemap_cron_hook' ) );
232            /* translators: %s is a human_time_diff until next sitemap generation. */
233            $no_nodes_warning = sprintf( __( 'No sitemap found. The system will try to build it again in %s.', 'jetpack' ), $next );
234        } else {
235            $no_nodes_warning = '';
236        }
237
238        $more_info = self::sanitize_with_links(
239            /* translators: %1$s: sitemaps.org URL. */
240            __(
241                'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
242                'jetpack'
243            ),
244            array(
245                1 => 'https://sitemaps.org',
246            )
247        );
248
249        $generated_by = self::sanitize_with_links(
250            /* translators: %s: jetpack.com URL. */
251            __(
252                'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
253                'jetpack'
254            ),
255            array(
256                1 => 'https://jetpack.com',
257            )
258        );
259
260        $css = self::sitemap_xsl_css();
261
262        return <<<XSL
263<?xml version='1.0' encoding='UTF-8'?>
264<xsl:stylesheet version='2.0'
265    xmlns:html='http://www.w3.org/TR/REC-html40'
266    xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
267    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
268<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
269<xsl:template match="/">
270<html xmlns="http://www.w3.org/1999/xhtml">
271<head>
272    <title>$title</title>
273    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
274    <style type='text/css'>
275$css
276    </style>
277</head>
278<body>
279    <div id='description'>
280        <h1>$title</h1>
281        <xsl:choose>
282            <xsl:when test='not(sitemap:sitemapindex/sitemap:sitemap)'>
283                <p><strong>$no_nodes_warning</strong></p>
284            </xsl:when>
285        </xsl:choose>
286        <p>$description</p>
287        <p>$more_info</p>
288    </div>
289    <div id='content'>
290        <table>
291            <tr>
292                <th>#</th>
293                <th>$header_url</th>
294                <th>$header_lastmod</th>
295            </tr>
296            <xsl:for-each select='sitemap:sitemapindex/sitemap:sitemap'>
297                <tr>
298                    <xsl:choose>
299                        <xsl:when test='position() mod 2 != 1'>
300                            <xsl:attribute name="class">odd</xsl:attribute>
301                        </xsl:when>
302                    </xsl:choose>
303                    <td>
304                        <xsl:value-of select = "position()" />
305                    </td>
306                    <td>
307                        <xsl:variable name='itemURL'>
308                            <xsl:value-of select='sitemap:loc'/>
309                        </xsl:variable>
310                        <a href='{\$itemURL}'>
311                            <xsl:value-of select='sitemap:loc'/>
312                        </a>
313                    </td>
314                    <td>
315                        <xsl:value-of select='sitemap:lastmod'/>
316                    </td>
317                </tr>
318            </xsl:for-each>
319        </table>
320    </div>
321    <div id='footer'>
322        <p>$generated_by</p>
323    </div>
324</body>
325</html>
326</xsl:template>
327</xsl:stylesheet>\n
328XSL;
329    }
330
331    /**
332     * Returns the xsl of an image sitemap xml file as a string.
333     *
334     * @access public
335     * @since 4.8.0
336     *
337     * @return string The contents of the xsl file.
338     */
339    public static function image_sitemap_xsl() {
340        $title            = esc_html( ent2ncr( __( 'XML Image Sitemap', 'jetpack' ) ) );
341        $header_url       = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
342        $header_image_url = esc_html( ent2ncr( __( 'Image URL', 'jetpack' ) ) );
343        $header_thumbnail = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
344        $header_lastmod   = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
345
346        $description = self::sanitize_with_links(
347            /* translators: %1$s: jetpack.com URL. %2$s: google.com URL. %3$s: bing.com URL. */
348            __(
349                'This is an XML Image Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
350                'jetpack'
351            ),
352            array(
353                1 => 'https://jetpack.com/',
354                2 => 'https://www.google.com/',
355                3 => 'https://www.bing.com/',
356            )
357        );
358
359        $more_info = self::sanitize_with_links(
360            /* translators: %1$s: sitemaps.org URL. */
361            __(
362                'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
363                'jetpack'
364            ),
365            array(
366                1 => 'https://sitemaps.org',
367            )
368        );
369
370        $generated_by = self::sanitize_with_links(
371            /* translators: %s: jetpack.com URL. */
372            __(
373                'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
374                'jetpack'
375            ),
376            array(
377                1 => 'https://jetpack.com',
378            )
379        );
380
381        $css = self::sitemap_xsl_css();
382
383        return <<<XSL
384<?xml version='1.0' encoding='UTF-8'?>
385<xsl:stylesheet version='2.0'
386    xmlns:html='http://www.w3.org/TR/REC-html40'
387    xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
388    xmlns:image='http://www.google.com/schemas/sitemap-image/1.1'
389    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
390<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
391<xsl:template match="/">
392<html xmlns="http://www.w3.org/1999/xhtml">
393<head>
394    <title>$title</title>
395    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
396    <style type='text/css'>
397$css
398    </style>
399</head>
400<body>
401    <div id='description'>
402        <h1>$title</h1>
403        <p>$description</p>
404        <p>$more_info</p>
405    </div>
406    <div id='content'>
407        <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
408        <table>
409            <tr>
410                <th>#</th>
411                <th>$header_url</th>
412                <th>$header_image_url</th>
413                <th>$header_lastmod</th>
414                <th>$header_thumbnail</th>
415            </tr>
416            <xsl:for-each select="sitemap:urlset/sitemap:url">
417                <tr>
418                    <xsl:choose>
419                        <xsl:when test='position() mod 2 != 1'>
420                            <xsl:attribute name="class">odd</xsl:attribute>
421                        </xsl:when>
422                    </xsl:choose>
423                    <td>
424                        <xsl:value-of select = "position()" />
425                    </td>
426                    <td>
427                        <xsl:variable name='pageURL'>
428                            <xsl:value-of select='sitemap:loc'/>
429                        </xsl:variable>
430                        <a href='{\$pageURL}'>
431                            <xsl:value-of select='sitemap:loc'/>
432                        </a>
433                    </td>
434                    <xsl:variable name='itemURL'>
435                        <xsl:value-of select='image:image/image:loc'/>
436                    </xsl:variable>
437                    <td>
438                        <a href='{\$itemURL}'>
439                            <xsl:value-of select='image:image/image:loc'/>
440                        </a>
441                    </td>
442                    <td>
443                        <xsl:value-of select='sitemap:lastmod'/>
444                    </td>
445                    <td>
446                        <a href='{\$itemURL}'>
447                            <img class='thumbnail' src='{\$itemURL}'/>
448                        </a>
449                    </td>
450                </tr>
451            </xsl:for-each>
452        </table>
453    </div>
454    <div id='footer'>
455        <p>$generated_by</p>
456    </div>
457</body>
458</html>
459</xsl:template>
460</xsl:stylesheet>\n
461XSL;
462    }
463
464    /**
465     * Returns the xsl of a video sitemap xml file as a string.
466     *
467     * @access public
468     * @since 4.8.0
469     *
470     * @return string The contents of the xsl file.
471     */
472    public static function video_sitemap_xsl() {
473        $title              = esc_html( ent2ncr( __( 'XML Video Sitemap', 'jetpack' ) ) );
474        $header_url         = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
475        $header_image_url   = esc_html( ent2ncr( __( 'Video URL', 'jetpack' ) ) );
476        $header_thumbnail   = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
477        $header_title       = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
478        $header_lastmod     = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
479        $header_description = esc_html( ent2ncr( __( 'Description', 'jetpack' ) ) );
480
481        $description = self::sanitize_with_links(
482            /* translators: %1$s: jetpack.com URL. %2$s: google.com URL. %3$s: bing.com URL. */
483            __(
484                'This is an XML Video Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
485                'jetpack'
486            ),
487            array(
488                1 => 'https://jetpack.com/',
489                2 => 'https://www.google.com/',
490                3 => 'https://www.bing.com/',
491            )
492        );
493
494        $more_info = self::sanitize_with_links(
495            /* translators: %1$s: sitemaps.org URL. */
496            __(
497                'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
498                'jetpack'
499            ),
500            array(
501                1 => 'https://sitemaps.org',
502            )
503        );
504
505        $generated_by = self::sanitize_with_links(
506            /* translators: %s: jetpack.com URL. */
507            __(
508                'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
509                'jetpack'
510            ),
511            array(
512                1 => 'https://jetpack.com',
513            )
514        );
515
516        $css = self::sitemap_xsl_css();
517
518        return <<<XSL
519<?xml version='1.0' encoding='UTF-8'?>
520<xsl:stylesheet version='2.0'
521    xmlns:html='http://www.w3.org/TR/REC-html40'
522    xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
523    xmlns:video='http://www.google.com/schemas/sitemap-video/1.1'
524    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
525<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
526<xsl:template match="/">
527<html xmlns="http://www.w3.org/1999/xhtml">
528<head>
529    <title>$title</title>
530    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
531    <style type='text/css'>
532$css
533    </style>
534</head>
535<body>
536    <div id='description'>
537        <h1>$title</h1>
538        <p>$description</p>
539        <p>$more_info</p>
540    </div>
541    <div id='content'>
542        <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
543        <table>
544            <tr>
545                <th>#</th>
546                <th>$header_url</th>
547                <th>$header_image_url</th>
548                <th>$header_title</th>
549                <th>$header_description</th>
550                <th>$header_lastmod</th>
551                <th>$header_thumbnail</th>
552            </tr>
553            <xsl:for-each select="sitemap:urlset/sitemap:url">
554                <tr>
555                    <xsl:choose>
556                        <xsl:when test='position() mod 2 != 1'>
557                            <xsl:attribute name="class">odd</xsl:attribute>
558                        </xsl:when>
559                    </xsl:choose>
560                    <td>
561                        <xsl:value-of select = "position()" />
562                    </td>
563                    <td>
564                        <xsl:variable name='pageURL'>
565                            <xsl:value-of select='sitemap:loc'/>
566                        </xsl:variable>
567                        <a href='{\$pageURL}'>
568                            <xsl:value-of select='sitemap:loc'/>
569                        </a>
570                    </td>
571                    <xsl:variable name='itemURL'>
572                        <xsl:value-of select='video:video/video:content_loc'/>
573                    </xsl:variable>
574                    <td>
575                        <a href='{\$itemURL}'>
576                            <xsl:value-of select='video:video/video:content_loc'/>
577                        </a>
578                    </td>
579                    <td>
580                        <xsl:value-of select='video:video/video:title'/>
581                    </td>
582                    <td>
583                        <xsl:value-of select='video:video/video:description' disable-output-escaping='yes'/>
584                    </td>
585                    <td>
586                        <xsl:value-of select='sitemap:lastmod'/>
587                    </td>
588                    <td>
589                        <xsl:variable name='thumbURL'>
590                            <xsl:value-of select='video:video/video:thumbnail_loc'/>
591                        </xsl:variable>
592                        <a href='{\$thumbURL}'>
593                            <img class='thumbnail' src='{\$thumbURL}'/>
594                        </a>
595                    </td>
596                </tr>
597            </xsl:for-each>
598        </table>
599    </div>
600    <div id='footer'>
601        <p>$generated_by</p>
602    </div>
603</body>
604</html>
605</xsl:template>
606</xsl:stylesheet>\n
607XSL;
608    }
609
610    /**
611     * Returns the xsl of a news sitemap xml file as a string.
612     *
613     * @access public
614     * @since 4.8.0
615     *
616     * @return string The contents of the xsl file.
617     */
618    public static function news_sitemap_xsl() {
619        $title          = esc_html( ent2ncr( __( 'XML News Sitemap', 'jetpack' ) ) );
620        $header_url     = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
621        $header_title   = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
622        $header_pubdate = esc_html( ent2ncr( __( 'Publication Date', 'jetpack' ) ) );
623
624        $description = self::sanitize_with_links(
625            /* translators: %1$s: jetpack.com URL. %2$s: google.com URL. %3$s: bing.com URL. */
626            __(
627                'This is an XML News Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
628                'jetpack'
629            ),
630            array(
631                1 => 'https://jetpack.com/',
632                2 => 'https://www.google.com/',
633                3 => 'https://www.bing.com/',
634            )
635        );
636
637        $more_info = self::sanitize_with_links(
638            /* translators: %1$s: sitemaps.org URL. */
639            __(
640                'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
641                'jetpack'
642            ),
643            array(
644                1 => 'https://sitemaps.org',
645            )
646        );
647
648        $generated_by = self::sanitize_with_links(
649            /* translators: %s: jetpack.com URL. */
650            __(
651                'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
652                'jetpack'
653            ),
654            array(
655                1 => 'https://jetpack.com',
656            )
657        );
658
659        $css = self::sitemap_xsl_css();
660
661        return <<<XSL
662<?xml version='1.0' encoding='UTF-8'?>
663<xsl:stylesheet version='2.0'
664    xmlns:html='http://www.w3.org/TR/REC-html40'
665    xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
666    xmlns:news='http://www.google.com/schemas/sitemap-news/0.9'
667    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
668<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
669<xsl:template match="/">
670<html xmlns="http://www.w3.org/1999/xhtml">
671<head>
672    <title>$title</title>
673    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
674    <style type='text/css'>
675$css
676    </style>
677</head>
678<body>
679    <div id='description'>
680        <h1>$title</h1>
681        <p>$description</p>
682        <p>$more_info</p>
683    </div>
684    <div id='content'>
685        <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
686        <table>
687            <tr>
688                <th>#</th>
689                <th>$header_url</th>
690                <th>$header_title</th>
691                <th>$header_pubdate</th>
692            </tr>
693            <xsl:for-each select="sitemap:urlset/sitemap:url">
694                <tr>
695                    <xsl:choose>
696                        <xsl:when test='position() mod 2 != 1'>
697                            <xsl:attribute name="class">odd</xsl:attribute>
698                        </xsl:when>
699                    </xsl:choose>
700                    <td>
701                        <xsl:value-of select = "position()" />
702                    </td>
703                    <xsl:variable name='pageURL'>
704                        <xsl:value-of select='sitemap:loc'/>
705                    </xsl:variable>
706                    <td>
707                        <a href='{\$pageURL}'>
708                            <xsl:value-of select='sitemap:loc'/>
709                        </a>
710                    </td>
711                    <td>
712                        <a href='{\$pageURL}'>
713                            <xsl:value-of select='news:news/news:title'/>
714                        </a>
715                    </td>
716                    <td>
717                        <xsl:value-of select='news:news/news:publication_date'/>
718                    </td>
719                </tr>
720            </xsl:for-each>
721        </table>
722    </div>
723    <div id='footer'>
724        <p>$generated_by</p>
725    </div>
726</body>
727</html>
728</xsl:template>
729</xsl:stylesheet>\n
730XSL;
731    }
732
733    /**
734     * The CSS to be included in sitemap xsl stylesheets;
735     * factored out for uniformity.
736     *
737     * @access public
738     * @since 4.8.0
739     *
740     * @return string The CSS.
741     */
742    public static function sitemap_xsl_css() {
743        return <<<'CSS'
744        body {
745            font: 14px 'Open Sans', Helvetica, Arial, sans-serif;
746            margin: 0;
747        }
748
749        a {
750            color: #3498db;
751            text-decoration: none;
752        }
753
754        h1 {
755            margin: 0;
756        }
757
758        #description {
759            background-color: #f0f2eb;
760            color: #000;
761            padding: 30px 30px 20px;
762        }
763
764        #description a {
765            color: #008710;
766        }
767
768        #content {
769            padding: 10px 30px 30px;
770            background: #fff;
771        }
772
773        a:hover {
774            border-bottom: 1px solid;
775        }
776
777        th, td {
778            font-size: 12px;
779        }
780
781        th {
782            text-align: left;
783            border-bottom: 1px solid #ccc;
784        }
785
786        th, td {
787            padding: 10px 15px;
788        }
789
790        .odd {
791            background: linear-gradient( 159.87deg, #f6f6f4 7.24%, #f7f4ea 64.73%, #ddedd5 116.53% );
792        }
793
794        #footer {
795            margin: 20px 30px;
796            font-size: 12px;
797            color: #999;
798        }
799
800        #footer a {
801            color: inherit;
802        }
803
804        #description a, #footer a {
805            border-bottom: 1px solid;
806        }
807
808        #description a:hover, #footer a:hover {
809            border-bottom: none;
810        }
811
812        img {
813            max-height: 100px;
814            max-width: 100px;
815        }
816CSS;
817    }
818}