| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
// phpcs:disable Generic.Classes.DuplicateClassName.Found -- sitemap-builder.php will require correct class file. |
| 3 |
/** |
| 4 |
* Sitemaps (per the protocol) are essentially lists of XML fragments; |
| 5 |
* lists which are subject to size constraints. The Jetpack_Sitemap_Buffer_Master |
| 6 |
* extends the Jetpack_Sitemap_Buffer class to represent the master sitemap |
| 7 |
* buffer. |
| 8 |
* |
| 9 |
* @since 5.3.0 |
| 10 |
* @package automattic/jetpack |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit( 0 ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* A buffer for constructing master sitemap xml files. |
| 19 |
* |
| 20 |
* @since 5.3.0 |
| 21 |
*/ |
| 22 |
class Jetpack_Sitemap_Buffer_Master extends Jetpack_Sitemap_Buffer { |
| 23 |
/** |
| 24 |
* Jetpack_Sitemap_Buffer_Master constructor. |
| 25 |
* |
| 26 |
* @param int $item_limit The maximum size of the buffer in items. |
| 27 |
* @param int $byte_limit The maximum size of the buffer in bytes. |
| 28 |
* @param string $time The initial datetime of the buffer. Must be in 'YYYY-MM-DD hh:mm:ss' format. |
| 29 |
*/ |
| 30 |
public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) { |
| 31 |
parent::__construct( $item_limit, $byte_limit, $time ); |
| 32 |
|
| 33 |
$this->doc->appendChild( |
| 34 |
$this->doc->createComment( "generator='jetpack-" . JETPACK__VERSION . "'" ) |
| 35 |
); |
| 36 |
|
| 37 |
$this->doc->appendChild( |
| 38 |
$this->doc->createComment( 'Jetpack_Sitemap_Buffer_Master' ) |
| 39 |
); |
| 40 |
|
| 41 |
$this->doc->appendChild( |
| 42 |
$this->doc->createProcessingInstruction( |
| 43 |
'xml-stylesheet', |
| 44 |
'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'sitemap-index.xsl' ) . '"' |
| 45 |
) |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns a DOM element that contains all master sitemap elements. |
| 51 |
*/ |
| 52 |
protected function get_root_element() { |
| 53 |
if ( ! isset( $this->root ) ) { |
| 54 |
$this->root = $this->doc->createElement( 'sitemapindex' ); |
| 55 |
$this->root->setAttribute( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' ); |
| 56 |
$this->doc->appendChild( $this->root ); |
| 57 |
$this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) ); |
| 58 |
} |
| 59 |
|
| 60 |
return $this->root; |
| 61 |
} |
| 62 |
} |
| 63 |
|