| @@ -6,51 +6,36 @@ | ||
| 6 | 6 | Author: Takayuki Miyoshi |
| 7 | 7 | Author URI: http://ideasilo.wordpress.com/ |
| 8 | 8 | Text Domain: bogo |
| 9 | 9 | Domain Path: /languages/ |
| 10 | -Version: 2.0 | |
| 10 | +Version: 2.4 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -/* Copyright 2007-2012 Takayuki Miyoshi (email: takayukister at gmail.com) | |
| 13 | +define( 'BOGO_VERSION', '2.4' ); | |
| 14 | 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. | |
| 15 | +define( 'BOGO_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); | |
| 19 | 16 | |
| 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. | |
| 17 | +define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) ); | |
| 24 | 18 | |
| 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 | -*/ | |
| 19 | +define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); | |
| 29 | 20 | |
| 30 | -define( 'BOGO_VERSION', '2.0' ); | |
| 21 | +define( 'BOGO_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); | |
| 31 | 22 | |
| 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 | 23 | require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 45 | 24 | require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 46 | 25 | require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 26 | +require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; | |
| 47 | 27 | 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'; | |
| 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'; | |
| 52 | 33 | |
| 34 | +if ( is_admin() ) { | |
| 35 | + require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; | |
| 36 | +} | |
| 37 | + | |
| 53 | 38 | add_action( 'plugins_loaded', 'bogo_plugins_loaded' ); |
| 54 | 39 | |
| 55 | 40 | function bogo_plugins_loaded() { |
| 56 | 41 | load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' ); |
| @@ -58,8 +43,10 @@ | ||
| 58 | 43 | |
| 59 | 44 | add_action( 'init', 'bogo_init' ); |
| 60 | 45 | |
| 61 | 46 | function bogo_init() { |
| 47 | + bogo_languages(); | |
| 48 | + | |
| 62 | 49 | if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { |
| 63 | 50 | $locale = get_locale(); |
| 64 | 51 | |
| 65 | 52 | if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) |
| @@ -71,8 +58,11 @@ | ||
| 71 | 58 | |
| 72 | 59 | function bogo_locale( $locale ) { |
| 73 | 60 | global $wp_rewrite, $wp_query; |
| 74 | 61 | |
| 62 | + if ( ! did_action( 'plugins_loaded' ) ) | |
| 63 | + return $locale; | |
| 64 | + | |
| 75 | 65 | if ( is_admin() ) |
| 76 | 66 | return bogo_get_user_locale(); |
| 77 | 67 | |
| 78 | 68 | $default_locale = bogo_get_default_locale(); |
| @@ -88,9 +78,11 @@ | ||
| 88 | 78 | $url = is_ssl() ? 'https://' : 'http://'; |
| 89 | 79 | $url .= $_SERVER['HTTP_HOST']; |
| 90 | 80 | $url .= $_SERVER['REQUEST_URI']; |
| 91 | 81 | |
| 92 | - $home = trailingslashit( home_url() ); | |
| 82 | + $home = set_url_scheme( get_option( 'home' ) ); | |
| 83 | + $home = trailingslashit( $home ); | |
| 84 | + | |
| 93 | 85 | $available_languages = bogo_available_languages(); |
| 94 | 86 | $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) ); |
| 95 | 87 | $available_languages = implode( '|', $available_languages ); |
| 96 | 88 | $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#'; |
| @@ -117,117 +109,21 @@ | ||
| 117 | 109 | |
| 118 | 110 | return $query_vars; |
| 119 | 111 | } |
| 120 | 112 | |
| 121 | -add_action( 'parse_query', 'bogo_parse_query' ); | |
| 113 | +add_shortcode( 'bogo', 'bogo_language_switcher' ); | |
| 122 | 114 | |
| 123 | -function bogo_parse_query( $query ) { | |
| 124 | - $qv = &$query->query_vars; | |
| 115 | +add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); | |
| 125 | 116 | |
| 126 | - if ( ! empty( $qv['bogo_suppress_locale_query'] ) ) | |
| 127 | - return; | |
| 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' ); | |
| 128 | 121 | |
| 129 | - if ( isset( $qv['post_type'] ) && 'any' != $qv['post_type'] ) { | |
| 130 | - $localizable = array_filter( (array) $qv['post_type'], 'bogo_is_localizable_post_type' ); | |
| 131 | - | |
| 132 | - if ( empty( $localizable ) ) { | |
| 133 | - $qv['bogo_suppress_locale_query'] = true; | |
| 134 | - return; | |
| 135 | - } | |
| 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' ); | |
| 136 | 126 | } |
| 137 | - | |
| 138 | - $lang = isset( $qv['lang'] ) ? $qv['lang'] : ''; | |
| 139 | - | |
| 140 | - if ( is_admin() ) { | |
| 141 | - $locale = $lang; | |
| 142 | - } else { | |
| 143 | - if ( $lang ) | |
| 144 | - $locale = bogo_get_closest_locale( $lang ); | |
| 145 | - else | |
| 146 | - $locale = get_locale(); | |
| 147 | - | |
| 148 | - if ( empty( $locale ) ) | |
| 149 | - $locale = bogo_get_default_locale(); | |
| 150 | - } | |
| 151 | - | |
| 152 | - if ( empty( $locale ) || ! bogo_is_available_locale( $locale ) ) { | |
| 153 | - $qv['bogo_suppress_locale_query'] = true; | |
| 154 | - return; | |
| 155 | - } | |
| 156 | - | |
| 157 | - $qv['lang'] = $locale; | |
| 158 | - | |
| 159 | - if ( is_admin() ) | |
| 160 | - return; | |
| 161 | - | |
| 162 | - if ( '' != $qv['pagename'] ) { | |
| 163 | - $query->queried_object = bogo_get_page_by_path( $qv['pagename'], $locale ); | |
| 164 | - | |
| 165 | - if ( ! empty( $query->queried_object ) ) | |
| 166 | - $query->queried_object_id = (int) $query->queried_object->ID; | |
| 167 | - else | |
| 168 | - unset( $query->queried_object ); | |
| 169 | - | |
| 170 | - if ( 'page' == get_option( 'show_on_front' ) | |
| 171 | - && isset( $query->queried_object_id ) | |
| 172 | - && $query->queried_object_id == get_option( 'page_for_posts' ) ) { | |
| 173 | - $query->is_page = false; | |
| 174 | - $query->is_home = true; | |
| 175 | - $query->is_posts_page = true; | |
| 176 | - } | |
| 177 | - } | |
| 178 | -} | |
| 179 | - | |
| 180 | -add_filter( 'posts_join', 'bogo_posts_join', 10, 2 ); | |
| 181 | - | |
| 182 | -function bogo_posts_join( $join, $query ) { | |
| 183 | - global $wpdb; | |
| 184 | - | |
| 185 | - $qv = &$query->query_vars; | |
| 186 | - | |
| 187 | - if ( ! empty( $qv['bogo_suppress_locale_query'] ) ) | |
| 188 | - return $join; | |
| 189 | - | |
| 190 | - $locale = empty( $qv['lang'] ) ? '' : $qv['lang']; | |
| 191 | - | |
| 192 | - if ( ! bogo_is_available_locale( $locale ) ) | |
| 193 | - return $join; | |
| 194 | - | |
| 195 | - if ( ! $meta_table = _get_meta_table( 'post' ) ) | |
| 196 | - return $join; | |
| 197 | - | |
| 198 | - $join .= " LEFT JOIN $meta_table AS postmeta_bogo ON ($wpdb->posts.ID = postmeta_bogo.post_id AND postmeta_bogo.meta_key = '_locale')"; | |
| 199 | - | |
| 200 | - return $join; | |
| 201 | -} | |
| 202 | - | |
| 203 | -add_filter( 'posts_where', 'bogo_posts_where', 10, 2 ); | |
| 204 | - | |
| 205 | -function bogo_posts_where( $where, $query ) { | |
| 206 | - global $wpdb; | |
| 207 | - | |
| 208 | - $qv = &$query->query_vars; | |
| 209 | - | |
| 210 | - if ( ! empty( $qv['bogo_suppress_locale_query'] ) ) | |
| 211 | - return $where; | |
| 212 | - | |
| 213 | - $locale = empty( $qv['lang'] ) ? '' : $qv['lang']; | |
| 214 | - | |
| 215 | - if ( ! bogo_is_available_locale( $locale ) ) | |
| 216 | - return $where; | |
| 217 | - | |
| 218 | - if ( ! $meta_table = _get_meta_table( 'post' ) ) | |
| 219 | - return $where; | |
| 220 | - | |
| 221 | - $where .= " AND (1=0"; | |
| 222 | - | |
| 223 | - $where .= $wpdb->prepare( " OR postmeta_bogo.meta_value LIKE %s", $locale ); | |
| 224 | - | |
| 225 | - if ( bogo_is_default_locale( $locale ) ) | |
| 226 | - $where .= " OR postmeta_bogo.meta_id IS NULL"; | |
| 227 | - | |
| 228 | - $where .= ")"; | |
| 229 | - | |
| 230 | - return $where; | |
| 231 | 127 | } |
| 232 | 128 | |
| 233 | 129 | ?> |