| @@ -80,9 +80,9 @@ | ||
| 80 | 80 | $this->description = &$this->locale; // Backward compatibility with Polylang < 1.2 |
| 81 | 81 | |
| 82 | 82 | $this->mo_id = PLL_MO::get_id( $this ); |
| 83 | 83 | |
| 84 | - $languages = include PLL_SETTINGS_INC . '/languages.php'; | |
| 84 | + include PLL_SETTINGS_INC . '/languages.php'; | |
| 85 | 85 | $this->w3c = isset( $languages[ $this->locale ]['w3c'] ) ? $languages[ $this->locale ]['w3c'] : str_replace( '_', '-', $this->locale ); |
| 86 | 86 | if ( isset( $languages[ $this->locale ]['facebook'] ) ) { |
| 87 | 87 | $this->facebook = $languages[ $this->locale ]['facebook']; |
| 88 | 88 | } |
| @@ -89,25 +89,18 @@ | ||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | - * Get the flag informations | |
| 94 | - * 'url' => Flag url | |
| 95 | - * 'src' => Optional, src attribute value if different of the url, for example if base64 encoded | |
| 96 | - * 'width' => Optional, flag width in pixels | |
| 97 | - * 'height' => Optional, flag height in pixels | |
| 93 | + * Sets flag_url and flag properties | |
| 98 | 94 | * |
| 99 | - * @since 2.6 | |
| 100 | - * | |
| 101 | - * @param string $code Flag code. | |
| 102 | - * @return array Flag informations. | |
| 95 | + * @since 1.2 | |
| 103 | 96 | */ |
| 104 | - public static function get_flag_informations( $code ) { | |
| 105 | - $flag = array( 'url' => '' ); | |
| 97 | + public function set_flag() { | |
| 98 | + $flags['flag']['url'] = ''; | |
| 106 | 99 | |
| 107 | 100 | // Polylang builtin flags |
| 108 | - if ( ! empty( $code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $code . '.png' ) ) ) { | |
| 109 | - $flag['url'] = $_url = plugins_url( $file, POLYLANG_FILE ); | |
| 101 | + if ( ! empty( $this->flag_code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $this->flag_code . '.png' ) ) ) { | |
| 102 | + $flags['flag']['url'] = $_url = plugins_url( $file, POLYLANG_FILE ); | |
| 110 | 103 | } |
| 111 | 104 | |
| 112 | 105 | /** |
| 113 | 106 | * Filter flag informations |
| @@ -120,34 +113,21 @@ | ||
| 120 | 113 | * |
| 121 | 114 | * @param array $flag Information about the flag |
| 122 | 115 | * @param string $code Flag code |
| 123 | 116 | */ |
| 124 | - $flag = apply_filters( 'pll_flag', $flag, $code ); | |
| 117 | + $flags['flag'] = apply_filters( 'pll_flag', $flags['flag'], $this->flag_code ); | |
| 125 | 118 | |
| 126 | - if ( empty( $flag['src'] ) ) { | |
| 119 | + if ( empty( $flags['flag']['src'] ) ) { | |
| 127 | 120 | // If using predefined flags and base64 encoded flags are preferred |
| 128 | - if ( isset( $_url ) && $flag['url'] === $_url && ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) ) { | |
| 129 | - list( $flag['width'], $flag['height'] ) = getimagesize( POLYLANG_DIR . $file ); | |
| 130 | - $file_contents = file_get_contents( POLYLANG_DIR . $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 131 | - $flag['src'] = 'data:image/png;base64,' . base64_encode( $file_contents ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 121 | + if ( isset( $_url ) && $flags['flag']['url'] === $_url && ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) ) { | |
| 122 | + $flags['flag']['src'] = 'data:image/png;base64,' . base64_encode( file_get_contents( POLYLANG_DIR . $file ) ); | |
| 132 | 123 | } else { |
| 133 | - $flag['src'] = esc_url( set_url_scheme( $flag['url'], 'relative' ) ); | |
| 124 | + $flags['flag']['src'] = esc_url( set_url_scheme( $flags['flag']['url'], 'relative' ) ); | |
| 134 | 125 | } |
| 135 | 126 | } |
| 136 | 127 | |
| 137 | - $flag['url'] = esc_url_raw( $flag['url'] ); | |
| 128 | + $flags['flag']['url'] = esc_url_raw( $flags['flag']['url'] ); | |
| 138 | 129 | |
| 139 | - return $flag; | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * Sets flag_url and flag properties | |
| 144 | - * | |
| 145 | - * @since 1.2 | |
| 146 | - */ | |
| 147 | - public function set_flag() { | |
| 148 | - $flags = array( 'flag' => self::get_flag_informations( $this->flag_code ) ); | |
| 149 | - | |
| 150 | 130 | // Custom flags ? |
| 151 | 131 | $directories = array( |
| 152 | 132 | PLL_LOCAL_DIR, |
| 153 | 133 | get_stylesheet_directory() . '/polylang', |
| @@ -209,32 +189,19 @@ | ||
| 209 | 189 | * @param string $slug language code |
| 210 | 190 | */ |
| 211 | 191 | $this->{$key} = apply_filters( |
| 212 | 192 | 'pll_get_flag', |
| 213 | - self::get_flag_html( $flag, $title, $this->name ), | |
| 193 | + empty( $flag['src'] ) ? '' : sprintf( | |
| 194 | + '<img src="%s" title="%s" alt="%s"%s%s />', | |
| 195 | + $flag['src'], | |
| 196 | + esc_attr( $title ), | |
| 197 | + esc_attr( $this->name ), | |
| 198 | + empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ), | |
| 199 | + empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ) | |
| 200 | + ), | |
| 214 | 201 | $this->slug |
| 215 | 202 | ); |
| 216 | 203 | } |
| 217 | - } | |
| 218 | - | |
| 219 | - /** | |
| 220 | - * Get HTML code for flag | |
| 221 | - * | |
| 222 | - * @since 2.7 | |
| 223 | - * | |
| 224 | - * @param array $flag flag properties: src, width and height | |
| 225 | - * @param string $title optional title attribute | |
| 226 | - * @param string $alt optional alt attribute | |
| 227 | - */ | |
| 228 | - public static function get_flag_html( $flag, $title = '', $alt = '' ) { | |
| 229 | - return empty( $flag['src'] ) ? '' : sprintf( | |
| 230 | - '<img src="%s"%s%s%s%s />', | |
| 231 | - $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'] ) | |
| 236 | - ); | |
| 237 | 204 | } |
| 238 | 205 | |
| 239 | 206 | /** |
| 240 | 207 | * Replace flag by custom flag |