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