| @@ -3,131 +3,46 @@ | ||
| 3 | 3 | * @package Polylang |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * Links model abstract class. | |
| 7 | + * Links model abstract class | |
| 8 | 8 | * |
| 9 | 9 | * @since 1.5 |
| 10 | 10 | */ |
| 11 | 11 | abstract class PLL_Links_Model { |
| 12 | - /** | |
| 13 | - * True if the child class uses pretty permalinks, false otherwise. | |
| 14 | - * | |
| 15 | - * @var bool | |
| 16 | - */ | |
| 12 | + public $model, $options; | |
| 13 | + public $home; // used to store the home url before it is filtered | |
| 17 | 14 | public $using_permalinks; |
| 18 | 15 | |
| 19 | 16 | /** |
| 20 | - * Stores the plugin options. | |
| 17 | + * Constructor | |
| 21 | 18 | * |
| 22 | - * @var array | |
| 23 | - */ | |
| 24 | - public $options; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * @var PLL_Model | |
| 28 | - */ | |
| 29 | - public $model; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Stores the home url before it is filtered. | |
| 33 | - * | |
| 34 | - * @var string | |
| 35 | - */ | |
| 36 | - public $home; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Constructor. | |
| 40 | - * | |
| 41 | 19 | * @since 1.5 |
| 42 | 20 | * |
| 43 | - * @param PLL_Model $model PLL_Model instance. | |
| 21 | + * @param object $model PLL_Model instance | |
| 44 | 22 | */ |
| 45 | 23 | public function __construct( &$model ) { |
| 46 | - $this->model = &$model; | |
| 24 | + $this->model = &$model; | |
| 47 | 25 | $this->options = &$model->options; |
| 48 | 26 | |
| 49 | 27 | $this->home = home_url(); |
| 50 | 28 | |
| 51 | - add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // After PLL_Static_Pages. | |
| 29 | + add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // after PLL_Static_Pages | |
| 52 | 30 | add_filter( 'pll_after_languages_cache', array( $this, 'pll_after_languages_cache' ) ); |
| 53 | 31 | |
| 54 | - // Adds our domains or subdomains to allowed hosts for safe redirection. | |
| 32 | + // adds our domains or subdomains to allowed hosts for safe redirection | |
| 55 | 33 | add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) ); |
| 56 | 34 | } |
| 57 | 35 | |
| 58 | 36 | /** |
| 59 | - * Adds the language code in url. | |
| 37 | + * Changes the language code in url | |
| 60 | 38 | * |
| 61 | - * @since 1.2 | |
| 62 | - * | |
| 63 | - * @param string $url The url to modify. | |
| 64 | - * @param PLL_Language $lang The language object. | |
| 65 | - * @return string Modified url. | |
| 66 | - */ | |
| 67 | - abstract public function add_language_to_link( $url, $lang ); | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Returns the url without language code. | |
| 71 | - * | |
| 72 | - * @since 1.2 | |
| 73 | - * | |
| 74 | - * @param string $url The url to modify. | |
| 75 | - * @return string Modified url. | |
| 76 | - */ | |
| 77 | - abstract public function remove_language_from_link( $url ); | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * Returns the link to the first page. | |
| 81 | - * | |
| 82 | - * @since 1.2 | |
| 83 | - * | |
| 84 | - * @param string $url The url to modify. | |
| 85 | - * @return string Modified url. | |
| 86 | - */ | |
| 87 | - abstract public function remove_paged_from_link( $url ); | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * Returns the link to a paged page. | |
| 91 | - * | |
| 92 | 39 | * @since 1.5 |
| 93 | 40 | * |
| 94 | - * @param string $url The url to modify. | |
| 95 | - * @param int $page The page number. | |
| 96 | - * @return string Modified url. | |
| 41 | + * @param string $url url to modify | |
| 42 | + * @param object $lang language | |
| 43 | + * @return string modified url | |
| 97 | 44 | */ |
| 98 | - abstract public function add_paged_to_link( $url, $page ); | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Returns the language based on language code in url. | |
| 102 | - * | |
| 103 | - * @since 1.2 | |
| 104 | - * @since 2.0 add $url argument. | |
| 105 | - * | |
| 106 | - * @param string $url Optional, defaults to thej current url. | |
| 107 | - * @return string Language slug. | |
| 108 | - */ | |
| 109 | - abstract public function get_language_from_url( $url = '' ); | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * Returns the static front page url. | |
| 113 | - * | |
| 114 | - * @since 1.8 | |
| 115 | - * | |
| 116 | - * @param PLL_Language $lang The language object. | |
| 117 | - * @return string The static front page url. | |
| 118 | - */ | |
| 119 | - abstract public function front_page_url( $lang ); | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * Changes the language code in url. | |
| 123 | - * | |
| 124 | - * @since 1.5 | |
| 125 | - * | |
| 126 | - * @param string $url The url to modify. | |
| 127 | - * @param PLL_Language $lang The language object. | |
| 128 | - * @return string Modified url. | |
| 129 | - */ | |
| 130 | 45 | public function switch_language_in_link( $url, $lang ) { |
| 131 | 46 | $url = $this->remove_language_from_link( $url ); |
| 132 | 47 | return $this->add_language_to_link( $url, $lang ); |
| 133 | 48 | } |
| @@ -132,13 +47,13 @@ | ||
| 132 | 47 | return $this->add_language_to_link( $url, $lang ); |
| 133 | 48 | } |
| 134 | 49 | |
| 135 | 50 | /** |
| 136 | - * Get hosts managed on the website. | |
| 51 | + * Get hosts managed on the website | |
| 137 | 52 | * |
| 138 | 53 | * @since 1.5 |
| 139 | 54 | * |
| 140 | - * @return string[] The list of hosts. | |
| 55 | + * @return array list of hosts | |
| 141 | 56 | */ |
| 142 | 57 | public function get_hosts() { |
| 143 | 58 | return array( wp_parse_url( $this->home, PHP_URL_HOST ) ); |
| 144 | 59 | } |
| @@ -143,13 +58,13 @@ | ||
| 143 | 58 | return array( wp_parse_url( $this->home, PHP_URL_HOST ) ); |
| 144 | 59 | } |
| 145 | 60 | |
| 146 | 61 | /** |
| 147 | - * Returns the home url in a given language. | |
| 62 | + * Returns the home url | |
| 148 | 63 | * |
| 149 | 64 | * @since 1.3.1 |
| 150 | 65 | * |
| 151 | - * @param PLL_Language $lang PLL_Language object. | |
| 66 | + * @param object $lang PLL_Language object | |
| 152 | 67 | * @return string |
| 153 | 68 | */ |
| 154 | 69 | public function home_url( $lang ) { |
| 155 | 70 | $url = trailingslashit( $this->home ); |
| @@ -156,14 +71,13 @@ | ||
| 156 | 71 | return $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ? $url : $this->add_language_to_link( $url, $lang ); |
| 157 | 72 | } |
| 158 | 73 | |
| 159 | 74 | /** |
| 160 | - * Sets the home urls in PLL_Language. | |
| 75 | + * Sets the home urls | |
| 161 | 76 | * |
| 162 | 77 | * @since 1.8 |
| 163 | 78 | * |
| 164 | - * @param PLL_Language $language PLL_Language object. | |
| 165 | - * @return void | |
| 79 | + * @param object $language | |
| 166 | 80 | */ |
| 167 | 81 | protected function set_home_url( $language ) { |
| 168 | 82 | // We should always have a default language here, except, temporarily, in PHPUnit tests. The test here protects against PHP notices. |
| 169 | 83 | if ( isset( $this->options['default_lang'] ) ) { |
| @@ -173,14 +87,14 @@ | ||
| 173 | 87 | } |
| 174 | 88 | } |
| 175 | 89 | |
| 176 | 90 | /** |
| 177 | - * Sets the home urls and flags before the languages are persistently cached. | |
| 91 | + * Sets the home urls and flags before the languages are persistently cached | |
| 178 | 92 | * |
| 179 | 93 | * @since 1.8 |
| 180 | 94 | * |
| 181 | - * @param PLL_Language[] $languages Array of PLL_Language objects. | |
| 182 | - * @return PLL_Language[] Array of PLL_Language objects with home url and flag. | |
| 95 | + * @param array $languages array of PLL_Language objects | |
| 96 | + * @return array | |
| 183 | 97 | */ |
| 184 | 98 | public function pll_languages_list( $languages ) { |
| 185 | 99 | foreach ( $languages as $language ) { |
| 186 | 100 | $this->set_home_url( $language ); |
| @@ -189,19 +103,19 @@ | ||
| 189 | 103 | return $languages; |
| 190 | 104 | } |
| 191 | 105 | |
| 192 | 106 | /** |
| 193 | - * Sets the home urls when not cached. | |
| 194 | - * Sets the home urls scheme. | |
| 107 | + * Sets the home urls when not cached | |
| 108 | + * Sets the home urls scheme | |
| 195 | 109 | * |
| 196 | 110 | * @since 1.8 |
| 197 | 111 | * |
| 198 | - * @param PLL_Language[] $languages Array of PLL_Language objects. | |
| 199 | - * @return PLL_Language[] Array of PLL_Language objects. | |
| 112 | + * @param array $languages array of PLL_Language objects | |
| 113 | + * @return array | |
| 200 | 114 | */ |
| 201 | 115 | public function pll_after_languages_cache( $languages ) { |
| 202 | 116 | foreach ( $languages as $language ) { |
| 203 | - // Get the home urls when not cached. | |
| 117 | + // Get the home urls when not cached | |
| 204 | 118 | if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || ( defined( 'PLL_CACHE_HOME_URL' ) && ! PLL_CACHE_HOME_URL ) ) { |
| 205 | 119 | $this->set_home_url( $language ); |
| 206 | 120 | } |
| 207 | 121 | |
| @@ -211,14 +125,14 @@ | ||
| 211 | 125 | return $languages; |
| 212 | 126 | } |
| 213 | 127 | |
| 214 | 128 | /** |
| 215 | - * Adds our domains or subdomains to allowed hosts for safe redirect. | |
| 129 | + * Adds our domains or subdomains to allowed hosts for safe redirection | |
| 216 | 130 | * |
| 217 | 131 | * @since 1.4.3 |
| 218 | 132 | * |
| 219 | - * @param string[] $hosts Allowed hosts. | |
| 220 | - * @return string[] Modified list of allowed hosts. | |
| 133 | + * @param array $hosts allowed hosts | |
| 134 | + * @return array | |
| 221 | 135 | */ |
| 222 | 136 | public function allowed_redirect_hosts( $hosts ) { |
| 223 | 137 | return array_unique( array_merge( $hosts, array_values( $this->get_hosts() ) ) ); |
| 224 | 138 | } |