sitemap-buffer-image.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_Image
  5. * extends the Jetpack_Sitemap_Buffer class to represent the single image sitemap
  6. * buffer.
  7. *
  8. * @since 5.3.0
  9. * @package Jetpack
  10. */
  11. /**
  12. * A buffer for constructing sitemap image xml files.
  13. *
  14. * @since 5.3.0
  15. */
  16. class Jetpack_Sitemap_Buffer_Image 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( 'image-sitemap.xsl' ) . '"'
  26. )
  27. );
  28. }
  29. protected function get_root_element() {
  30. if ( ! isset( $this->root ) ) {
  31. /**
  32. * Filter the XML namespaces included in image sitemaps.
  33. *
  34. * @module sitemaps
  35. *
  36. * @since 4.8.0
  37. *
  38. * @param array $namespaces Associative array with namespaces and namespace URIs.
  39. */
  40. $namespaces = apply_filters(
  41. 'jetpack_sitemap_image_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. 'xmlns:image' => 'http://www.google.com/schemas/sitemap-image/1.1',
  47. )
  48. );
  49. $this->root = $this->doc->createElement( 'urlset' );
  50. foreach ( $namespaces as $name => $value ) {
  51. $this->root->setAttribute( $name, $value );
  52. }
  53. $this->doc->appendChild( $this->root );
  54. $this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) );
  55. }
  56. return $this->root;
  57. }
  58. }