PluginProbe
Bogo / 2.9
Bogo v2.9
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 +333 -359 trunk2.9 View file →
@@ -3,18 +3,16 @@
3 3 require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php';
4 4 require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
5 5 require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
6 6 require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
7 -require_once BOGO_PLUGIN_DIR . '/admin/includes/language-packs.php';
8 -require_once BOGO_PLUGIN_DIR . '/admin/includes/terms-translation.php';
9 7
10 -add_action( 'admin_init', 'bogo_upgrade', 10, 0 );
8 +add_action( 'admin_init', 'bogo_upgrade' );
11 9
12 10 function bogo_upgrade() {
13 11 $old_ver = bogo_get_prop( 'version' );
14 12 $new_ver = BOGO_VERSION;
15 13
16 - if ( $old_ver !== $new_ver ) {
14 + if ( $old_ver != $new_ver ) {
17 15 require_once BOGO_PLUGIN_DIR . '/admin/includes/upgrade.php';
18 16 do_action( 'bogo_upgrade', $new_ver, $old_ver );
19 17 bogo_set_prop( 'version', $new_ver );
20 18 }
@@ -19,213 +17,109 @@
19 17 bogo_set_prop( 'version', $new_ver );
20 18 }
21 19 }
22 20
23 -add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts', 10, 1 );
21 +add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
24 22
25 23 function bogo_admin_enqueue_scripts( $hook_suffix ) {
26 24 wp_enqueue_style( 'bogo-admin',
27 25 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
28 - array(), BOGO_VERSION, 'all'
29 - );
26 + array(), BOGO_VERSION, 'all' );
30 27
31 28 if ( is_rtl() ) {
32 29 wp_enqueue_style( 'bogo-admin-rtl',
33 30 plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ),
34 - array(), BOGO_VERSION, 'all'
35 - );
31 + array(), BOGO_VERSION, 'all' );
36 32 }
37 33
38 - $assets = include BOGO_PLUGIN_DIR . '/admin/includes/js/index.asset.php';
39 -
40 34 wp_enqueue_script( 'bogo-admin',
41 - plugins_url( 'admin/includes/js/index.js', BOGO_PLUGIN_BASENAME ),
42 - $assets['dependencies'],
43 - $assets['version'],
44 - array( 'in_footer' => true )
45 - );
35 + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
36 + array( 'jquery' ), BOGO_VERSION, true );
46 37
47 - wp_set_script_translations( 'bogo-admin', 'bogo' );
38 + $local_args = array(
39 + 'saveAlert' => __(
40 + "The changes you made will be lost if you navigate away from this page.",
41 + 'bogo' ),
42 + 'rest_api' => array(
43 + 'url' => trailingslashit( rest_url( 'bogo/v1' ) ),
44 + 'nonce' => wp_create_nonce( 'wp_rest' ) ) );
48 45
49 - $available_languages = array();
46 + if ( 'nav-menus.php' == $hook_suffix ) {
47 + $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
48 + $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
49 + $locales = array();
50 50
51 - foreach ( bogo_available_languages() as $locale => $language ) {
52 - $native_name = bogo_get_language_native_name( $locale );
53 -
54 - if ( bogo_locale_is_alone( $locale ) ) {
55 - $native_name = bogo_get_short_name( $native_name );
51 + foreach ( (array) $nav_menu_items as $item ) {
52 + $locales[$item->db_id] = $item->bogo_locales;
56 53 }
57 54
58 - $tags = array(
59 - bogo_language_tag( $locale ),
60 - bogo_lang_slug( $locale ),
61 - );
55 + $local_args = array_merge( $local_args, array(
56 + 'availableLanguages' => bogo_available_languages( array(
57 + 'exclude_enus_if_inactive' => true,
58 + 'orderby' => 'value' ) ),
59 + 'locales' => $locales,
60 + 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
61 + 'cbPrefix' => 'menu-item-bogo-locale' ) );
62 + }
62 63
63 - $available_languages[$locale] = array(
64 - 'name' => $language,
65 - 'nativename' => trim( $native_name ),
66 - 'country' => bogo_get_country_code( $locale ),
67 - 'tags' => array_unique( array_filter( $tags ) ),
68 - );
64 + if ( 'options-general.php' == $hook_suffix ) {
65 + $local_args = array_merge( $local_args, array(
66 + 'defaultLocale' => bogo_get_default_locale() ) );
69 67 }
70 68
71 - $bogo_obj = array(
72 - 'availableLanguages' => $available_languages,
73 - 'defaultLocale' => bogo_get_default_locale(),
74 - 'currentPost' => array(),
75 - 'localizablePostTypes' => bogo_localizable_post_types(),
76 - 'showFlags' => apply_filters( 'bogo_use_flags', true ),
77 - );
78 -
79 - if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
80 - if ( $screen = get_current_screen() and $screen->is_block_editor() ) {
81 - wp_enqueue_script( 'bogo-block-editor' );
82 - }
83 -
84 - $user_locale = bogo_get_user_locale();
85 -
86 - $current_post = array(
87 - 'locale' => $user_locale,
88 - 'lang' => bogo_lang_slug( $user_locale ),
89 - 'translations' => array(),
90 - );
91 -
92 - if ( $post = get_post() ) {
93 - $current_post['postId'] = $post->ID;
94 - $post_type_object = get_post_type_object( $post->post_type );
95 - $edit_post_cap = $post_type_object->cap->edit_post;
96 -
97 - if ( $locale = get_post_meta( $post->ID, '_locale', true ) ) {
98 - $current_post['locale'] = $locale;
99 - $current_post['lang'] = bogo_lang_slug( $locale );
100 - }
101 -
102 - $available_locales = bogo_available_locales( array(
103 - 'exclude' => array( $current_post['locale'] ),
104 - ) );
105 -
106 - foreach ( $available_locales as $locale ) {
107 - $current_post['translations'][$locale] = array();
108 -
109 - $translation = bogo_get_post_translation( $post->ID, $locale );
110 -
111 - if ( $translation ) {
112 - $current_post['translations'][$locale] = array(
113 - 'postId' => $translation->ID,
114 - 'postTitle' => $translation->post_title,
115 - 'editLink' => current_user_can( $edit_post_cap, $translation->ID )
116 - ? get_edit_post_link( $translation, 'raw' )
117 - : '',
118 - );
119 - }
120 - }
121 - }
122 -
123 - $bogo_obj['currentPost'] = $current_post;
69 + if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) {
70 + $post = $GLOBALS['post'];
71 + $local_args = array_merge( $local_args, array(
72 + 'post_id' => $post->ID ) );
124 73 }
125 74
126 - wp_add_inline_script( 'bogo-admin',
127 - sprintf(
128 - 'var bogo = %s;',
129 - wp_json_encode( $bogo_obj, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
130 - ),
131 - 'before'
132 - );
75 + wp_localize_script( 'bogo-admin', '_bogo', $local_args );
133 76 }
134 77
135 -add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 );
78 +add_action( 'admin_menu', 'bogo_admin_menu' );
136 79
137 80 function bogo_admin_menu() {
138 - add_menu_page(
139 - __( 'Languages', 'bogo' ),
140 - __( 'Languages', 'bogo' ),
141 - 'bogo_manage_language_packs',
142 - 'bogo',
143 - 'bogo_tools_page',
144 - 'dashicons-translation',
145 - 73 // between Users (70) and Tools (75)
146 - );
81 + add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ),
82 + 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page',
83 + 'dashicons-translation', 73 ); // between Users (70) and Tools (75)
147 84
148 - $tools = add_submenu_page(
149 - 'bogo',
150 - __( 'Language Packs', 'bogo' ),
151 - __( 'Language Packs', 'bogo' ),
152 - 'bogo_manage_language_packs',
153 - 'bogo',
154 - 'bogo_tools_page'
155 - );
85 + $tools = add_submenu_page( 'bogo',
86 + __( 'Installed Languages', 'bogo' ),
87 + __( 'Installed Languages', 'bogo' ),
88 + 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' );
156 89
157 - add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 );
90 + add_action( 'load-' . $tools, 'bogo_load_tools_page' );
158 91
159 - $available_locales = bogo_available_locales( array(
160 - 'current_user_can_access' => true,
161 - 'exclude' => array( bogo_get_default_locale() ),
162 - ) );
92 + $texts = add_submenu_page( 'bogo',
93 + __( 'Translatable Text Strings', 'bogo' ),
94 + __( 'Text Translation', 'bogo' ),
95 + 'bogo_edit_text_translation', 'bogo-texts', 'bogo_texts_page' );
163 96
164 - if ( 0 < count( $available_locales ) ) {
165 - $texts = add_submenu_page(
166 - 'bogo',
167 - __( 'Terms Translation', 'bogo' ),
168 - __( 'Terms Translation', 'bogo' ),
169 - 'bogo_edit_terms_translation',
170 - 'bogo-texts',
171 - 'bogo_texts_page'
172 - );
173 -
174 - add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 );
175 - }
97 + add_action( 'load-' . $texts, 'bogo_load_texts_page' );
176 98 }
177 99
178 -add_filter(
179 - 'set_screen_option_bogo_texts_per_page',
180 - 'bogo_set_screen_options',
181 - 10, 3
182 -);
183 -
184 -function bogo_set_screen_options( $result, $option, $value ) {
185 - $bogo_screens = array(
186 - 'bogo_texts_per_page',
187 - );
188 -
189 - if ( in_array( $option, $bogo_screens ) ) {
190 - $result = $value;
191 - }
192 -
193 - return $result;
194 -}
195 -
196 100 function bogo_load_tools_page() {
197 101 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
198 102
199 - $action = $_GET['action'] ?? '';
200 - $locale = $_GET['locale'] ?? null;
103 + $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
201 104
202 - if ( 'activate' === $action ) {
105 + if ( 'install_translation' == $action ) {
203 106 check_admin_referer( 'bogo-tools' );
204 107
205 108 if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
206 - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) );
109 + wp_die( __( "You are not allowed to install translations.", 'bogo' ) );
207 110 }
208 111
209 - if ( 'en_US' === $locale ) {
210 - bogo_set_prop( 'enus_deactivated', false );
112 + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
211 113
114 + if ( wp_download_language_pack( $locale ) ) {
212 115 $redirect_to = add_query_arg(
213 - array( 'message' => 'enus_activated' ),
214 - menu_page_url( 'bogo', false )
215 - );
116 + array( 'locale' => $locale, 'message' => 'install_success' ),
117 + menu_page_url( 'bogo', false ) );
216 118 } else {
217 - if ( wp_download_language_pack( $locale ) ) {
218 - $redirect_to = add_query_arg(
219 - array( 'locale' => $locale, 'message' => 'install_success' ),
220 - menu_page_url( 'bogo', false )
221 - );
222 - } else {
223 - $redirect_to = add_query_arg(
224 - array( 'locale' => $locale, 'message' => 'install_failed' ),
225 - menu_page_url( 'bogo', false )
226 - );
227 - }
119 + $redirect_to = add_query_arg(
120 + array( 'locale' => $locale, 'message' => 'install_failed' ),
121 + menu_page_url( 'bogo', false ) );
228 122 }
229 123
230 124 wp_safe_redirect( $redirect_to );
231 125 exit();
@@ -230,34 +124,25 @@
230 124 wp_safe_redirect( $redirect_to );
231 125 exit();
232 126 }
233 127
234 - if ( 'deactivate' === $action ) {
128 + if ( 'delete_translation' == $action ) {
235 129 check_admin_referer( 'bogo-tools' );
236 130
237 131 if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
238 - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) );
132 + wp_die( __( "You are not allowed to delete translations.", 'bogo' ) );
239 133 }
240 134
241 - if ( 'en_US' === $locale ) {
242 - bogo_set_prop( 'enus_deactivated', true );
135 + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
243 136
137 + if ( bogo_delete_language_pack( $locale ) ) {
244 138 $redirect_to = add_query_arg(
245 - array( 'message' => 'enus_deactivated' ),
246 - menu_page_url( 'bogo', false )
247 - );
139 + array( 'locale' => $locale, 'message' => 'delete_success' ),
140 + menu_page_url( 'bogo', false ) );
248 141 } else {
249 - if ( bogo_delete_language_pack( $locale ) ) {
250 - $redirect_to = add_query_arg(
251 - array( 'locale' => $locale, 'message' => 'delete_success' ),
252 - menu_page_url( 'bogo', false )
253 - );
254 - } else {
255 - $redirect_to = add_query_arg(
256 - array( 'locale' => $locale, 'message' => 'delete_failed' ),
257 - menu_page_url( 'bogo', false )
258 - );
259 - }
142 + $redirect_to = add_query_arg(
143 + array( 'locale' => $locale, 'message' => 'delete_failed' ),
144 + menu_page_url( 'bogo', false ) );
260 145 }
261 146
262 147 wp_safe_redirect( $redirect_to );
263 148 exit();
@@ -262,254 +147,343 @@
262 147 wp_safe_redirect( $redirect_to );
263 148 exit();
264 149 }
265 150
266 - if ( 'promote' === $action ) {
151 + if ( 'deactivate_enus' == $action ) {
267 152 check_admin_referer( 'bogo-tools' );
268 153
269 - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
270 - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) );
271 - }
154 + bogo_set_prop( 'enus_deactivated', true );
272 155
273 - if ( 'en_US' === $locale or ! bogo_is_available_locale( $locale ) ) {
274 - $locale = '';
275 - }
156 + $redirect_to = add_query_arg(
157 + array( 'message' => 'enus_deactivated' ),
158 + menu_page_url( 'bogo', false ) );
276 159
277 - if ( update_option( 'WPLANG', $locale ) ) {
278 - $redirect_to = add_query_arg(
279 - array( 'locale' => $locale, 'message' => 'promote_success' ),
280 - menu_page_url( 'bogo', false )
281 - );
282 - } else {
283 - $redirect_to = add_query_arg(
284 - array( 'locale' => $locale, 'message' => 'promote_failed' ),
285 - menu_page_url( 'bogo', false )
286 - );
287 - }
160 + wp_safe_redirect( $redirect_to );
161 + exit();
162 + }
288 163
164 + if ( 'activate_enus' == $action ) {
165 + check_admin_referer( 'bogo-tools' );
166 +
167 + bogo_set_prop( 'enus_deactivated', false );
168 +
169 + $redirect_to = add_query_arg(
170 + array( 'message' => 'enus_activated' ),
171 + menu_page_url( 'bogo', false ) );
172 +
289 173 wp_safe_redirect( $redirect_to );
290 174 exit();
291 175 }
176 +}
292 177
293 - if ( 'translate' === $action ) {
294 - check_admin_referer( 'bogo-tools' );
178 +function bogo_load_texts_page() {
179 + $action = isset( $_POST['action'] ) ? $_POST['action'] : '';
295 180
296 - if ( ! current_user_can( 'bogo_edit_terms_translation', $locale ) ) {
297 - wp_die( wp_kses_data( __( 'You are not allowed to edit translations.', 'bogo' ) ) );
181 + if ( 'save' == $action ) {
182 + check_admin_referer( 'bogo-edit-text-translation' );
183 +
184 + if ( ! current_user_can( 'bogo_edit_text_translation' ) ) {
185 + wp_die( __( "You are not allowed to edit translations.", 'bogo' ) );
298 186 }
299 187
300 - $is_active = ( 'en_US' === $locale )
301 - ? ! bogo_is_enus_deactivated()
302 - : bogo_is_available_locale( $locale );
188 + $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null;
303 189
304 - if ( ! bogo_is_default_locale( $locale ) and $is_active ) {
305 - $redirect_to = add_query_arg(
306 - array( 'locale' => $locale ),
307 - menu_page_url( 'bogo-texts', false ) );
190 + $blogname =
191 + isset( $_POST['blogname'] ) ? $_POST['blogname'] : '';
192 + $blogdescription =
193 + isset( $_POST['blogdescription'] ) ? $_POST['blogdescription'] : '';
308 194
309 - wp_safe_redirect( $redirect_to );
310 - exit();
195 + $entries = array(
196 + array(
197 + 'singular' => 'blogname',
198 + 'translations' => array( $blogname ),
199 + 'context' => 'blogname' ),
200 + array(
201 + 'singular' => 'blogdescription',
202 + 'translations' => array( $blogdescription ),
203 + 'context' => 'blogdescription' ) );
204 +
205 + if ( Bogo_POMO::export( $locale, $entries ) ) {
206 + $message = 'translation_saved';
207 + } else {
208 + $message = 'translation_failed';
311 209 }
312 - }
313 210
314 - $current_screen = get_current_screen();
211 + $redirect_to = add_query_arg(
212 + array( 'locale' => $locale, 'message' => $message ),
213 + menu_page_url( 'bogo-texts', false ) );
315 214
316 - add_filter( 'manage_' . $current_screen->id . '_columns',
317 - array( 'Bogo_Language_Packs_List_Table', 'define_columns' ),
318 - 10, 1
319 - );
215 + wp_safe_redirect( $redirect_to );
216 + exit();
217 + }
320 218 }
321 219
322 220 function bogo_tools_page() {
323 - $list_table = new Bogo_Language_Packs_List_Table();
324 - $list_table->prepare_items();
221 + $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
222 + $can_install = wp_can_install_language_pack();
325 223
224 + $default_locale = bogo_get_default_locale();
225 + $available_locales = bogo_available_locales();
226 +
326 227 ?>
327 228 <div class="wrap">
328 229
329 -<h1 class="wp-heading-inline"><?php
330 - echo esc_html( __( 'Language Packs', 'bogo' ) );
331 -?></h1>
230 +<h1><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h1>
332 231
333 -<?php
334 - if ( ! empty( $_REQUEST['s'] ) ) {
335 - echo sprintf(
336 - '<span class="subtitle">%s</span>',
337 - wp_kses_data( sprintf(
338 - /* translators: %s: search query */
339 - __( 'Search results for: <strong>%s</strong>', 'bogo' ),
340 - esc_html( $_REQUEST['s'] )
341 - ) )
342 - );
343 - }
344 -?>
345 -
346 -<hr class="wp-header-end">
347 -
348 232 <?php bogo_admin_notice(); ?>
349 233
350 -<?php $list_table->views(); ?>
234 +<table id="bogo-languages-table" class="widefat">
235 +<thead>
236 + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
237 +</thead>
238 +<tfoot>
239 + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
240 +</tfoot>
241 +<tbody id="translations">
242 + <tr class="active"><th>1</th><td>
243 + <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
244 + [<?php echo esc_html( $default_locale ); ?>]
245 + <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div>
246 + </td></tr>
351 247
352 -<form method="get" action="" id="bogo-language-packs">
353 - <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
354 - <?php $list_table->search_box( __( 'Search Language', 'bogo' ), 'bogo-language-packs' ); ?>
355 - <?php $list_table->display(); ?>
356 -</form>
357 -
358 -</div>
359 248 <?php
360 -}
249 + $count = 1;
361 250
362 -function bogo_load_texts_page() {
363 - $action = $_POST['action'] ?? '';
251 + foreach ( $available_locales as $locale ) {
252 + if ( $locale == $default_locale ) {
253 + continue;
254 + }
364 255
365 - if ( 'save' === $action ) {
366 - check_admin_referer( 'bogo-edit-text-translation' );
256 + $count += 1;
257 + $class = 'active';
367 258
368 - if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) {
369 - wp_die( wp_kses_data( __( 'You are not allowed to edit translations.', 'bogo' ) ) );
259 + if ( 'en_US' == $locale ) {
260 + $status = $enus_deactivated
261 + ? esc_html( __( 'Inactive', 'bogo' ) )
262 + : esc_html( __( 'Active', 'bogo' ) );
263 + } else {
264 + $status = esc_html( __( 'Installed', 'bogo' ) );
370 265 }
371 266
372 - $locale = $_POST['locale'] ?? null;
267 + if ( 'en_US' == $locale ) {
268 + if ( $enus_deactivated ) {
269 + $activate_link = menu_page_url( 'bogo', false );
270 + $activate_link = add_query_arg(
271 + array( 'action' => 'activate_enus' ),
272 + $activate_link );
273 + $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' );
274 + $activate_link = sprintf(
275 + '<a href="%1$s" class="activate">%2$s</a>',
276 + $activate_link,
277 + esc_html( __( 'Activate', 'bogo' ) ) );
373 278
374 - if ( ! bogo_is_available_locale( $locale ) ) {
375 - return;
376 - }
279 + $status = sprintf(
280 + '<div class="status"><span class="status">%s</span> | %s</div>',
281 + $status, $activate_link );
282 + $class = '';
283 + } else {
284 + $deactivate_link = menu_page_url( 'bogo', false );
285 + $deactivate_link = add_query_arg(
286 + array( 'action' => 'deactivate_enus' ),
287 + $deactivate_link );
288 + $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' );
289 + $deactivate_link = sprintf(
290 + '<a href="%1$s" class="deactivate">%2$s</a>',
291 + $deactivate_link,
292 + esc_html( __( 'Deactivate', 'bogo' ) ) );
377 293
378 - if ( ! current_user_can( 'bogo_access_locale', $locale ) ) {
379 - wp_die( wp_kses_data( __( 'You are not allowed to edit terms in this locale.', 'bogo' ) ) );
380 - }
294 + $status = sprintf(
295 + '<div class="status"><span class="status">%s</span> | %s</div>',
296 + $status, $deactivate_link );
297 + }
298 + } elseif ( $can_install ) {
299 + $delete_link = menu_page_url( 'bogo', false );
300 + $delete_link = add_query_arg(
301 + array( 'action' => 'delete_translation', 'locale' => $locale ),
302 + $delete_link );
303 + $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' );
381 304
382 - $entries = array();
305 + if ( ! $delete_language = bogo_get_language( $locale ) ) {
306 + $delete_language = $locale;
307 + }
383 308
384 - foreach ( (array) bogo_terms_translation( $locale ) as $item ) {
385 - $translation = $item['translated'];
309 + $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $delete_language );
386 310
387 - $cap = $item['cap'] ?? 'bogo_edit_terms_translation';
311 + $delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;">%2$s</a>',
312 + $delete_link,
313 + esc_html( __( 'Delete', 'bogo' ) ),
314 + esc_js( $delete_confirm ) );
388 315
389 - if ( isset( $_POST[$item['name']] ) and current_user_can( $cap ) ) {
390 - $translation = $_POST[$item['name']];
391 - }
392 -
393 - $entries[] = array(
394 - 'singular' => $item['name'],
395 - 'translations' => array( $translation ),
396 - 'context' => preg_replace( '/:.*$/', '', $item['name'] ),
397 - );
316 + $status = sprintf(
317 + '<div class="status"><span class="status">%s</span> | %s</div>',
318 + $status, $delete_link );
398 319 }
320 +?>
321 + <tr class="<?php echo esc_attr( $class ); ?>">
322 + <th><?php echo $count; ?></th>
323 + <td>
324 + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
325 + [<?php echo esc_html( $locale ); ?>]
326 + <?php echo $status; ?>
327 + </td>
328 + </tr>
329 +<?php
330 + }
399 331
400 - if ( Bogo_POMO::export( $locale, $entries ) ) {
401 - $message = 'translation_saved';
402 - } else {
403 - $message = 'translation_failed';
332 + foreach ( wp_get_available_translations() as $locale => $translation ) {
333 + if ( in_array( $locale, $available_locales ) ) {
334 + continue;
404 335 }
405 336
406 - $redirect_to = add_query_arg(
407 - array(
408 - 'locale' => $locale,
409 - 'message' => $message,
410 - 'paged' => absint( $_POST['paged'] ?? 1 ),
411 - ),
412 - menu_page_url( 'bogo-texts', false )
413 - );
337 + $count += 1;
414 338
415 - wp_safe_redirect( $redirect_to );
416 - exit();
339 + $install_link = '';
417 340
418 - } else {
419 - $current_screen = get_current_screen();
341 + if ( $can_install ) {
342 + $install_link = menu_page_url( 'bogo', false );
343 + $install_link = add_query_arg(
344 + array( 'action' => 'install_translation', 'locale' => $locale ),
345 + $install_link );
346 + $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
347 + $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
348 + $install_link, esc_html( __( 'Install', 'bogo' ) ) );
349 + }
350 +?>
351 + <tr><th><?php echo $count; ?></th><td>
352 + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
353 + [<?php echo esc_html( $locale ); ?>]
354 + <?php echo $install_link; ?>
355 + </td></tr>
356 +<?php
357 + }
358 +?>
420 359
421 - add_filter( 'manage_' . $current_screen->id . '_columns',
422 - array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ),
423 - 10, 1
424 - );
360 +</tbody>
361 +</table>
425 362
426 - add_screen_option( 'per_page', array(
427 - 'default' => 20,
428 - 'option' => 'bogo_texts_per_page',
429 - ) );
430 - }
363 +</div>
364 +<?php
431 365 }
432 366
433 367 function bogo_texts_page() {
434 - $list_table = new Bogo_Terms_Translation_List_Table();
435 - $list_table->prepare_items();
368 + $locale_to_edit = isset( $_GET['locale'] ) ? $_GET['locale'] : '';
369 + Bogo_POMO::import( $locale_to_edit );
436 370
437 371 ?>
438 372 <div class="wrap">
439 373
440 -<h1 class="wp-heading-inline"><?php
441 - echo esc_html( __( 'Terms Translation', 'bogo' ) );
442 -?></h1>
374 +<h1><?php echo esc_html( __( 'Translatable Text Strings', 'bogo' ) ); ?></h1>
443 375
376 +<?php bogo_admin_notice(); ?>
377 +
378 +<form action="" method="post" id="bogo-translatable-text-strings">
379 +<input type="hidden" name="action" value="save" />
380 +<?php wp_nonce_field( 'bogo-edit-text-translation' ); ?>
381 +
382 +<p>
383 +<select name="locale" id="select-locale">
384 + <option value=""><?php echo esc_html( __( '-- Select Language to Edit --', 'bogo' ) ); ?></option>
444 385 <?php
445 - if ( ! empty( $_REQUEST['s'] ) ) {
446 - echo sprintf(
447 - '<span class="subtitle">%s</span>',
448 - wp_kses_data( sprintf(
449 - /* translators: %s: search query */
450 - __( 'Search results for: <strong>%s</strong>', 'bogo' ),
451 - esc_html( $_REQUEST['s'] )
452 - ) )
453 - );
386 + foreach ( bogo_available_locales() as $locale ) {
387 + echo sprintf( '<option value="%1$s"%3$s>%2$s</option>',
388 + esc_attr( $locale ),
389 + esc_html( bogo_get_language( $locale ) ),
390 + $locale == $locale_to_edit ? ' selected="selected"' : '' );
454 391 }
455 392 ?>
393 +</select>
394 +</p>
456 395
457 -<hr class="wp-header-end">
396 +<?php if ( bogo_is_available_locale( $locale_to_edit ) ) : ?>
397 +<table class="form-table">
398 +<tbody>
399 + <tr>
400 + <th scope="row"><label for="blogname"><?php echo esc_html( __( 'Site Title' ) ); ?></label></th>
401 + <td><input name="blogname" type="text" id="blogname" value="<?php echo esc_attr( bogo_translate( 'blogname', 'blogname', get_option( 'blogname' ) ) ); ?>" class="regular-text" /></td>
402 + </tr>
403 + <tr>
404 + <th scope="row"><label for="blogdescription"><?php echo esc_html( __( 'Tagline' ) ); ?></label></th>
405 + <td><input name="blogdescription" type="text" id="blogdescription" value="<?php echo esc_attr( bogo_translate( 'blogdescription', 'blogdescription', get_option( 'blogdescription' ) ) ); ?>" class="regular-text" /></td>
406 + </tr>
407 +</tbody>
408 +</table>
458 409
459 -<?php bogo_admin_notice(); ?>
460 -
461 -<form action="" method="get">
462 -<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ?? '' ); ?>" />
463 -<input type="hidden" name="locale" value="<?php echo esc_attr( $_REQUEST['locale'] ?? '' ); ?>" />
464 -<?php
465 - $list_table->search_box(
466 - __( 'Search Translation', 'bogo' ), 'bogo-terms-translation'
467 - );
468 -?>
410 +<?php submit_button(); ?>
411 +<?php endif; ?>
469 412 </form>
470 -
471 -<form action="" method="post" id="bogo-terms-translation">
472 -<input type="hidden" name="action" value="save" />
473 -<input type="hidden" name="paged" value="<?php echo absint( $_GET['paged'] ?? '' ); ?>" />
474 -<?php
475 - wp_nonce_field( 'bogo-edit-text-translation' );
476 - $list_table->display();
477 -?>
478 -</form>
479 413 </div>
480 414 <?php
481 415 }
482 416
483 417 function bogo_admin_notice( $reason = '' ) {
484 - if ( empty( $reason ) and isset( $_GET['message'] ) ) {
418 + if ( empty( $reason ) && isset( $_GET['message'] ) ) {
485 419 $reason = $_GET['message'];
486 420 }
487 421
488 - if ( 'install_success' === $reason ) {
489 - $message = __( 'Translation installed successfully.', 'bogo' );
490 - } elseif ( 'install_failed' === $reason ) {
491 - $message = __( 'Translation install failed.', 'bogo' );
492 - } elseif ( 'promote_success' === $reason ) {
493 - $message = __( 'Site language set successfully.', 'bogo' );
494 - } elseif ( 'promote_failed' === $reason ) {
495 - $message = __( 'Setting site language failed.', 'bogo' );
496 - } elseif ( 'delete_success' === $reason ) {
497 - $message = __( 'Translation uninstalled successfully.', 'bogo' );
498 - } elseif ( 'delete_failed' === $reason ) {
499 - $message = __( 'Translation uninstall failed.', 'bogo' );
500 - } elseif ( 'enus_deactivated' === $reason ) {
501 - $message = __( 'English (United States) deactivated.', 'bogo' );
502 - } elseif ( 'enus_activated' === $reason ) {
503 - $message = __( 'English (United States) activated.', 'bogo' );
504 - } elseif ( 'translation_saved' === $reason ) {
505 - $message = __( 'Translation saved.', 'bogo' );
506 - } elseif ( 'translation_failed' === $reason ) {
507 - $message = __( 'Saving translation failed.', 'bogo' );
422 + if ( 'install_success' == $reason ) {
423 + $message = __( "Translation installed successfully.", 'bogo' );
424 + } elseif ( 'install_failed' == $reason ) {
425 + $message = __( "Translation install failed.", 'bogo' );
426 + } elseif ( 'delete_success' == $reason ) {
427 + $message = __( "Translation uninstalled successfully.", 'bogo' );
428 + } elseif ( 'delete_failed' == $reason ) {
429 + $message = __( "Translation uninstall failed.", 'bogo' );
430 + } elseif ( 'enus_deactivated' == $reason ) {
431 + $message = __( "English (United States) deactivated.", 'bogo' );
432 + } elseif ( 'enus_activated' == $reason ) {
433 + $message = __( "English (United States) activated.", 'bogo' );
434 + } elseif ( 'translation_saved' == $reason ) {
435 + $message = __( "Translation saved.", 'bogo' );
436 + } elseif ( 'translation_failed' == $reason ) {
437 + $message = __( "Saving translation failed.", 'bogo' );
508 438 } else {
509 439 return false;
510 440 }
511 441
512 - wp_admin_notice( $message, array(
513 - 'type' => str_ends_with( $reason, '_failed' ) ? 'error' : 'success',
514 - ) );
442 + if ( '_failed' == substr( $reason, -7 ) ) {
443 + echo sprintf(
444 + '<div class="error notice notice-error is-dismissible"><p>%s</p></div>',
445 + esc_html( $message ) );
446 + } else {
447 + echo sprintf(
448 + '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>',
449 + esc_html( $message ) );
450 + }
451 +}
452 +
453 +function bogo_delete_language_pack( $locale ) {
454 + if ( 'en_US' == $locale
455 + || ! bogo_is_available_locale( $locale )
456 + || bogo_is_default_locale( $locale ) ) {
457 + return false;
458 + }
459 +
460 + if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) {
461 + return false;
462 + }
463 +
464 + $target_files = array(
465 + sprintf( '%s.mo', $locale ),
466 + sprintf( '%s.po', $locale ),
467 + sprintf( 'admin-%s.mo', $locale ),
468 + sprintf( 'admin-%s.po', $locale ),
469 + sprintf( 'admin-network-%s.mo', $locale ),
470 + sprintf( 'admin-network-%s.po', $locale ),
471 + sprintf( 'continents-cities-%s.mo', $locale ),
472 + sprintf( 'continents-cities-%s.po', $locale ) );
473 +
474 + foreach ( $files as $file ) {
475 + if ( '.' === $file[0] || is_dir( $file ) ) {
476 + continue;
477 + }
478 +
479 + if ( in_array( $file, $target_files ) ) {
480 + $result = @unlink( path_join( WP_LANG_DIR, $file ) );
481 +
482 + if ( ! $result ) {
483 + return false;
484 + }
485 + }
486 + }
487 +
488 + return true;
515 489 }