PluginProbe
Redirection / 4.8
Redirection v4.8
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 / http-header.php

http-header.php in Redirection 4.8, at matches/http-header.php

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Header_Match extends Red_Match {
4 use FromNotFrom_Match;
5
6 public $name;
7 public $value;
8 public $regex;
9
10 public function name() {
11 return __( 'URL and HTTP header', 'redirection' );
12 }
13
14 public function save( array $details, $no_target_url = false ) {
15 $data = array(
16 'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false,
17 'name' => isset( $details['name'] ) ? $this->sanitize_name( $details['name'] ) : '',
18 'value' => isset( $details['value'] ) ? $this->sanitize_value( $details['value'] ) : '',
19 );
20
21 return $this->save_data( $details, $no_target_url, $data );
22 }
23
24 public function sanitize_name( $name ) {
25 $name = $this->sanitize_url( $name );
26 $name = str_replace( ' ', '', $name );
27 $name = preg_replace( '/[^A-Za-z0-9\-_]/', '', $name );
28
29 return trim( trim( $name, ':' ) );
30 }
31
32 public function sanitize_value( $value ) {
33 return $this->sanitize_url( $value );
34 }
35
36 public function is_match( $url ) {
37 if ( $this->regex ) {
38 $regex = new Red_Regex( $this->value, true );
39 return $regex->is_match( Redirection_Request::get_header( $this->name ) );
40 }
41
42 return Redirection_Request::get_header( $this->name ) === $this->value;
43 }
44
45 public function get_data() {
46 return array_merge( array(
47 'regex' => $this->regex,
48 'name' => $this->name,
49 'value' => $this->value,
50 ), $this->get_from_data() );
51 }
52
53 public function load( $values ) {
54 $values = $this->load_data( $values );
55 $this->regex = isset( $values['regex'] ) ? $values['regex'] : false;
56 $this->name = isset( $values['name'] ) ? $values['name'] : '';
57 $this->value = isset( $values['value'] ) ? $values['value'] : '';
58 }
59 }
60