| 1 |
<?php |
| 2 |
|
| 3 |
class Agent_Match extends Red_Match { |
| 4 |
use FromNotFrom_Match; |
| 5 |
|
| 6 |
public $agent; |
| 7 |
public $regex; |
| 8 |
|
| 9 |
public function name() { |
| 10 |
return __( 'URL and user agent', 'redirection' ); |
| 11 |
} |
| 12 |
|
| 13 |
public function save( array $details, $no_target_url = false ) { |
| 14 |
$data = array( |
| 15 |
'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false, |
| 16 |
'agent' => isset( $details['agent'] ) ? $this->sanitize_agent( $details['agent'] ) : '', |
| 17 |
); |
| 18 |
|
| 19 |
return $this->save_data( $details, $no_target_url, $data ); |
| 20 |
} |
| 21 |
|
| 22 |
private function sanitize_agent( $agent ) { |
| 23 |
return $this->sanitize_url( $agent ); |
| 24 |
} |
| 25 |
|
| 26 |
public function is_match( $url ) { |
| 27 |
if ( $this->regex ) { |
| 28 |
$regex = new Red_Regex( $this->agent, true ); |
| 29 |
return $regex->is_match( Redirection_Request::get_user_agent() ); |
| 30 |
} |
| 31 |
|
| 32 |
return $this->agent === Redirection_Request::get_user_agent(); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_data() { |
| 36 |
return array_merge( array( |
| 37 |
'regex' => $this->regex, |
| 38 |
'agent' => $this->agent, |
| 39 |
), $this->get_from_data() ); |
| 40 |
} |
| 41 |
|
| 42 |
public function load( $values ) { |
| 43 |
$values = $this->load_data( $values ); |
| 44 |
$this->regex = isset( $values['regex'] ) ? $values['regex'] : false; |
| 45 |
$this->agent = isset( $values['agent'] ) ? $values['agent'] : ''; |
| 46 |
} |
| 47 |
} |
| 48 |
|