HEX
Server: LiteSpeed
System: Linux cde2.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dtptviut (1121)
PHP: 8.0.30
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dtptviut/public_html/wp-content/plugins/nitropack/classes/WordPress/Sitemap.php
<?php

namespace NitroPack\WordPress;

/**
 * Sitemap is only used in CacheWarmup.php when the user switches it ON. Checks if we have SEO plugin with sitemap and if so, uses that one instead.
 * For example, if Yoast plugin is present - it will use Yoast sitemap.xml and it will display a tooltip message in Cache Warmup setting.
 */
class Sitemap {
	/**
	 * Checks if any of the supported sitemap plugins are active.
	 *
	 * @return bool True if any supported sitemap plugin is active, false otherwise.
	 */
	public function active_sitemap_plugins() {
		return
			\NitroPack\Integration\Plugin\YoastSEO::isActive() ||
			\NitroPack\Integration\Plugin\JetPackNP::isActive() ||
			\NitroPack\Integration\Plugin\SquirrlySEO::isActive() ||
			\NitroPack\Integration\Plugin\RankMathNP::isActive();
	}

	public function get_site_maps() {
		$sitemapUrls['YoastSEO'] = \NitroPack\Integration\Plugin\YoastSEO::getSitemapURL();
		$sitemapUrls['JetPack'] = \NitroPack\Integration\Plugin\JetPackNP::getSitemapURL();
		$sitemapUrls['SquirrlySEO'] = \NitroPack\Integration\Plugin\SquirrlySEO::getSitemapURL();
		$sitemapUrls['RankMath'] = \NitroPack\Integration\Plugin\RankMathNP::getSitemapURL();

		return $sitemapUrls;
	}
	/**
	 * Retrieves the default sitemap URL for WordPress.
	 *
	 * @return string|false The default sitemap URL or false if not available.
	 */
	public function get_default_sitemap() {

		$defaultSiteMap = \NitroPack\Integration\Plugin\WPCacheHelper::getSitemapURL();
		if ( $defaultSiteMap ) {
			$this->set_sitemap_indication_msg( 'WordPress', $defaultSiteMap );
			return $defaultSiteMap;
		}

		return false;
	}
	/**
	 * Evaluates the sitemap to be used for cache warmup based on the available sitemap URLs.
	 *
	 * @param array|null $sitemapUrls An associative array of sitemap URLs from different providers.
	 * @return string|false The selected sitemap URL or false if no suitable sitemap is found.
	 */
	public function evaluate_warmup_sitemap( ?array $sitemapUrls = null ) {

		$sitemapProviders = array(
			'YoastSEO' => 'Yoast!',
			'SquirrlySEO' => 'Squirrly SEO',
			'RankMath' => 'Rank Math',
			'JetPack' => 'Jetpack',
		);

		foreach ( $sitemapProviders as $provider => $name ) {
			if ( isset( $sitemapUrls[ $provider ] ) && $sitemapUrls[ $provider ] ) {
				$this->set_sitemap_indication_msg( $name, $sitemapUrls[ $provider ] );
				return $sitemapUrls[ $provider ];
			}
		}

		return $this->get_default_sitemap();
	}
	/**
	 * Display tooltip information in Cache Warmup setting
	 *
	 * @param string $pluginName
	 * @param string $sitemapURL
	 * @return void
	 */
	private function set_sitemap_indication_msg( string $pluginName, string $sitemapURL ) {
		$sitemapURI = explode( "/", parse_url( $sitemapURL, PHP_URL_PATH ) );
		$msg = $sitemapURI[1] . ' used by ' . $pluginName;
		update_option( 'nitropack-warmup-sitemap', $msg );
	}

}