| @@ -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 | } |
| @@ -104,9 +101,9 @@ | ||
| 104 | 101 | * @param string $code Flag code. |
| 105 | 102 | * @return array Flag informations. |
| 106 | 103 | */ |
| 107 | 104 | public static function get_flag_informations( $code ) { |
| 108 | - $flag = array( 'url' => '' ); | |
| 105 | + $flag['url'] = ''; | |
| 109 | 106 | |
| 110 | 107 | // Polylang builtin flags |
| 111 | 108 | if ( ! empty( $code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $code . '.png' ) ) ) { |
| 112 | 109 | $flag['url'] = $_url = plugins_url( $file, POLYLANG_FILE ); |
| @@ -147,9 +144,9 @@ | ||
| 147 | 144 | * |
| 148 | 145 | * @since 1.2 |
| 149 | 146 | */ |
| 150 | 147 | public function set_flag() { |
| 151 | - $flags = array( 'flag' => self::get_flag_informations( $this->flag_code ) ); | |
| 148 | + $flags['flag'] = self::get_flag_informations( $this->flag_code ); | |
| 152 | 149 | |
| 153 | 150 | // Custom flags ? |
| 154 | 151 | $directories = array( |
| 155 | 152 | PLL_LOCAL_DIR, |
| @@ -212,9 +209,16 @@ | ||
| 212 | 209 | * @param string $slug language code |
| 213 | 210 | */ |
| 214 | 211 | $this->{$key} = apply_filters( |
| 215 | 212 | 'pll_get_flag', |
| 216 | - self::get_flag_html( $flag, $title, $this->name ), | |
| 213 | + empty( $flag['src'] ) ? '' : sprintf( | |
| 214 | + '<img src="%s" title="%s" alt="%s"%s%s />', | |
| 215 | + $flag['src'], | |
| 216 | + esc_attr( $title ), | |
| 217 | + esc_attr( $this->name ), | |
| 218 | + empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ), | |
| 219 | + empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ) | |
| 220 | + ), | |
| 217 | 221 | $this->slug |
| 218 | 222 | ); |
| 219 | 223 | } |
| 220 | 224 | } |
| @@ -219,69 +223,26 @@ | ||
| 219 | 223 | } |
| 220 | 224 | } |
| 221 | 225 | |
| 222 | 226 | /** |
| 223 | - * Get HTML code for flag | |
| 227 | + * Replace flag by custom flag | |
| 228 | + * Takes care of url scheme | |
| 224 | 229 | * |
| 225 | - * @since 2.7 | |
| 226 | - * | |
| 227 | - * @param array $flag flag properties: src, width and height | |
| 228 | - * @param string $title optional title attribute | |
| 229 | - * @param string $alt optional alt attribute | |
| 230 | + * @since 1.7 | |
| 230 | 231 | */ |
| 231 | - public static function get_flag_html( $flag, $title = '', $alt = '' ) { | |
| 232 | - if ( empty( $flag['src'] ) ) { | |
| 233 | - return ''; | |
| 232 | + public function set_custom_flag() { | |
| 233 | + // Overwrite with custom flags on frontend only | |
| 234 | + if ( ! empty( $this->custom_flag ) ) { | |
| 235 | + $this->flag = $this->custom_flag; | |
| 236 | + $this->flag_url = $this->custom_flag_url; | |
| 237 | + unset( $this->custom_flag, $this->custom_flag_url ); // hide this | |
| 234 | 238 | } |
| 235 | 239 | |
| 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 />', | |
| 256 | - $flag['src'], | |
| 257 | - $title_attr, | |
| 258 | - $alt_attr, | |
| 259 | - $width_attr, | |
| 260 | - $height_attr, | |
| 261 | - $style | |
| 262 | - ); | |
| 240 | + // Set url scheme, also for default flags | |
| 241 | + $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 263 | 242 | } |
| 264 | 243 | |
| 265 | 244 | /** |
| 266 | - * Returns the html of the custom flag if any, or the default flag otherwise. | |
| 267 | - * | |
| 268 | - * @since 2.8 | |
| 269 | - */ | |
| 270 | - public function get_display_flag() { | |
| 271 | - return empty( $this->custom_flag ) ? $this->flag : $this->custom_flag; | |
| 272 | - } | |
| 273 | - | |
| 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; | |
| 281 | - } | |
| 282 | - | |
| 283 | - /** | |
| 284 | 245 | * Updates post and term count |
| 285 | 246 | * |
| 286 | 247 | * @since 1.2 |
| 287 | 248 | */ |
| @@ -303,23 +264,16 @@ | ||
| 303 | 264 | $this->home_url = $home_url; |
| 304 | 265 | } |
| 305 | 266 | |
| 306 | 267 | /** |
| 307 | - * Sets the scheme of the home url and the flag urls | |
| 268 | + * Set home_url scheme | |
| 269 | + * this can't be cached across pages | |
| 308 | 270 | * |
| 309 | - * This can't be cached across pages. | |
| 310 | - * | |
| 311 | - * @since 2.8 | |
| 271 | + * @since 1.6.4 | |
| 312 | 272 | */ |
| 313 | - public function set_url_scheme() { | |
| 273 | + public function set_home_url_scheme() { | |
| 314 | 274 | $this->home_url = set_url_scheme( $this->home_url ); |
| 315 | 275 | $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 | 276 | } |
| 323 | 277 | |
| 324 | 278 | /** |
| 325 | 279 | * Returns the language locale |