sitemap-buffer-factory.php
1 year ago
sitemap-buffer-fallback.php
2 years ago
sitemap-buffer-image-fallback.php
2 years ago
sitemap-buffer-image-xmlwriter.php
1 year ago
sitemap-buffer-image.php
4 years ago
sitemap-buffer-master-fallback.php
2 years ago
sitemap-buffer-master-xmlwriter.php
1 year ago
sitemap-buffer-master.php
4 years ago
sitemap-buffer-news-fallback.php
2 years ago
sitemap-buffer-news-xmlwriter.php
1 year ago
sitemap-buffer-news.php
4 years ago
sitemap-buffer-page-fallback.php
2 years ago
sitemap-buffer-page-xmlwriter.php
1 year ago
sitemap-buffer-page.php
4 years ago
sitemap-buffer-video-fallback.php
1 year ago
sitemap-buffer-video-xmlwriter.php
1 year ago
sitemap-buffer-video.php
4 years ago
sitemap-buffer-xmlwriter.php
1 year ago
sitemap-buffer.php
1 year ago
sitemap-builder.php
1 year ago
sitemap-constants.php
1 year ago
sitemap-finder.php
2 years ago
sitemap-librarian.php
1 year ago
sitemap-logger.php
1 year ago
sitemap-state.php
2 years ago
sitemap-stylist.php
2 years ago
sitemaps.php
1 year ago
sitemap-buffer-page-xmlwriter.php
73 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * XMLWriter implementation of the page sitemap buffer. |
| 4 | * |
| 5 | * @since 14.6 |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * A buffer for constructing sitemap page xml files using XMLWriter. |
| 11 | * |
| 12 | * @since 14.6 |
| 13 | */ |
| 14 | class Jetpack_Sitemap_Buffer_Page_XMLWriter extends Jetpack_Sitemap_Buffer_XMLWriter { |
| 15 | |
| 16 | /** |
| 17 | * Initialize the buffer with required headers and root element. |
| 18 | */ |
| 19 | protected function initialize_buffer() { |
| 20 | // Add generator comment |
| 21 | $this->writer->writeComment( "generator='jetpack-" . JETPACK__VERSION . "'" ); |
| 22 | $this->writer->writeComment( 'Jetpack_Sitemap_Buffer_Page_XMLWriter' ); |
| 23 | |
| 24 | // Add stylesheet |
| 25 | $this->writer->writePi( |
| 26 | 'xml-stylesheet', |
| 27 | 'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'sitemap.xsl' ) . '"' |
| 28 | ); |
| 29 | |
| 30 | // Start root element with namespaces |
| 31 | $this->writer->startElement( 'urlset' ); |
| 32 | |
| 33 | /** |
| 34 | * Filter the attribute value pairs used for namespace and namespace URI mappings. |
| 35 | * |
| 36 | * @module sitemaps |
| 37 | * |
| 38 | * @since 3.9.0 |
| 39 | * |
| 40 | * @param array $namespaces Associative array with namespaces and namespace URIs. |
| 41 | */ |
| 42 | $namespaces = apply_filters( |
| 43 | 'jetpack_sitemap_ns', |
| 44 | array( |
| 45 | 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', |
| 46 | 'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', |
| 47 | 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9', |
| 48 | ) |
| 49 | ); |
| 50 | |
| 51 | foreach ( $namespaces as $name => $value ) { |
| 52 | $this->writer->writeAttribute( $name, $value ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Append a URL entry to the sitemap. |
| 58 | * |
| 59 | * @param array $array The URL item to append. |
| 60 | */ |
| 61 | protected function append_item( $array ) { |
| 62 | if ( ! empty( $array['url'] ) ) { |
| 63 | $this->writer->startElement( 'url' ); |
| 64 | |
| 65 | foreach ( $array['url'] as $tag => $value ) { |
| 66 | $this->writer->writeElement( $tag, strval( $value ) ); |
| 67 | } |
| 68 | |
| 69 | $this->writer->endElement(); // url |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |