PluginProbe
Polylang / 2.3
Polylang v2.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/language.php +38 -110 2.72.3 View file →
@@ -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,104 +89,35 @@
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 );
110 - }
101 + if ( ! empty( $this->flag_code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $this->flag_code . '.png' ) ) ) {
102 + $flags['flag']['url'] = esc_url_raw( plugins_url( $file, POLYLANG_FILE ) );
111 103
112 - /**
113 - * Filter flag informations
114 - * 'url' => Flag url
115 - * 'src' => Optional, src attribute value if different of the url, for example if base64 encoded
116 - * 'width' => Optional, flag width in pixels
117 - * 'height' => Optional, flag height in pixels
118 - *
119 - * @since 2.4
120 - *
121 - * @param array $flag Information about the flag
122 - * @param string $code Flag code
123 - */
124 - $flag = apply_filters( 'pll_flag', $flag, $code );
125 -
126 - if ( empty( $flag['src'] ) ) {
127 - // 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
104 + // If base64 encoded flags are preferred
105 + if ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) {
106 + $flags['flag']['src'] = 'data:image/png;base64,' . base64_encode( file_get_contents( POLYLANG_DIR . $file ) );
132 107 } else {
133 - $flag['src'] = esc_url( set_url_scheme( $flag['url'], 'relative' ) );
108 + $flags['flag']['src'] = esc_url( plugins_url( $file, POLYLANG_FILE ) );
134 109 }
135 110 }
136 111
137 - $flag['url'] = esc_url_raw( $flag['url'] );
138 -
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 112 // Custom flags ?
151 - $directories = array(
152 - PLL_LOCAL_DIR,
153 - get_stylesheet_directory() . '/polylang',
154 - get_template_directory() . '/polylang',
155 - );
156 -
157 - foreach ( $directories as $dir ) {
158 - if ( file_exists( $file = "{$dir}/{$this->locale}.png" ) || file_exists( $file = "{$dir}/{$this->locale}.jpg" ) || file_exists( $file = "{$dir}/{$this->locale}.svg" ) ) {
159 - $flags['custom_flag']['url'] = content_url( '/' . str_replace( WP_CONTENT_DIR, '', $file ) );
160 - break;
161 - }
113 + if ( file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.png' ) ) || file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.jpg' ) ) ) {
114 + $url = content_url( '/polylang' . $file );
115 + $flags['custom_flag']['url'] = esc_url_raw( $url );
116 + $flags['custom_flag']['src'] = esc_url( $url );
162 117 }
163 118
164 119 /**
165 - * Filter the custom flag informations
166 - * 'url' => Flag url
167 - * 'src' => Optional, src attribute value if different of the url, for example if base64 encoded
168 - * 'width' => Optional, flag width in pixels
169 - * 'height' => Optional, flag height in pixels
170 - *
171 - * @since 2.4
172 - *
173 - * @param array $flag Information about the custom flag
174 - * @param string $code Flag code
175 - */
176 - $flags['custom_flag'] = apply_filters( 'pll_custom_flag', empty( $flags['custom_flag'] ) ? null : $flags['custom_flag'], $this->flag_code );
177 -
178 - if ( ! empty( $flags['custom_flag']['url'] ) ) {
179 - if ( empty( $flags['custom_flag']['src'] ) ) {
180 - $flags['custom_flag']['src'] = esc_url( set_url_scheme( $flags['custom_flag']['url'], 'relative' ) );
181 - }
182 -
183 - $flags['custom_flag']['url'] = esc_url_raw( $flags['custom_flag']['url'] );
184 - } else {
185 - unset( $flags['custom_flag'] );
186 - }
187 -
188 - /**
189 120 * Filter the flag title attribute
190 121 * Defaults to the language name
191 122 *
192 123 * @since 0.7
@@ -207,11 +138,15 @@
207 138 *
208 139 * @param string $flag html markup of the flag or empty string
209 140 * @param string $slug language code
210 141 */
211 - $this->{$key} = apply_filters(
212 - 'pll_get_flag',
213 - self::get_flag_html( $flag, $title, $this->name ),
142 + $this->{$key} = apply_filters( 'pll_get_flag', empty( $flag['src'] ) ? '' :
143 + sprintf(
144 + '<img src="%s" title="%s" alt="%s" />',
145 + $flag['src'],
146 + esc_attr( $title ),
147 + esc_attr( $this->name )
148 + ),
214 149 $this->slug
215 150 );
216 151 }
217 152 }
@@ -216,28 +151,8 @@
216 151 }
217 152 }
218 153
219 154 /**
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 - }
238 -
239 - /**
240 155 * Replace flag by custom flag
241 156 * Takes care of url scheme
242 157 *
243 158 * @since 1.7
@@ -250,9 +165,15 @@
250 165 unset( $this->custom_flag, $this->custom_flag_url ); // hide this
251 166 }
252 167
253 168 // Set url scheme, also for default flags
254 - $this->flag_url = set_url_scheme( $this->flag_url );
169 + if ( is_ssl() ) {
170 + $this->flag = str_replace( 'http://', 'https://', $this->flag );
171 + $this->flag_url = str_replace( 'http://', 'https://', $this->flag_url );
172 + } else {
173 + $this->flag = str_replace( 'https://', 'http://', $this->flag );
174 + $this->flag_url = str_replace( 'https://', 'http://', $this->flag_url );
175 + }
255 176 }
256 177
257 178 /**
258 179 * Updates post and term count
@@ -283,10 +204,17 @@
283 204 *
284 205 * @since 1.6.4
285 206 */
286 207 public function set_home_url_scheme() {
287 - $this->home_url = set_url_scheme( $this->home_url );
288 - $this->search_url = set_url_scheme( $this->search_url );
208 + if ( is_ssl() ) {
209 + $this->home_url = str_replace( 'http://', 'https://', $this->home_url );
210 + $this->search_url = str_replace( 'http://', 'https://', $this->search_url );
211 + }
212 +
213 + else {
214 + $this->home_url = str_replace( 'https://', 'http://', $this->home_url );
215 + $this->search_url = str_replace( 'https://', 'http://', $this->search_url );
216 + }
289 217 }
290 218
291 219 /**
292 220 * Returns the language locale