Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.48% covered (success)
90.48%
19 / 21
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Jetpack_Sitemap_Buffer_Video_XMLWriter
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 initialize_buffer
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 start_root
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
 append_item
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2/**
3 * XMLWriter implementation of the video sitemap buffer.
4 *
5 * @since 14.6
6 * @package automattic/jetpack
7 */
8
9if ( ! defined( 'ABSPATH' ) ) {
10    exit( 0 );
11}
12
13/**
14 * A buffer for constructing sitemap video xml files using XMLWriter.
15 *
16 * @since 14.6
17 */
18class Jetpack_Sitemap_Buffer_Video_XMLWriter extends Jetpack_Sitemap_Buffer_XMLWriter {
19
20    /**
21     * Initialize the buffer with required headers (no root element here).
22     */
23    protected function initialize_buffer() {
24        // Add generator comment
25        $this->writer->writeComment( "generator='jetpack-" . JETPACK__VERSION . "'" );
26        $this->writer->writeComment( 'Jetpack_Sitemap_Buffer_Video_XMLWriter' );
27
28        // Add stylesheet
29        foreach ( Jetpack_Sitemap_Stylist::sitemap_stylesheet_urls() as $url ) {
30            $this->writer->writePi( 'xml-stylesheet', 'type="text/css" href="' . esc_xml( $url ) . '"' );
31        }
32    }
33
34    /**
35     * Start the root element and write its namespaces.
36     */
37    protected function start_root() {
38        $this->writer->startElement( 'urlset' );
39
40        /**
41         * Filter the XML namespaces included in video sitemaps.
42         *
43         * @module sitemaps
44         *
45         * @since 4.8.0
46         *
47         * @param array $namespaces Associative array with namespaces and namespace URIs.
48         */
49        $namespaces = apply_filters(
50            'jetpack_sitemap_video_ns',
51            array(
52                'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
53                'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
54                'xmlns'              => 'http://www.sitemaps.org/schemas/sitemap/0.9',
55                'xmlns:video'        => 'http://www.google.com/schemas/sitemap-video/1.1',
56            )
57        );
58
59        foreach ( $namespaces as $name => $value ) {
60            $this->writer->writeAttribute( $name, $value );
61        }
62    }
63
64    /**
65     * Append a URL entry with video information to the sitemap.
66     *
67     * @param array $array The URL item to append.
68     */
69    protected function append_item( $array ) {
70        // Return early if missing fundamental data.
71        if ( empty( $array['url']['video:video'] ) ) {
72            return;
73        }
74
75        $this->array_to_xml( $array );
76    }
77}