PluginProbe
Redirection / 5.4
Redirection v5.4
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 / server.php

server.php in Redirection 5.4, at matches/server.php

63 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 * Match the server URL. Used to match requests for another domain.
5 */
6 class Server_Match extends Red_Match {
7 use FromNotFrom_Match;
8
9 /**
10 * Server URL.
11 *
12 * @var String
13 */
14 public $server = '';
15
16 public function name() {
17 return __( 'URL and server', 'redirection' );
18 }
19
20 public function save( array $details, $no_target_url = false ) {
21 $data = array( 'server' => isset( $details['server'] ) ? $this->sanitize_server( $details['server'] ) : '' );
22
23 return $this->save_data( $details, $no_target_url, $data );
24 }
25
26 private function sanitize_server( $server ) {
27 if ( strpos( $server, 'http' ) === false ) {
28 $server = ( is_ssl() ? 'https://' : 'http://' ) . $server;
29 }
30
31 $parts = wp_parse_url( $server );
32
33 if ( isset( $parts['host'] ) ) {
34 return $parts['scheme'] . '://' . $parts['host'];
35 }
36
37 return '';
38 }
39
40 public function is_match( $url ) {
41 $server = wp_parse_url( $this->server, PHP_URL_HOST );
42
43 return $server === Redirection_Request::get_server_name();
44 }
45
46 public function get_data() {
47 return array_merge( array(
48 'server' => $this->server,
49 ), $this->get_from_data() );
50 }
51
52 /**
53 * Load the match data into this instance.
54 *
55 * @param string $values Match values, as read from the database (plain text or serialized PHP).
56 * @return void
57 */
58 public function load( $values ) {
59 $values = $this->load_data( $values );
60 $this->server = isset( $values['server'] ) ? $values['server'] : '';
61 }
62 }
63