Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Sitemap_Buffer_Image
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 get_root_element
0.00% covered (danger)
0.00%
0 / 16
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_Image
6 * extends the Jetpack_Sitemap_Buffer class to represent the single image 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 image xml files.
19 *
20 * @since 5.3.0
21 */
22class Jetpack_Sitemap_Buffer_Image extends Jetpack_Sitemap_Buffer {
23
24    /**
25     * Jetpack_Sitemap_Buffer_Image constructor.
26     *
27     * @param int    $item_limit The maximum size of the buffer in items.
28     * @param int    $byte_limit The maximum size of the buffer in bytes.
29     * @param string $time The initial datetime of the buffer. Must be in 'YYYY-MM-DD hh:mm:ss' format.
30     */
31    public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) {
32        parent::__construct( $item_limit, $byte_limit, $time );
33
34        $this->doc->appendChild(
35            $this->doc->createComment( "generator='jetpack-" . JETPACK__VERSION . "'" )
36        );
37
38        $this->doc->appendChild(
39            $this->doc->createComment( 'Jetpack_Sitemap_Buffer_Image' )
40        );
41
42        $this->doc->appendChild(
43            $this->doc->createProcessingInstruction(
44                'xml-stylesheet',
45                'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'image-sitemap.xsl' ) . '"'
46            )
47        );
48    }
49
50    /**
51     * Returns a DOM element that contains all image sitemap elements.
52     */
53    protected function get_root_element() {
54        if ( ! isset( $this->root ) ) {
55
56            /**
57             * Filter the XML namespaces included in image sitemaps.
58             *
59             * @module sitemaps
60             *
61             * @since 4.8.0
62             *
63             * @param array $namespaces Associative array with namespaces and namespace URIs.
64             */
65            $namespaces = apply_filters(
66                'jetpack_sitemap_image_ns',
67                array(
68                    'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
69                    'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
70                    'xmlns'              => 'http://www.sitemaps.org/schemas/sitemap/0.9',
71                    'xmlns:image'        => 'http://www.google.com/schemas/sitemap-image/1.1',
72                )
73            );
74
75            $this->root = $this->doc->createElement( 'urlset' );
76
77            foreach ( $namespaces as $name => $value ) {
78                $this->root->setAttribute( $name, $value );
79            }
80
81            $this->doc->appendChild( $this->root );
82            $this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) );
83        }
84
85        return $this->root;
86    }
87}