| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Links model for use when using one domain per language |
| 8 | 5 | * for example mysite.com/sth and mysite.fr/qqch |
| @@ -12,15 +9,8 @@ | ||
| 12 | 9 | */ |
| 13 | 10 | class PLL_Links_Domain extends PLL_Links_Abstract_Domain { |
| 14 | 11 | |
| 15 | 12 | /** |
| 16 | - * An array with language code as keys and the host as values. | |
| 17 | - * | |
| 18 | - * @var string[] | |
| 19 | - */ | |
| 20 | - protected $hosts; | |
| 21 | - | |
| 22 | - /** | |
| 23 | 13 | * Constructor |
| 24 | 14 | * |
| 25 | 15 | * @since 1.8 |
| 26 | 16 | * |
| @@ -41,15 +31,15 @@ | ||
| 41 | 31 | * links_model interface |
| 42 | 32 | * |
| 43 | 33 | * @since 1.2 |
| 44 | 34 | * |
| 45 | - * @param string $url The url to modify. | |
| 46 | - * @param PLL_Language $lang The language object. | |
| 47 | - * @return string Modified url. | |
| 35 | + * @param string $url url to modify | |
| 36 | + * @param object $lang language | |
| 37 | + * @return string modified url | |
| 48 | 38 | */ |
| 49 | 39 | public function add_language_to_link( $url, $lang ) { |
| 50 | 40 | if ( ! empty( $lang ) && ! empty( $this->hosts[ $lang->slug ] ) ) { |
| 51 | - $url = preg_replace( '#://(' . wp_parse_url( $this->home, PHP_URL_HOST ) . ')($|/.*)#', '://' . $this->hosts[ $lang->slug ] . '$2', $url ); | |
| 41 | + $url = preg_replace( '#:\/\/(' . parse_url( $this->home, PHP_URL_HOST ) . ')($|\/.*)#', '://' . $this->hosts[ $lang->slug ] . '$2', $url ); | |
| 52 | 42 | } |
| 53 | 43 | return $url; |
| 54 | 44 | } |
| 55 | 45 | |
| @@ -63,20 +53,20 @@ | ||
| 63 | 53 | * @return string modified url |
| 64 | 54 | */ |
| 65 | 55 | public function remove_language_from_link( $url ) { |
| 66 | 56 | if ( ! empty( $this->hosts ) ) { |
| 67 | - $url = preg_replace( '#://(' . implode( '|', $this->hosts ) . ')($|/.*)#', '://' . wp_parse_url( $this->home, PHP_URL_HOST ) . '$2', $url ); | |
| 57 | + $url = preg_replace( '#:\/\/(' . implode( '|', $this->hosts ) . ')($|\/.*)#', '://' . parse_url( $this->home, PHP_URL_HOST ) . '$2', $url ); | |
| 68 | 58 | } |
| 69 | 59 | return $url; |
| 70 | 60 | } |
| 71 | 61 | |
| 72 | 62 | /** |
| 73 | - * Returns the home url in a given language. | |
| 74 | - * links_model interface. | |
| 63 | + * Returns the home url | |
| 64 | + * links_model interface | |
| 75 | 65 | * |
| 76 | 66 | * @since 1.3.1 |
| 77 | 67 | * |
| 78 | - * @param PLL_Language $lang PLL_Language object. | |
| 68 | + * @param object $lang PLL_Language object | |
| 79 | 69 | * @return string |
| 80 | 70 | */ |
| 81 | 71 | public function home_url( $lang ) { |
| 82 | 72 | return trailingslashit( empty( $this->options['domains'][ $lang->slug ] ) ? $this->home : $this->options['domains'][ $lang->slug ] ); |
| @@ -82,26 +72,18 @@ | ||
| 82 | 72 | return trailingslashit( empty( $this->options['domains'][ $lang->slug ] ) ? $this->home : $this->options['domains'][ $lang->slug ] ); |
| 83 | 73 | } |
| 84 | 74 | |
| 85 | 75 | /** |
| 86 | - * Get hosts managed on the website. | |
| 76 | + * Get hosts managed on the website | |
| 87 | 77 | * |
| 88 | 78 | * @since 1.5 |
| 89 | 79 | * |
| 90 | - * @return string[] List of hosts. | |
| 80 | + * @return array list of hosts | |
| 91 | 81 | */ |
| 92 | 82 | public function get_hosts() { |
| 93 | 83 | $hosts = array(); |
| 94 | 84 | foreach ( $this->options['domains'] as $lang => $domain ) { |
| 95 | - $host = wp_parse_url( $domain, PHP_URL_HOST ); | |
| 96 | - // idn_to_ascii is much faster than the WordPress method. | |
| 97 | - if ( function_exists( 'idn_to_ascii' ) ) { | |
| 98 | - // The use of the constant is mandatory in PHP 7.2 and PHP 7.3 to avoid a deprecated notice. | |
| 99 | - $hosts[ $lang ] = defined( 'INTL_IDNA_VARIANT_UTS46' ) ? idn_to_ascii( $host, 0, INTL_IDNA_VARIANT_UTS46 ) : idn_to_ascii( $host ); | |
| 100 | - } else { | |
| 101 | - $hosts[ $lang ] = Requests_IDNAEncoder::encode( $host ); | |
| 102 | - } | |
| 85 | + $hosts[ $lang ] = parse_url( $domain, PHP_URL_HOST ); | |
| 103 | 86 | } |
| 104 | - | |
| 105 | 87 | return $hosts; |
| 106 | 88 | } |
| 107 | 89 | } |