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