PluginProbe
Bogo / 2.1.3
Bogo v2.1.3
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
bogo / bogo.php

bogo.php in Bogo 2.1.3, at bogo.php

129 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.3
11 */
12
13 /* Copyright 2007-2014 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.3' );
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 bogo_languages();
64
65 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
66 $locale = get_locale();
67
68 if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale )
69 setcookie( 'lang', $locale, 0, '/' );
70 }
71 }
72
73 add_filter( 'locale', 'bogo_locale' );
74
75 function bogo_locale( $locale ) {
76 global $wp_rewrite, $wp_query;
77
78 if ( ! did_action( 'plugins_loaded' ) )
79 return $locale;
80
81 if ( is_admin() )
82 return bogo_get_user_locale();
83
84 $default_locale = bogo_get_default_locale();
85
86 if ( ! empty( $wp_query->query_vars ) ) {
87 if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) )
88 return $closest;
89 else
90 return $default_locale;
91 }
92
93 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
94 $url = is_ssl() ? 'https://' : 'http://';
95 $url .= $_SERVER['HTTP_HOST'];
96 $url .= $_SERVER['REQUEST_URI'];
97
98 $home = set_url_scheme( get_option( 'home' ) );
99 $home = trailingslashit( $home );
100
101 $available_languages = bogo_available_languages();
102 $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) );
103 $available_languages = implode( '|', $available_languages );
104 $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#';
105
106 if ( preg_match( $pattern, $url, $matches )
107 && $closest = bogo_get_closest_locale( $matches[1] ) )
108 return $closest;
109 }
110
111 $lang = bogo_get_lang_from_url();
112
113 if ( $lang && $closest = bogo_get_closest_locale( $lang ) )
114 return $closest;
115
116 $locale = $default_locale;
117
118 return $locale;
119 }
120
121 add_filter( 'query_vars', 'bogo_query_vars' );
122
123 function bogo_query_vars( $query_vars ) {
124 $query_vars[] = 'lang';
125
126 return $query_vars;
127 }
128
129 ?>