PluginProbe
Redirection / 4.8
Redirection v4.8
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / matches / user-agent.php

user-agent.php in Redirection 4.8, at matches/user-agent.php

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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