| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\EditorOne\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class Slug_Normalizer { |
| 10 |
|
| 11 |
public function normalize( string $slug ): string { |
| 12 |
if ( 0 !== strpos( $slug, 'http' ) ) { |
| 13 |
return $slug; |
| 14 |
} |
| 15 |
|
| 16 |
$parsed = wp_parse_url( $slug ); |
| 17 |
$path = basename( $parsed['path'] ?? '' ); |
| 18 |
|
| 19 |
if ( ! empty( $parsed['query'] ) ) { |
| 20 |
$path .= '?' . $parsed['query']; |
| 21 |
} |
| 22 |
|
| 23 |
if ( ! empty( $parsed['fragment'] ) ) { |
| 24 |
$path .= '#' . $parsed['fragment']; |
| 25 |
} |
| 26 |
|
| 27 |
return $path; |
| 28 |
} |
| 29 |
|
| 30 |
public function is_excluded( string $item_slug, array $excluded_slugs ): bool { |
| 31 |
if ( in_array( $item_slug, $excluded_slugs, true ) ) { |
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
$normalized_slug = $this->normalize( $item_slug ); |
| 36 |
|
| 37 |
return in_array( $normalized_slug, $excluded_slugs, true ); |
| 38 |
} |
| 39 |
} |
| 40 |
|