PluginProbe
Redirection / 3.3
Redirection v3.3
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 / models / match.php

match.php in Redirection 3.3, at models/match.php

120 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 abstract class Red_Match {
4 public function __construct( $values = '' ) {
5 if ( $values ) {
6 $this->load( $values );
7 }
8 }
9
10 abstract public function save( array $details, $no_target_url = false );
11 abstract public function name();
12 abstract public function get_target( $url, $matched_url, $regex );
13 abstract public function get_data();
14 abstract public function load( $values );
15
16 public function sanitize_url( $url ) {
17 // No new lines
18 $url = preg_replace( "/[\r\n\t].*?$/s", '', $url );
19
20 // Clean control codes
21 $url = preg_replace( '/[^\PC\s]/u', '', $url );
22
23 return $url;
24 }
25
26 protected function get_target_regex_url( $matched_url, $target, $url ) {
27 return preg_replace( '@' . str_replace( '@', '\\@', $matched_url ) . '@', $target, $url );
28 }
29
30 static function create( $name, $data = '' ) {
31 $avail = self::available();
32 if ( isset( $avail[ strtolower( $name ) ] ) ) {
33 $classname = $name . '_match';
34
35 if ( ! class_exists( strtolower( $classname ) ) ) {
36 include( dirname( __FILE__ ) . '/../matches/' . $avail[ strtolower( $name ) ] );
37 }
38
39 return new $classname( $data );
40 }
41
42 return false;
43 }
44
45 static function all() {
46 $data = array();
47
48 $avail = self::available();
49 foreach ( $avail as $name => $file ) {
50 $obj = self::create( $name );
51 $data[ $name ] = $obj->name();
52 }
53
54 return $data;
55 }
56
57 static function available() {
58 return array(
59 'url' => 'url.php',
60 'referrer' => 'referrer.php',
61 'agent' => 'user-agent.php',
62 'login' => 'login.php',
63 'header' => 'http-header.php',
64 'custom' => 'custom-filter.php',
65 'cookie' => 'cookie.php',
66 'role' => 'user-role.php',
67 'server' => 'server.php',
68 );
69 }
70 }
71
72 trait FromNotFrom_Match {
73 public $url_from;
74 public $url_notfrom;
75
76 private function save_data( array $details, $no_target_url, array $data ) {
77 if ( $no_target_url === false ) {
78 return array_merge( array(
79 'url_from' => isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : '',
80 'url_notfrom' => isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : '',
81 ), $data );
82 }
83
84 return $data;
85 }
86
87 private function get_matched_target( $matched ) {
88 if ( $this->url_from !== '' && $matched ) {
89 return $this->url_from;
90 }
91
92 if ( $this->url_notfrom !== '' && ! $matched ) {
93 return $this->url_notfrom;
94 }
95
96 return false;
97 }
98
99 private function load_data( $values ) {
100 $values = unserialize( $values );
101
102 if ( isset( $values['url_from'] ) ) {
103 $this->url_from = $values['url_from'];
104 }
105
106 if ( isset( $values['url_notfrom'] ) ) {
107 $this->url_notfrom = $values['url_notfrom'];
108 }
109
110 return $values;
111 }
112
113 private function get_from_data() {
114 return array(
115 'url_from' => $this->url_from,
116 'url_notfrom' => $this->url_notfrom,
117 );
118 }
119 }
120