PluginProbe
Redirection / 3.4
Redirection v3.4
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 3.4, at matches/referrer.php

70 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 function get_target( $url, $matched_url, $regex ) {
32 $target = false;
33 $matched = Redirection_Request::get_referrer() === $this->referrer;
34
35 if ( $this->regex ) {
36 $matched = preg_match( '@'.str_replace( '@', '\\@', $this->referrer ).'@', Redirection_Request::get_referrer(), $matches ) > 0;
37 }
38
39 // Check if referrer matches
40 if ( $matched && $this->url_from !== '' ) {
41 $target = $this->url_from;
42 } elseif ( ! $matched && $this->url_notfrom !== '' ) {
43 $target = $this->url_notfrom;
44 }
45
46 if ( $regex && $target ) {
47 $target = $this->get_target_regex_url( $matched_url, $target, $url );
48 }
49
50 return $target;
51 }
52
53 public function get_data() {
54 return array(
55 'url_from' => $this->url_from,
56 'url_notfrom' => $this->url_notfrom,
57 'regex' => $this->regex,
58 'referrer' => $this->referrer,
59 );
60 }
61
62 public function load( $values ) {
63 $values = unserialize( $values );
64 $this->url_from = $values['url_from'];
65 $this->url_notfrom = $values['url_notfrom'];
66 $this->regex = $values['regex'];
67 $this->referrer = $values['referrer'];
68 }
69 }
70