| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Bogo |
| 4 |
Description: A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on. |
| 5 |
Plugin URI: http://ideasilo.wordpress.com/bogo/ |
| 6 |
Author: Takayuki Miyoshi |
| 7 |
Author URI: http://ideasilo.wordpress.com/ |
| 8 |
Text Domain: bogo |
| 9 |
Domain Path: /languages/ |
| 10 |
Version: 2.3 |
| 11 |
*/ |
| 12 |
|
| 13 |
define( 'BOGO_VERSION', '2.3' ); |
| 14 |
|
| 15 |
define( 'BOGO_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 16 |
|
| 17 |
define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) ); |
| 18 |
|
| 19 |
define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); |
| 20 |
|
| 21 |
define( 'BOGO_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); |
| 22 |
|
| 23 |
require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 24 |
require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 25 |
require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 26 |
require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; |
| 27 |
require_once BOGO_PLUGIN_DIR . '/includes/widgets.php'; |
| 28 |
require_once BOGO_PLUGIN_DIR . '/includes/post.php'; |
| 29 |
require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| 30 |
require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; |
| 31 |
require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 32 |
require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; |
| 33 |
|
| 34 |
if ( is_admin() ) { |
| 35 |
require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; |
| 36 |
} |
| 37 |
|
| 38 |
add_action( 'plugins_loaded', 'bogo_plugins_loaded' ); |
| 39 |
|
| 40 |
function bogo_plugins_loaded() { |
| 41 |
load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' ); |
| 42 |
} |
| 43 |
|
| 44 |
add_action( 'init', 'bogo_init' ); |
| 45 |
|
| 46 |
function bogo_init() { |
| 47 |
bogo_languages(); |
| 48 |
|
| 49 |
if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { |
| 50 |
$locale = get_locale(); |
| 51 |
|
| 52 |
if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) |
| 53 |
setcookie( 'lang', $locale, 0, '/' ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
add_filter( 'locale', 'bogo_locale' ); |
| 58 |
|
| 59 |
function bogo_locale( $locale ) { |
| 60 |
global $wp_rewrite, $wp_query; |
| 61 |
|
| 62 |
if ( ! did_action( 'plugins_loaded' ) ) |
| 63 |
return $locale; |
| 64 |
|
| 65 |
if ( is_admin() ) |
| 66 |
return bogo_get_user_locale(); |
| 67 |
|
| 68 |
$default_locale = bogo_get_default_locale(); |
| 69 |
|
| 70 |
if ( ! empty( $wp_query->query_vars ) ) { |
| 71 |
if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) ) |
| 72 |
return $closest; |
| 73 |
else |
| 74 |
return $default_locale; |
| 75 |
} |
| 76 |
|
| 77 |
if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { |
| 78 |
$url = is_ssl() ? 'https://' : 'http://'; |
| 79 |
$url .= $_SERVER['HTTP_HOST']; |
| 80 |
$url .= $_SERVER['REQUEST_URI']; |
| 81 |
|
| 82 |
$home = set_url_scheme( get_option( 'home' ) ); |
| 83 |
$home = trailingslashit( $home ); |
| 84 |
|
| 85 |
$available_languages = bogo_available_languages(); |
| 86 |
$available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) ); |
| 87 |
$available_languages = implode( '|', $available_languages ); |
| 88 |
$pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#'; |
| 89 |
|
| 90 |
if ( preg_match( $pattern, $url, $matches ) |
| 91 |
&& $closest = bogo_get_closest_locale( $matches[1] ) ) |
| 92 |
return $closest; |
| 93 |
} |
| 94 |
|
| 95 |
$lang = bogo_get_lang_from_url(); |
| 96 |
|
| 97 |
if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) |
| 98 |
return $closest; |
| 99 |
|
| 100 |
$locale = $default_locale; |
| 101 |
|
| 102 |
return $locale; |
| 103 |
} |
| 104 |
|
| 105 |
add_filter( 'query_vars', 'bogo_query_vars' ); |
| 106 |
|
| 107 |
function bogo_query_vars( $query_vars ) { |
| 108 |
$query_vars[] = 'lang'; |
| 109 |
|
| 110 |
return $query_vars; |
| 111 |
} |
| 112 |
|
| 113 |
add_shortcode( 'bogo', 'bogo_language_switcher' ); |
| 114 |
|
| 115 |
add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); |
| 116 |
|
| 117 |
function bogo_enqueue_scripts() { |
| 118 |
wp_enqueue_style( 'bogo', |
| 119 |
plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ), |
| 120 |
array(), BOGO_VERSION, 'all' ); |
| 121 |
|
| 122 |
if ( is_rtl() ) { |
| 123 |
wp_enqueue_style( 'bogo-rtl', |
| 124 |
plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ), |
| 125 |
array(), BOGO_VERSION, 'all' ); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
?> |