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