PluginProbe
Redirection / 2.9
Redirection v2.9
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
← All changes | models/match.php +8 -112 4.02.9 View file →
@@ -1,9 +1,7 @@
1 1 <?php
2 2
3 3 abstract class Red_Match {
4 - protected $type;
5 -
6 4 public function __construct( $values = '' ) {
7 5 if ( $values ) {
8 6 $this->load( $values );
9 7 }
@@ -8,15 +6,11 @@
8 6 $this->load( $values );
9 7 }
10 8 }
11 9
12 - public function get_type() {
13 - return $this->type;
14 - }
15 -
16 10 abstract public function save( array $details, $no_target_url = false );
17 11 abstract public function name();
18 - abstract public function get_target( $url, $matched_url, Red_Source_Flags $flag );
12 + abstract public function get_target( $url, $matched_url, $regex );
19 13 abstract public function get_data();
20 14 abstract public function load( $values );
21 15
22 16 public function sanitize_url( $url ) {
@@ -28,26 +22,22 @@
28 22
29 23 return $url;
30 24 }
31 25
32 - protected function get_target_regex_url( $source_url, $target_url, $requested_url, Red_Source_Flags $flags ) {
33 - $regex = new Red_Regex( $source_url, $flags->is_ignore_case() );
34 -
35 - return $regex->replace( $target_url, $requested_url );
26 + protected function get_target_regex_url( $matched_url, $target, $url ) {
27 + return preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url );
36 28 }
37 29
38 30 static function create( $name, $data = '' ) {
39 31 $avail = self::available();
40 32 if ( isset( $avail[ strtolower( $name ) ] ) ) {
41 - $classname = $name . '_match';
33 + $classname = $name.'_match';
42 34
43 35 if ( ! class_exists( strtolower( $classname ) ) ) {
44 - include( dirname( __FILE__ ) . '/../matches/' . $avail[ strtolower( $name ) ] );
36 + include( dirname( __FILE__ ).'/../matches/'.$avail[ strtolower( $name ) ] );
45 37 }
46 38
47 - $class = new $classname( $data );
48 - $class->type = $name;
49 - return $class;
39 + return new $classname( $data );
50 40 }
51 41
52 42 return false;
53 43 }
@@ -64,106 +54,12 @@
64 54 return $data;
65 55 }
66 56
67 57 static function available() {
68 - return array(
58 + return array(
69 59 'url' => 'url.php',
70 60 'referrer' => 'referrer.php',
71 61 'agent' => 'user-agent.php',
72 62 'login' => 'login.php',
73 - 'header' => 'http-header.php',
74 - 'custom' => 'custom-filter.php',
75 - 'cookie' => 'cookie.php',
76 - 'role' => 'user-role.php',
77 - 'server' => 'server.php',
78 - 'ip' => 'ip.php',
79 - 'page' => 'page.php',
80 - );
81 - }
82 -}
83 -
84 -trait FromUrl_Match {
85 - public $url;
86 -
87 - private function save_data( array $details, $no_target_url, array $data ) {
88 - if ( $no_target_url === false ) {
89 - return array_merge( array(
90 - 'url' => isset( $details['url'] ) ? $this->sanitize_url( $details['url'] ) : '',
91 - ), $data );
92 - }
93 -
94 - return $data;
95 - }
96 -
97 - private function get_matched_target( $matched ) {
98 - if ( $matched ) {
99 - return $this->url;
100 - }
101 -
102 - return false;
103 - }
104 -
105 - private function load_data( $values ) {
106 - $values = unserialize( $values );
107 -
108 - if ( isset( $values['url'] ) ) {
109 - $this->url = $values['url'];
110 - }
111 -
112 - return $values;
113 - }
114 -
115 - private function get_from_data() {
116 - return array(
117 - 'url' => $this->url,
118 - );
119 - }
120 -}
121 -
122 -trait FromNotFrom_Match {
123 - public $url_from;
124 - public $url_notfrom;
125 -
126 - private function save_data( array $details, $no_target_url, array $data ) {
127 - if ( $no_target_url === false ) {
128 - return array_merge( array(
129 - 'url_from' => isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : '',
130 - 'url_notfrom' => isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : '',
131 - ), $data );
132 - }
133 -
134 - return $data;
135 - }
136 -
137 - private function get_matched_target( $matched ) {
138 - if ( $this->url_from !== '' && $matched ) {
139 - return $this->url_from;
140 - }
141 -
142 - if ( $this->url_notfrom !== '' && ! $matched ) {
143 - return $this->url_notfrom;
144 - }
145 -
146 - return false;
147 - }
148 -
149 - private function load_data( $values ) {
150 - $values = unserialize( $values );
151 -
152 - if ( isset( $values['url_from'] ) ) {
153 - $this->url_from = $values['url_from'];
154 - }
155 -
156 - if ( isset( $values['url_notfrom'] ) ) {
157 - $this->url_notfrom = $values['url_notfrom'];
158 - }
159 -
160 - return $values;
161 - }
162 -
163 - private function get_from_data() {
164 - return array(
165 - 'url_from' => $this->url_from,
166 - 'url_notfrom' => $this->url_notfrom,
167 - );
63 + );
168 64 }
169 65 }