| 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 |
$dir = '/images/flag-icons'; |
| 37 |
$file = ''; |
| 38 |
|
| 39 |
$special_cases = array( |
| 40 |
'ca' => 'catalonia', |
| 41 |
'gd' => 'scotland', |
| 42 |
'cy' => 'wales', |
| 43 |
'am' => 'et', |
| 44 |
'az' => 'az', |
| 45 |
'bs' => 'ba', |
| 46 |
'el' => 'gr', |
| 47 |
'et' => 'ee', |
| 48 |
'fi' => 'fi', |
| 49 |
'ga' => 'ie', |
| 50 |
'hr' => 'hr', |
| 51 |
'ht' => 'ht', |
| 52 |
'hy' => 'am', |
| 53 |
'ja' => 'jp', |
| 54 |
'kk' => 'kz', |
| 55 |
'lo' => 'la', |
| 56 |
'lv' => 'lv', |
| 57 |
'mn' => 'mn', |
| 58 |
'sq' => 'al', |
| 59 |
'tg' => 'tj', |
| 60 |
'th' => 'th', |
| 61 |
'tl' => 'ph', |
| 62 |
'uk' => 'ua', |
| 63 |
'vi' => 'vn' ); |
| 64 |
|
| 65 |
if ( isset( $special_cases[$locale] ) ) { |
| 66 |
$file = $special_cases[$locale] . '.png'; |
| 67 |
} elseif ( preg_match( '/_([A-Z]{2})$/', $locale, $matches ) ) { |
| 68 |
$file = strtolower( $matches[1] ) . '.png'; |
| 69 |
} |
| 70 |
|
| 71 |
$url = ''; |
| 72 |
|
| 73 |
if ( $file && file_exists( path_join( BOGO_PLUGIN_DIR . $dir, $file ) ) ) { |
| 74 |
$url = path_join( BOGO_PLUGIN_URL . $dir, $file ); |
| 75 |
} |
| 76 |
|
| 77 |
return apply_filters( 'bogo_get_flag', $url, $locale ); |
| 78 |
} |
| 79 |
|
| 80 |
?> |