| 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.1.2 |
| 11 |
*/ |
| 12 |
|
| 13 |
/* Copyright 2007-2013 Takayuki Miyoshi (email: takayukister at gmail.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
define( 'BOGO_VERSION', '2.1.2' ); |
| 31 |
|
| 32 |
if ( ! defined( 'BOGO_PLUGIN_BASENAME' ) ) |
| 33 |
define( 'BOGO_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 34 |
|
| 35 |
if ( ! defined( 'BOGO_PLUGIN_NAME' ) ) |
| 36 |
define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) ); |
| 37 |
|
| 38 |
if ( ! defined( 'BOGO_PLUGIN_DIR' ) ) |
| 39 |
define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); |
| 40 |
|
| 41 |
if ( ! defined( 'BOGO_PLUGIN_URL' ) ) |
| 42 |
define( 'BOGO_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); |
| 43 |
|
| 44 |
require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 45 |
require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 46 |
require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 47 |
require_once BOGO_PLUGIN_DIR . '/includes/widgets.php'; |
| 48 |
require_once BOGO_PLUGIN_DIR . '/includes/post-l10n-functions.php'; |
| 49 |
require_once BOGO_PLUGIN_DIR . '/includes/user-l10n-functions.php'; |
| 50 |
require_once BOGO_PLUGIN_DIR . '/includes/post-l10n.php'; |
| 51 |
require_once BOGO_PLUGIN_DIR . '/includes/user-l10n.php'; |
| 52 |
require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 53 |
|
| 54 |
add_action( 'plugins_loaded', 'bogo_plugins_loaded' ); |
| 55 |
|
| 56 |
function bogo_plugins_loaded() { |
| 57 |
load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' ); |
| 58 |
} |
| 59 |
|
| 60 |
add_action( 'init', 'bogo_init' ); |
| 61 |
|
| 62 |
function bogo_init() { |
| 63 |
global $bogo_languages; |
| 64 |
|
| 65 |
$bogo_languages = bogo_languages(); |
| 66 |
|
| 67 |
if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { |
| 68 |
$locale = get_locale(); |
| 69 |
|
| 70 |
if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) |
| 71 |
setcookie( 'lang', $locale, 0, '/' ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
add_filter( 'locale', 'bogo_locale' ); |
| 76 |
|
| 77 |
function bogo_locale( $locale ) { |
| 78 |
global $wp_rewrite, $wp_query; |
| 79 |
|
| 80 |
if ( ! did_action( 'plugins_loaded' ) ) |
| 81 |
return $locale; |
| 82 |
|
| 83 |
if ( is_admin() ) |
| 84 |
return bogo_get_user_locale(); |
| 85 |
|
| 86 |
$default_locale = bogo_get_default_locale(); |
| 87 |
|
| 88 |
if ( ! empty( $wp_query->query_vars ) ) { |
| 89 |
if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) ) |
| 90 |
return $closest; |
| 91 |
else |
| 92 |
return $default_locale; |
| 93 |
} |
| 94 |
|
| 95 |
if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { |
| 96 |
$url = is_ssl() ? 'https://' : 'http://'; |
| 97 |
$url .= $_SERVER['HTTP_HOST']; |
| 98 |
$url .= $_SERVER['REQUEST_URI']; |
| 99 |
|
| 100 |
$home = set_url_scheme( get_option( 'home' ) ); |
| 101 |
$home = trailingslashit( $home ); |
| 102 |
|
| 103 |
$available_languages = bogo_available_languages(); |
| 104 |
$available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) ); |
| 105 |
$available_languages = implode( '|', $available_languages ); |
| 106 |
$pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#'; |
| 107 |
|
| 108 |
if ( preg_match( $pattern, $url, $matches ) |
| 109 |
&& $closest = bogo_get_closest_locale( $matches[1] ) ) |
| 110 |
return $closest; |
| 111 |
} |
| 112 |
|
| 113 |
$lang = bogo_get_lang_from_url(); |
| 114 |
|
| 115 |
if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) |
| 116 |
return $closest; |
| 117 |
|
| 118 |
$locale = $default_locale; |
| 119 |
|
| 120 |
return $locale; |
| 121 |
} |
| 122 |
|
| 123 |
add_filter( 'query_vars', 'bogo_query_vars' ); |
| 124 |
|
| 125 |
function bogo_query_vars( $query_vars ) { |
| 126 |
$query_vars[] = 'lang'; |
| 127 |
|
| 128 |
return $query_vars; |
| 129 |
} |
| 130 |
|
| 131 |
?> |