sitemap-buffer-page-fallback.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_Page
  5. * extends the Jetpack_Sitemap_Buffer class to represent the single page sitemap
  6. * buffer.
  7. *
  8. * @since 5.3.0
  9. * @package Jetpack
  10. */
  11. /**
  12. * A buffer for constructing sitemap page xml files for users with no libxml support.
  13. *
  14. * @since 5.3.0
  15. */
  16. class Jetpack_Sitemap_Buffer_Page 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 3.9.0
  25. *
  26. * @param array $namespaces Associative array with namespaces and namespace URIs.
  27. */
  28. $namespaces = apply_filters(
  29. 'jetpack_sitemap_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. )
  35. );
  36. $jetpack_version = JETPACK__VERSION;
  37. $sitemap_xsl_url = $this->finder->construct_sitemap_url( 'sitemap.xsl' );
  38. $this->root = array(
  39. "<!-- generator='jetpack-{$jetpack_version}' -->" . PHP_EOL
  40. . "<?xml-stylesheet type='text/xsl' href='{$sitemap_xsl_url}'?>" . PHP_EOL
  41. . '<urlset ' . $this->array_to_xml_attr_string( $namespaces ) . '>',
  42. '</urlset>'
  43. );
  44. $this->byte_capacity -= strlen( join( '', $this->root ) );
  45. }
  46. return $this->root;
  47. }
  48. }