PluginProbe
Redirection / 4.0
Redirection v4.0
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 4.0, at matches/referrer.php

71 lines 1.9 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 public $url_from;
7 public $url_notfrom;
8
9 function name() {
10 return __( 'URL and referrer', '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 'referrer' => isset( $details['referrer'] ) ? $this->sanitize_referrer( $details['referrer'] ) : '',
17 );
18
19 if ( $no_target_url === false ) {
20 $data['url_from'] = isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : '';
21 $data['url_notfrom'] = isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : '';
22 }
23
24 return $data;
25 }
26
27 public function sanitize_referrer( $agent ) {
28 return $this->sanitize_url( $agent );
29 }
30
31 public function get_target( $requested_url, $source_url, Red_Source_Flags $flags ) {
32 $target = false;
33 $matched = Redirection_Request::get_referrer() === $this->referrer;
34
35 if ( $this->regex ) {
36 $regex = new Red_Regex( $this->referrer, true );
37 $matched = $regex->is_match( Redirection_Request::get_referrer() );
38 }
39
40 // Check if referrer matches
41 if ( $matched && $this->url_from !== '' ) {
42 $target = $this->url_from;
43 } elseif ( ! $matched && $this->url_notfrom !== '' ) {
44 $target = $this->url_notfrom;
45 }
46
47 if ( $flags->is_regex() && $target ) {
48 $target = $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
49 }
50
51 return $target;
52 }
53
54 public function get_data() {
55 return array(
56 'url_from' => $this->url_from,
57 'url_notfrom' => $this->url_notfrom,
58 'regex' => $this->regex,
59 'referrer' => $this->referrer,
60 );
61 }
62
63 public function load( $values ) {
64 $values = unserialize( $values );
65 $this->url_from = $values['url_from'];
66 $this->url_notfrom = $values['url_notfrom'];
67 $this->regex = $values['regex'];
68 $this->referrer = $values['referrer'];
69 }
70 }
71