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

[auto] plugin: bogo 3.2

parent c3a98ad8
This diff is collapsed.
/* Language Packs */
#bogo-languages-table tbody th {
width: 2em;
border-left: inherit;
#bogo-language-packs td:first-child {
border-right: 0;
padding-left: inherit;
padding-right: 16px;
}
#bogo-languages-table tbody tr.active th {
border-left: inherit;
#bogo-language-packs tr.active td:first-child {
border-right: 4px solid #00a0d2;
padding-left: inherit;
padding-right: 12px;
}
#bogo-languages-table tbody a.install,
#bogo-languages-table tbody a.activate {
margin-left: inherit;
margin-right: .4em;
#bogo-language-packs td.status li.post-count,
#bogo-language-packs td.status li.page-count {
float: right;
margin: 6px 0 0 16px;
}
#bogo-language-packs td.status li.post-count a::before,
#bogo-language-packs td.status li.page-count a::before {
padding-left: 4px;
}
/* Terms Translation */
#bogo-translation-table input.large-text {
#bogo-terms-translation .large-text {
padding-right: 0;
margin-right: 0;
}
#bogo-translation-table input.large-text:hover {
#bogo-terms-translation .large-text:hover {
padding-right: 5px;
margin-right: 1px;
}
#bogo-translation-table input.large-text:focus {
#bogo-terms-translation .large-text:focus {
padding-right: 5px;
margin-right: 1px;
}
......
......@@ -40,66 +40,57 @@ fieldset.bogo-locale-options label.bogo-locale-option input[type="checkbox"] {
/* Language Packs */
#bogo-languages-table {
margin-top: 20px;
}
#bogo-languages-table tbody th,
#bogo-languages-table tbody td {
#bogo-language-packs td {
box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.1) inset;
padding: 10px;
}
#bogo-languages-table thead tr th:first-child,
#bogo-languages-table tfoot tr th:first-child,
#bogo-languages-table tbody tr td:first-child {
width: 2em;
#bogo-language-packs td:first-child {
border-left: 0;
padding-left: 16px;
}
#bogo-languages-table tbody tr.active th,
#bogo-languages-table tbody tr.active td {
#bogo-language-packs tr.active td {
background-color: #f7fcfe;
}
#bogo-languages-table tbody tr.active td:first-child {
#bogo-language-packs tr.active td:first-child {
border-left: 4px solid #00a0d2;
padding-left: 12px;
}
#bogo-languages-table tbody tr:last-child td,
#bogo-languages-table tbody tr:last-child th {
border-bottom: none;
box-shadow: none;
}
#bogo-languages-table tbody td strong {
font-size: 14px;
font-weight: 400;
#bogo-language-packs td.status ul {
margin: 0;
}
#bogo-languages-table tbody tr.active td strong {
font-weight: 600;
#bogo-language-packs td.status li.post-count,
#bogo-language-packs td.status li.page-count {
float: left;
margin: 6px 16px 0 0;
}
#bogo-languages-table tbody div.status {
color: #555;
#bogo-language-packs td.status li.post-count a::before,
#bogo-language-packs td.status li.page-count a::before {
font: normal 20px/1 dashicons;
color: #82878c;
content: '\f159';
display: inline-block;
vertical-align: top;
padding-right: 4px;
text-decoration: none;
}
#bogo-languages-table tbody div.row-actions a.delete,
#bogo-languages-table tbody div.row-actions a.deactivate {
color: #a00;
#bogo-language-packs td.status li.post-count a::before {
content: '\f109';
}
#bogo-languages-table tbody div.row-actions a.delete:hover,
#bogo-languages-table tbody div.row-actions a.deactivate:hover {
color: #f00;
#bogo-language-packs td.status li.page-count a::before {
content: '\f105';
}
/* Terms Translation */
#bogo-translation-table input.large-text {
#bogo-terms-translation .large-text {
background: transparent;
color: #555;
font-size: 13px;
......@@ -109,7 +100,7 @@ fieldset.bogo-locale-options label.bogo-locale-option input[type="checkbox"] {
margin-left: 0;
}
#bogo-translation-table input.large-text:hover {
#bogo-terms-translation .large-text:hover {
background: #fff;
color: #32373c;
font-size: 14px;
......@@ -119,7 +110,7 @@ fieldset.bogo-locale-options label.bogo-locale-option input[type="checkbox"] {
margin-left: 1px;
}
#bogo-translation-table input.large-text:focus {
#bogo-terms-translation .large-text:focus {
background: #fff;
color: #32373c;
font-size: 14px;
......
......@@ -2,85 +2,18 @@
'use strict';
if ( typeof _bogo === 'undefined' || _bogo === null ) {
if ( typeof bogo === 'undefined' || bogo === null ) {
return;
}
$( function() {
$( 'body.nav-menus-php .menu-item' ).bogoAddLocaleSelector();
} );
$( document ).ajaxSuccess( function( event, request, settings ) {
$( 'body.nav-menus-php .menu-item' ).bogoAddLocaleSelector();
} );
$.fn.bogoAddLocaleSelector = function() {
return this.each( function() {
if ( _bogo.hasSelector( this ) ) {
return;
}
var id = $( this ).attr( 'id' ).replace( 'menu-item-', '' );
var $selector = _bogo.selector( id );
$( this ).find( '.menu-item-settings' ).prepend( $selector );
} );
}
_bogo.hasSelector = function( elm ) {
return $( elm ).is( ':has(.bogo-locale-options)' );
}
_bogo.selector = function( id ) {
var $selector = $( '<fieldset class="bogo-locale-options"></fieldset>' );
if ( _bogo.availableLanguages ) {
var $legend = $( '<legend></legend>' ).append( _bogo.selectorLegend );
$selector.append( $legend );
$.each( _bogo.availableLanguages, function( i, val ) {
var checked = false;
if ( ! _bogo.locales[ id ] || -1 < $.inArray( i, _bogo.locales[ id ] ) ) {
checked = true;
}
$selector.append( _bogo.checkbox( id, i, checked ) );
} );
}
return $selector;
}
_bogo.checkbox = function( id, locale, checked ) {
var prefix = _bogo.cbPrefix || 'bogo-locale';
var name_attr = prefix + '[' + id + '][]';
var id_attr = 'edit-' + prefix + '-' + id + '-' + locale;
var $cb = $( '<input type="checkbox" />' );
$cb.attr( 'name', name_attr );
$cb.attr( 'id', id_attr );
$cb.attr( 'value', locale );
$cb.prop( 'checked', checked );
var $label = $( '<label class="bogo-locale-option"></label>' );
$label.attr( 'for', id_attr );
$label.append( _bogo.langName( locale ) );
if ( checked ) {
$label.addClass( 'checked' );
}
return $label.prepend( $cb );
}
_bogo.langName = function( locale ) {
return _bogo.availableLanguages[ locale ] || '';
}
bogo.langName = function( locale ) {
return bogo.availableLanguages[ locale ] || '';
};
$( function() {
$( 'body.options-general-php select#WPLANG' ).each( function() {
$( this ).find( 'option[selected="selected"]' ).removeAttr( 'selected' );
var val = _bogo.defaultLocale || 'en_US';
var val = bogo.defaultLocale || 'en_US';
val = ( 'en_US' == val ? '' : val );
$( this ).find( 'option[value="' + val + '"]' ).first().attr( 'selected', 'selected' );
} );
......@@ -88,14 +21,13 @@
$( function() {
$( '#bogo-add-translation' ).click( function() {
if ( ! _bogo.post_id ) {
if ( ! bogo.post_id ) {
return;
}
var locale = $( '#bogo-translations-to-add' ).val();
var rest_url = _bogo.rest_api.url +
'posts/' + _bogo.post_id +
'/translations/' + locale;
var rest_url = bogo.apiSettings.getRoute(
'/posts/' + bogo.post_id + '/translations/' + locale );
$( '#bogo-add-translation' ).next( '.spinner' )
.css( 'visibility', 'visible' );
......@@ -103,7 +35,7 @@
type: 'POST',
url: rest_url,
beforeSend: function( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', _bogo.rest_api.nonce );
xhr.setRequestHeader( 'X-WP-Nonce', bogo.apiSettings.nonce );
}
} ).done( function( response ) {
var post = response[ locale ];
......@@ -114,8 +46,14 @@
var $added = $( '<a></a>' ).attr( {
href: post.edit_link,
target: '_blank'
} ).html( post.title.rendered );
target: '_blank',
rel: 'noopener noreferrer'
} ).html( function() {
var output = post.title.rendered;
output += ' <span class="screen-reader-text">'
+ bogo.screenReaderText.targetBlank + '</span>';
return output;
} );
$added = $( '<li></li>' ).append( $added ).append(
' [' + post.lang.name + ']' );
......@@ -133,23 +71,23 @@
} );
$( function() {
if ( 'bogo-texts' == _bogo.pagenow ) {
if ( 'bogo-texts' == bogo.pagenow ) {
$( window ).on( 'beforeunload', function( event ) {
var changed = false;
$( '#bogo-translatable-text-strings :text' ).each( function() {
$( '#bogo-terms-translation :text' ).each( function() {
if ( this.defaultValue != $( this ).val() ) {
changed = true;
}
} );
if ( changed ) {
event.returnValue = _bogo.saveAlert;
return _bogo.saveAlert;
event.returnValue = bogo.saveAlert;
return bogo.saveAlert;
}
} );
$( '#bogo-translatable-text-strings' ).submit( function() {
$( '#bogo-terms-translation' ).submit( function() {
$( window ).off( 'beforeunload' );
} );
......@@ -159,4 +97,14 @@
}
} );
bogo.apiSettings.getRoute = function( path ) {
var url = bogo.apiSettings.root;
url = url.replace(
bogo.apiSettings.namespace,
bogo.apiSettings.namespace + path );
return url;
};
} )( jQuery );
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class Bogo_Language_Packs_List_Table extends WP_List_Table {
private $count_active = 0;
private $count_inactive = 0;
public static function define_columns() {
$columns = array(
'name' => __( 'Language', 'bogo' ),
'status' => __( 'Status', 'bogo' ),
);
return $columns;
}
public function get_columns() {
return get_column_headers( get_current_screen() );
}
public function prepare_items() {
$this->items = array();
$search_keys = empty( $_REQUEST['s'] )
? array()
: preg_split( '/[\s]+/', $_REQUEST['s'] );
$status = isset( $_REQUEST['status'] )
? trim( $_REQUEST['status'] )
: '';
$locales = array_unique( array_merge(
array( bogo_get_default_locale() ),
bogo_available_locales( 'exclude_enus_if_inactive=1' ),
array( 'en_US' ),
array_keys( wp_get_available_translations() )
) );
foreach ( $locales as $locale ) {
$language = bogo_get_language( $locale );
$is_active = ( 'en_US' == $locale )
? ! bogo_is_enus_deactivated()
: bogo_is_available_locale( $locale );
if ( $is_active ) {
$this->count_active += 1;
} else {
$this->count_inactive += 1;
}
if ( $search_keys ) {
$haystack = $locale . ' ' . $language;
$needle_found = true;
foreach ( $search_keys as $needle ) {
if ( false === stripos( $haystack, $needle ) ) {
$needle_found = false;
break;
}
}
if ( ! $needle_found ) {
continue;
}
}
if ( 'active' == $status && ! $is_active
|| 'inactive' == $status && $is_active ) {
continue;
}
$this->items[] = (object) array(
'locale' => $locale,
'language' => $language,
'active' => $is_active,
);
}
$this->set_pagination_args( array(
'total_items' => count( $this->items ),
'total_pages' => 1,
) );
}
protected function get_views() {
$links = array();
$menu_page_url = menu_page_url( 'bogo', false );
$status = isset( $_REQUEST['status'] )
? trim( $_REQUEST['status'] )
: '';
// All
$count_all = $this->count_active + $this->count_inactive;
$all = sprintf(
_nx(
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
$count_all, 'language status', 'bogo' ),
number_format_i18n( $count_all )
);
$links['all'] = sprintf(
'<a href="%1$s"%2$s>%3$s</a>',
esc_url( $menu_page_url ),
'' === $status ? ' class="current"' : '',
$all
);
// Active
$active = sprintf(
_nx(
'Active <span class="count">(%s)</span>',
'Active <span class="count">(%s)</span>',
$this->count_active, 'language status', 'bogo' ),
number_format_i18n( $this->count_active )
);
$links['active'] = sprintf(
'<a href="%1$s"%2$s>%3$s</a>',
esc_url( add_query_arg( 'status', 'active', $menu_page_url ) ),
'active' == $status ? ' class="current"' : '',
$active
);
// Inactive
$inactive = sprintf(
_nx(
'Inactive <span class="count">(%s)</span>',
'Inactive <span class="count">(%s)</span>',
$this->count_inactive, 'language status', 'bogo' ),
number_format_i18n( $this->count_inactive )
);
$links['inactive'] = sprintf(
'<a href="%1$s"%2$s>%3$s</a>',
esc_url( add_query_arg( 'status', 'inactive', $menu_page_url ) ),
'inactive' == $status ? ' class="current"' : '',
$inactive
);
return $links;
}
public function column_name( $item ) {
echo sprintf(
'<strong>%1$s</strong> [%2$s]',
esc_html( $item->language ),
esc_html( $item->locale )
);
}
public function column_status( $item ) {
$status = '';
if ( $item->active ) {
if ( bogo_is_default_locale( $item->locale ) ) {
$status = __( 'Site Language', 'bogo' );
} else {
$status = __( 'Active', 'bogo' );
}
} else {
$status = __( 'Inactive', 'bogo' );
}
if ( $status ) {
echo sprintf(
'<div class="status">%s</div>',
esc_html( $status )
);
}
if ( $item->active ) {
$this->render_post_count( $item );
}
}
private function render_post_count( $item ) {
$count_posts = bogo_count_posts( $item->locale, 'post' );
$count_pages = bogo_count_posts( $item->locale, 'page' );
if ( $count_posts ) {
$count_posts = sprintf(
_n( '%s Post', '%s Posts', $count_posts, 'bogo' ),
number_format_i18n( $count_posts )
);
}
if ( $count_pages ) {
$count_pages = sprintf(
_n( '%s Page', '%s Pages', $count_pages, 'bogo' ),
number_format_i18n( $count_pages )
);
}
$edit_url = add_query_arg(
array(
'post_status' => 'publish',
'lang' => $item->locale,
),
admin_url( 'edit.php' )
);
echo '<ul>';
if ( $count_posts ) {
echo sprintf(
'<li class="post-count"><a href="%1$s">%2$s</a></li>',
esc_url( add_query_arg( 'post_type', 'post', $edit_url ) ),
esc_html( $count_posts )
);
}
if ( $count_pages ) {
echo sprintf(
'<li class="page-count"><a href="%1$s">%2$s</a></li>',
esc_url( add_query_arg( 'post_type', 'page', $edit_url ) ),
esc_html( $count_pages )
);
}
echo '</ul>';
}
public function single_row( $item ) {
echo $item->active
? '<tr class="active">'
: '<tr>';
$this->single_row_columns( $item );
echo '</tr>';
}
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $column_name !== $primary ) {
return '';
}
$actions = array();
if ( 'en_US' == $item->locale || $this->can_install_language_pack() ) {
if ( bogo_is_default_locale( $item->locale ) ) {
// nothing
} elseif ( $item->active ) {
$actions = array(
'promote' => $this->action_link( $item, 'promote' ),
'deactivate' => $this->action_link( $item, 'deactivate' ),
);