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

referrer.php in Redirection 5.1, at matches/referrer.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 referrer
5 */
6 class Referrer_Match extends Red_Match {
7 use FromNotFrom_Match;
8
9 /**
10 * Referrer
11 *
12 * @var String
13 */
14 public $referrer = '';
15
16 /**
17 * Regex match?
18 *
19 * @var boolean
20 */
21 public $regex = false;
22
23 public function name() {
24 return __( 'URL and referrer', '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 'referrer' => isset( $details['referrer'] ) ? $this->sanitize_referrer( $details['referrer'] ) : '',
31 );
32
33 return $this->save_data( $details, $no_target_url, $data );
34 }
35
36 public function sanitize_referrer( $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->referrer, true );
43 return $regex->is_match( Redirection_Request::get_referrer() );
44 }
45
46 return Redirection_Request::get_referrer() === $this->referrer;
47 }
48
49 public function get_data() {
50 return array_merge( array(
51 'regex' => $this->regex,
52 'referrer' => $this->referrer,
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->referrer = isset( $values['referrer'] ) ? $values['referrer'] : '';
66 }
67 }
68