PluginProbe
Redirection / 2.7
Redirection v2.7
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 2.7, at matches/user-agent.php

43 lines 1.3 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 public $user_agent;
5
6 function name() {
7 return __( 'URL and user agent', 'redirection' );
8 }
9
10 public function save( array $details, $no_target_url = false ) {
11 $data = array(
12 'regex' => isset( $details['action_data_regex'] ) && $details['action_data_regex'] === 'true' ? true : false,
13 'agent' => isset( $details['action_data_agent'] ) ? $this->sanitize_agent( $details['action_data_agent'] ) : '',
14 );
15
16 if ( $no_target_url === false ) {
17 $data['url_from'] = isset( $details['action_data_url_from'] ) ? $this->sanitize_url( $details['action_data_url_from'] ) : '';
18 $data['url_notfrom'] = isset( $details['action_data_url_notfrom'] ) ? $this->sanitize_url( $details['action_data_url_notfrom'] ) : '';
19 }
20
21 return $data;
22 }
23
24 private function sanitize_agent( $agent ) {
25 return $this->sanitize_url( $agent );
26 }
27
28 function initialize( $url ) {
29 $this->url = array( $url, '' );
30 }
31
32 function get_target( $url, $matched_url, $regex ) {
33 // Check if referrer matches
34 if ( preg_match( '@'.str_replace( '@', '\\@', $this->user_agent ).'@i', $_SERVER['HTTP_USER_AGENT'], $matches ) > 0 ) {
35 return preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url_from, $url );
36 } elseif ( $this->url_notfrom !== '' ) {
37 return $this->url_notfrom;
38 }
39
40 return false;
41 }
42 }
43