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 / from-url.php

from-url.php in Redirection 5.1, at matches/from-url.php

92 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Trait to add redirect matching that adds a matched target
5 */
6 trait FromUrl_Match {
7 /**
8 * URL to match against
9 *
10 * @var string
11 */
12 public $url = '';
13
14 /**
15 * Save data to an array, ready for serializing.
16 *
17 * @param array $details New match data.
18 * @param boolean $no_target_url Does the action have a target URL.
19 * @param array $data Existing match data.
20 * @return array
21 */
22 private function save_data( array $details, $no_target_url, array $data ) {
23 if ( $no_target_url === false ) {
24 return array_merge( [
25 'url' => isset( $details['url'] ) ? $this->sanitize_url( $details['url'] ) : '',
26 ], $data );
27 }
28
29 return $data;
30 }
31
32 /**
33 * Get target URL for this match, depending on whether we match or not
34 *
35 * @param string $requested_url Request URL.
36 * @param string $source_url Redirect source URL.
37 * @param Red_Source_Flags $flags Redirect flags.
38 * @param boolean $matched Is the URL matched.
39 * @return string|false
40 */
41 public function get_target_url( $requested_url, $source_url, Red_Source_Flags $flags, $matched ) {
42 $target = $this->get_matched_target( $matched );
43
44 if ( $flags->is_regex() && $target ) {
45 return $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
46 }
47
48 return $target;
49 }
50
51 /**
52 * Return the matched target, if one exists.
53 *
54 * @param boolean $matched Is it matched.
55 * @return false|string
56 */
57 private function get_matched_target( $matched ) {
58 if ( $matched ) {
59 return $this->url;
60 }
61
62 return false;
63 }
64
65 /**
66 * Load the data into the instance.
67 *
68 * @param String $values Serialized PHP data.
69 * @return array
70 */
71 private function load_data( $values ) {
72 $values = unserialize( $values );
73
74 if ( isset( $values['url'] ) ) {
75 $this->url = $values['url'];
76 }
77
78 return $values;
79 }
80
81 /**
82 * Get the loaded data as an array.
83 *
84 * @return array<url: string>
85 */
86 private function get_from_data() {
87 return [
88 'url' => $this->url,
89 ];
90 }
91 }
92