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