| @@ -3,23 +3,28 @@ | ||
| 3 | 3 | * @package Polylang |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * Links model for use when the language code is added in url as a subdomain | |
| 8 | - * for example en.mysite.com/something | |
| 9 | - * implements the "links_model interface" | |
| 7 | + * Links model for use when the language code is added in the url as a subdomain | |
| 8 | + * for example en.mysite.com/something. | |
| 10 | 9 | * |
| 11 | 10 | * @since 1.2 |
| 12 | 11 | */ |
| 13 | 12 | class PLL_Links_Subdomain extends PLL_Links_Abstract_Domain { |
| 13 | + /** | |
| 14 | + * Stores whether the home url includes www. or not. | |
| 15 | + * Either '://' or '://www.'. | |
| 16 | + * | |
| 17 | + * @var string | |
| 18 | + */ | |
| 14 | 19 | protected $www; |
| 15 | 20 | |
| 16 | 21 | /** |
| 17 | - * Constructor | |
| 22 | + * Constructor. | |
| 18 | 23 | * |
| 19 | 24 | * @since 1.7.4 |
| 20 | 25 | * |
| 21 | - * @param object $model PLL_Model instance | |
| 26 | + * @param PLL_Model $model Instance of PLL_Model. | |
| 22 | 27 | */ |
| 23 | 28 | public function __construct( &$model ) { |
| 24 | 29 | parent::__construct( $model ); |
| 25 | 30 | $this->www = ( false === strpos( $this->home, '://www.' ) ) ? '://' : '://www.'; |
| @@ -25,16 +30,15 @@ | ||
| 25 | 30 | $this->www = ( false === strpos( $this->home, '://www.' ) ) ? '://' : '://www.'; |
| 26 | 31 | } |
| 27 | 32 | |
| 28 | 33 | /** |
| 29 | - * Adds the language code in url | |
| 30 | - * links_model interface | |
| 34 | + * Adds the language code in a url. | |
| 31 | 35 | * |
| 32 | 36 | * @since 1.2 |
| 33 | 37 | * |
| 34 | - * @param string $url url to modify | |
| 35 | - * @param object $lang language | |
| 36 | - * @return string modified url | |
| 38 | + * @param string $url The url to modify. | |
| 39 | + * @param PLL_Language|false $lang The language object. | |
| 40 | + * @return string The modified url. | |
| 37 | 41 | */ |
| 38 | 42 | public function add_language_to_link( $url, $lang ) { |
| 39 | 43 | if ( ! empty( $lang ) && false === strpos( $url, '://' . $lang->slug . '.' ) ) { |
| 40 | 44 | $url = $this->options['default_lang'] == $lang->slug && $this->options['hide_default'] ? $url : str_replace( $this->www, '://' . $lang->slug . '.', $url ); |
| @@ -42,15 +46,14 @@ | ||
| 42 | 46 | return $url; |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | 49 | /** |
| 46 | - * Returns the url without language code | |
| 47 | - * links_model interface | |
| 50 | + * Returns the url without the language code. | |
| 48 | 51 | * |
| 49 | 52 | * @since 1.2 |
| 50 | 53 | * |
| 51 | - * @param string $url url to modify | |
| 52 | - * @return string modified url | |
| 54 | + * @param string $url The url to modify. | |
| 55 | + * @return string The modified url. | |
| 53 | 56 | */ |
| 54 | 57 | public function remove_language_from_link( $url ) { |
| 55 | 58 | $languages = array(); |
| 56 | 59 | |
| @@ -67,18 +70,19 @@ | ||
| 67 | 70 | return $url; |
| 68 | 71 | } |
| 69 | 72 | |
| 70 | 73 | /** |
| 71 | - * Get hosts managed on the website | |
| 74 | + * Get the hosts managed on the website. | |
| 72 | 75 | * |
| 73 | 76 | * @since 1.5 |
| 74 | 77 | * |
| 75 | - * @return array list of hosts | |
| 78 | + * @return string[] The list of hosts. | |
| 76 | 79 | */ |
| 77 | 80 | public function get_hosts() { |
| 78 | 81 | $hosts = array(); |
| 79 | 82 | foreach ( $this->model->get_languages_list() as $lang ) { |
| 80 | - $hosts[ $lang->slug ] = wp_parse_url( $this->home_url( $lang ), PHP_URL_HOST ); | |
| 83 | + $host = wp_parse_url( $this->home_url( $lang ), PHP_URL_HOST ); | |
| 84 | + $hosts[ $lang->slug ] = $host ? $host : ''; | |
| 81 | 85 | } |
| 82 | 86 | return $hosts; |
| 83 | 87 | } |
| 84 | 88 | } |