Commit 23745cb8 authored by lucha's avatar lucha
Browse files

[auto] plugin: bogo 3.2

parent c3a98ad8
......@@ -4,6 +4,8 @@ require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php';
require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
require_once BOGO_PLUGIN_DIR . '/admin/includes/language-packs.php';
require_once BOGO_PLUGIN_DIR . '/admin/includes/terms-translation.php';
add_action( 'admin_init', 'bogo_upgrade' );
......@@ -39,42 +41,24 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) {
'saveAlert' => __(
"The changes you made will be lost if you navigate away from this page.",
'bogo' ),
'rest_api' => array(
'url' => trailingslashit( rest_url( 'bogo/v1' ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'apiSettings' => array(
'root' => esc_url_raw( rest_url( 'bogo/v1' ) ),
'namespace' => 'bogo/v1',
'nonce' => ( wp_installing() && ! is_multisite() )
? '' : wp_create_nonce( 'wp_rest' ),
),
'screenReaderText' => array(
/* translators: accessibility text */
'targetBlank' => __( '(opens in a new window)', 'bogo' ),
),
'availableLanguages' => bogo_available_languages( array(
'exclude_enus_if_inactive' => true,
'orderby' => 'value',
) ),
'defaultLocale' => bogo_get_default_locale(),
'pagenow' => isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
);
if ( 'nav-menus.php' == $hook_suffix ) {
$nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
$nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
$locales = array();
if ( $nav_menu_items ) {
foreach ( $nav_menu_items as $item ) {
$locales[$item->db_id] = $item->bogo_locales;
}
}
$local_args = array_merge( $local_args, array(
'availableLanguages' => bogo_available_languages( array(
'exclude_enus_if_inactive' => true,
'orderby' => 'value',
) ),
'locales' => $locales,
'selectorLegend' =>
/* translators: followed by available languages list */
__( 'Displayed on pages in', 'bogo' ),
'cbPrefix' => 'menu-item-bogo-locale',
) );
}
if ( 'options-general.php' == $hook_suffix ) {
$local_args = array_merge( $local_args, array(
'defaultLocale' => bogo_get_default_locale(),
) );
}
if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) {
$post = $GLOBALS['post'];
$local_args = array_merge( $local_args, array(
......@@ -82,9 +66,7 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) {
) );
}
$local_args['pagenow'] = isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '';
wp_localize_script( 'bogo-admin', '_bogo', $local_args );
wp_localize_script( 'bogo-admin', 'bogo', $local_args );
}
add_action( 'admin_menu', 'bogo_admin_menu' );
......@@ -101,85 +83,117 @@ function bogo_admin_menu() {
add_action( 'load-' . $tools, 'bogo_load_tools_page' );
$texts = add_submenu_page( 'bogo',
__( 'Terms Translation', 'bogo' ),
__( 'Terms Translation', 'bogo' ),
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' );
$available_locales = bogo_available_locales( array(
'exclude_enus_if_inactive' => true,
'current_user_can_access' => true,
) );
if ( 1 < count( $available_locales ) ) {
$texts = add_submenu_page( 'bogo',
__( 'Terms Translation', 'bogo' ),
__( 'Terms Translation', 'bogo' ),
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' );
add_action( 'load-' . $texts, 'bogo_load_texts_page' );
}
}
add_filter( 'set-screen-option', 'bogo_set_screen_options', 10, 3 );
function bogo_set_screen_options( $result, $option, $value ) {
$bogo_screens = array(
'languages_page_bogo_texts_per_page',
);
if ( in_array( $option, $bogo_screens ) ) {
$result = $value;
}
add_action( 'load-' . $texts, 'bogo_load_texts_page' );
return $result;
}
function bogo_load_tools_page() {
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
$action = isset( $_GET['action'] ) ? $_GET['action'] : '';
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
if ( 'install_translation' == $action ) {
if ( 'activate' == $action ) {
check_admin_referer( 'bogo-tools' );
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
wp_die( __( "You are not allowed to install translations.", 'bogo' ) );
wp_die( __( "You are not allowed to manage translations.", 'bogo' ) );
}
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
if ( 'en_US' == $locale ) {
bogo_set_prop( 'enus_deactivated', false );
if ( wp_download_language_pack( $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_success' ),
array( 'message' => 'enus_activated' ),
menu_page_url( 'bogo', false ) );
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_failed' ),
menu_page_url( 'bogo', false ) );
if ( wp_download_language_pack( $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_success' ),
menu_page_url( 'bogo', false ) );
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_failed' ),
menu_page_url( 'bogo', false ) );
}
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'set_site_lang' == $action ) {
if ( 'deactivate' == $action ) {
check_admin_referer( 'bogo-tools' );
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
wp_die( __( "You are not allowed to manage translations.", 'bogo' ) );
}
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) {
$locale = '';
}
if ( 'en_US' == $locale ) {
bogo_set_prop( 'enus_deactivated', true );
if ( update_option( 'WPLANG', $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'site_lang_success' ),
array( 'message' => 'enus_deactivated' ),
menu_page_url( 'bogo', false ) );
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'site_lang_failed' ),
menu_page_url( 'bogo', false ) );
if ( bogo_delete_language_pack( $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_success' ),
menu_page_url( 'bogo', false ) );
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_failed' ),
menu_page_url( 'bogo', false ) );
}
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'delete_translation' == $action ) {
if ( 'promote' == $action ) {
check_admin_referer( 'bogo-tools' );
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
wp_die( __( "You are not allowed to delete translations.", 'bogo' ) );
wp_die( __( "You are not allowed to manage translations.", 'bogo' ) );
}
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) {
$locale = '';
}
if ( bogo_delete_language_pack( $locale ) ) {
if ( update_option( 'WPLANG', $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_success' ),
array( 'locale' => $locale, 'message' => 'promote_success' ),
menu_page_url( 'bogo', false ) );
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_failed' ),
array( 'locale' => $locale, 'message' => 'promote_failed' ),
menu_page_url( 'bogo', false ) );
}
......@@ -187,31 +201,70 @@ function bogo_load_tools_page() {
exit();
}
if ( 'deactivate_enus' == $action ) {
if ( 'translate' == $action ) {
check_admin_referer( 'bogo-tools' );
bogo_set_prop( 'enus_deactivated', true );
if ( ! current_user_can( 'bogo_edit_terms_translation', $locale ) ) {
wp_die( __( "You are not allowed to edit translations.", 'bogo' ) );
}
$redirect_to = add_query_arg(
array( 'message' => 'enus_deactivated' ),
menu_page_url( 'bogo', false ) );
$is_active = ( 'en_US' == $locale )
? ! bogo_is_enus_deactivated()
: bogo_is_available_locale( $locale );
wp_safe_redirect( $redirect_to );
exit();
if ( ! bogo_is_default_locale( $locale ) && $is_active ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale ),
menu_page_url( 'bogo-texts', false ) );
wp_safe_redirect( $redirect_to );
exit();
}
}
if ( 'activate_enus' == $action ) {
check_admin_referer( 'bogo-tools' );
$current_screen = get_current_screen();
bogo_set_prop( 'enus_deactivated', false );
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Bogo_Language_Packs_List_Table', 'define_columns' ) );
}
$redirect_to = add_query_arg(
array( 'message' => 'enus_activated' ),
menu_page_url( 'bogo', false ) );
function bogo_tools_page() {
$list_table = new Bogo_Language_Packs_List_Table();
$list_table->prepare_items();
wp_safe_redirect( $redirect_to );
exit();
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php
echo esc_html( __( 'Language Packs', 'bogo' ) );
?></h1>
<?php
if ( ! empty( $_REQUEST['s'] ) ) {
echo sprintf(
'<span class="subtitle">%s</span>',
sprintf(
__( 'Search results for &#8220;%s&#8221;', 'bogo' ),
esc_html( $_REQUEST['s'] )
)
);
}
?>
<hr class="wp-header-end">
<?php bogo_admin_notice(); ?>
<?php $list_table->views(); ?>
<form method="get" action="" id="bogo-language-packs">
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
<?php $list_table->search_box( __( 'Search Language', 'bogo' ), 'bogo-language-packs' ); ?>
<?php $list_table->display(); ?>
</form>
</div>
<?php
}
function bogo_load_texts_page() {
......@@ -228,8 +281,16 @@ function bogo_load_texts_page() {
$entries = array();
foreach ( (array) bogo_terms_translation( $locale ) as $item ) {
$entries[] = array(
'singular' => $item['name'],
'translations' => array( $item['translated'] ),
'context' => preg_replace( '/:.*$/', '', $item['name'] ),
);
}
foreach ( $_POST as $p_key => $p_val ) {
if ( in_array( $p_key, array( 'action', 'locale', 'submit' ) )
if ( in_array( $p_key, array( 'action', 'locale', 'submit', 'paged' ) )
|| substr( $p_key, 0, 1 ) == '_' ) {
continue;
}
......@@ -248,323 +309,73 @@ function bogo_load_texts_page() {
}
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => $message ),
menu_page_url( 'bogo-texts', false ) );
array(
'locale' => $locale,
'message' => $message,
'paged' => isset( $_POST['paged'] ) ? absint( $_POST['paged'] ) : 1,
),
menu_page_url( 'bogo-texts', false )
);
wp_safe_redirect( $redirect_to );
exit();
}
}
function bogo_tools_page() {
$enus_deactivated = bogo_is_enus_deactivated();
$can_install = wp_can_install_language_pack();
$default_locale = bogo_get_default_locale();
$available_locales = bogo_available_locales();
?>
<div class="wrap">
<h1><?php echo esc_html( __( 'Language Packs', 'bogo' ) ); ?></h1>
<?php bogo_admin_notice(); ?>
<table id="bogo-languages-table" class="widefat">
<thead>
<tr><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
</thead>
<tfoot>
<tr><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
</tfoot>
<tbody id="translations">
<tr class="active" id="language-1"><td>
<strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
[<?php echo esc_html( $default_locale ); ?>]
<div class="status"><?php echo esc_html( __( 'Site Language', 'bogo' ) ); ?></div>
</td></tr>
<?php
$count = 1;
foreach ( $available_locales as $locale ) {
if ( $locale == $default_locale ) {
continue;
}
$count += 1;
$row_actions = array();
$class = 'active';
if ( ! $language = bogo_get_language( $locale ) ) {
$language = $locale;
}
if ( 'en_US' == $locale ) {
$status = $enus_deactivated
? __( 'Inactive', 'bogo' ) : __( 'Active', 'bogo' );
} else {
$status = __( 'Installed', 'bogo' );
}
if ( 'en_US' == $locale ) {
if ( $enus_deactivated ) {
$activate_link = menu_page_url( 'bogo', false );
$activate_link = add_query_arg(
array( 'action' => 'activate_enus' ),
$activate_link );
$activate_link = wp_nonce_url( $activate_link, 'bogo-tools' );
$activate_link = sprintf(
'<a href="%1$s" class="activate" aria-label="%3$s">%2$s</a>',
$activate_link,
esc_html( __( 'Activate', 'bogo' ) ),
esc_attr(
sprintf( __( 'Activate %s language pack', 'bogo' ), $language ) ) );
$row_actions = array( $activate_link );
$class = '';
} else {
$sitelang_link = menu_page_url( 'bogo', false );
$sitelang_link = add_query_arg(
array( 'action' => 'set_site_lang', 'locale' => $locale ),
$sitelang_link );
$sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' );
$sitelang_link = sprintf(
'<a href="%1$s" class="sitelang" aria-label="%3$s">%2$s</a>',
$sitelang_link,
esc_html( __( 'Set as Site Language', 'bogo' ) ),
esc_attr( sprintf(
/* translators: %s: language name */
__( 'Set %s as Site Language', 'bogo' ),
$language
) )
);
$deactivate_link = menu_page_url( 'bogo', false );
$deactivate_link = add_query_arg(
array( 'action' => 'deactivate_enus' ),
$deactivate_link );
$deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' );
$deactivate_link = sprintf(
'<a href="%1$s" class="deactivate" aria-label="%3$s">%2$s</a>',
$deactivate_link,
esc_html( __( 'Deactivate', 'bogo' ) ),
esc_attr( sprintf(
/* translators: %s: language name */
__( 'Deactivate %s language pack', 'bogo' ),
$language
) )
);
$row_actions = array( $sitelang_link, $deactivate_link );
}
} elseif ( $can_install ) {
$sitelang_link = menu_page_url( 'bogo', false );
$sitelang_link = add_query_arg(
array( 'action' => 'set_site_lang', 'locale' => $locale ),
$sitelang_link );
$sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' );
$sitelang_link = sprintf(
'<a href="%1$s" class="sitelang" aria-label="%3$s">%2$s</a>',
$sitelang_link,
esc_html( __( 'Set as Site Language', 'bogo' ) ),
esc_attr( sprintf(
/* translators: %s: language name */
__( 'Set %s as Site Language', 'bogo' ),
$language
) )
);
$delete_link = menu_page_url( 'bogo', false );
$delete_link = add_query_arg(
array( 'action' => 'delete_translation', 'locale' => $locale ),
$delete_link );
$delete_link = wp_nonce_url( $delete_link, 'bogo-tools' );
$delete_confirm = sprintf(
/* translators: %s: language name */
__( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ),
$language );
$delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;" aria-label="%4$s">%2$s</a>',
$delete_link,
esc_html( __( 'Delete', 'bogo' ) ),
esc_js( $delete_confirm ),
esc_attr( sprintf(
/* translators: %s: language name */
__( 'Delete %s language pack', 'bogo' ),
$language
) )
);
$row_actions = array( $sitelang_link, $delete_link );
}
?>
<tr class="<?php echo esc_attr( $class ); ?>" id="language-<?php echo absint( $count ); ?>">
<td>
<strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
[<?php echo esc_html( $locale ); ?>]
<div class="status"><?php echo esc_html( $status ); ?></div>
<div class="row-actions"><?php echo implode( ' | ', $row_actions ); ?></div>
</td>
</tr>
<?php
}
} else {
$current_screen = get_current_screen();
foreach ( wp_get_available_translations() as $locale => $translation ) {
if ( in_array( $locale, $available_locales ) ) {
continue;
}
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ) );
$count += 1;
$row_actions = array();
$install_link = '';
if ( $can_install ) {
$install_link = menu_page_url( 'bogo', false );
$install_link = add_query_arg(
array( 'action' => 'install_translation', 'locale' => $locale ),
$install_link );
$install_link = wp_nonce_url( $install_link, 'bogo-tools' );
$install_link = sprintf( '<a href="%1$s" class="install" aria-label="%3$s">%2$s</a>',
$install_link,
esc_html( __( 'Install', 'bogo' ) ),
esc_attr( sprintf(
/* translators: %s: language name */
__( 'Install %s language pack', 'bogo' ),
bogo_get_language( $locale )
) )
);
$row_actions = array( $install_link );
}
?>
<tr id="language-<?php echo absint( $count ); ?>"><td>
<strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
[<?php echo esc_html( $locale ); ?>]
<div class="row-actions"><?php echo implode( ' | ', $row_actions ); ?></div>
</td></tr>
<?php
add_screen_option( 'per_page', array(
'label' => __( 'Items', 'bogo' ),
'default' => 20,
) );
}
?>
</tbody>
</table>
</div>
<?php
}
function bogo_texts_page() {
$locale_to_edit = isset( $_GET['locale'] ) ? $_GET['locale'] : '';
if ( ! Bogo_POMO::import( $locale_to_edit ) ) {
Bogo_POMO::reset();
}
$list_table = new Bogo_Terms_Translation_List_Table();
$list_table->prepare_items();
?>
<div class="wrap">
<h1><?php echo esc_html( __( 'Terms Translation', 'bogo' ) ); ?></h1>
<h1 class="wp-heading-inline"><?php
echo esc_html( __( 'Terms Translation', 'bogo' ) );
?></h1>
<?php bogo_admin_notice(); ?>
<form action="" method="post" id="bogo-translatable-text-strings">
<input type="hidden" name="action" value="save" />
<?php wp_nonce_field( 'bogo-edit-text-translation' ); ?>
<p>
<select name="locale" id="select-locale">
<option value=""><?php echo esc_html( __( '-- Select Language to Edit --', 'bogo' ) ); ?></option>
<?php
$available_locales = bogo_available_locales(
array( 'current_user_can_access' => true ) );
foreach ( $available_locales as $locale ) {
echo sprintf( '<option value="%1$s"%3$s>%2$s</option>',
esc_attr( $locale ),
esc_html( bogo_get_language( $locale ) ),
$locale == $locale_to_edit ? ' selected="selected"' : '' );
if ( ! empty( $_REQUEST['s'] ) ) {
echo sprintf(
'<span class="subtitle">%s</span>',
sprintf(
__( 'Search results for &#8220;%s&#8221;', 'bogo' ),
esc_html( $_REQUEST['s'] )
)
);
}