Commit 59995999 authored by agata's avatar agata

[auto] plugin: bogo 3.3.2

parent 70144a5f
......@@ -7,7 +7,7 @@ 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' );
add_action( 'admin_init', 'bogo_upgrade', 10, 0 );
function bogo_upgrade() {
$old_ver = bogo_get_prop( 'version' );
......@@ -20,81 +20,140 @@ function bogo_upgrade() {
}
}
add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts', 10, 1 );
function bogo_admin_enqueue_scripts( $hook_suffix ) {
wp_enqueue_style( 'bogo-admin',
plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
array(), BOGO_VERSION, 'all' );
array(), BOGO_VERSION, 'all'
);
if ( is_rtl() ) {
wp_enqueue_style( 'bogo-admin-rtl',
plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ),
array(), BOGO_VERSION, 'all' );
array(), BOGO_VERSION, 'all'
);
}
wp_enqueue_script( 'bogo-admin',
plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
array( 'jquery' ), BOGO_VERSION, true );
array( 'jquery' ), BOGO_VERSION, true
);
$available_languages = bogo_available_languages( array(
'orderby' => 'value',
) );
$add_translation_l10n = array();
foreach ( $available_languages as $locale => $lang ) {
$add_translation_l10n[$locale] = sprintf(
/* translators: %s: language name */
__( 'Add %s Translation', 'bogo' ),
$lang
);
}
$local_args = array(
'saveAlert' => __(
"The changes you made will be lost if you navigate away from this page.",
'bogo' ),
'l10n' => array(
/* translators: accessibility text */
'targetBlank' => __( '(opens in a new window)', 'bogo' ),
'language' => __( 'Language', 'bogo' ),
'none' => __( 'None', 'bogo' ),
'translations' => __( 'Translations', 'bogo' ),
'addTranslation' => $add_translation_l10n,
'noticePostCreation' => __( "Translation post created.", 'bogo' ),
'editPost' => __( 'Edit Post', 'bogo' ),
'saveAlert' => __( "The changes you made will be lost if you navigate away from this page.", 'bogo' ),
),
'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',
) ),
'availableLanguages' => $available_languages,
'defaultLocale' => bogo_get_default_locale(),
'pagenow' => isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
'currentPost' => array(),
'localizablePostTypes' => bogo_localizable_post_types(),
);
if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) {
$post = $GLOBALS['post'];
$local_args = array_merge( $local_args, array(
'post_id' => $post->ID,
) );
if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
$user_locale = bogo_get_user_locale();
$current_post = array(
'locale' => $user_locale,
'lang' => bogo_lang_slug( $user_locale ),
'translations' => array(),
);
if ( $post = get_post() ) {
$current_post['postId'] = $post->ID;
$post_type_object = get_post_type_object( $post->post_type );
$edit_post_cap = $post_type_object->cap->edit_post;
if ( $locale = get_post_meta( $post->ID, '_locale', true ) ) {
$current_post['locale'] = $locale;
$current_post['lang'] = bogo_lang_slug( $locale );
}
$available_locales = bogo_available_locales( array(
'exclude' => array( $current_post['locale'] ),
) );
foreach ( $available_locales as $locale ) {
$current_post['translations'][$locale] = array();
$translation = bogo_get_post_translation( $post->ID, $locale );
if ( $translation ) {
$current_post['translations'][$locale] = array(
'postId' => $translation->ID,
'postTitle' => $translation->post_title,
'editLink' => current_user_can( $edit_post_cap, $translation->ID )
? get_edit_post_link( $translation, 'raw' )
: '',
);
}
}
}
$local_args['currentPost'] = $current_post;
}
wp_localize_script( 'bogo-admin', 'bogo', $local_args );
}
add_action( 'admin_menu', 'bogo_admin_menu' );
add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 );
function bogo_admin_menu() {
add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ),
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page',
'dashicons-translation', 73 ); // between Users (70) and Tools (75)
'dashicons-translation', 73 // between Users (70) and Tools (75)
);
$tools = add_submenu_page( 'bogo',
__( 'Language Packs', 'bogo' ),
__( 'Language Packs', 'bogo' ),
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' );
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page'
);
add_action( 'load-' . $tools, 'bogo_load_tools_page' );
add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 );
$available_locales = bogo_available_locales( array(
'exclude_enus_if_inactive' => true,
'current_user_can_access' => true,
'exclude' => array( bogo_get_default_locale() ),
) );
if ( 1 < count( $available_locales ) ) {
if ( 0 < count( $available_locales ) ) {
$texts = add_submenu_page( 'bogo',
__( 'Terms Translation', 'bogo' ),
__( 'Terms Translation', 'bogo' ),
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' );
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page'
);
add_action( 'load-' . $texts, 'bogo_load_texts_page' );
add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 );
}
}
......@@ -130,16 +189,19 @@ function bogo_load_tools_page() {
$redirect_to = add_query_arg(
array( 'message' => 'enus_activated' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
} else {
if ( wp_download_language_pack( $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_success' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'install_failed' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
}
}
......@@ -159,16 +221,19 @@ function bogo_load_tools_page() {
$redirect_to = add_query_arg(
array( 'message' => 'enus_deactivated' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
} else {
if ( bogo_delete_language_pack( $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_success' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'delete_failed' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
}
}
......@@ -183,18 +248,21 @@ function bogo_load_tools_page() {
wp_die( __( "You are not allowed to manage translations.", 'bogo' ) );
}
if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) {
if ( 'en_US' == $locale
or ! bogo_is_available_locale( $locale ) ) {
$locale = '';
}
if ( update_option( 'WPLANG', $locale ) ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'promote_success' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
} else {
$redirect_to = add_query_arg(
array( 'locale' => $locale, 'message' => 'promote_failed' ),
menu_page_url( 'bogo', false ) );
menu_page_url( 'bogo', false )
);
}
wp_safe_redirect( $redirect_to );
......@@ -212,7 +280,8 @@ function bogo_load_tools_page() {
? ! bogo_is_enus_deactivated()
: bogo_is_available_locale( $locale );
if ( ! bogo_is_default_locale( $locale ) && $is_active ) {
if ( ! bogo_is_default_locale( $locale )
and $is_active ) {
$redirect_to = add_query_arg(
array( 'locale' => $locale ),
menu_page_url( 'bogo-texts', false ) );
......@@ -225,7 +294,9 @@ function bogo_load_tools_page() {
$current_screen = get_current_screen();
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Bogo_Language_Packs_List_Table', 'define_columns' ) );
array( 'Bogo_Language_Packs_List_Table', 'define_columns' ),
10, 1
);
}
function bogo_tools_page() {
......@@ -244,6 +315,7 @@ function bogo_tools_page() {
echo sprintf(
'<span class="subtitle">%s</span>',
sprintf(
/* translators: %s: search query */
__( 'Search results for &#8220;%s&#8221;', 'bogo' ),
esc_html( $_REQUEST['s'] )
)
......@@ -273,32 +345,38 @@ function bogo_load_texts_page() {
if ( 'save' == $action ) {
check_admin_referer( 'bogo-edit-text-translation' );
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null;
if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) {
wp_die( __( "You are not allowed to edit translations.", 'bogo' ) );
}
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null;
if ( ! bogo_is_available_locale( $locale ) ) {
return;
}
if ( ! current_user_can( 'bogo_access_locale', $locale ) ) {
wp_die( __( "You are not allowed to edit terms in this locale.", 'bogo' ) );
}
$entries = array();
foreach ( (array) bogo_terms_translation( $locale ) as $item ) {
$entries[] = array(
'singular' => $item['name'],
'translations' => array( $item['translated'] ),
'context' => preg_replace( '/:.*$/', '', $item['name'] ),
);
}
$translation = $item['translated'];
foreach ( $_POST as $p_key => $p_val ) {
if ( in_array( $p_key, array( 'action', 'locale', 'submit', 'paged' ) )
|| substr( $p_key, 0, 1 ) == '_' ) {
continue;
$cap = isset( $item['cap'] )
? $item['cap']
: 'bogo_edit_terms_translation';
if ( isset( $_POST[$item['name']] )
and current_user_can( $cap ) ) {
$translation = $_POST[$item['name']];
}
$entries[] = array(
'singular' => $p_key,
'translations' => array( $p_val ),
'context' => preg_replace( '/:.*$/', '', $p_key ),
'singular' => $item['name'],
'translations' => array( $translation ),
'context' => preg_replace( '/:.*$/', '', $item['name'] ),
);
}
......@@ -324,7 +402,9 @@ function bogo_load_texts_page() {
$current_screen = get_current_screen();
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ) );
array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ),
10, 1
);
add_screen_option( 'per_page', array(
'label' => __( 'Items', 'bogo' ),
......@@ -349,6 +429,7 @@ function bogo_texts_page() {
echo sprintf(
'<span class="subtitle">%s</span>',
sprintf(
/* translators: %s: search query */
__( 'Search results for &#8220;%s&#8221;', 'bogo' ),
esc_html( $_REQUEST['s'] )
)
......@@ -361,8 +442,8 @@ function bogo_texts_page() {
<?php bogo_admin_notice(); ?>
<form action="" method="get">
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
<input type="hidden" name="locale" value="<?php echo esc_attr( $_REQUEST['locale'] ); ?>" />
<input type="hidden" name="page" value="<?php echo isset( $_REQUEST['page'] ) ? esc_attr( $_REQUEST['page'] ) : ''; ?>" />
<input type="hidden" name="locale" value="<?php echo isset( $_REQUEST['locale'] ) ? esc_attr( $_REQUEST['locale'] ) : ''; ?>" />
<?php
$list_table->search_box(
__( 'Search Translation', 'bogo' ), 'bogo-terms-translation'
......@@ -372,7 +453,7 @@ function bogo_texts_page() {
<form action="" method="post" id="bogo-terms-translation">
<input type="hidden" name="action" value="save" />
<input type="hidden" name="paged" value="<?php echo absint( $_GET['paged'] ); ?>" />
<input type="hidden" name="paged" value="<?php echo isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; ?>" />
<?php
wp_nonce_field( 'bogo-edit-text-translation' );
$list_table->display();
......@@ -383,7 +464,7 @@ function bogo_texts_page() {
}
function bogo_admin_notice( $reason = '' ) {
if ( empty( $reason ) && isset( $_GET['message'] ) ) {
if ( empty( $reason ) and isset( $_GET['message'] ) ) {
$reason = $_GET['message'];
}
......@@ -414,10 +495,12 @@ function bogo_admin_notice( $reason = '' ) {
if ( '_failed' == substr( $reason, -7 ) ) {
echo sprintf(
'<div class="error notice notice-error is-dismissible"><p>%s</p></div>',
esc_html( $message ) );
esc_html( $message )
);
} else {
echo sprintf(
'<div class="updated notice notice-success is-dismissible"><p>%s</p></div>',
esc_html( $message ) );
esc_html( $message )
);
}
}
......@@ -21,13 +21,13 @@
$( function() {
$( '#bogo-add-translation' ).click( function() {
if ( ! bogo.post_id ) {
if ( ! bogo.currentPost.postId ) {
return;
}
var locale = $( '#bogo-translations-to-add' ).val();
var rest_url = bogo.apiSettings.getRoute(
'/posts/' + bogo.post_id + '/translations/' + locale );
'/posts/' + bogo.currentPost.postId + '/translations/' + locale );
$( '#bogo-add-translation' ).next( '.spinner' )
.css( 'visibility', 'visible' );
......@@ -51,12 +51,12 @@
} ).html( function() {
var output = post.title.rendered;
output += ' <span class="screen-reader-text">'
+ bogo.screenReaderText.targetBlank + '</span>';
+ bogo.l10n.targetBlank + '</span>';
return output;
} );
$added = $( '<li></li>' ).append( $added ).append(
' [' + post.lang.name + ']' );
' [' + bogo.availableLanguages[ locale ] + ']' );
$( '#bogo-translations' ).append( $added );
$( '#bogo-translations-to-add option[value="' + locale + '"]' ).detach();
......@@ -82,8 +82,8 @@
} );
if ( changed ) {
event.returnValue = bogo.saveAlert;
return bogo.saveAlert;
event.returnValue = bogo.l10n.saveAlert;
return bogo.l10n.saveAlert;
}
} );
......
......@@ -35,7 +35,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
$locales = array_unique( array_merge(
array( bogo_get_default_locale() ),
bogo_available_locales( 'exclude_enus_if_inactive=1' ),
bogo_available_locales(),
array( 'en_US' ),
array_keys( wp_get_available_translations() )
) );
......@@ -69,8 +69,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
}
}
if ( 'active' == $status && ! $is_active
|| 'inactive' == $status && $is_active ) {
if ( 'active' == $status and ! $is_active
or 'inactive' == $status and $is_active ) {
continue;
}
......@@ -99,6 +99,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
$count_all = $this->count_active + $this->count_inactive;
$all = sprintf(
/* translators: %s: number of language packs */
_nx(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
......@@ -115,6 +116,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
// Active
$active = sprintf(
/* translators: %s: number of language packs */
_nx(
'Active <span class="count">(%s)</span>',
'Active <span class="count">(%s)</span>',
......@@ -131,6 +133,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
// Inactive
$inactive = sprintf(
/* translators: %s: number of language packs */
_nx(
'Inactive <span class="count">(%s)</span>',
'Inactive <span class="count">(%s)</span>',
......@@ -188,6 +191,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
if ( $count_posts ) {
$count_posts = sprintf(
/* translators: %s: number of posts */
_n( '%s Post', '%s Posts', $count_posts, 'bogo' ),
number_format_i18n( $count_posts )
);
......@@ -195,6 +199,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
if ( $count_pages ) {
$count_pages = sprintf(
/* translators: %s: number of pages */
_n( '%s Page', '%s Pages', $count_pages, 'bogo' ),
number_format_i18n( $count_pages )
);
......@@ -245,7 +250,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
$actions = array();
if ( 'en_US' == $item->locale || $this->can_install_language_pack() ) {
if ( 'en_US' == $item->locale
or $this->can_install_language_pack() ) {
if ( bogo_is_default_locale( $item->locale ) ) {
// nothing
} elseif ( $item->active ) {
......@@ -260,7 +266,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
}
}
if ( $item->active && ! bogo_is_default_locale( $item->locale ) ) {
if ( $item->active
and ! bogo_is_default_locale( $item->locale ) ) {
$actions['translate'] = $this->action_link( $item, 'translate' );
}
......@@ -374,12 +381,13 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table {
function bogo_delete_language_pack( $locale ) {
if ( 'en_US' == $locale
|| ! bogo_is_available_locale( $locale )
|| bogo_is_default_locale( $locale ) ) {
or ! bogo_is_available_locale( $locale )
or bogo_is_default_locale( $locale ) ) {
return false;
}
if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) {
if ( ! is_dir( WP_LANG_DIR )
or ! $files = scandir( WP_LANG_DIR ) ) {
return false;
}
......@@ -395,7 +403,8 @@ function bogo_delete_language_pack( $locale ) {
);
foreach ( $files as $file ) {
if ( '.' === $file[0] || is_dir( $file ) ) {
if ( '.' === $file[0]
or is_dir( $file ) ) {
continue;
}
......
......@@ -12,14 +12,14 @@ class Bogo_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
$parallel_output = preg_replace(
'/<div class="menu-item-settings wp-clearfix" id="menu-item-settings-([0-9]+)">/',
'<div class="menu-item-settings wp-clearfix has-bogo-settings" id="menu-item-settings-${1}">' . $this->language_settings( $item ),
$parallel_output, 1 );
$parallel_output, 1
);
$output .= $parallel_output;
}
private function language_settings( $menu_item ) {
$available_languages = bogo_available_languages( array(
'exclude_enus_if_inactive' => true,
'orderby' => 'value',
) );
......@@ -101,12 +101,12 @@ function bogo_update_nav_menu_item( $menu_id, $menu_item_id ) {
foreach ( (array) bogo_available_locales() as $locale ) {
if ( in_array( $locale, $current_locales )
&& ! in_array( $locale, $requested_locales ) ) {
and ! in_array( $locale, $requested_locales ) ) {
delete_post_meta( $menu_item_id, '_locale', $locale );
}
if ( ! in_array( $locale, $current_locales )
&& in_array( $locale, $requested_locales ) ) {
and in_array( $locale, $requested_locales ) ) {
add_post_meta( $menu_item_id, '_locale', $locale );
}
}
......
......@@ -2,7 +2,7 @@
/* Posts List Table */
add_filter( 'manage_pages_columns', 'bogo_pages_columns' );
add_filter( 'manage_pages_columns', 'bogo_pages_columns', 10, 1 );
function bogo_pages_columns( $posts_columns ) {
return bogo_posts_columns( $posts_columns, 'page' );
......@@ -19,16 +19,20 @@ function bogo_posts_columns( $posts_columns, $post_type ) {
$posts_columns = array_merge(
array_slice( $posts_columns, 0, 3 ),
array( 'locale' => __( 'Locale', 'bogo' ) ),
array_slice( $posts_columns, 3 ) );
array_slice( $posts_columns, 3 )
);
}
return $posts_columns;
}
add_action( 'manage_pages_custom_column',
'bogo_manage_posts_custom_column', 10, 2 );
'bogo_manage_posts_custom_column', 10, 2
);
add_action( 'manage_posts_custom_column',
'bogo_manage_posts_custom_column', 10, 2 );
'bogo_manage_posts_custom_column', 10, 2
);
function bogo_manage_posts_custom_column( $column_name, $post_id ) {
if ( 'locale' != $column_name ) {
......@@ -54,17 +58,19 @@ function bogo_manage_posts_custom_column( $column_name, $post_id ) {
}
echo sprintf( '<a href="%1$s">%2$s</a>',
esc_url( add_query_arg(