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 +69 -156 2.02.9 View file →
@@ -6,51 +6,39 @@
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.9
11 11 */
12 12
13 -/* Copyright 2007-2012 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.0' );
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';
28 +require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
47 29 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';
30 +require_once BOGO_PLUGIN_DIR . '/includes/post.php';
31 +require_once BOGO_PLUGIN_DIR . '/includes/user.php';
32 +require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
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
37 +if ( is_admin() ) {
38 + require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
39 +}
40 +
53 41 add_action( 'plugins_loaded', 'bogo_plugins_loaded' );
54 42
55 43 function bogo_plugins_loaded() {
56 44 load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
@@ -58,13 +46,17 @@
58 46
59 47 add_action( 'init', 'bogo_init' );
60 48
61 49 function bogo_init() {
50 + bogo_languages();
51 + Bogo_POMO::import( get_locale() );
52 +
62 53 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
63 54 $locale = get_locale();
64 55
65 - if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale )
56 + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) {
66 57 setcookie( 'lang', $locale, 0, '/' );
58 + }
67 59 }
68 60 }
69 61
70 62 add_filter( 'locale', 'bogo_locale' );
@@ -71,18 +63,31 @@
71 63
72 64 function bogo_locale( $locale ) {
73 65 global $wp_rewrite, $wp_query;
74 66
75 - if ( is_admin() )
76 - return bogo_get_user_locale();
67 + if ( ! did_action( 'plugins_loaded' ) ) {
68 + return $locale;
69 + }
77 70
71 + static $bogo_locale = '';
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 +
78 81 $default_locale = bogo_get_default_locale();
79 82
80 83 if ( ! empty( $wp_query->query_vars ) ) {
81 - if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) )
82 - return $closest;
83 - else
84 - 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 + }
85 90 }
86 91
87 92 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
88 93 $url = is_ssl() ? 'https://' : 'http://';
@@ -88,27 +93,29 @@
88 93 $url = is_ssl() ? 'https://' : 'http://';
89 94 $url .= $_SERVER['HTTP_HOST'];
90 95 $url .= $_SERVER['REQUEST_URI'];
91 96
92 - $home = trailingslashit( home_url() );
93 - $available_languages = bogo_available_languages();
94 - $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) );
95 - $available_languages = implode( '|', $available_languages );
96 - $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#';
97 + $home = set_url_scheme( get_option( 'home' ) );
98 + $home = trailingslashit( $home );
97 99
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 . ')(/|$)#';
104 +
98 105 if ( preg_match( $pattern, $url, $matches )
99 - && $closest = bogo_get_closest_locale( $matches[1] ) )
100 - return $closest;
106 + && $closest = bogo_get_closest_locale( $matches[1] ) ) {
107 + return $bogo_locale = $closest;
108 + }
101 109 }
102 110
103 111 $lang = bogo_get_lang_from_url();
104 112
105 - if ( $lang && $closest = bogo_get_closest_locale( $lang ) )
106 - return $closest;
113 + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
114 + return $bogo_locale = $closest;
115 + }
107 116
108 - $locale = $default_locale;
109 -
110 - return $locale;
117 + return $bogo_locale = $default_locale;
111 118 }
112 119
113 120 add_filter( 'query_vars', 'bogo_query_vars' );
114 121
@@ -117,117 +124,23 @@
117 124
118 125 return $query_vars;
119 126 }
120 127
121 -add_action( 'parse_query', 'bogo_parse_query' );
128 +add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
122 129
123 -function bogo_parse_query( $query ) {
124 - $qv = &$query->query_vars;
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' );
125 134
126 - if ( ! empty( $qv['bogo_suppress_locale_query'] ) )
127 - return;
128 -
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 - }
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' );
136 139 }
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 140 }
179 141
180 -add_filter( 'posts_join', 'bogo_posts_join', 10, 2 );
142 +add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
181 143
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;
144 +function bogo_deactivate() {
145 + bogo_delete_prop( 'lang_rewrite_regex' );
201 146 }
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 -}
232 -
233 -?>