PluginProbe
Bogo / 2.4
Bogo v2.4
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/flags.php +38 -30 trunk2.4 View file →
@@ -1,29 +1,42 @@
1 1 <?php
2 2
3 -/**
4 - * Returns a URL of the national flag icon.
5 - *
6 - * @deprecated 3.7
7 - */
8 -function bogo_get_flag( $locale ) {
9 - if ( WP_DEBUG ) {
10 - wp_trigger_error(
11 - __FUNCTION__,
12 - sprintf(
13 - /* translators: 1: PHP function name, 2: version number */
14 - __( 'Function %1$s is <strong>deprecated</strong> since Bogo version %2$s with no alternative available.', 'bogo' ),
15 - __FUNCTION__,
16 - '3.7'
17 - ),
18 - E_USER_DEPRECATED
19 - );
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 + }
20 16 }
21 17
22 - $locale = explode( '_', $locale );
23 - $locale = array_slice( $locale, 0, 2 ); // de_DE_formal => de_DE
24 - $locale = implode( '_', $locale );
18 + if ( ! $flags ) {
19 + return;
20 + }
25 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 + $dir = '/images/flag-icons';
37 + $file = '';
38 +
26 39 $special_cases = array(
27 40 'ca' => 'catalonia',
28 41 'gd' => 'scotland',
29 42 'cy' => 'wales',
@@ -28,11 +41,9 @@
28 41 'gd' => 'scotland',
29 42 'cy' => 'wales',
30 43 'am' => 'et',
31 44 'az' => 'az',
32 - 'bel' => 'by',
33 45 'bs' => 'ba',
34 - 'dzo' => 'bt',
35 46 'el' => 'gr',
36 47 'et' => 'ee',
37 48 'fi' => 'fi',
38 49 'ga' => 'ie',
@@ -40,9 +51,8 @@
40 51 'ht' => 'ht',
41 52 'hy' => 'am',
42 53 'ja' => 'jp',
43 54 'kk' => 'kz',
44 - 'km' => 'kh',
45 55 'lo' => 'la',
46 56 'lv' => 'lv',
47 57 'mn' => 'mn',
48 58 'sq' => 'al',
@@ -49,24 +59,22 @@
49 59 'tg' => 'tj',
50 60 'th' => 'th',
51 61 'tl' => 'ph',
52 62 'uk' => 'ua',
53 - 'vi' => 'vn',
54 - );
63 + 'vi' => 'vn' );
55 64
56 65 if ( isset( $special_cases[$locale] ) ) {
57 66 $file = $special_cases[$locale] . '.png';
58 67 } elseif ( preg_match( '/_([A-Z]{2})$/', $locale, $matches ) ) {
59 68 $file = strtolower( $matches[1] ) . '.png';
60 - } else {
61 - $file = 'zz.png'; // 'zz.png' doesn't exist, just a dummy.
62 69 }
63 70
64 - $file = path_join( 'images/flag-icons', $file );
65 71 $url = '';
66 72
67 - if ( file_exists( path_join( BOGO_PLUGIN_DIR, $file ) ) ) {
68 - $url = bogo_plugin_url( $file );
73 + if ( $file && file_exists( path_join( BOGO_PLUGIN_DIR . $dir, $file ) ) ) {
74 + $url = path_join( BOGO_PLUGIN_URL . $dir, $file );
69 75 }
70 76
71 77 return apply_filters( 'bogo_get_flag', $url, $locale );
72 78 }
79 +
80 +?>