Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Sitemap_Buffer_Page
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 get_root_element
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
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_Page
6 * extends the Jetpack_Sitemap_Buffer class to represent the single page sitemap
7 * buffer.
8 *
9 * @since 5.3.0
10 * @package automattic/jetpack
11 */
12
13if ( ! defined( 'ABSPATH' ) ) {
14    exit( 0 );
15}
16
17/**
18 * A buffer for constructing sitemap page xml files.
19 *
20 * @since 5.3.0
21 */
22class Jetpack_Sitemap_Buffer_Page extends Jetpack_Sitemap_Buffer {
23    /**
24     * Jetpack_Sitemap_Buffer_Page 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        $this->doc->appendChild(
37            $this->doc->createComment( 'Jetpack_Sitemap_Buffer_Page' )
38        );
39
40        foreach ( Jetpack_Sitemap_Stylist::sitemap_stylesheet_urls() as $url ) {
41            $this->doc->appendChild(
42                $this->doc->createProcessingInstruction( 'xml-stylesheet', 'type="text/css" href="' . esc_xml( $url ) . '"' )
43            );
44        }
45    }
46
47    /**
48     * Returns a DOM element that contains all single page sitemap elements.
49     */
50    protected function get_root_element() {
51        if ( ! isset( $this->root ) ) {
52
53            /**
54             * Filter the attribute value pairs used for namespace and namespace URI mappings.
55             *
56             * @module sitemaps
57             *
58             * @since 3.9.0
59             *
60             * @param array $namespaces Associative array with namespaces and namespace URIs.
61             */
62            $namespaces = apply_filters(
63                'jetpack_sitemap_ns',
64                array(
65                    'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
66                    'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
67                    'xmlns'              => 'http://www.sitemaps.org/schemas/sitemap/0.9',
68                )
69            );
70
71            $this->root = $this->doc->createElement( 'urlset' );
72
73            foreach ( $namespaces as $name => $value ) {
74                $this->root->setAttribute( $name, $value );
75            }
76
77            $this->doc->appendChild( $this->root );
78            $this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) );
79        }
80
81        return $this->root;
82    }
83}