PluginProbe
Redirection / 5.2
Redirection v5.2
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 / language.php

language.php in Redirection 5.2, at matches/language.php

67 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Check the client language
5 */
6 class Language_Match extends Red_Match {
7 use FromNotFrom_Match;
8
9 /**
10 * Language to check.
11 *
12 * @var String
13 */
14 public $language = '';
15
16 public function name() {
17 return __( 'URL and language', 'redirection' );
18 }
19
20 public function save( array $details, $no_target_url = false ) {
21 $data = array( 'language' => isset( $details['language'] ) ? $this->sanitize_language( $details['language'] ) : '' );
22
23 return $this->save_data( $details, $no_target_url, $data );
24 }
25
26 /**
27 * Sanitize the language value to a CSV string
28 *
29 * @param String $language User supplied language strings.
30 * @return String
31 */
32 private function sanitize_language( $language ) {
33 $parts = explode( ',', str_replace( ' ', '', $language ) );
34 return implode( ',', $parts );
35 }
36
37 public function is_match( $url ) {
38 $matches = explode( ',', $this->language );
39 $requested = Redirection_Request::get_accept_language();
40
41 foreach ( $matches as $match ) {
42 if ( in_array( $match, $requested, true ) ) {
43 return true;
44 }
45 }
46
47 return false;
48 }
49
50 public function get_data() {
51 return array_merge( array(
52 'language' => $this->language,
53 ), $this->get_from_data() );
54 }
55
56 /**
57 * Load the match data into this instance.
58 *
59 * @param String $values Match values, as read from the database (plain text or serialized PHP).
60 * @return void
61 */
62 public function load( $values ) {
63 $values = $this->load_data( $values );
64 $this->language = isset( $values['language'] ) ? $values['language'] : '';
65 }
66 }
67