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