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 +197 -22 2.52.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
@@ -85,13 +87,13 @@
85 87 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
86 88
87 89 if ( wp_download_language_pack( $locale ) ) {
88 90 $redirect_to = add_query_arg(
89 - array( 'locale' => $locale, 'message' => 'success' ),
91 + array( 'locale' => $locale, 'message' => 'install_success' ),
90 92 menu_page_url( 'bogo-tools', false ) );
91 93 } else {
92 94 $redirect_to = add_query_arg(
93 - array( 'locale' => $locale, 'message' => 'failed' ),
95 + array( 'locale' => $locale, 'message' => 'install_failed' ),
94 96 menu_page_url( 'bogo-tools', false ) );
95 97 }
96 98
97 99 wp_safe_redirect( $redirect_to );
@@ -96,21 +98,63 @@
96 98
97 99 wp_safe_redirect( $redirect_to );
98 100 exit();
99 101 }
100 -}
101 102
102 -function bogo_tools_page() {
103 - $message = "";
103 + if ( 'delete_translation' == $action ) {
104 + check_admin_referer( 'bogo-tools' );
104 105
105 - if ( isset( $_GET['message'] ) ) {
106 - if ( 'success' == $_GET['message'] ) {
107 - $message = __( "Translation installed successfully.", 'bogo' );
108 - } elseif ( 'failed' == $_GET['message'] ) {
109 - $message = __( "Translation install failed.", 'bogo' );
106 + if ( ! current_user_can( 'update_core' ) ) {
107 + wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
110 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();
111 124 }
112 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 + }
151 +}
152 +
153 +function bogo_tools_page() {
154 + $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
155 + $can_install = wp_can_install_language_pack();
156 +
113 157 $default_locale = bogo_get_default_locale();
114 158 $available_locales = bogo_available_locales();
115 159
116 160 ?>
@@ -117,11 +161,9 @@
117 161 <div class="wrap">
118 162
119 163 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
120 164
121 -<?php if ( ! empty( $message ) ) : ?>
122 -<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
123 -<?php endif; ?>
165 +<?php bogo_admin_notice(); ?>
124 166
125 167 <h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
126 168
127 169 <table id="bogo-languages-table" class="widefat">
@@ -131,12 +173,12 @@
131 173 <tfoot>
132 174 <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
133 175 </tfoot>
134 176 <tbody id="translations">
135 - <tr><th>1</th><td><p>
177 + <tr class="active"><th>1</th><td><p>
136 178 <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
137 179 [<?php echo esc_html( $default_locale ); ?>]
138 - <br /><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?>
180 + <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div>
139 181 </p></td></tr>
140 182
141 183 <?php
142 184 $count = 1;
@@ -146,19 +188,84 @@
146 188 continue;
147 189 }
148 190
149 191 $count += 1;
192 + $class = 'active';
193 +
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 + }
150 255 ?>
151 - <tr><th><?php echo $count; ?></th><td><p>
256 + <tr class="<?php echo esc_attr( $class ); ?>">
257 + <th><?php echo $count; ?></th>
258 + <td><p>
152 259 <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
153 260 [<?php echo esc_html( $locale ); ?>]
154 - <br /><?php echo esc_html( __( 'Installed', 'bogo' ) ); ?>
155 - </p></td></tr>
261 + <?php echo $status; ?>
262 + </p>
263 + </td>
264 + </tr>
156 265 <?php
157 266 }
158 267
159 - $can_install = wp_can_install_language_pack();
160 -
161 268 foreach ( wp_get_available_translations() as $locale => $translation ) {
162 269 if ( in_array( $locale, $available_locales ) ) {
163 270 continue;
164 271 }
@@ -192,5 +299,73 @@
192 299 </div>
193 300 <?php
194 301 }
195 302
196 -?>
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 +}