PluginProbe
Redirection / 5.0.1
Redirection v5.0.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 / models / url / url-match.php

url-match.php in Redirection 5.0.1, at models/url/url-match.php

75 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get a URL suitable for matching in the database
5 */
6 class Red_Url_Match {
7 /**
8 * URL
9 *
10 * @var String
11 */
12 private $url;
13
14 /**
15 * Constructor
16 *
17 * @param String $url The URL to match.
18 */
19 public function __construct( $url ) {
20 $this->url = $url;
21 }
22
23 /**
24 * Get the plain 'matched' URL:
25 *
26 * - Lowercase
27 * - No trailing slashes
28 *
29 * @return string URL
30 */
31 public function get_url() {
32 // Remove query params, and decode any encoded characters
33 $url = new Red_Url_Path( $this->url );
34 $path = $url->get_without_trailing_slash();
35
36 // URL encode
37 $decode = [
38 '/',
39 ':',
40 '[',
41 ']',
42 '@',
43 '~',
44 ',',
45 '(',
46 ')',
47 ';',
48 ];
49
50 // URL encode everything - this converts any i10n to the proper encoding
51 $path = rawurlencode( $path );
52
53 // We also converted things we dont want encoding, such as a /. Change these back
54 foreach ( $decode as $char ) {
55 $path = str_replace( rawurlencode( $char ), $char, $path );
56 }
57
58 // Lowercase everything
59 $path = Red_Url_Path::to_lower( $path );
60
61 return $path ? $path : '/';
62 }
63
64 /**
65 * Get the URL with parameters re-ordered into alphabetical order
66 *
67 * @return String
68 */
69 public function get_url_with_params() {
70 $query = new Red_Url_Query( $this->url, new Red_Source_Flags( [ Red_Source_Flags::FLAG_CASE => true ] ) );
71
72 return $query->get_url_with_query( $this->get_url() );
73 }
74 }
75