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