PluginProbe
Redirection / 5.1
Redirection v5.1
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 5.1, at matches/user-agent.php

68 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Match the user agent
5 */
6 class Agent_Match extends Red_Match {
7 use FromNotFrom_Match;
8
9 /**
10 * User agent.
11 *
12 * @var String
13 */
14 public $agent = '';
15
16 /**
17 * Is this a regex match?
18 *
19 * @var boolean
20 */
21 public $regex = false;
22
23 public function name() {
24 return __( 'URL and user agent', 'redirection' );
25 }
26
27 public function save( array $details, $no_target_url = false ) {
28 $data = array(
29 'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false,
30 'agent' => isset( $details['agent'] ) ? $this->sanitize_agent( $details['agent'] ) : '',
31 );
32
33 return $this->save_data( $details, $no_target_url, $data );
34 }
35
36 private function sanitize_agent( $agent ) {
37 return $this->sanitize_url( $agent );
38 }
39
40 public function is_match( $url ) {
41 if ( $this->regex ) {
42 $regex = new Red_Regex( $this->agent, true );
43 return $regex->is_match( Redirection_Request::get_user_agent() );
44 }
45
46 return $this->agent === Redirection_Request::get_user_agent();
47 }
48
49 public function get_data() {
50 return array_merge( array(
51 'regex' => $this->regex,
52 'agent' => $this->agent,
53 ), $this->get_from_data() );
54 }
55
56 /**
57 * Load the match data into this instance.
58 *
59 * @param String $values Match values, as read from the database (plain text or serialized PHP).
60 * @return void
61 */
62 public function load( $values ) {
63 $values = $this->load_data( $values );
64 $this->regex = isset( $values['regex'] ) ? $values['regex'] : false;
65 $this->agent = isset( $values['agent'] ) ? $values['agent'] : '';
66 }
67 }
68