| @@ -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,46 +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 | - return empty( $flag['src'] ) ? '' : sprintf( | |
| 233 | - '<img src="%s"%s%s%s%s />', | |
| 234 | - $flag['src'], | |
| 235 | - empty( $title ) ? '' : sprintf( ' title="%s"', esc_attr( $title ) ), | |
| 236 | - empty( $alt ) ? '' : sprintf( ' alt="%s"', esc_attr( $alt ) ), | |
| 237 | - empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ), | |
| 238 | - empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ) | |
| 239 | - ); | |
| 240 | - } | |
| 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 | |
| 238 | + } | |
| 241 | 239 | |
| 242 | - /** | |
| 243 | - * Returns the html of the custom flag if any, or the default flag otherwise. | |
| 244 | - * | |
| 245 | - * @since 2.8 | |
| 246 | - */ | |
| 247 | - public function get_display_flag() { | |
| 248 | - return empty( $this->custom_flag ) ? $this->flag : $this->custom_flag; | |
| 240 | + // Set url scheme, also for default flags | |
| 241 | + $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 249 | 242 | } |
| 250 | 243 | |
| 251 | 244 | /** |
| 252 | - * Returns the url of the custom flag if any, or the default flag otherwise. | |
| 253 | - * | |
| 254 | - * @since 2.8 | |
| 255 | - */ | |
| 256 | - public function get_display_flag_url() { | |
| 257 | - return empty( $this->custom_flag_url ) ? $this->flag : $this->custom_flag_url; | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | 245 | * Updates post and term count |
| 262 | 246 | * |
| 263 | 247 | * @since 1.2 |
| 264 | 248 | */ |
| @@ -280,23 +264,16 @@ | ||
| 280 | 264 | $this->home_url = $home_url; |
| 281 | 265 | } |
| 282 | 266 | |
| 283 | 267 | /** |
| 284 | - * Sets the scheme of the home url and the flag urls | |
| 268 | + * Set home_url scheme | |
| 269 | + * this can't be cached across pages | |
| 285 | 270 | * |
| 286 | - * This can't be cached across pages. | |
| 287 | - * | |
| 288 | - * @since 2.8 | |
| 271 | + * @since 1.6.4 | |
| 289 | 272 | */ |
| 290 | - public function set_url_scheme() { | |
| 273 | + public function set_home_url_scheme() { | |
| 291 | 274 | $this->home_url = set_url_scheme( $this->home_url ); |
| 292 | 275 | $this->search_url = set_url_scheme( $this->search_url ); |
| 293 | - | |
| 294 | - // Set url scheme, also for the flags. | |
| 295 | - $this->flag_url = set_url_scheme( $this->flag_url ); | |
| 296 | - if ( ! empty( $this->custom_flag_url ) ) { | |
| 297 | - $this->custom_flag_url = set_url_scheme( $this->custom_flag_url ); | |
| 298 | - } | |
| 299 | 276 | } |
| 300 | 277 | |
| 301 | 278 | /** |
| 302 | 279 | * Returns the language locale |