| 1 |
<?php |
| 2 |
|
| 3 |
include_once dirname( __FILE__ ) . '/url-query.php'; |
| 4 |
include_once dirname( __FILE__ ) . '/url-path.php'; |
| 5 |
include_once dirname( __FILE__ ) . '/url-match.php'; |
| 6 |
include_once dirname( __FILE__ ) . '/url-flags.php'; |
| 7 |
|
| 8 |
class Red_Url { |
| 9 |
private $url; |
| 10 |
|
| 11 |
public function __construct( $url = '' ) { |
| 12 |
$this->url = $url; |
| 13 |
$this->url = str_replace( ' ', '%20', $this->url ); // deprecated |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Get the raw URL |
| 18 |
* |
| 19 |
* @return string URL |
| 20 |
*/ |
| 21 |
public function get_url() { |
| 22 |
return $this->url; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Match a target URL against the current URL, using any match flags |
| 27 |
* |
| 28 |
* @param string $requested_url Target URL |
| 29 |
* @param Red_Source_Flags $flags Match flags |
| 30 |
* @return boolean |
| 31 |
*/ |
| 32 |
public function is_match( $requested_url, Red_Source_Flags $flags ) { |
| 33 |
if ( $flags->is_regex() ) { |
| 34 |
$regex = new Red_Regex( $this->url, $flags->is_ignore_case() ); |
| 35 |
|
| 36 |
return $regex->is_match( $requested_url ); |
| 37 |
} |
| 38 |
|
| 39 |
$path = new Red_Url_Path( $this->url ); |
| 40 |
$query = new Red_Url_Query( $this->url ); |
| 41 |
|
| 42 |
return $path->is_match( $requested_url, $flags ) && $query->is_match( $requested_url, $flags ); |
| 43 |
} |
| 44 |
} |
| 45 |
|