Completed
Push — update/sitemaps-libxml ( 788f64...e35b89 )
by
unknown
11:52 queued 02:33
created

modules/sitemaps/sitemap-buffer-image.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Sitemaps (per the protocol) are essentially lists of XML fragments;
4
 * lists which are subject to size constraints. The Jetpack_Sitemap_Buffer_Image
5
 * extends the Jetpack_Sitemap_Buffer class to represent the single image sitemap
6
 * buffer.
7
 *
8
 * @since 5.1.0
9
 * @package Jetpack
10
 */
11
12
/**
13
 * A buffer for constructing sitemap image xml files.
14
 *
15
 * @since 5.1.0
16
 */
17 View Code Duplication
class Jetpack_Sitemap_Buffer_Image extends Jetpack_Sitemap_Buffer {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Jetpack_Sitemap_Buffer_Image has been defined more than once; this definition is ignored, only the first definition in modules/sitemaps/sitemap-buffer-image-fallback.php (L17-56) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
18
19
	public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) {
20
		parent::__construct( $item_limit, $byte_limit, $time );
21
22
		$this->doc->appendChild(
23
			$this->doc->createComment( "generator='jetpack-" . JETPACK__VERSION . "'" )
24
		);
25
26
		$this->doc->appendChild(
27
			$this->doc->createProcessingInstruction(
28
				'xml-stylesheet',
29
				'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'image-sitemap.xsl' ) . '"'
30
			)
31
		);
32
	}
33
34
	protected function get_root_element() {
35
		if ( ! isset( $this->root ) ) {
36
37
			/**
38
			 * Filter the XML namespaces included in image sitemaps.
39
			 *
40
			 * @module sitemaps
41
			 *
42
			 * @since 4.8.0
43
			 *
44
			 * @param array $namespaces Associative array with namespaces and namespace URIs.
45
			 */
46
			$namespaces = apply_filters(
47
				'jetpack_sitemap_image_ns',
48
				array(
49
					'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
50
					'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
51
					'xmlns'              => 'http://www.sitemaps.org/schemas/sitemap/0.9',
52
					'xmlns:image'        => 'http://www.google.com/schemas/sitemap-image/1.1',
53
				)
54
			);
55
56
			$this->root = $this->doc->createElement( 'urlset' );
57
58
			foreach ( $namespaces as $name => $value ) {
59
				$this->root->setAttribute( $name, $value );
60
			}
61
62
			$this->doc->appendChild( $this->root );
63
			$this->byte_capacity -= strlen( $this->doc->saveXML( $this->root ) );
64
		}
65
66
		return $this->root;
67
	}
68
}
69