<?php
/**
 * Sitemap Stylesheet
 *
 * Serves the XSL stylesheet for browser-friendly sitemap display.
 *
 * @package SEOvaultSEO
 */

namespace SEOvaultSEO\Sitemap;

/**
 * Serves the sitemap XSL stylesheet
 */
class Stylesheet {

	/**
	 * Output the XSL stylesheet.
	 */
	public static function output() {
		if ( ! headers_sent() ) {
			status_header( 200 );
			header( 'Content-Type: text/xsl; charset=UTF-8' );
			header( 'X-Robots-Tag: noindex, follow' );
		}

		$file = SEOVAULT_SEO_DIR . 'assets/xsl/sitemap.xsl';
		if ( file_exists( $file ) ) {
			// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
			$xsl = file_get_contents( $file );
			if ( false !== $xsl ) {
				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- XSL stylesheet must be output raw.
				echo $xsl;
				return;
			}
		}

		echo '<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>';
	}
}
