← All changes
|
modules/sitemaps/sitemap-buffer-video-fallback.php
+65
-0
16.2-beta
→
16.3-beta
View file →
| @@ -1,0 +1,65 @@ | ||
| 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_Video | |
| 6 | + * extends the Jetpack_Sitemap_Buffer class to represent the single video 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 sitemap video xml files for users without libxml support. | |
| 19 | + * | |
| 20 | + * @since 5.3.0 | |
| 21 | + * @phan-suppress PhanRedefinedClassReference -- Don't conflict with real version. | |
| 22 | + */ | |
| 23 | +class Jetpack_Sitemap_Buffer_Video extends Jetpack_Sitemap_Buffer_Fallback { | |
| 24 | + // @phan-suppress-previous-line UnusedSuppression -- It's used. | |
| 25 | + /** | |
| 26 | + * Returns a DOM element that contains all video sitemap elements. | |
| 27 | + */ | |
| 28 | + protected function get_root_element() { | |
| 29 | + if ( ! isset( $this->root ) ) { | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Filter the XML namespaces included in video 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_video_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:video' => 'http://www.google.com/schemas/sitemap-video/1.1', | |
| 47 | + ) | |
| 48 | + ); | |
| 49 | + | |
| 50 | + $video_sitemap_xsl_url = $this->finder->construct_sitemap_url( 'video-sitemap.xsl' ); | |
| 51 | + $jetpack_version = JETPACK__VERSION; | |
| 52 | + | |
| 53 | + $this->root = array( | |
| 54 | + "<!-- generator='jetpack-{$jetpack_version}' -->" . PHP_EOL | |
| 55 | + . "<?xml-stylesheet type='text/xsl' href='{$video_sitemap_xsl_url}'?>" . PHP_EOL | |
| 56 | + . '<urlset ' . $this->array_to_xml_attr_string( $namespaces ) . '>', | |
| 57 | + '</urlset>', | |
| 58 | + ); | |
| 59 | + | |
| 60 | + $this->byte_capacity -= strlen( implode( '', $this->root ) ); | |
| 61 | + } | |
| 62 | + | |
| 63 | + return $this->root; | |
| 64 | + } | |
| 65 | +} | |