PluginProbe
Bogo / 2.7
Bogo v2.7
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
bogo / admin / admin.php

admin.php in Bogo 2.7, at admin/admin.php

369 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
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
8 add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
9
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 ) ) {
18 wp_enqueue_style( 'bogo-admin',
19 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
20 array(), BOGO_VERSION, 'all' );
21
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 }
27 }
28
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 if ( 'nav-menus.php' == $hook_suffix ) {
40 $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
41 $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
42 $locales = array();
43
44 foreach ( (array) $nav_menu_items as $item ) {
45 $locales[$item->db_id] = $item->bogo_locales;
46 }
47
48 wp_localize_script( 'bogo-admin', '_bogo', array(
49 'availableLanguages' => bogo_available_languages( array(
50 'exclude_enus_if_inactive' => true,
51 'orderby' => 'value' ) ),
52 'locales' => $locales,
53 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
54 'cbPrefix' => 'menu-item-bogo-locale' ) );
55 }
56
57 if ( 'options-general.php' == $hook_suffix ) {
58 wp_localize_script( 'bogo-admin', '_bogo', array(
59 'defaultLocale' => bogo_get_default_locale() ) );
60 }
61 }
62
63 add_action( 'admin_menu', 'bogo_admin_menu' );
64
65 function bogo_admin_menu() {
66 $tools = add_management_page(
67 __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ),
68 'update_core', 'bogo-tools', 'bogo_tools_page' );
69
70 add_action( 'load-' . $tools, 'bogo_load_tools_page' );
71 }
72
73 function bogo_load_tools_page() {
74 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
75
76 $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
77
78 if ( 'install_translation' == $action ) {
79 check_admin_referer( 'bogo-tools' );
80
81 if ( ! current_user_can( 'update_core' ) ) {
82 wp_die( __( 'You are not allowed to install translations.', 'bogo' ) );
83 }
84
85 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
86
87 if ( wp_download_language_pack( $locale ) ) {
88 $redirect_to = add_query_arg(
89 array( 'locale' => $locale, 'message' => 'install_success' ),
90 menu_page_url( 'bogo-tools', false ) );
91 } else {
92 $redirect_to = add_query_arg(
93 array( 'locale' => $locale, 'message' => 'install_failed' ),
94 menu_page_url( 'bogo-tools', false ) );
95 }
96
97 wp_safe_redirect( $redirect_to );
98 exit();
99 }
100
101 if ( 'delete_translation' == $action ) {
102 check_admin_referer( 'bogo-tools' );
103
104 if ( ! current_user_can( 'update_core' ) ) {
105 wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
106 }
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 }
123
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 ?>
159 <div class="wrap">
160
161 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
162
163 <?php bogo_admin_notice(); ?>
164
165 <h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
166
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
181 <?php
182 $count = 1;
183
184 foreach ( $available_locales as $locale ) {
185 if ( $locale == $default_locale ) {
186 continue;
187 }
188
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 }
253 ?>
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>
262 <?php
263 }
264
265 foreach ( wp_get_available_translations() as $locale => $translation ) {
266 if ( in_array( $locale, $available_locales ) ) {
267 continue;
268 }
269
270 $count += 1;
271
272 $install_link = '';
273
274 if ( $can_install ) {
275 $install_link = menu_page_url( 'bogo-tools', false );
276 $install_link = add_query_arg(
277 array( 'action' => 'install_translation', 'locale' => $locale ),
278 $install_link );
279 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
280 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
281 $install_link, esc_html( __( 'Install', 'bogo' ) ) );
282 }
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 }
291 ?>
292
293 </tbody>
294 </table>
295
296 </div>
297 <?php
298 }
299
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 }
369