PluginProbe
Bogo / 2.6
Bogo v2.6
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | includes/functions.php +493 -5 trunk2.6 View file →
@@ -1,6 +1,497 @@
1 1 <?php
2 2
3 +function bogo_languages() {
4 + static $languages = array();
5 + static $textdomain_loaded = false;
6 +
7 + if ( $languages && $textdomain_loaded ) {
8 + return apply_filters( 'bogo_languages', $languages );
9 + }
10 +
11 + $languages = array(
12 + 'af' => __( 'Afrikaans', 'bogo' ),
13 + 'am' => __( 'Amharic', 'bogo' ),
14 + 'an' => __( 'Aragonese', 'bogo' ),
15 + 'ar' => __( 'Arabic', 'bogo' ),
16 + 'ary' => __( 'Moroccan Arabic', 'bogo' ),
17 + 'as' => __( 'Assamese', 'bogo' ),
18 + 'az' => __( 'Azerbaijani', 'bogo' ),
19 + 'be_BY' => __( 'Belarusian', 'bogo' ),
20 + 'bg_BG' => __( 'Bulgarian', 'bogo' ),
21 + 'bn_BD' => __( 'Bangla', 'bogo' ),
22 + 'bn_IN' => __( 'Indian Bengali', 'bogo' ),
23 + 'bo' => __( 'Tibetan', 'bogo' ),
24 + 'bs_BA' => __( 'Bosnian', 'bogo' ),
25 + 'ca' => __( 'Catalan', 'bogo' ),
26 + 'ckb' => __( 'Central Kurdish', 'bogo' ),
27 + 'co' => __( 'Corsican', 'bogo' ),
28 + 'cs_CZ' => __( 'Czech', 'bogo' ),
29 + 'cy' => __( 'Welsh', 'bogo' ),
30 + 'da_DK' => __( 'Danish', 'bogo' ),
31 + 'de_DE' => __( 'German', 'bogo' ),
32 + 'de_DE_formal' => __( 'German (Formal)', 'bogo' ),
33 + 'de_CH' => __( 'German (Switzerland)', 'bogo' ),
34 + 'dv' => __( 'Dhivehi', 'bogo' ),
35 + 'el' => __( 'Greek', 'bogo' ),
36 + 'en_US' => __( 'English (United States)', 'bogo' ),
37 + 'en_AU' => __( 'English (Australia)', 'bogo' ),
38 + 'en_CA' => __( 'English (Canada)', 'bogo' ),
39 + 'en_GB' => __( 'English (UK)', 'bogo' ),
40 + 'en_NZ' => __( 'English (New Zealand)', 'bogo' ),
41 + 'en_ZA' => __( 'English (South Africa)', 'bogo' ),
42 + 'eo' => __( 'Esperanto', 'bogo' ),
43 + 'es_ES' => __( 'Spanish (Spain)', 'bogo' ),
44 + 'es_CL' => __( 'Spanish (Chile)', 'bogo' ),
45 + 'es_CO' => __( 'Spanish (Colombia)', 'bogo' ),
46 + 'es_MX' => __( 'Spanish (Mexico)', 'bogo' ),
47 + 'es_PE' => __( 'Spanish (Peru)', 'bogo' ),
48 + 'es_VE' => __( 'Spanish (Venezuela)', 'bogo' ),
49 + 'et' => __( 'Estonian', 'bogo' ),
50 + 'eu' => __( 'Basque', 'bogo' ),
51 + 'fa_IR' => __( 'Persian', 'bogo' ),
52 + 'fi' => __( 'Finnish', 'bogo' ),
53 + 'fo' => __( 'Faroese', 'bogo' ),
54 + 'fr_FR' => __( 'French (France)', 'bogo' ),
55 + 'fr_BE' => __( 'French (Belgium)', 'bogo' ),
56 + 'fy' => __( 'Frisian', 'bogo' ),
57 + 'ga' => __( 'Irish', 'bogo' ),
58 + 'gd' => __( 'Scottish Gaelic', 'bogo' ),
59 + 'gl_ES' => __( 'Galician', 'bogo' ),
60 + 'gu' => __( 'Gujarati', 'bogo' ),
61 + 'haz' => __( 'Hazaragi', 'bogo' ),
62 + 'he_IL' => __( 'Hebrew', 'bogo' ),
63 + 'hi_IN' => __( 'Hindi', 'bogo' ),
64 + 'hr' => __( 'Croatian', 'bogo' ),
65 + 'ht' => __( 'Haitian', 'bogo' ),
66 + 'hu_HU' => __( 'Hungarian', 'bogo' ),
67 + 'hy' => __( 'Armenian', 'bogo' ),
68 + 'id_ID' => __( 'Indonesian', 'bogo' ),
69 + 'is_IS' => __( 'Icelandic', 'bogo' ),
70 + 'it_IT' => __( 'Italian', 'bogo' ),
71 + 'ja' => __( 'Japanese', 'bogo' ),
72 + 'jv_ID' => __( 'Javanese', 'bogo' ),
73 + 'ka_GE' => __( 'Georgian', 'bogo' ),
74 + 'kk' => __( 'Kazakh', 'bogo' ),
75 + 'km_KH' => __( 'Khmer', 'bogo' ),
76 + 'kn' => __( 'Kannada', 'bogo' ),
77 + 'ko_KR' => __( 'Korean', 'bogo' ),
78 + 'li' => __( 'Limburgish', 'bogo' ),
79 + 'lo' => __( 'Lao', 'bogo' ),
80 + 'lt_LT' => __( 'Lithuanian', 'bogo' ),
81 + 'lv' => __( 'Latvian', 'bogo' ),
82 + 'mg_MG' => __( 'Malagasy', 'bogo' ),
83 + 'mk_MK' => __( 'Macedonian', 'bogo' ),
84 + 'ml_IN' => __( 'Malayalam', 'bogo' ),
85 + 'mn' => __( 'Mongolian', 'bogo' ),
86 + 'mr' => __( 'Marathi', 'bogo' ),
87 + 'ms_MY' => __( 'Malay', 'bogo' ),
88 + 'mt_MT' => __( 'Maltese', 'bogo' ),
89 + 'my_MM' => __( 'Burmese', 'bogo' ),
90 + 'nb_NO' => __( 'Norwegian (Bokmål)', 'bogo' ),
91 + 'ne_NP' => __( 'Nepali', 'bogo' ),
92 + 'ni_ID' => __( 'Nias', 'bogo' ),
93 + 'nl_NL' => __( 'Dutch', 'bogo' ),
94 + 'nn_NO' => __( 'Norwegian (Nynorsk)', 'bogo' ),
95 + 'oci' => __( 'Occitan', 'bogo' ),
96 + 'os' => __( 'Ossetic', 'bogo' ),
97 + 'pa_IN' => __( 'Punjabi', 'bogo' ),
98 + 'pl_PL' => __( 'Polish', 'bogo' ),
99 + 'ps' => __( 'Pashto', 'bogo' ),
100 + 'pt_BR' => __( 'Portuguese (Brazil)', 'bogo' ),
101 + 'pt_PT' => __( 'Portuguese (Portugal)', 'bogo' ),
102 + 'ro_RO' => __( 'Romanian', 'bogo' ),
103 + 'ru_RU' => __( 'Russian', 'bogo' ),
104 + 'sa_IN' => __( 'Sanskrit', 'bogo' ),
105 + 'si_LK' => __( 'Sinhala', 'bogo' ),
106 + 'sk_SK' => __( 'Slovak', 'bogo' ),
107 + 'sl_SI' => __( 'Slovenian', 'bogo' ),
108 + 'so_SO' => __( 'Somali', 'bogo' ),
109 + 'sq' => __( 'Albanian', 'bogo' ),
110 + 'sr_RS' => __( 'Serbian', 'bogo' ),
111 + 'sv_SE' => __( 'Swedish', 'bogo' ),
112 + 'su_ID' => __( 'Sundanese', 'bogo' ),
113 + 'sw' => __( 'Swahili', 'bogo' ),
114 + 'ta_IN' => __( 'Tamil', 'bogo' ),
115 + 'te' => __( 'Telugu', 'bogo' ),
116 + 'tg' => __( 'Tajik', 'bogo' ),
117 + 'th' => __( 'Thai', 'bogo' ),
118 + 'tl' => __( 'Tagalog', 'bogo' ),
119 + 'tr_TR' => __( 'Turkish', 'bogo' ),
120 + 'tt_RU' => __( 'Tatar', 'bogo' ),
121 + 'ug_CN' => __( 'Uighur', 'bogo' ),
122 + 'uk' => __( 'Ukrainian', 'bogo' ),
123 + 'ur' => __( 'Urdu', 'bogo' ),
124 + 'uz_UZ' => __( 'Uzbek', 'bogo' ),
125 + 'vi' => __( 'Vietnamese', 'bogo' ),
126 + 'zh_CN' => __( 'Chinese (China)', 'bogo' ),
127 + 'zh_TW' => __( 'Chinese (Taiwan)', 'bogo' )
128 + );
129 +
130 + if ( is_textdomain_loaded( 'bogo' ) ) {
131 + $textdomain_loaded = true;
132 + }
133 +
134 + asort( $languages, SORT_STRING );
135 +
136 + return apply_filters( 'bogo_languages', $languages );
137 +}
138 +
139 +function bogo_get_language( $locale ) {
140 + $languages = bogo_languages();
141 +
142 + if ( isset( $languages[$locale] ) )
143 + return $languages[$locale];
144 +
145 + return null;
146 +}
147 +
148 +function bogo_get_language_native_name( $locale ) {
149 + if ( 'en_US' == $locale ) {
150 + return 'English (United States)';
151 + }
152 +
153 + if ( ! function_exists( 'wp_get_available_translations' ) ) {
154 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
155 + }
156 +
157 + static $available_translations = array();
158 +
159 + if ( empty( $available_translations ) ) {
160 + $available_translations = wp_get_available_translations();
161 + }
162 +
163 + if ( isset( $available_translations[$locale]['native_name'] ) ) {
164 + return $available_translations[$locale]['native_name'];
165 + }
166 +
167 + return false;
168 +}
169 +
170 +function bogo_get_default_locale() {
171 + if ( defined( 'WPLANG' ) ) {
172 + $locale = WPLANG;
173 + }
174 +
175 + if ( is_multisite() ) {
176 + if ( defined( 'WP_INSTALLING' )
177 + || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
178 + $ms_locale = get_site_option( 'WPLANG' );
179 + }
180 +
181 + if ( $ms_locale !== false ) {
182 + $locale = $ms_locale;
183 + }
184 + } else {
185 + $db_locale = get_option( 'WPLANG' );
186 +
187 + if ( $db_locale !== false ) {
188 + $locale = $db_locale;
189 + }
190 + }
191 +
192 + if ( empty( $locale ) ) {
193 + $locale = 'en_US';
194 + }
195 +
196 + return $locale;
197 +}
198 +
199 +function bogo_is_default_locale( $locale ) {
200 + $default_locale = bogo_get_default_locale();
201 +
202 + return ! empty( $locale ) && $locale == bogo_get_default_locale();
203 +}
204 +
205 +function bogo_available_locales( $args = '' ) {
206 + $defaults = array(
207 + 'exclude' => array(),
208 + 'exclude_enus_if_inactive' => false,
209 + 'current_user_can_access' => false );
210 +
211 + $args = wp_parse_args( $args, $defaults );
212 +
213 + $installed_locales = get_available_languages();
214 + $installed_locales[] = bogo_get_default_locale();
215 +
216 + $exclude_enus = $args['exclude_enus_if_inactive']
217 + && bogo_get_prop( 'enus_deactivated' );
218 +
219 + if ( ! $exclude_enus ) {
220 + $installed_locales[] = 'en_US';
221 + }
222 +
223 + $installed_locales = array_unique( $installed_locales );
224 + $installed_locales = array_filter( $installed_locales );
225 +
226 + $available_locales = array();
227 +
228 + foreach ( $installed_locales as $locale ) {
229 + if ( in_array( $locale, (array) $args['exclude'] ) ) {
230 + continue;
231 + }
232 +
233 + if ( $args['current_user_can_access']
234 + && ! current_user_can( 'bogo_access_locale', $locale ) ) {
235 + continue;
236 + }
237 +
238 + $available_locales[] = $locale;
239 + }
240 +
241 + return $available_locales;
242 +}
243 +
244 +function bogo_available_languages( $args = '' ) {
245 + $defaults = array(
246 + 'exclude' => array(),
247 + 'orderby' => 'key',
248 + 'order' => 'ASC',
249 + 'current_user_can_access' => false );
250 +
251 + $args = wp_parse_args( $args, $defaults );
252 +
253 + $langs = array();
254 +
255 + $available_locales = bogo_available_locales( $args );
256 +
257 + foreach ( $available_locales as $locale ) {
258 + $lang = bogo_get_language( $locale );
259 + $langs[$locale] = empty( $lang ) ? "[$locale]" : $lang;
260 + }
261 +
262 + if ( 'value' == $args['orderby'] ) {
263 + natcasesort( $langs );
264 +
265 + if ( 'DESC' == $args['order'] ) {
266 + $langs = array_reverse( $langs );
267 + }
268 + } else {
269 + if ( 'DESC' == $args['order'] ) {
270 + krsort( $langs );
271 + } else {
272 + ksort( $langs );
273 + }
274 + }
275 +
276 + $langs = apply_filters( 'bogo_available_languages', $langs, $args );
277 +
278 + return $langs;
279 +}
280 +
281 +function bogo_is_available_locale( $locale ) {
282 + if ( empty( $locale ) ) {
283 + return false;
284 + }
285 +
286 + static $available_locales = array();
287 +
288 + if ( empty( $available_locales ) ) {
289 + $available_locales = bogo_available_locales();
290 + }
291 +
292 + return in_array( $locale, $available_locales );
293 +}
294 +
295 +function bogo_filter_locales( $locales, $filter = 'available' ) {
296 + return array_intersect( $locales, bogo_available_locales() );
297 +}
298 +
299 +function bogo_language_tag( $locale ) {
300 + // http://www.ietf.org/rfc/bcp/bcp47.txt
301 + $tag = preg_replace( '/[^0-9a-zA-Z]+/', '-', $locale );
302 + $tag = trim( $tag, '-' );
303 +
304 + return apply_filters( 'bogo_language_tag', $tag, $locale );
305 +}
306 +
307 +function bogo_lang_slug( $locale ) {
308 + $tag = bogo_language_tag( $locale );
309 + $slug = $tag;
310 +
311 + if ( false !== $pos = strpos( $tag, '-' ) )
312 + $slug = substr( $tag, 0, $pos );
313 +
314 + $variations = preg_grep( '/^' . $slug . '/', bogo_available_locales() );
315 +
316 + if ( 1 < count( $variations ) )
317 + $slug = $tag;
318 +
319 + return apply_filters( 'bogo_lang_slug', $slug, $locale );
320 +}
321 +
322 +function bogo_get_lang_regex() {
323 + $langs = array_map( 'bogo_lang_slug', bogo_available_locales() );
324 + $langs = array_filter( $langs );
325 +
326 + if ( empty( $langs ) )
327 + return '';
328 +
329 + return '(' . implode( '|', $langs ) . ')';
330 +}
331 +
332 +function bogo_get_closest_locale( $var ) {
333 + $var = strtolower( $var );
334 +
335 + if ( ! preg_match( '/^([a-z]{2})(?:[_-]([a-z]{2}))?/', $var, $matches ) )
336 + return false;
337 +
338 + $language_code = $matches[1];
339 + $region_code = isset( $matches[2] ) ? $matches[2] : '';
340 +
341 + $locales = bogo_available_locales();
342 +
343 + if ( $region_code ) {
344 + $locale = $language_code . '_' . strtoupper( $region_code );
345 +
346 + if ( false !== array_search( $locale, $locales ) )
347 + return $locale;
348 + }
349 +
350 + $locale = $language_code;
351 +
352 + if ( false !== array_search( $locale, $locales ) )
353 + return $locale;
354 +
355 + if ( $matches = preg_grep( "/^{$locale}_/", $locales ) )
356 + return array_shift( $matches );
357 +
358 + return false;
359 +}
360 +
361 +function bogo_http_accept_languages() {
362 + if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
363 + return false;
364 +
365 + $languages = array();
366 +
367 + foreach ( explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) as $lang ) {
368 + $lang = trim( strtolower( $lang ) );
369 +
370 + if ( preg_match( '/^([a-z-]+)(?:;q=([0-9.]+))?$/', $lang, $matches ) ) {
371 + $language_tag = $matches[1];
372 + $qvalue = isset( $matches[2] ) ? 0 + $matches[2] : 1;
373 +
374 + if ( preg_match( '/^([a-z]{2})(?:-([a-z]{2}))?$/', $language_tag, $matches ) ) {
375 + $language_tag = $matches[1];
376 +
377 + if ( isset( $matches[2] ) )
378 + $language_tag .= '_' . strtoupper( $matches[2] );
379 +
380 + $languages[$language_tag] = $qvalue;
381 + }
382 + }
383 + }
384 +
385 + natsort( $languages );
386 +
387 + return array_reverse( array_keys( $languages ) );
388 +}
389 +
390 +function bogo_url( $url = null, $lang = null ) {
391 + if ( ! $lang )
392 + $lang = get_locale();
393 +
394 + $args = array(
395 + 'using_permalinks' => (bool) get_option( 'permalink_structure' ) );
396 +
397 + return bogo_get_url_with_lang( $url, $lang, $args );
398 +}
399 +
400 +function bogo_get_url_with_lang( $url = null, $lang = null, $args = '' ) {
401 + $defaults = array(
402 + 'using_permalinks' => true );
403 +
404 + $args = wp_parse_args( $args, $defaults );
405 +
406 + if ( ! $url ) {
407 + if ( ! $url = redirect_canonical( $url, false ) ) {
408 + $url = is_ssl() ? 'https://' : 'http://';
409 + $url .= $_SERVER['HTTP_HOST'];
410 + $url .= $_SERVER['REQUEST_URI'];
411 + }
412 +
413 + if ( $frag = strstr( $url, '#' ) ) {
414 + $url = substr( $url, 0, - strlen( $frag ) );
415 + }
416 +
417 + if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) {
418 + parse_str( $query, $query_vars );
419 +
420 + foreach ( array_keys( $query_vars ) as $qv ) {
421 + if ( ! get_query_var( $qv ) ) {
422 + $url = remove_query_arg( $qv, $url );
423 + }
424 + }
425 + }
426 + }
427 +
428 + $default_locale = bogo_get_default_locale();
429 +
430 + if ( ! $lang ) {
431 + $lang = $default_locale;
432 + }
433 +
434 + $home = set_url_scheme( get_option( 'home' ) );
435 + $home = trailingslashit( $home );
436 +
437 + $url = remove_query_arg( 'lang', $url );
438 +
439 + if ( ! $args['using_permalinks'] ) {
440 + if ( $lang != $default_locale ) {
441 + $url = add_query_arg( array( 'lang' => bogo_lang_slug( $lang ) ), $url );
442 + }
443 +
444 + return $url;
445 + }
446 +
447 + $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() );
448 +
449 + $tail_slashed = ( '/' == substr( $url, -1 ) );
450 +
451 + $url = preg_replace(
452 + '#^' . preg_quote( $home ) . '((' . implode( '|', $available_languages ) . ')/)?#',
453 + $home . ( $lang == $default_locale ? '' : bogo_lang_slug( $lang ) . '/' ),
454 + trailingslashit( $url ) );
455 +
456 + if ( ! $tail_slashed ) {
457 + $url = untrailingslashit( $url );
458 + }
459 +
460 + return $url;
461 +}
462 +
463 +function bogo_get_lang_from_url( $url = '' ) {
464 + if ( ! $url ) {
465 + $url = is_ssl() ? 'https://' : 'http://';
466 + $url .= $_SERVER['HTTP_HOST'];
467 + $url .= $_SERVER['REQUEST_URI'];
468 + }
469 +
470 + if ( $frag = strstr( $url, '#' ) )
471 + $url = substr( $url, 0, - strlen( $frag ) );
472 +
473 + $home = set_url_scheme( get_option( 'home' ) );
474 + $home = trailingslashit( $home );
475 +
476 + $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() );
477 +
478 + $regex = '#^' . preg_quote( $home ) . '(' . implode( '|', $available_languages ) . ')/#';
479 +
480 + if ( preg_match( $regex, trailingslashit( $url ), $matches ) )
481 + return $matches[1];
482 +
483 + if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) {
484 + parse_str( $query, $query_vars );
485 +
486 + if ( isset( $query_vars['lang'] )
487 + && in_array( $query_vars['lang'], $available_languages ) )
488 + return $query_vars['lang'];
489 + }
490 +
491 + return false;
492 +}
493 +
3 494 function bogo_get_prop( $prop ) {
4 495 $option = get_option( 'bogo' );
5 496
6 497 if ( ! is_array( $option ) ) {
@@ -6,12 +497,11 @@
6 497 if ( ! is_array( $option ) ) {
7 498 $option = array();
8 499 }
9 500
10 - return $option[$prop] ?? '';
501 + return isset( $option[$prop] ) ? $option[$prop] : '';
11 502 }
12 503
13 -
14 504 function bogo_set_prop( $prop, $value ) {
15 505 $option = get_option( 'bogo' );
16 506
17 507 if ( ! is_array( $option ) ) {
@@ -22,9 +512,8 @@
22 512
23 513 update_option( 'bogo', $option );
24 514 }
25 515
26 -
27 516 function bogo_delete_prop( $prop ) {
28 517 $option = get_option( 'bogo' );
29 518
30 519 if ( ! is_array( $option ) ) {
@@ -37,13 +526,12 @@
37 526
38 527 update_option( 'bogo', $option );
39 528 }
40 529
41 -
42 530 function bogo_plugin_url( $path = '' ) {
43 531 $url = plugins_url( $path, BOGO_PLUGIN );
44 532
45 - if ( is_ssl() and 'http:' === substr( $url, 0, 5 ) ) {
533 + if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) {
46 534 $url = 'https:' . substr( $url, 5 );
47 535 }
48 536
49 537 return $url;