| @@ -1,220 +1,88 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | - * A language object is made of two terms in 'language' and 'term_language' taxonomies. | |
| 8 | - * Manipulating only one object per language instead of two terms should make things easier. | |
| 4 | + * A language object is made of two terms in 'language' and 'term_language' taxonomies | |
| 5 | + * manipulating only one object per language instead of two terms should make things easier | |
| 9 | 6 | * |
| 7 | + * Properties: | |
| 8 | + * term_id => id of term in 'language' taxonomy | |
| 9 | + * name => language name. Ex: English | |
| 10 | + * slug => language code used in url. Ex: en | |
| 11 | + * term_group => order of the language when displayed in a list of languages | |
| 12 | + * term_taxonomy_id => term taxonomy id in 'language' taxonomy | |
| 13 | + * taxonomy => 'language' | |
| 14 | + * description => language locale for backward compatibility | |
| 15 | + * parent => 0 / not used | |
| 16 | + * count => number of posts and pages in that language | |
| 17 | + * tl_term_id => id of the term in 'term_language' taxonomy | |
| 18 | + * tl_term_taxonomy_id => term taxonomy id in 'term_language' taxonomy | |
| 19 | + * tl_count => number of terms in that language ( not used by Polylang ) | |
| 20 | + * locale => WordPress language locale. Ex: en_US | |
| 21 | + * is_rtl => 1 if the language is rtl | |
| 22 | + * w3c => W3C locale | |
| 23 | + * flag_code => code of the flag | |
| 24 | + * flag_url => url of the flag | |
| 25 | + * flag => html img of the flag | |
| 26 | + * custom_flag_url => url of the custom flag if exists, internal use only, moves to flag_url on frontend | |
| 27 | + * custom_flag => html img of the custom flag if exists, internal use only, moves to flag on frontend | |
| 28 | + * home_url => home url in this language | |
| 29 | + * search_url => home url to use in search forms | |
| 30 | + * host => host of this language | |
| 31 | + * mo_id => id of the post storing strings translations | |
| 32 | + * page_on_front => id of the page on front in this language ( set from pll_languages_list filter ) | |
| 33 | + * page_for_posts => id of the page for posts in this language ( set from pll_languages_list filter ) | |
| 34 | + * | |
| 10 | 35 | * @since 1.2 |
| 11 | 36 | */ |
| 12 | 37 | class PLL_Language { |
| 13 | - /** | |
| 14 | - * Id of the term in 'language' taxonomy. | |
| 15 | - * | |
| 16 | - * @var int | |
| 17 | - */ | |
| 18 | - public $term_id; | |
| 38 | + public $term_id, $name, $slug, $term_group, $term_taxonomy_id, $taxonomy, $description, $parent, $count; | |
| 39 | + public $tl_term_id, $tl_term_taxonomy_id, $tl_count; | |
| 40 | + public $locale, $is_rtl; | |
| 41 | + public $w3c, $facebook; | |
| 42 | + public $flag_url, $flag; | |
| 43 | + public $home_url, $search_url; | |
| 44 | + public $host, $mo_id; | |
| 45 | + public $page_on_front, $page_for_posts; | |
| 19 | 46 | |
| 20 | 47 | /** |
| 21 | - * Language name. Ex: English. | |
| 48 | + * Constructor: builds a language object given its two corresponding terms in language and term_language taxonomies | |
| 22 | 49 | * |
| 23 | - * @var string | |
| 24 | - */ | |
| 25 | - public $name; | |
| 26 | - | |
| 27 | - /** | |
| 28 | - * Language code used in url. Ex: en. | |
| 29 | - * | |
| 30 | - * @var string | |
| 31 | - */ | |
| 32 | - public $slug; | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * Order of the language when displayed in a list of languages. | |
| 36 | - * | |
| 37 | - * @var int | |
| 38 | - */ | |
| 39 | - public $term_group; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * Term taxonomy id in 'language' taxonomy. | |
| 43 | - * | |
| 44 | - * @var int | |
| 45 | - */ | |
| 46 | - public $term_taxonomy_id; | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Number of posts and pages in that language. | |
| 50 | - * | |
| 51 | - * @var int | |
| 52 | - */ | |
| 53 | - public $count; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * Id of the term in 'term_language' taxonomy. | |
| 57 | - * | |
| 58 | - * @var int | |
| 59 | - */ | |
| 60 | - public $tl_term_id; | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * Term taxonomy id in 'term_language' taxonomy. | |
| 64 | - * | |
| 65 | - * @var int | |
| 66 | - */ | |
| 67 | - public $tl_term_taxonomy_id; | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Number of terms in that language. | |
| 71 | - * | |
| 72 | - * @var int | |
| 73 | - */ | |
| 74 | - public $tl_count; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * WordPress language locale. Ex: en_US. | |
| 78 | - * | |
| 79 | - * @var string | |
| 80 | - */ | |
| 81 | - public $locale; | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * 1 if the language is rtl, 0 otherwise. | |
| 85 | - * | |
| 86 | - * @var int | |
| 87 | - */ | |
| 88 | - public $is_rtl; | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * W3C locale. | |
| 92 | - * | |
| 93 | - * @var string. | |
| 94 | - */ | |
| 95 | - public $w3c; | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * Facebook locale. | |
| 99 | - * | |
| 100 | - * @var string. | |
| 101 | - */ | |
| 102 | - public $facebook; | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * Home url in this language. | |
| 106 | - * | |
| 107 | - * @var string | |
| 108 | - */ | |
| 109 | - public $home_url; | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * Home url to use in search forms. | |
| 113 | - * | |
| 114 | - * @var string | |
| 115 | - */ | |
| 116 | - public $search_url; | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * Host corresponding to this language. | |
| 120 | - * | |
| 121 | - * @var string | |
| 122 | - */ | |
| 123 | - public $host; | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * Id of the post storing strings translations. | |
| 127 | - * | |
| 128 | - * @var int | |
| 129 | - */ | |
| 130 | - public $mo_id; | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * Id of the page on front in this language ( set from pll_languages_list filter ). | |
| 134 | - * | |
| 135 | - * @var int | |
| 136 | - */ | |
| 137 | - public $page_on_front; | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * Id of the page for posts in this language ( set from pll_languages_list filter ). | |
| 141 | - * | |
| 142 | - * @var int | |
| 143 | - */ | |
| 144 | - public $page_for_posts; | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * Code of the flag. | |
| 148 | - * | |
| 149 | - * @var string | |
| 150 | - */ | |
| 151 | - public $flag_code; | |
| 152 | - | |
| 153 | - /** | |
| 154 | - * Url of the flag. | |
| 155 | - * | |
| 156 | - * @var string | |
| 157 | - */ | |
| 158 | - public $flag_url; | |
| 159 | - | |
| 160 | - /** | |
| 161 | - * Html markup of the flag. | |
| 162 | - * | |
| 163 | - * @var string | |
| 164 | - */ | |
| 165 | - public $flag; | |
| 166 | - | |
| 167 | - /** | |
| 168 | - * Url of the custom flag if it exists. | |
| 169 | - * | |
| 170 | - * @var string | |
| 171 | - */ | |
| 172 | - public $custom_flag_url; | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * Html markup of the custom flag if it exists. | |
| 176 | - * | |
| 177 | - * @var string | |
| 178 | - */ | |
| 179 | - public $custom_flag; | |
| 180 | - | |
| 181 | - /** | |
| 182 | - * Constructor: builds a language object given its two corresponding terms in 'language' and 'term_language' taxonomies. | |
| 183 | - * | |
| 184 | 50 | * @since 1.2 |
| 185 | 51 | * |
| 186 | - * @param WP_Term|array $language Term in 'language' taxonomy or language object properties stored as an array. | |
| 187 | - * @param WP_Term $term_language Corresponding 'term_language' term. | |
| 52 | + * @param object|array $language 'language' term or language object properties stored as an array | |
| 53 | + * @param object $term_language Corresponding 'term_language' term | |
| 188 | 54 | */ |
| 189 | 55 | public function __construct( $language, $term_language = null ) { |
| 56 | + // Build the object from all properties stored as an array | |
| 190 | 57 | if ( empty( $term_language ) ) { |
| 191 | - // Build the object from all properties stored as an array. | |
| 192 | 58 | foreach ( $language as $prop => $value ) { |
| 193 | 59 | $this->$prop = $value; |
| 194 | 60 | } |
| 195 | - } else { | |
| 196 | - // Build the object from taxonomy terms. | |
| 197 | - $this->term_id = (int) $language->term_id; | |
| 198 | - $this->name = $language->name; | |
| 199 | - $this->slug = $language->slug; | |
| 200 | - $this->term_group = (int) $language->term_group; | |
| 201 | - $this->term_taxonomy_id = (int) $language->term_taxonomy_id; | |
| 202 | - $this->count = (int) $language->count; | |
| 61 | + } | |
| 203 | 62 | |
| 63 | + // Build the object from taxonomies | |
| 64 | + else { | |
| 65 | + foreach ( $language as $prop => $value ) { | |
| 66 | + $this->$prop = in_array( $prop, array( 'term_id', 'term_taxonomy_id', 'count' ) ) ? (int) $language->$prop : $language->$prop; | |
| 67 | + } | |
| 68 | + | |
| 204 | 69 | $this->tl_term_id = (int) $term_language->term_id; |
| 205 | 70 | $this->tl_term_taxonomy_id = (int) $term_language->term_taxonomy_id; |
| 206 | 71 | $this->tl_count = (int) $term_language->count; |
| 207 | 72 | |
| 208 | - // The description field can contain any property. | |
| 73 | + // The description field can contain any property | |
| 74 | + // Backward compatibility for is_rtl | |
| 209 | 75 | $description = maybe_unserialize( $language->description ); |
| 210 | 76 | foreach ( $description as $prop => $value ) { |
| 211 | 77 | 'rtl' == $prop ? $this->is_rtl = $value : $this->$prop = $value; |
| 212 | 78 | } |
| 213 | 79 | |
| 80 | + $this->description = &$this->locale; // Backward compatibility with Polylang < 1.2 | |
| 81 | + | |
| 214 | 82 | $this->mo_id = PLL_MO::get_id( $this ); |
| 215 | 83 | |
| 216 | - $languages = include POLYLANG_DIR . '/settings/languages.php'; | |
| 84 | + include PLL_SETTINGS_INC . '/languages.php'; | |
| 217 | 85 | $this->w3c = isset( $languages[ $this->locale ]['w3c'] ) ? $languages[ $this->locale ]['w3c'] : str_replace( '_', '-', $this->locale ); |
| 218 | 86 | if ( isset( $languages[ $this->locale ]['facebook'] ) ) { |
| 219 | 87 | $this->facebook = $languages[ $this->locale ]['facebook']; |
| 220 | 88 | } |
| @@ -221,123 +89,43 @@ | ||
| 221 | 89 | } |
| 222 | 90 | } |
| 223 | 91 | |
| 224 | 92 | /** |
| 225 | - * Get the flag informations: | |
| 93 | + * sets flag_url and flag properties | |
| 226 | 94 | * |
| 227 | - * @since 2.6 | |
| 228 | - * | |
| 229 | - * @param string $code Flag code. | |
| 230 | - * @return array { | |
| 231 | - * Flag informations. | |
| 232 | - * | |
| 233 | - * @type string $url Flag url. | |
| 234 | - * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. | |
| 235 | - * @type int $width Optional, flag width in pixels. | |
| 236 | - * @type int $height Optional, flag height in pixels. | |
| 237 | - * } | |
| 238 | - */ | |
| 239 | - public static function get_flag_informations( $code ) { | |
| 240 | - $flag = array( 'url' => '' ); | |
| 241 | - | |
| 242 | - // Polylang builtin flags. | |
| 243 | - if ( ! empty( $code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $code . '.png' ) ) ) { | |
| 244 | - $flag['url'] = plugins_url( $file, POLYLANG_FILE ); | |
| 245 | - | |
| 246 | - // If base64 encoded flags are preferred. | |
| 247 | - if ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) { | |
| 248 | - list( $flag['width'], $flag['height'] ) = getimagesize( POLYLANG_DIR . $file ); | |
| 249 | - $file_contents = file_get_contents( POLYLANG_DIR . $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 250 | - $flag['src'] = 'data:image/png;base64,' . base64_encode( $file_contents ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 251 | - } | |
| 252 | - } | |
| 253 | - | |
| 254 | - /** | |
| 255 | - * Filters flag informations: | |
| 256 | - * | |
| 257 | - * @since 2.4 | |
| 258 | - * | |
| 259 | - * @param array $flag { | |
| 260 | - * Information about the flag. | |
| 261 | - * | |
| 262 | - * @type string $url Flag url. | |
| 263 | - * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. | |
| 264 | - * @type int $width Optional, flag width in pixels. | |
| 265 | - * @type int $height Optional, flag height in pixels. | |
| 266 | - * } | |
| 267 | - * @param string $code Flag code. | |
| 268 | - */ | |
| 269 | - $flag = apply_filters( 'pll_flag', $flag, $code ); | |
| 270 | - | |
| 271 | - $flag['url'] = esc_url_raw( $flag['url'] ); | |
| 272 | - | |
| 273 | - if ( empty( $flag['src'] ) ) { | |
| 274 | - $flag['src'] = esc_url( set_url_scheme( $flag['url'], 'relative' ) ); | |
| 275 | - } | |
| 276 | - | |
| 277 | - return $flag; | |
| 278 | - } | |
| 279 | - | |
| 280 | - /** | |
| 281 | - * Sets flag_url and flag properties. | |
| 282 | - * | |
| 283 | 95 | * @since 1.2 |
| 284 | - * | |
| 285 | - * @return void | |
| 286 | 96 | */ |
| 287 | 97 | public function set_flag() { |
| 288 | - $flags = array( 'flag' => self::get_flag_informations( $this->flag_code ) ); | |
| 98 | + $flags['flag']['url'] = ''; | |
| 289 | 99 | |
| 290 | - // Custom flags? | |
| 291 | - $directories = array( | |
| 292 | - PLL_LOCAL_DIR, | |
| 293 | - get_stylesheet_directory() . '/polylang', | |
| 294 | - get_template_directory() . '/polylang', | |
| 295 | - ); | |
| 100 | + // Polylang builtin flags | |
| 101 | + if ( ! empty( $this->flag_code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $this->flag_code . '.png' ) ) ) { | |
| 102 | + $flags['flag']['url'] = esc_url_raw( plugins_url( $file, POLYLANG_FILE ) ); | |
| 296 | 103 | |
| 297 | - foreach ( $directories as $dir ) { | |
| 298 | - if ( file_exists( $file = "{$dir}/{$this->locale}.png" ) || file_exists( $file = "{$dir}/{$this->locale}.jpg" ) || file_exists( $file = "{$dir}/{$this->locale}.svg" ) ) { | |
| 299 | - $flags['custom_flag']['url'] = content_url( '/' . str_replace( WP_CONTENT_DIR, '', $file ) ); | |
| 300 | - break; | |
| 104 | + // If base64 encoded flags are preferred | |
| 105 | + if ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) { | |
| 106 | + $flags['flag']['src'] = 'data:image/png;base64,' . base64_encode( file_get_contents( POLYLANG_DIR . $file ) ); | |
| 107 | + } else { | |
| 108 | + $flags['flag']['src'] = esc_url( plugins_url( $file, POLYLANG_FILE ) ); | |
| 301 | 109 | } |
| 302 | 110 | } |
| 303 | 111 | |
| 304 | - /** | |
| 305 | - * Filters the custom flag informations. | |
| 306 | - * | |
| 307 | - * @param array $flag { | |
| 308 | - * Information about the custom flag. | |
| 309 | - * | |
| 310 | - * @type string $url Flag url. | |
| 311 | - * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. | |
| 312 | - * @type int $width Optional, flag width in pixels. | |
| 313 | - * @type int $height Optional, flag height in pixels. | |
| 314 | - * } | |
| 315 | - * @param string $code Flag code. | |
| 316 | - * | |
| 317 | - * @since 2.4 | |
| 318 | - */ | |
| 319 | - $flags['custom_flag'] = apply_filters( 'pll_custom_flag', empty( $flags['custom_flag'] ) ? null : $flags['custom_flag'], $this->flag_code ); | |
| 320 | - | |
| 321 | - if ( ! empty( $flags['custom_flag']['url'] ) ) { | |
| 322 | - if ( empty( $flags['custom_flag']['src'] ) ) { | |
| 323 | - $flags['custom_flag']['src'] = esc_url( set_url_scheme( $flags['custom_flag']['url'], 'relative' ) ); | |
| 324 | - } | |
| 325 | - | |
| 326 | - $flags['custom_flag']['url'] = esc_url_raw( $flags['custom_flag']['url'] ); | |
| 327 | - } else { | |
| 328 | - unset( $flags['custom_flag'] ); | |
| 112 | + // Custom flags ? | |
| 113 | + if ( file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.png' ) ) || file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.jpg' ) ) ) { | |
| 114 | + $url = content_url( '/polylang' . $file ); | |
| 115 | + $flags['custom_flag']['url'] = esc_url_raw( $url ); | |
| 116 | + $flags['custom_flag']['src'] = esc_url( $url ); | |
| 329 | 117 | } |
| 330 | 118 | |
| 331 | 119 | /** |
| 332 | - * Filters the flag title attribute. | |
| 333 | - * Defaults to the language name. | |
| 120 | + * Filter the flag title attribute | |
| 121 | + * Defaults to the language name | |
| 334 | 122 | * |
| 335 | 123 | * @since 0.7 |
| 336 | 124 | * |
| 337 | - * @param string $title The flag title attribute. | |
| 338 | - * @param string $slug The language code. | |
| 339 | - * @param string $locale The language locale. | |
| 125 | + * @param string $title the flag title attribute | |
| 126 | + * @param string $slug the language code | |
| 127 | + * @param string $locale the language locale | |
| 340 | 128 | */ |
| 341 | 129 | $title = apply_filters( 'pll_flag_title', $this->name, $this->slug, $this->locale ); |
| 342 | 130 | |
| 343 | 131 | foreach ( $flags as $key => $flag ) { |
| @@ -343,18 +131,22 @@ | ||
| 343 | 131 | foreach ( $flags as $key => $flag ) { |
| 344 | 132 | $this->{$key . '_url'} = empty( $flag['url'] ) ? '' : $flag['url']; |
| 345 | 133 | |
| 346 | 134 | /** |
| 347 | - * Filters the html markup of a flag. | |
| 135 | + * Filter the html markup of a flag | |
| 348 | 136 | * |
| 349 | 137 | * @since 1.0.2 |
| 350 | 138 | * |
| 351 | - * @param string $flag Html markup of the flag or empty string. | |
| 352 | - * @param string $slug Language code. | |
| 139 | + * @param string $flag html markup of the flag or empty string | |
| 140 | + * @param string $slug language code | |
| 353 | 141 | */ |
| 354 | - $this->{$key} = apply_filters( | |
| 355 | - 'pll_get_flag', | |
| 356 | - self::get_flag_html( $flag, $title, $this->name ), | |
| 142 | + $this->{$key} = apply_filters( 'pll_get_flag', empty( $flag['src'] ) ? '' : | |
| 143 | + sprintf( | |
| 144 | + '<img src="%s" title="%s" alt="%s" />', | |
| 145 | + $flag['src'], | |
| 146 | + esc_attr( $title ), | |
| 147 | + esc_attr( $this->name ) | |
| 148 | + ), | |
| 357 | 149 | $this->slug |
| 358 | 150 | ); |
| 359 | 151 | } |
| 360 | 152 | } |
| @@ -359,91 +151,48 @@ | ||
| 359 | 151 | } |
| 360 | 152 | } |
| 361 | 153 | |
| 362 | 154 | /** |
| 363 | - * Get HTML code for flag. | |
| 155 | + * Replace flag by custom flag | |
| 156 | + * Takes care of url scheme | |
| 364 | 157 | * |
| 365 | - * @since 2.7 | |
| 366 | - * | |
| 367 | - * @param array $flag Flag properties: src, width and height. | |
| 368 | - * @param string $title Optional title attribute. | |
| 369 | - * @param string $alt Optional alt attribute. | |
| 370 | - * @return string | |
| 158 | + * @since 1.7 | |
| 371 | 159 | */ |
| 372 | - public static function get_flag_html( $flag, $title = '', $alt = '' ) { | |
| 373 | - if ( empty( $flag['src'] ) ) { | |
| 374 | - return ''; | |
| 160 | + public function set_custom_flag() { | |
| 161 | + // Overwrite with custom flags on frontend only | |
| 162 | + if ( ! empty( $this->custom_flag ) ) { | |
| 163 | + $this->flag = $this->custom_flag; | |
| 164 | + $this->flag_url = $this->custom_flag_url; | |
| 165 | + unset( $this->custom_flag, $this->custom_flag_url ); // hide this | |
| 375 | 166 | } |
| 376 | 167 | |
| 377 | - $alt_attr = empty( $alt ) ? '' : sprintf( ' alt="%s"', esc_attr( $alt ) ); | |
| 378 | - $width_attr = empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ); | |
| 379 | - $height_attr = empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ); | |
| 380 | - | |
| 381 | - $style = ''; | |
| 382 | - $sizes = array_intersect_key( $flag, array_flip( array( 'width', 'height' ) ) ); | |
| 383 | - | |
| 384 | - if ( ! empty( $sizes ) ) { | |
| 385 | - array_walk( | |
| 386 | - $sizes, | |
| 387 | - function ( &$value, $key ) { | |
| 388 | - $value = sprintf( '%s: %dpx;', esc_attr( $key ), (int) $value ); | |
| 389 | - } | |
| 390 | - ); | |
| 391 | - $style = sprintf( ' style="%s"', implode( ' ', $sizes ) ); | |
| 168 | + // Set url scheme, also for default flags | |
| 169 | + if ( is_ssl() ) { | |
| 170 | + $this->flag = str_replace( 'http://', 'https://', $this->flag ); | |
| 171 | + $this->flag_url = str_replace( 'http://', 'https://', $this->flag_url ); | |
| 172 | + } else { | |
| 173 | + $this->flag = str_replace( 'https://', 'http://', $this->flag ); | |
| 174 | + $this->flag_url = str_replace( 'https://', 'http://', $this->flag_url ); | |
| 392 | 175 | } |
| 393 | - | |
| 394 | - return sprintf( | |
| 395 | - '<img src="%s"%s%s%s%s />', | |
| 396 | - $flag['src'], | |
| 397 | - $alt_attr, | |
| 398 | - $width_attr, | |
| 399 | - $height_attr, | |
| 400 | - $style | |
| 401 | - ); | |
| 402 | 176 | } |
| 403 | 177 | |
| 404 | 178 | /** |
| 405 | - * Returns the html of the custom flag if any, or the default flag otherwise. | |
| 179 | + * Updates post and term count | |
| 406 | 180 | * |
| 407 | - * @since 2.8 | |
| 408 | - * | |
| 409 | - * @return string | |
| 410 | - */ | |
| 411 | - public function get_display_flag() { | |
| 412 | - return empty( $this->custom_flag ) ? $this->flag : $this->custom_flag; | |
| 413 | - } | |
| 414 | - | |
| 415 | - /** | |
| 416 | - * Returns the url of the custom flag if any, or the default flag otherwise. | |
| 417 | - * | |
| 418 | - * @since 2.8 | |
| 419 | - * | |
| 420 | - * @return string | |
| 421 | - */ | |
| 422 | - public function get_display_flag_url() { | |
| 423 | - return empty( $this->custom_flag_url ) ? $this->flag_url : $this->custom_flag_url; | |
| 424 | - } | |
| 425 | - | |
| 426 | - /** | |
| 427 | - * Updates post and term count. | |
| 428 | - * | |
| 429 | 181 | * @since 1.2 |
| 430 | - * | |
| 431 | - * @return void | |
| 432 | 182 | */ |
| 433 | 183 | public function update_count() { |
| 434 | - wp_update_term_count( $this->term_taxonomy_id, 'language' ); // Posts count. | |
| 435 | - wp_update_term_count( $this->tl_term_taxonomy_id, 'term_language' ); // Terms count. | |
| 184 | + wp_update_term_count( $this->term_taxonomy_id, 'language' ); // posts count | |
| 185 | + wp_update_term_count( $this->tl_term_taxonomy_id, 'term_language' ); // terms count | |
| 436 | 186 | } |
| 437 | 187 | |
| 438 | 188 | /** |
| 439 | - * Set home_url and search_url properties. | |
| 189 | + * Set home_url and search_url properties | |
| 440 | 190 | * |
| 441 | 191 | * @since 1.3 |
| 442 | 192 | * |
| 443 | - * @param string $search_url Home url to use in search forms. | |
| 444 | - * @param string $home_url Home url. | |
| 445 | - * @return void | |
| 193 | + * @param string $search_url | |
| 194 | + * @param string $home_url | |
| 446 | 195 | */ |
| 447 | 196 | public function set_home_url( $search_url, $home_url ) { |
| 448 | 197 | $this->search_url = $search_url; |
| 449 | 198 | $this->home_url = $home_url; |
| @@ -449,34 +198,32 @@ | ||
| 449 | 198 | $this->home_url = $home_url; |
| 450 | 199 | } |
| 451 | 200 | |
| 452 | 201 | /** |
| 453 | - * Sets the scheme of the home url and the flag urls. | |
| 202 | + * Set home_url scheme | |
| 203 | + * this can't be cached across pages | |
| 454 | 204 | * |
| 455 | - * This can't be cached across pages. | |
| 456 | - * | |
| 457 | - * @since 2.8 | |
| 458 | - * | |
| 459 | - * @return void | |
| 205 | + * @since 1.6.4 | |
| 460 | 206 | */ |
| 461 | - public function set_url_scheme() { | |
| 462 | - $this->home_url = set_url_scheme( $this->home_url ); | |
| 463 | - $this->search_url = set_url_scheme( $this->search_url ); | |
| 207 | + public function set_home_url_scheme() { | |
| 208 | + if ( is_ssl() ) { | |
| 209 | + $this->home_url = str_replace( 'http://', 'https://', $this->home_url ); | |
| 210 | + $this->search_url = str_replace( 'http://', 'https://', $this->search_url ); | |
| 211 | + } | |
| 464 | 212 | |
| 465 | - // Set url scheme, also for the flags. | |
| 466 | - $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 467 | - if ( ! empty( $this->custom_flag_url ) ) { | |
| 468 | - $this->custom_flag_url = set_url_scheme( $this->custom_flag_url ); | |
| 213 | + else { | |
| 214 | + $this->home_url = str_replace( 'https://', 'http://', $this->home_url ); | |
| 215 | + $this->search_url = str_replace( 'https://', 'http://', $this->search_url ); | |
| 469 | 216 | } |
| 470 | 217 | } |
| 471 | 218 | |
| 472 | 219 | /** |
| 473 | - * Returns the language locale. | |
| 474 | - * Converts WP locales to W3C valid locales for display. | |
| 220 | + * Returns the language locale | |
| 221 | + * Converts WP locales to W3C valid locales for display | |
| 475 | 222 | * |
| 476 | 223 | * @since 1.8 |
| 477 | 224 | * |
| 478 | - * @param string $filter Either 'display' or 'raw', defaults to raw. | |
| 225 | + * @param string $filter either 'display' or 'raw', defaults to raw | |
| 479 | 226 | * @return string |
| 480 | 227 | */ |
| 481 | 228 | public function get_locale( $filter = 'raw' ) { |
| 482 | 229 | return 'display' === $filter ? $this->w3c : $this->locale; |