sitemap-buffer-news-fallback.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Sitemaps (per the protocol) are essentially lists of XML fragments;
  4. * lists which are subject to size constraints. The Jetpack_Sitemap_Buffer_News
  5. * extends the Jetpack_Sitemap_Buffer class to represent the single news sitemap
  6. * buffer.
  7. *
  8. * @since 5.3.0
  9. * @package Jetpack
  10. */
  11. /**
  12. * A buffer for constructing sitemap image xml files for users without libxml support.
  13. *
  14. * @since 5.3.0
  15. */
  16. class Jetpack_Sitemap_Buffer_News extends Jetpack_Sitemap_Buffer_Fallback {
  17. protected function get_root_element() {
  18. if ( ! isset( $this->root ) ) {
  19. /**
  20. * Filter the attribute value pairs used for namespace and namespace URI mappings.
  21. *
  22. * @module sitemaps
  23. *
  24. * @since 4.8.0
  25. *
  26. * @param array $namespaces Associative array with namespaces and namespace URIs.
  27. */
  28. $namespaces = apply_filters(
  29. 'jetpack_sitemap_news_ns',
  30. array(
  31. 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  32. 'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
  33. 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
  34. 'xmlns:news' => 'http://www.google.com/schemas/sitemap-news/0.9',
  35. )
  36. );
  37. $jetpack_version = JETPACK__VERSION;
  38. $news_sitemap_xsl_url = $this->finder->construct_sitemap_url( 'news-sitemap.xsl' );
  39. $this->root = array(
  40. "<!-- generator='jetpack-{$jetpack_version}' -->" . PHP_EOL
  41. . "<?xml-stylesheet type='text/xsl' href='{$news_sitemap_xsl_url}'?>" . PHP_EOL
  42. . '<urlset ' . $this->array_to_xml_attr_string( $namespaces ) . '>',
  43. '</urlset>'
  44. );
  45. $this->byte_capacity -= strlen( join( '', $this->root ) );
  46. }
  47. return $this->root;
  48. }
  49. }