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 +240 -57 2.4.22.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,20 +98,65 @@
96 98
97 99 wp_safe_redirect( $redirect_to );
98 100 exit();
99 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 + }
100 151 }
101 152
102 153 function bogo_tools_page() {
103 - $message = "";
154 + $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
155 + $can_install = wp_can_install_language_pack();
104 156
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' );
110 - }
111 - }
157 + $default_locale = bogo_get_default_locale();
158 + $available_locales = bogo_available_locales();
112 159
113 160 ?>
114 161 <div class="wrap">
115 162
@@ -114,58 +161,121 @@
114 161 <div class="wrap">
115 162
116 163 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
117 164
118 -<?php if ( ! empty( $message ) ) : ?>
119 -<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
120 -<?php endif; ?>
165 +<?php bogo_admin_notice(); ?>
121 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 +
122 183 <?php
123 - bogo_toolbox_installed_translations();
124 - bogo_toolbox_add_translations();
125 -?>
184 + $count = 1;
126 185
127 -</div>
128 -<?php
129 -}
186 + foreach ( $available_locales as $locale ) {
187 + if ( $locale == $default_locale ) {
188 + continue;
189 + }
130 190
131 -function bogo_toolbox_installed_translations() {
132 - $title = __( 'Available Languages', 'bogo' );
191 + $count += 1;
192 + $class = 'active';
133 193
134 - $default_locale = bogo_get_default_locale();
135 - $languages = array( $default_locale => bogo_get_language( $default_locale ) )
136 - + 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 + }
137 255 ?>
138 -<div class="tool-box">
139 -<h3 class="title"><?php echo esc_html( $title ); ?></h3>
140 -<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>
141 265 <?php
142 - foreach ( $languages as $locale => $language ) {
143 - echo sprintf( '<li>%s</li>', esc_html( $language ) );
144 266 }
145 -?>
146 -</ul>
147 -</div>
148 -<?php
149 -}
150 267
151 -function bogo_toolbox_add_translations() {
152 - if ( ! wp_can_install_language_pack() ) {
153 - return;
154 - }
268 + foreach ( wp_get_available_translations() as $locale => $translation ) {
269 + if ( in_array( $locale, $available_locales ) ) {
270 + continue;
271 + }
155 272
156 - $title = __( 'Add Languages', 'bogo' );
273 + $count += 1;
157 274
158 - $available_translations = wp_get_available_translations();
159 - $languages = array_diff( bogo_languages(), bogo_available_languages() );
275 + $install_link = '';
160 276
161 -?>
162 -<div class="tool-box">
163 -<h3 class="title"><?php echo esc_html( $title ); ?></h3>
164 -<ul id="translations">
165 -<?php
166 - foreach ( $languages as $locale => $language ) {
167 - if ( isset( $available_translations[$locale] ) ) {
277 + if ( $can_install ) {
168 278 $install_link = menu_page_url( 'bogo-tools', false );
169 279 $install_link = add_query_arg(
170 280 array( 'action' => 'install_translation', 'locale' => $locale ),
171 281 $install_link );
@@ -170,19 +280,92 @@
170 280 array( 'action' => 'install_translation', 'locale' => $locale ),
171 281 $install_link );
172 282 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
173 283 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
174 - $install_link, __( 'Install', 'bogo' ) );
175 -
176 - echo sprintf( '<li>%1$s %2$s</li>',
177 - esc_html( $language ), $install_link );
178 - } else {
179 - echo sprintf( '<li>%s</li>', esc_html( $language ) );
284 + $install_link, esc_html( __( 'Install', 'bogo' ) ) );
180 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
181 293 }
182 294 ?>
183 -</ul>
295 +
296 +</tbody>
297 +</table>
298 +
184 299 </div>
185 300 <?php
186 301 }
187 302
188 -?>
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 +}