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 / referrer.php

referrer.php in Redirection 2.7, at matches/referrer.php

49 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 class Referrer_Match extends Red_Match {
4 public $referrer;
5 public $regex;
6
7 function name() {
8 return __( 'URL and referrer', 'redirection' );
9 }
10
11 public function save( array $details, $no_target_url = false ) {
12 $data = array(
13 'regex' => isset( $details['action_data_regex'] ) && $details['action_data_regex'] === 'true' ? true : false,
14 'referrer' => isset( $details['action_data_referrer'] ) ? $this->sanitize_referrer( $details['action_data_referrer'] ) : '',
15 );
16
17 if ( $no_target_url === false ) {
18 $data['url_from'] = isset( $details['action_data_url_from'] ) ? $this->sanitize_url( $details['action_data_url_from'] ) : '';
19 $data['url_notfrom'] = isset( $details['action_data_url_notfrom'] ) ? $this->sanitize_url( $details['action_data_url_notfrom'] ) : '';
20 }
21
22 return $data;
23 }
24
25 public function sanitize_referrer( $agent ) {
26 return $this->sanitize_url( $agent );
27 }
28
29 function initialize( $url ) {
30 $this->url = array( $url, '' );
31 }
32
33 function get_target( $url, $matched_url, $regex ) {
34 $target = false;
35
36 // Check if referrer matches
37 if ( ( $this->regex === false && Redirection_Request::get_referrer() === $this->referrer ) || ( $this->regex === true && preg_match( '@'.str_replace( '@', '\\@', $this->referrer ).'@', Redirection_Request::get_referrer(), $matches ) ) ) {
38 $target = $this->url_from;
39
40 if ( $regex ) {
41 $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url );
42 }
43 } elseif ( $this->url_notfrom !== '' ) {
44 $target = $this->url_notfrom;
45 }
46 return $target;
47 }
48 }
49