| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A language object is made of two terms in 'language' and 'term_language' taxonomies |
| 8 | 5 | * manipulating only one object per language instead of two terms should make things easier |
| @@ -83,9 +80,9 @@ | ||
| 83 | 80 | $this->description = &$this->locale; // Backward compatibility with Polylang < 1.2 |
| 84 | 81 | |
| 85 | 82 | $this->mo_id = PLL_MO::get_id( $this ); |
| 86 | 83 | |
| 87 | - $languages = include POLYLANG_DIR . '/settings/languages.php'; | |
| 84 | + $languages = include PLL_SETTINGS_INC . '/languages.php'; | |
| 88 | 85 | $this->w3c = isset( $languages[ $this->locale ]['w3c'] ) ? $languages[ $this->locale ]['w3c'] : str_replace( '_', '-', $this->locale ); |
| 89 | 86 | if ( isset( $languages[ $this->locale ]['facebook'] ) ) { |
| 90 | 87 | $this->facebook = $languages[ $this->locale ]['facebook']; |
| 91 | 88 | } |
| @@ -228,57 +225,34 @@ | ||
| 228 | 225 | * @param string $title optional title attribute |
| 229 | 226 | * @param string $alt optional alt attribute |
| 230 | 227 | */ |
| 231 | 228 | public static function get_flag_html( $flag, $title = '', $alt = '' ) { |
| 232 | - if ( empty( $flag['src'] ) ) { | |
| 233 | - return ''; | |
| 234 | - } | |
| 235 | - | |
| 236 | - $title_attr = empty( $title ) ? '' : sprintf( ' title="%s"', esc_attr( $title ) ); | |
| 237 | - $alt_attr = empty( $alt ) ? '' : sprintf( ' alt="%s"', esc_attr( $alt ) ); | |
| 238 | - $width_attr = empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ); | |
| 239 | - $height_attr = empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ); | |
| 240 | - | |
| 241 | - $style = ''; | |
| 242 | - $sizes = array_intersect_key( $flag, array_flip( array( 'width', 'height' ) ) ); | |
| 243 | - | |
| 244 | - if ( ! empty( $sizes ) ) { | |
| 245 | - array_walk( | |
| 246 | - $sizes, | |
| 247 | - function ( &$value, $key ) { | |
| 248 | - $value = sprintf( '%s: %dpx;', esc_attr( $key ), (int) $value ); | |
| 249 | - } | |
| 250 | - ); | |
| 251 | - $style = sprintf( ' style="%s"', implode( ' ', $sizes ) ); | |
| 252 | - } | |
| 253 | - | |
| 254 | - return sprintf( | |
| 255 | - '<img src="%s"%s%s%s%s%s />', | |
| 229 | + return empty( $flag['src'] ) ? '' : sprintf( | |
| 230 | + '<img src="%s"%s%s%s%s />', | |
| 256 | 231 | $flag['src'], |
| 257 | - $title_attr, | |
| 258 | - $alt_attr, | |
| 259 | - $width_attr, | |
| 260 | - $height_attr, | |
| 261 | - $style | |
| 232 | + empty( $title ) ? '' : sprintf( ' title="%s"', esc_attr( $title ) ), | |
| 233 | + empty( $alt ) ? '' : sprintf( ' alt="%s"', esc_attr( $alt ) ), | |
| 234 | + empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ), | |
| 235 | + empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ) | |
| 262 | 236 | ); |
| 263 | 237 | } |
| 264 | 238 | |
| 265 | 239 | /** |
| 266 | - * Returns the html of the custom flag if any, or the default flag otherwise. | |
| 240 | + * Replace flag by custom flag | |
| 241 | + * Takes care of url scheme | |
| 267 | 242 | * |
| 268 | - * @since 2.8 | |
| 243 | + * @since 1.7 | |
| 269 | 244 | */ |
| 270 | - public function get_display_flag() { | |
| 271 | - return empty( $this->custom_flag ) ? $this->flag : $this->custom_flag; | |
| 272 | - } | |
| 245 | + public function set_custom_flag() { | |
| 246 | + // Overwrite with custom flags on frontend only | |
| 247 | + if ( ! empty( $this->custom_flag ) ) { | |
| 248 | + $this->flag = $this->custom_flag; | |
| 249 | + $this->flag_url = $this->custom_flag_url; | |
| 250 | + unset( $this->custom_flag, $this->custom_flag_url ); // hide this | |
| 251 | + } | |
| 273 | 252 | |
| 274 | - /** | |
| 275 | - * Returns the url of the custom flag if any, or the default flag otherwise. | |
| 276 | - * | |
| 277 | - * @since 2.8 | |
| 278 | - */ | |
| 279 | - public function get_display_flag_url() { | |
| 280 | - return empty( $this->custom_flag_url ) ? $this->flag_url : $this->custom_flag_url; | |
| 253 | + // Set url scheme, also for default flags | |
| 254 | + $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 281 | 255 | } |
| 282 | 256 | |
| 283 | 257 | /** |
| 284 | 258 | * Updates post and term count |
| @@ -303,23 +277,16 @@ | ||
| 303 | 277 | $this->home_url = $home_url; |
| 304 | 278 | } |
| 305 | 279 | |
| 306 | 280 | /** |
| 307 | - * Sets the scheme of the home url and the flag urls | |
| 281 | + * Set home_url scheme | |
| 282 | + * this can't be cached across pages | |
| 308 | 283 | * |
| 309 | - * This can't be cached across pages. | |
| 310 | - * | |
| 311 | - * @since 2.8 | |
| 284 | + * @since 1.6.4 | |
| 312 | 285 | */ |
| 313 | - public function set_url_scheme() { | |
| 286 | + public function set_home_url_scheme() { | |
| 314 | 287 | $this->home_url = set_url_scheme( $this->home_url ); |
| 315 | 288 | $this->search_url = set_url_scheme( $this->search_url ); |
| 316 | - | |
| 317 | - // Set url scheme, also for the flags. | |
| 318 | - $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 319 | - if ( ! empty( $this->custom_flag_url ) ) { | |
| 320 | - $this->custom_flag_url = set_url_scheme( $this->custom_flag_url ); | |
| 321 | - } | |
| 322 | 289 | } |
| 323 | 290 | |
| 324 | 291 | /** |
| 325 | 292 | * Returns the language locale |