| 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( $url, $matched_url, $regex ) { |
| 11 |
$target = false; |
| 12 |
$matched = Redirection_Request::get_cookie( $this->name ) === $this->value; |
| 13 |
|
| 14 |
if ( $this->regex ) { |
| 15 |
$matched = preg_match( '@' . str_replace( '@', '\\@', $this->value ) . '@', Redirection_Request::get_cookie( $this->name ), $matches ) > 0; |
| 16 |
} |
| 17 |
|
| 18 |
// Check if referrer matches |
| 19 |
if ( $matched && $this->url_from !== '' ) { |
| 20 |
$target = $this->url_from; |
| 21 |
} elseif ( ! $matched && $this->url_notfrom !== '' ) { |
| 22 |
$target = $this->url_notfrom; |
| 23 |
} |
| 24 |
|
| 25 |
if ( $regex && $target ) { |
| 26 |
$target = $this->get_target_regex_url( $matched_url, $target, $url ); |
| 27 |
} |
| 28 |
|
| 29 |
return $target; |
| 30 |
} |
| 31 |
} |
| 32 |
|