PluginProbe
Bogo / 2.4
Bogo v2.4
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 +57 -252 2.62.4 View file →
@@ -34,11 +34,9 @@
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( array(
39 - 'exclude_enus_if_inactive' => true,
40 - 'orderby' => 'value' ) ),
38 + 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
41 39 'locales' => $locales,
42 40 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
43 41 'cbPrefix' => $prefix ) );
44 42
@@ -47,20 +45,8 @@
47 45 array(), BOGO_VERSION, 'all' );
48 46
49 47 return;
50 48 }
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 - }
63 49 }
64 50
65 51 add_action( 'admin_menu', 'bogo_admin_menu' );
66 52
@@ -87,13 +73,13 @@
87 73 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
88 74
89 75 if ( wp_download_language_pack( $locale ) ) {
90 76 $redirect_to = add_query_arg(
91 - array( 'locale' => $locale, 'message' => 'install_success' ),
77 + array( 'locale' => $locale, 'message' => 'success' ),
92 78 menu_page_url( 'bogo-tools', false ) );
93 79 } else {
94 80 $redirect_to = add_query_arg(
95 - array( 'locale' => $locale, 'message' => 'install_failed' ),
81 + array( 'locale' => $locale, 'message' => 'failed' ),
96 82 menu_page_url( 'bogo-tools', false ) );
97 83 }
98 84
99 85 wp_safe_redirect( $redirect_to );
@@ -98,184 +84,76 @@
98 84
99 85 wp_safe_redirect( $redirect_to );
100 86 exit();
101 87 }
88 +}
102 89
103 - if ( 'delete_translation' == $action ) {
104 - check_admin_referer( 'bogo-tools' );
90 +function bogo_tools_page() {
91 + $message = "";
105 92
106 - if ( ! current_user_can( 'update_core' ) ) {
107 - wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
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' );
108 98 }
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 99 }
125 100
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 -
157 - $default_locale = bogo_get_default_locale();
158 - $available_locales = bogo_available_locales();
159 -
160 101 ?>
161 102 <div class="wrap">
162 103
163 104 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
164 105
165 -<?php bogo_admin_notice(); ?>
106 +<?php if ( ! empty( $message ) ) : ?>
107 +<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
108 +<?php endif; ?>
166 109
167 -<h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
110 +<?php
111 + bogo_toolbox_installed_translations();
112 + bogo_toolbox_add_translations();
113 +?>
168 114
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 -
115 +</div>
183 116 <?php
184 - $count = 1;
117 +}
185 118
186 - foreach ( $available_locales as $locale ) {
187 - if ( $locale == $default_locale ) {
188 - continue;
189 - }
119 +function bogo_toolbox_installed_translations() {
120 + $title = __( 'Available Languages', 'bogo' );
190 121
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 - }
122 + $default_locale = bogo_get_default_locale();
123 + $languages = array( $default_locale => bogo_get_language( $default_locale ) )
124 + + bogo_available_languages();
255 125 ?>
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>
126 +<div class="tool-box">
127 +<h3 class="title"><?php echo esc_html( $title ); ?></h3>
128 +<ul id="translations">
265 129 <?php
130 + foreach ( $languages as $locale => $language ) {
131 + echo sprintf( '<li>%s</li>', esc_html( $language ) );
266 132 }
133 +?>
134 +</ul>
135 +</div>
136 +<?php
137 +}
267 138
268 - foreach ( wp_get_available_translations() as $locale => $translation ) {
269 - if ( in_array( $locale, $available_locales ) ) {
270 - continue;
271 - }
139 +function bogo_toolbox_add_translations() {
140 + if ( ! wp_can_install_language_pack() ) {
141 + return;
142 + }
272 143
273 - $count += 1;
144 + $title = __( 'Add Languages', 'bogo' );
274 145
275 - $install_link = '';
146 + $available_translations = wp_get_available_translations();
147 + $languages = array_diff( bogo_languages(), bogo_available_languages() );
276 148
277 - if ( $can_install ) {
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] ) ) {
278 156 $install_link = menu_page_url( 'bogo-tools', false );
279 157 $install_link = add_query_arg(
280 158 array( 'action' => 'install_translation', 'locale' => $locale ),
281 159 $install_link );
@@ -280,92 +158,19 @@
280 158 array( 'action' => 'install_translation', 'locale' => $locale ),
281 159 $install_link );
282 160 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
283 161 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
284 - $install_link, esc_html( __( 'Install', 'bogo' ) ) );
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 ) );
285 168 }
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
293 169 }
294 170 ?>
295 -
296 -</tbody>
297 -</table>
298 -
171 +</ul>
299 172 </div>
300 173 <?php
301 174 }
302 175
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 -}
176 +?>