PluginProbe
Bogo / 2.9
Bogo v2.9
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
← All changes | bogo.php +45 -28 2.4.22.9 View file →
@@ -6,24 +6,26 @@
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.4.2
10 +Version: 2.9
11 11 */
12 12
13 -define( 'BOGO_VERSION', '2.4.2' );
13 +define( 'BOGO_VERSION', '2.9' );
14 14
15 -define( 'BOGO_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
15 +define( 'BOGO_PLUGIN', __FILE__ );
16 16
17 +define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) );
18 +
17 19 define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) );
18 20
19 -define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) );
21 +define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) );
20 22
21 -define( 'BOGO_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
22 -
23 23 require_once BOGO_PLUGIN_DIR . '/includes/functions.php';
24 +require_once BOGO_PLUGIN_DIR . '/includes/pomo.php';
24 25 require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php';
25 26 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
27 +require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
26 28 require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
27 29 require_once BOGO_PLUGIN_DIR . '/includes/widgets.php';
28 30 require_once BOGO_PLUGIN_DIR . '/includes/post.php';
29 31 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
@@ -29,8 +31,9 @@
29 31 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
30 32 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
31 33 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
32 34 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
35 +require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php';
33 36
34 37 if ( is_admin() ) {
35 38 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
36 39 }
@@ -44,14 +47,16 @@
44 47 add_action( 'init', 'bogo_init' );
45 48
46 49 function bogo_init() {
47 50 bogo_languages();
51 + Bogo_POMO::import( get_locale() );
48 52
49 53 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
50 54 $locale = get_locale();
51 55
52 - if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale )
56 + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) {
53 57 setcookie( 'lang', $locale, 0, '/' );
58 + }
54 59 }
55 60 }
56 61
57 62 add_filter( 'locale', 'bogo_locale' );
@@ -58,21 +63,31 @@
58 63
59 64 function bogo_locale( $locale ) {
60 65 global $wp_rewrite, $wp_query;
61 66
62 - if ( ! did_action( 'plugins_loaded' ) )
67 + if ( ! did_action( 'plugins_loaded' ) ) {
63 68 return $locale;
69 + }
64 70
65 - if ( is_admin() )
66 - return bogo_get_user_locale();
71 + static $bogo_locale = '';
67 72
73 + if ( $bogo_locale ) {
74 + return $bogo_locale;
75 + }
76 +
77 + if ( is_admin() ) {
78 + return $bogo_locale = bogo_get_user_locale();
79 + }
80 +
68 81 $default_locale = bogo_get_default_locale();
69 82
70 83 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;
84 + if ( ( $lang = get_query_var( 'lang' ) )
85 + && $closest = bogo_get_closest_locale( $lang ) ) {
86 + return $bogo_locale = $closest;
87 + } else {
88 + return $bogo_locale = $default_locale;
89 + }
75 90 }
76 91
77 92 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
78 93 $url = is_ssl() ? 'https://' : 'http://';
@@ -81,26 +96,26 @@
81 96
82 97 $home = set_url_scheme( get_option( 'home' ) );
83 98 $home = trailingslashit( $home );
84 99
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 . ')(/|$)#';
100 + $available_locales = bogo_available_locales();
101 + $available_locales = array_map( 'bogo_lang_slug', $available_locales );
102 + $available_locales = implode( '|', $available_locales );
103 + $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#';
89 104
90 105 if ( preg_match( $pattern, $url, $matches )
91 - && $closest = bogo_get_closest_locale( $matches[1] ) )
92 - return $closest;
106 + && $closest = bogo_get_closest_locale( $matches[1] ) ) {
107 + return $bogo_locale = $closest;
108 + }
93 109 }
94 110
95 111 $lang = bogo_get_lang_from_url();
96 112
97 - if ( $lang && $closest = bogo_get_closest_locale( $lang ) )
98 - return $closest;
113 + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
114 + return $bogo_locale = $closest;
115 + }
99 116
100 - $locale = $default_locale;
101 -
102 - return $locale;
117 + return $bogo_locale = $default_locale;
103 118 }
104 119
105 120 add_filter( 'query_vars', 'bogo_query_vars' );
106 121
@@ -109,10 +124,8 @@
109 124
110 125 return $query_vars;
111 126 }
112 127
113 -add_shortcode( 'bogo', 'bogo_language_switcher' );
114 -
115 128 add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
116 129
117 130 function bogo_enqueue_scripts() {
118 131 wp_enqueue_style( 'bogo',
@@ -125,5 +138,9 @@
125 138 array(), BOGO_VERSION, 'all' );
126 139 }
127 140 }
128 141
129 -?>
142 +add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
143 +
144 +function bogo_deactivate() {
145 + bogo_delete_prop( 'lang_rewrite_regex' );
146 +}