PluginProbe
Bogo / 2.6
Bogo v2.6
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 | admin/admin.php +252 -57 2.42.6 View file →
@@ -34,9 +34,11 @@
34 34 array( 'jquery' ),
35 35 BOGO_VERSION, true );
36 36
37 37 wp_localize_script( 'bogo-admin', '_bogo', array(
38 - 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
38 + 'availableLanguages' => bogo_available_languages( array(
39 + 'exclude_enus_if_inactive' => true,
40 + 'orderby' => 'value' ) ),
39 41 'locales' => $locales,
40 42 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
41 43 'cbPrefix' => $prefix ) );
42 44
@@ -45,8 +47,20 @@
45 47 array(), BOGO_VERSION, 'all' );
46 48
47 49 return;
48 50 }
51 +
52 + if ( 'options-general.php' == $hook_suffix ) {
53 + wp_enqueue_script( 'bogo-admin',
54 + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
55 + array( 'jquery' ),
56 + BOGO_VERSION, true );
57 +
58 + wp_localize_script( 'bogo-admin', '_bogo', array(
59 + 'defaultLocale' => bogo_get_default_locale() ) );
60 +
61 + return;
62 + }
49 63 }
50 64
51 65 add_action( 'admin_menu', 'bogo_admin_menu' );
52 66
@@ -73,13 +87,13 @@
73 87 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
74 88
75 89 if ( wp_download_language_pack( $locale ) ) {
76 90 $redirect_to = add_query_arg(
77 - array( 'locale' => $locale, 'message' => 'success' ),
91 + array( 'locale' => $locale, 'message' => 'install_success' ),
78 92 menu_page_url( 'bogo-tools', false ) );
79 93 } else {
80 94 $redirect_to = add_query_arg(
81 - array( 'locale' => $locale, 'message' => 'failed' ),
95 + array( 'locale' => $locale, 'message' => 'install_failed' ),
82 96 menu_page_url( 'bogo-tools', false ) );
83 97 }
84 98
85 99 wp_safe_redirect( $redirect_to );
@@ -84,20 +98,65 @@
84 98
85 99 wp_safe_redirect( $redirect_to );
86 100 exit();
87 101 }
102 +
103 + if ( 'delete_translation' == $action ) {
104 + check_admin_referer( 'bogo-tools' );
105 +
106 + if ( ! current_user_can( 'update_core' ) ) {
107 + wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
108 + }
109 +
110 + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
111 +
112 + if ( bogo_delete_language_pack( $locale ) ) {
113 + $redirect_to = add_query_arg(
114 + array( 'locale' => $locale, 'message' => 'delete_success' ),
115 + menu_page_url( 'bogo-tools', false ) );
116 + } else {
117 + $redirect_to = add_query_arg(
118 + array( 'locale' => $locale, 'message' => 'delete_failed' ),
119 + menu_page_url( 'bogo-tools', false ) );
120 + }
121 +
122 + wp_safe_redirect( $redirect_to );
123 + exit();
124 + }
125 +
126 + if ( 'deactivate_enus' == $action ) {
127 + check_admin_referer( 'bogo-tools' );
128 +
129 + bogo_set_prop( 'enus_deactivated', true );
130 +
131 + $redirect_to = add_query_arg(
132 + array( 'message' => 'enus_deactivated' ),
133 + menu_page_url( 'bogo-tools', false ) );
134 +
135 + wp_safe_redirect( $redirect_to );
136 + exit();
137 + }
138 +
139 + if ( 'activate_enus' == $action ) {
140 + check_admin_referer( 'bogo-tools' );
141 +
142 + bogo_set_prop( 'enus_deactivated', false );
143 +
144 + $redirect_to = add_query_arg(
145 + array( 'message' => 'enus_activated' ),
146 + menu_page_url( 'bogo-tools', false ) );
147 +
148 + wp_safe_redirect( $redirect_to );
149 + exit();
150 + }
88 151 }
89 152
90 153 function bogo_tools_page() {
91 - $message = "";
154 + $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
155 + $can_install = wp_can_install_language_pack();
92 156
93 - if ( isset( $_GET['message'] ) ) {
94 - if ( 'success' == $_GET['message'] ) {
95 - $message = __( "Translation installed successfully.", 'bogo' );
96 - } elseif ( 'failed' == $_GET['message'] ) {
97 - $message = __( "Translation install failed.", 'bogo' );
98 - }
99 - }
157 + $default_locale = bogo_get_default_locale();
158 + $available_locales = bogo_available_locales();
100 159
101 160 ?>
102 161 <div class="wrap">
103 162
@@ -102,58 +161,121 @@
102 161 <div class="wrap">
103 162
104 163 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
105 164
106 -<?php if ( ! empty( $message ) ) : ?>
107 -<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
108 -<?php endif; ?>
165 +<?php bogo_admin_notice(); ?>
109 166
167 +<h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
168 +
169 +<table id="bogo-languages-table" class="widefat">
170 +<thead>
171 + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
172 +</thead>
173 +<tfoot>
174 + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
175 +</tfoot>
176 +<tbody id="translations">
177 + <tr class="active"><th>1</th><td><p>
178 + <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
179 + [<?php echo esc_html( $default_locale ); ?>]
180 + <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div>
181 + </p></td></tr>
182 +
110 183 <?php
111 - bogo_toolbox_installed_translations();
112 - bogo_toolbox_add_translations();
113 -?>
184 + $count = 1;
114 185
115 -</div>
116 -<?php
117 -}
186 + foreach ( $available_locales as $locale ) {
187 + if ( $locale == $default_locale ) {
188 + continue;
189 + }
118 190
119 -function bogo_toolbox_installed_translations() {
120 - $title = __( 'Available Languages', 'bogo' );
191 + $count += 1;
192 + $class = 'active';
121 193
122 - $default_locale = bogo_get_default_locale();
123 - $languages = array( $default_locale => bogo_get_language( $default_locale ) )
124 - + bogo_available_languages();
194 + if ( 'en_US' == $locale ) {
195 + $status = $enus_deactivated
196 + ? esc_html( __( 'Inactive', 'bogo' ) )
197 + : esc_html( __( 'Active', 'bogo' ) );
198 + } else {
199 + $status = esc_html( __( 'Installed', 'bogo' ) );
200 + }
201 +
202 + if ( 'en_US' == $locale ) {
203 + if ( $enus_deactivated ) {
204 + $activate_link = menu_page_url( 'bogo-tools', false );
205 + $activate_link = add_query_arg(
206 + array( 'action' => 'activate_enus' ),
207 + $activate_link );
208 + $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' );
209 + $activate_link = sprintf(
210 + '<a href="%1$s" class="activate">%2$s</a>',
211 + $activate_link,
212 + esc_html( __( 'Activate', 'bogo' ) ) );
213 +
214 + $status = sprintf(
215 + '<div class="status"><span class="status">%s</span> | %s</div>',
216 + $status, $activate_link );
217 + $class = '';
218 + } else {
219 + $deactivate_link = menu_page_url( 'bogo-tools', false );
220 + $deactivate_link = add_query_arg(
221 + array( 'action' => 'deactivate_enus' ),
222 + $deactivate_link );
223 + $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' );
224 + $deactivate_link = sprintf(
225 + '<a href="%1$s" class="deactivate">%2$s</a>',
226 + $deactivate_link,
227 + esc_html( __( 'Deactivate', 'bogo' ) ) );
228 +
229 + $status = sprintf(
230 + '<div class="status"><span class="status">%s</span> | %s</div>',
231 + $status, $deactivate_link );
232 + }
233 + } elseif ( $can_install ) {
234 + $delete_link = menu_page_url( 'bogo-tools', false );
235 + $delete_link = add_query_arg(
236 + array( 'action' => 'delete_translation', 'locale' => $locale ),
237 + $delete_link );
238 + $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' );
239 +
240 + if ( ! $delete_language = bogo_get_language( $locale ) ) {
241 + $delete_language = $locale;
242 + }
243 +
244 + $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $delete_language );
245 +
246 + $delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;">%2$s</a>',
247 + $delete_link,
248 + esc_html( __( 'Delete', 'bogo' ) ),
249 + esc_js( $delete_confirm ) );
250 +
251 + $status = sprintf(
252 + '<div class="status"><span class="status">%s</span> | %s</div>',
253 + $status, $delete_link );
254 + }
125 255 ?>
126 -<div class="tool-box">
127 -<h3 class="title"><?php echo esc_html( $title ); ?></h3>
128 -<ul id="translations">
256 + <tr class="<?php echo esc_attr( $class ); ?>">
257 + <th><?php echo $count; ?></th>
258 + <td><p>
259 + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
260 + [<?php echo esc_html( $locale ); ?>]
261 + <?php echo $status; ?>
262 + </p>
263 + </td>
264 + </tr>
129 265 <?php
130 - foreach ( $languages as $locale => $language ) {
131 - echo sprintf( '<li>%s</li>', esc_html( $language ) );
132 266 }
133 -?>
134 -</ul>
135 -</div>
136 -<?php
137 -}
138 267
139 -function bogo_toolbox_add_translations() {
140 - if ( ! wp_can_install_language_pack() ) {
141 - return;
142 - }
268 + foreach ( wp_get_available_translations() as $locale => $translation ) {
269 + if ( in_array( $locale, $available_locales ) ) {
270 + continue;
271 + }
143 272
144 - $title = __( 'Add Languages', 'bogo' );
273 + $count += 1;
145 274
146 - $available_translations = wp_get_available_translations();
147 - $languages = array_diff( bogo_languages(), bogo_available_languages() );
275 + $install_link = '';
148 276
149 -?>
150 -<div class="tool-box">
151 -<h3 class="title"><?php echo esc_html( $title ); ?></h3>
152 -<ul id="translations">
153 -<?php
154 - foreach ( $languages as $locale => $language ) {
155 - if ( isset( $available_translations[$locale] ) ) {
277 + if ( $can_install ) {
156 278 $install_link = menu_page_url( 'bogo-tools', false );
157 279 $install_link = add_query_arg(
158 280 array( 'action' => 'install_translation', 'locale' => $locale ),
159 281 $install_link );
@@ -158,19 +280,92 @@
158 280 array( 'action' => 'install_translation', 'locale' => $locale ),
159 281 $install_link );
160 282 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
161 283 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
162 - $install_link, __( 'Install', 'bogo' ) );
163 -
164 - echo sprintf( '<li>%1$s %2$s</li>',
165 - esc_html( $language ), $install_link );
166 - } else {
167 - echo sprintf( '<li>%s</li>', esc_html( $language ) );
284 + $install_link, esc_html( __( 'Install', 'bogo' ) ) );
168 285 }
286 +?>
287 + <tr><th><?php echo $count; ?></th><td><p>
288 + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
289 + [<?php echo esc_html( $locale ); ?>]
290 + <?php echo $install_link; ?>
291 + </p></td></tr>
292 +<?php
169 293 }
170 294 ?>
171 -</ul>
295 +
296 +</tbody>
297 +</table>
298 +
172 299 </div>
173 300 <?php
174 301 }
175 302
176 -?>
303 +function bogo_admin_notice( $reason = '' ) {
304 + if ( empty( $reason ) && isset( $_GET['message'] ) ) {
305 + $reason = $_GET['message'];
306 + }
307 +
308 + if ( 'install_success' == $reason ) {
309 + $message = __( "Translation installed successfully.", 'bogo' );
310 + } elseif ( 'install_failed' == $reason ) {
311 + $message = __( "Translation install failed.", 'bogo' );
312 + } elseif ( 'delete_success' == $reason ) {
313 + $message = __( "Translation uninstalled successfully.", 'bogo' );
314 + } elseif ( 'delete_failed' == $reason ) {
315 + $message = __( "Translation uninstall failed.", 'bogo' );
316 + } elseif ( 'enus_deactivated' == $reason ) {
317 + $message = __( "English (United States) deactivated.", 'bogo' );
318 + } elseif ( 'enus_activated' == $reason ) {
319 + $message = __( "English (United States) activated.", 'bogo' );
320 + } else {
321 + return false;
322 + }
323 +
324 + if ( 'install_failed' == $reason || 'delete_failed' == $reason ) {
325 + echo sprintf(
326 + '<div class="error notice notice-error is-dismissible"><p>%s</p></div>',
327 + esc_html( $message ) );
328 + } else {
329 + echo sprintf(
330 + '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>',
331 + esc_html( $message ) );
332 + }
333 +}
334 +
335 +function bogo_delete_language_pack( $locale ) {
336 + if ( 'en_US' == $locale
337 + || ! bogo_is_available_locale( $locale )
338 + || bogo_is_default_locale( $locale ) ) {
339 + return false;
340 + }
341 +
342 + if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) {
343 + return false;
344 + }
345 +
346 + $target_files = array(
347 + sprintf( '%s.mo', $locale ),
348 + sprintf( '%s.po', $locale ),
349 + sprintf( 'admin-%s.mo', $locale ),
350 + sprintf( 'admin-%s.po', $locale ),
351 + sprintf( 'admin-network-%s.mo', $locale ),
352 + sprintf( 'admin-network-%s.po', $locale ),
353 + sprintf( 'continents-cities-%s.mo', $locale ),
354 + sprintf( 'continents-cities-%s.po', $locale ) );
355 +
356 + foreach ( $files as $file ) {
357 + if ( '.' === $file[0] || is_dir( $file ) ) {
358 + continue;
359 + }
360 +
361 + if ( in_array( $file, $target_files ) ) {
362 + $result = @unlink( path_join( WP_LANG_DIR, $file ) );
363 +
364 + if ( ! $result ) {
365 + return false;
366 + }
367 + }
368 + }
369 +
370 + return true;
371 +}