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
bogo / includes / flags.php

flags.php in Bogo 2.6, at includes/flags.php

83 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'wp_head', 'bogo_flag_css' );
4
5 function bogo_flag_css() {
6 $flags = array();
7
8 if ( apply_filters( 'bogo_use_flags', true ) ) {
9 $locales = bogo_available_locales();
10
11 foreach ( $locales as $locale ) {
12 if ( $flag = bogo_get_flag( $locale ) ) {
13 $flags[$locale] = $flag;
14 }
15 }
16 }
17
18 if ( ! $flags ) {
19 return;
20 }
21
22 $side = is_rtl() ? 'right' : 'left';
23
24 echo '<style type="text/css">' . "\n";
25
26 foreach ( $flags as $locale => $flag ) {
27 echo '.bogo-language-switcher .' . bogo_language_tag( $locale ) . ' {';
28 echo ' background: url("' . $flag . '") no-repeat ' . $side . ' center;';
29 echo ' }' . "\n";
30 }
31
32 echo '</style>' . "\n";
33 }
34
35 function bogo_get_flag( $locale ) {
36 $locale = explode( '_', $locale );
37 $locale = array_slice( $locale, 0, 2 ); // de_DE_formal => de_DE
38 $locale = implode( '_', $locale );
39
40 $special_cases = array(
41 'ca' => 'catalonia',
42 'gd' => 'scotland',
43 'cy' => 'wales',
44 'am' => 'et',
45 'az' => 'az',
46 'bs' => 'ba',
47 'el' => 'gr',
48 'et' => 'ee',
49 'fi' => 'fi',
50 'ga' => 'ie',
51 'hr' => 'hr',
52 'ht' => 'ht',
53 'hy' => 'am',
54 'ja' => 'jp',
55 'kk' => 'kz',
56 'lo' => 'la',
57 'lv' => 'lv',
58 'mn' => 'mn',
59 'sq' => 'al',
60 'tg' => 'tj',
61 'th' => 'th',
62 'tl' => 'ph',
63 'uk' => 'ua',
64 'vi' => 'vn' );
65
66 if ( isset( $special_cases[$locale] ) ) {
67 $file = $special_cases[$locale] . '.png';
68 } elseif ( preg_match( '/_([A-Z]{2})$/', $locale, $matches ) ) {
69 $file = strtolower( $matches[1] ) . '.png';
70 } else {
71 $file = 'zz.png'; // 'zz.png' doesn't exist, just a dummy.
72 }
73
74 $file = path_join( 'images/flag-icons', $file );
75 $url = '';
76
77 if ( file_exists( path_join( BOGO_PLUGIN_DIR, $file ) ) ) {
78 $url = bogo_plugin_url( $file );
79 }
80
81 return apply_filters( 'bogo_get_flag', $url, $locale );
82 }
83