| @@ -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 |
| @@ -40,9 +37,9 @@ | ||
| 40 | 37 | * @return string modified url |
| 41 | 38 | */ |
| 42 | 39 | public function add_language_to_link( $url, $lang ) { |
| 43 | 40 | if ( ! empty( $lang ) && ! empty( $this->hosts[ $lang->slug ] ) ) { |
| 44 | - $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 ); | |
| 45 | 42 | } |
| 46 | 43 | return $url; |
| 47 | 44 | } |
| 48 | 45 | |
| @@ -56,9 +53,9 @@ | ||
| 56 | 53 | * @return string modified url |
| 57 | 54 | */ |
| 58 | 55 | public function remove_language_from_link( $url ) { |
| 59 | 56 | if ( ! empty( $this->hosts ) ) { |
| 60 | - $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 ); | |
| 61 | 58 | } |
| 62 | 59 | return $url; |
| 63 | 60 | } |
| 64 | 61 | |
| @@ -84,17 +81,9 @@ | ||
| 84 | 81 | */ |
| 85 | 82 | public function get_hosts() { |
| 86 | 83 | $hosts = array(); |
| 87 | 84 | foreach ( $this->options['domains'] as $lang => $domain ) { |
| 88 | - $host = wp_parse_url( $domain, PHP_URL_HOST ); | |
| 89 | - // idn_to_ascii is much faster than the WordPress method. | |
| 90 | - if ( function_exists( 'idn_to_ascii' ) ) { | |
| 91 | - // The use of the constant is mandatory in PHP 7.2 and PHP 7.3 to avoid a deprecated notice. | |
| 92 | - $hosts[ $lang ] = defined( 'INTL_IDNA_VARIANT_UTS46' ) ? idn_to_ascii( $host, 0, INTL_IDNA_VARIANT_UTS46 ) : idn_to_ascii( $host ); | |
| 93 | - } else { | |
| 94 | - $hosts[ $lang ] = Requests_IDNAEncoder::encode( $host ); | |
| 95 | - } | |
| 85 | + $hosts[ $lang ] = parse_url( $domain, PHP_URL_HOST ); | |
| 96 | 86 | } |
| 97 | - | |
| 98 | 87 | return $hosts; |
| 99 | 88 | } |
| 100 | 89 | } |