sitemap-buffer-page.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.
  13. *
  14. * @since 5.3.0
  15. */
  16. class Jetpack_Sitemap_Buffer_Page extends Jetpack_Sitemap_Buffer {
  17. public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) {
  18. parent::__construct( $item_limit, $byte_limit, $time );
  19. $this->doc->appendChild(
  20. $this->doc->createComment( "generator='jetpack-" . JETPACK__VERSION . "'" )
  21. );
  22. $this->doc->appendChild(
  23. $this->doc->createProcessingInstruction(
  24. 'xml-stylesheet',
  25. 'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'sitemap.xsl' ) . '"'
  26. )
  27. );
  28. }
  29. protected function get_root_element() {
  30. if ( ! isset( $this->root ) ) {
  31. /**
  32. * Filter the attribute value pairs used for namespace and namespace URI mappings.
  33. *
  34. * @module sitemaps
  35. *
  36. * @since 3.9.0
  37. *
  38. * @param array $namespaces Associative array with namespaces and namespace URIs.
  39. */
  40. $namespaces = apply_filters(
  41. 'jetpack_sitemap_ns',
  42. array(
  43. 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  44. 'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
  45. 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
  46. )
  47. );
  48. $this->root = $this->doc->createElement( 'urlset' );
  49. foreach ( $namespaces as $name => $value ) {
  50. $this->root->setAttribute( $name, $value );
  51. }
  52. $this->doc->appendChild( $this->root );
  53. $this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) );
  54. }
  55. return $this->root;
  56. }
  57. }