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 +332 -10 2.32.6 View file →
@@ -1,17 +1,19 @@
1 1 <?php
2 2
3 -require_once BOGO_PLUGIN_DIR . '/admin/user.php';
4 -require_once BOGO_PLUGIN_DIR . '/admin/post.php';
5 -require_once BOGO_PLUGIN_DIR . '/admin/nav-menu.php';
6 -require_once BOGO_PLUGIN_DIR . '/admin/widgets.php';
3 +require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php';
4 +require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
5 +require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
6 +require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
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 - if ( 'widgets.php' == $hook_suffix || 'user-edit.php' == $hook_suffix ) {
11 + if ( false !== strpos( $hook_suffix, 'bogo-tools' )
12 + || 'widgets.php' == $hook_suffix
13 + || 'user-edit.php' == $hook_suffix ) {
12 14 wp_enqueue_style( 'bogo-admin',
13 - plugins_url( 'admin/admin.css', BOGO_PLUGIN_BASENAME ),
15 + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
14 16 array(), BOGO_VERSION, 'all' );
15 17
16 18 return;
17 19 }
@@ -27,23 +29,343 @@
27 29
28 30 $prefix = 'menu-item-bogo-locale';
29 31
30 32 wp_enqueue_script( 'bogo-admin',
31 - plugins_url( 'admin/admin.js', BOGO_PLUGIN_BASENAME ),
33 + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
32 34 array( 'jquery' ),
33 35 BOGO_VERSION, true );
34 36
35 37 wp_localize_script( 'bogo-admin', '_bogo', array(
36 - 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
38 + 'availableLanguages' => bogo_available_languages( array(
39 + 'exclude_enus_if_inactive' => true,
40 + 'orderby' => 'value' ) ),
37 41 'locales' => $locales,
38 42 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
39 43 'cbPrefix' => $prefix ) );
40 44
41 45 wp_enqueue_style( 'bogo-admin',
42 - plugins_url( 'admin/admin.css', BOGO_PLUGIN_BASENAME ),
46 + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
43 47 array(), BOGO_VERSION, 'all' );
44 48
45 49 return;
46 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 + }
47 63 }
48 64
49 -?>
65 +add_action( 'admin_menu', 'bogo_admin_menu' );
66 +
67 +function bogo_admin_menu() {
68 + $tools = add_management_page(
69 + __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ),
70 + 'update_core', 'bogo-tools', 'bogo_tools_page' );
71 +
72 + add_action( 'load-' . $tools, 'bogo_load_tools_page' );
73 +}
74 +
75 +function bogo_load_tools_page() {
76 + require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
77 +
78 + $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
79 +
80 + if ( 'install_translation' == $action ) {
81 + check_admin_referer( 'bogo-tools' );
82 +
83 + if ( ! current_user_can( 'update_core' ) ) {
84 + wp_die( __( 'You are not allowed to install translations.', 'bogo' ) );
85 + }
86 +
87 + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
88 +
89 + if ( wp_download_language_pack( $locale ) ) {
90 + $redirect_to = add_query_arg(
91 + array( 'locale' => $locale, 'message' => 'install_success' ),
92 + menu_page_url( 'bogo-tools', false ) );
93 + } else {
94 + $redirect_to = add_query_arg(
95 + array( 'locale' => $locale, 'message' => 'install_failed' ),
96 + menu_page_url( 'bogo-tools', false ) );
97 + }
98 +
99 + wp_safe_redirect( $redirect_to );
100 + exit();
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 + }
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 +?>
161 +<div class="wrap">
162 +
163 +<h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
164 +
165 +<?php bogo_admin_notice(); ?>
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 +
183 +<?php
184 + $count = 1;
185 +
186 + foreach ( $available_locales as $locale ) {
187 + if ( $locale == $default_locale ) {
188 + continue;
189 + }
190 +
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 + }
255 +?>
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>
265 +<?php
266 + }
267 +
268 + foreach ( wp_get_available_translations() as $locale => $translation ) {
269 + if ( in_array( $locale, $available_locales ) ) {
270 + continue;
271 + }
272 +
273 + $count += 1;
274 +
275 + $install_link = '';
276 +
277 + if ( $can_install ) {
278 + $install_link = menu_page_url( 'bogo-tools', false );
279 + $install_link = add_query_arg(
280 + array( 'action' => 'install_translation', 'locale' => $locale ),
281 + $install_link );
282 + $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
283 + $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
284 + $install_link, esc_html( __( 'Install', 'bogo' ) ) );
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
293 + }
294 +?>
295 +
296 +</tbody>
297 +</table>
298 +
299 +</div>
300 +<?php
301 +}
302 +
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 +}