| 1 |
<?php |
| 2 |
|
| 3 |
include_once dirname( __FILE__ ) . '/http-header.php'; |
| 4 |
|
| 5 |
class Cookie_Match extends Header_Match { |
| 6 |
function name() { |
| 7 |
return __( 'URL and cookie', 'redirection' ); |
| 8 |
} |
| 9 |
|
| 10 |
function get_target( $requested_url, $source_url, Red_Source_Flags $flags ) { |
| 11 |
$target = false; |
| 12 |
$matched = Redirection_Request::get_cookie( $this->name ) === $this->value; |
| 13 |
|
| 14 |
if ( $this->regex ) { |
| 15 |
$regex = new Red_Regex( $this->value, true ); |
| 16 |
$matched = $regex->is_match( Redirection_Request::get_cookie( $this->name ) ); |
| 17 |
} |
| 18 |
|
| 19 |
// Check if referrer matches |
| 20 |
if ( $matched && $this->url_from !== '' ) { |
| 21 |
$target = $this->url_from; |
| 22 |
} elseif ( ! $matched && $this->url_notfrom !== '' ) { |
| 23 |
$target = $this->url_notfrom; |
| 24 |
} |
| 25 |
|
| 26 |
if ( $flags->is_regex() && $target ) { |
| 27 |
$target = $this->get_target_regex_url( $source_url, $target, $requested_url, $flags ); |
| 28 |
} |
| 29 |
|
| 30 |
return $target; |
| 31 |
} |
| 32 |
} |
| 33 |
|