• File: request-path.php
  • Full Path: /home/slvgwrnz/public_html/wp-content/plugins/elementor/modules/agents/classes/request-path.php
  • Date Modified: 11/05/2026 9:17 AM
  • File size: 1.44 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Elementor\Modules\Agents\Classes;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Request_Path {

	/**
	 * Extract the relative path from REQUEST_URI, stripping the home URL
	 * prefix for subdirectory installs and decoding percent-encoded characters.
	 *
	 * @return string Relative path with leading slash, or empty string on failure.
	 */
	public static function get_relative_path(): string {
		$request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) );

		$path = wp_parse_url( $request_uri, PHP_URL_PATH );

		if ( ! is_string( $path ) ) {
			return '';
		}

		$path = rawurldecode( $path );

		$home_path = wp_parse_url( home_url(), PHP_URL_PATH );

		if ( ! is_string( $home_path ) || '' === $home_path || '/' === $home_path ) {
			return $path;
		}

		$home_path = rawurldecode( untrailingslashit( $home_path ) );

		if ( 0 === strpos( $path, $home_path . '/' ) ) {
			return substr( $path, strlen( $home_path ) );
		}

		return '';
	}

	/**
	 * Check whether the current request URI matches a given filename.
	 * Handles subdirectory WordPress installs transparently.
	 *
	 * @param string $filename e.g. 'llms.txt' or 'llms-full.txt'
	 */
	public static function matches( string $filename ): bool {
		$path = self::get_relative_path();

		if ( '' === $path ) {
			return false;
		}

		$path = untrailingslashit( $path );

		$trimmed_path = ltrim( $path, '/' );

		return '/' . $filename === $path || $trimmed_path === $filename;
	}
}