diff --git a/css/msls.css b/css/msls.css index fe7b8437..a8c9b1f6 100644 --- a/css/msls.css +++ b/css/msls.css @@ -1 +1 @@ -div#msls.postbox label{width:16px;margin-right:6px}div#msls.postbox select,select.msls-translations{width:226px}#msls.postbox .inside li{display:flex;align-items:center}#msls.postbox .inside li label{display:flex;flex-grow:.1}#msls.postbox .inside li input.msls_title,#msls.postbox .inside li select{flex-grow:.9}#msls-content-import .button-primary{margin:1em auto}.flag-icon{height:1em;overflow:hidden;color:transparent} \ No newline at end of file +div#msls.postbox label{margin-right:6px}div#msls.postbox select,select.msls-translations{width:226px}#msls.postbox .inside li{display:flex;align-items:center}#msls.postbox .inside li label{display:flex}#msls.postbox .inside li input.msls_title,#msls.postbox .inside li select{flex-grow:1}#msls-content-import .button-primary{margin:1em auto}.flag-icon{width:1.3333em!important;height:1em!important;vertical-align:middle;overflow:hidden;line-height:1!important;color:transparent}.msls-icon-wrapper{display:inline-flex;justify-content:center;align-items:center;text-align:center}.msls-icon-wrapper.flag{min-width:36px}.msls-icon-wrapper.label{min-width:48px}label .msls-icon-wrapper{text-align:left}#wpadminbar * .language-badge,#wpadminbar .language-badge,.language-badge{display:inline-block;min-width:32px;height:auto;padding:4px 6px;white-space:nowrap;font-size:10px;line-height:1;text-align:center;background-color:currentColor;border-radius:9px;user-select:none}#wpadminbar * .language-badge>span,#wpadminbar .language-badge>span,.language-badge>span{display:inline-block;vertical-align:top;margin:0 1px;font-size:10px;font-weight:600;text-transform:uppercase;color:#fff;text-align:center;line-height:1}#wpadminbar * .language-badge>span:nth-child( 2 ),#wpadminbar .language-badge>span:nth-child( 2 ),.language-badge>span:nth-child( 2 ){opacity:.5}.column-mslscol .language-badge{margin:0 1px!important}#wpadminbar * .language-badge,#wpadminbar .language-badge{position:relative;top:-1px;padding-top:3px;padding-bottom:3px;background-color:transparent;border:1px solid currentColor}#wpadminbar * .language-badge>span,#wpadminbar .language-badge>span{color:currentColor} \ No newline at end of file diff --git a/css/msls.less b/css/msls.less index 5d7247ea..7042b82a 100644 --- a/css/msls.less +++ b/css/msls.less @@ -1,7 +1,6 @@ @select-width: 226px; div#msls.postbox { label { - width: 16px; margin-right: 6px; } select { @@ -18,10 +17,9 @@ select.msls-translations { align-items: center; label { display: flex; - flex-grow: .1; } input.msls_title, select{ - flex-grow: .9; + flex-grow: 1; } } } @@ -32,8 +30,91 @@ select.msls-translations { margin: 1em auto; } } + .flag-icon { - height: 1em; + width: 1.3333em !important; + height: 1em !important; + vertical-align: middle; overflow: hidden; + line-height: 1 !important; color: transparent; } + +.msls-icon-wrapper { + display: inline-flex; + justify-content: center; + align-items: center; + + text-align: center; + + &.flag { + min-width: 36px; + } + + &.label { + min-width: 48px; + } + + label & { + text-align: left; + } +} + +.language-badge, +#wpadminbar .language-badge, +#wpadminbar * .language-badge { + display: inline-block; + min-width: 32px; + height: auto; + padding: 4px 6px; + white-space: nowrap; + + font-size: 10px; + line-height: 1; + text-align: center; + + background-color: currentColor; + border-radius: 9px; + + user-select: none; + + & > span { + display: inline-block; + vertical-align: top; + margin: 0 1px; + + font-size: 10px; + font-weight: 600; + line-height: 1; + text-transform: uppercase; + color: #fff; + text-align: center; + line-height: 1; + + &:nth-child( 2 ) { + opacity: 0.5; + } + } +} + +.column-mslscol .language-badge { + margin: 0 1px !important; +} + +#wpadminbar .language-badge, +#wpadminbar * .language-badge { + position: relative; + top: -1px; + + // margin-left: 4px; + // margin-right: 4px; + padding-top: 3px; + padding-bottom: 3px; + + background-color: transparent; + border: 1px currentColor solid; + + & > span { + color: currentColor; + } +} \ No newline at end of file diff --git a/includes/Component/Icon.php b/includes/Component/Icon.php index d750fd2c..db8754ef 100644 --- a/includes/Component/Icon.php +++ b/includes/Component/Icon.php @@ -17,7 +17,9 @@ abstract class Icon { * Icon constructor */ public function __construct() { - $this->map = include $this->get_include(); + if( $this->get_include() ) { + $this->map = include $this->get_include(); + } } /** diff --git a/includes/Component/Icon/IconLabel.php b/includes/Component/Icon/IconLabel.php new file mode 100644 index 00000000..5fb56bf6 --- /dev/null +++ b/includes/Component/Icon/IconLabel.php @@ -0,0 +1,34 @@ +map[ $language ] ) ) { + // return $this->map[ $language ]; + // } + + return '' . implode( '', explode( '_', $language ) ) . ''; + } + +} \ No newline at end of file diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index 172afa0d..af6c017f 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -225,6 +225,7 @@ public function language_section(): int { public function main_section(): int { $map = [ 'display' => __( 'Display', 'multisite-language-switcher' ), + 'admin_display' => __( 'Admin Display', 'multisite-language-switcher' ), 'sort_by_description' => __( 'Sort languages', 'multisite-language-switcher' ), 'output_current_blog' => __( 'Current language link', 'multisite-language-switcher' ), 'only_with_translation' => __( 'Translation links', 'multisite-language-switcher' ), @@ -317,6 +318,13 @@ public function display() { echo ( new Select( 'display', MslsLink::get_types_description(), $this->options->display ) )->render(); } + /** + * Shows the select-form-field 'admin_display' + */ + public function admin_display() { + echo ( new Select( 'admin_display', array( 'flag' => __( 'Flag', 'multisite-language-switcher' ), 'label' => __( 'Label', 'multisite-language-switcher' ) ), $this->options->admin_display ) )->render(); + } + /** * Shows the select-form-field 'reference_user' */ diff --git a/includes/MslsAdminIcon.php b/includes/MslsAdminIcon.php index ca5bc5f3..bfec183a 100644 --- a/includes/MslsAdminIcon.php +++ b/includes/MslsAdminIcon.php @@ -8,6 +8,7 @@ namespace lloc\Msls; use lloc\Msls\Component\Icon\IconSvg; +use lloc\Msls\Component\Icon\IconLabel; /** * Handles the icon links in the backend @@ -233,6 +234,13 @@ public function get_icon(): string { ); } + if ( 'label' === $this->iconType ) { + return sprintf( '%s', + $this->language, + ( new IconLabel() )->get( $this->language ) + ); + } + if ( empty( $this->href ) ) { return ''; } diff --git a/includes/MslsBlog.php b/includes/MslsBlog.php index f9bfb9d6..4f63b49c 100644 --- a/includes/MslsBlog.php +++ b/includes/MslsBlog.php @@ -40,6 +40,8 @@ public function __construct( $obj, $description ) { $this->language = MslsBlogCollection::get_blog_language( $this->obj->userblog_id ); } + $this->options = MslsOptions::instance(); + $this->description = (string) $description; } @@ -72,7 +74,15 @@ public function get_description(): string { * @return string */ public function get_title(): string { - return sprintf( '%1$s (%2$s)', $this->obj->blogname, $this->get_description() ); + $icon = new MslsAdminIcon( null ); + $icon->set_language( $this->language ); + if( $this->options->admin_display === 'label' ) { + $icon->set_icon_type( 'label' ); + } else { + $icon->set_icon_type( 'flag' ); + } + + return sprintf( '%1$s %2$s', $this->obj->blogname, ' ' ); } /** diff --git a/includes/MslsCustomColumn.php b/includes/MslsCustomColumn.php index 2b5707ba..6bfbc545 100644 --- a/includes/MslsCustomColumn.php +++ b/includes/MslsCustomColumn.php @@ -47,21 +47,28 @@ public static function init() { public function th( $columns ) { $blogs = $this->collection->get(); if ( $blogs ) { - $arr = []; + $html; foreach ( $blogs as $blog ) { $language = $blog->get_language(); $icon = new MslsAdminIcon( null ); - $icon->set_language( $language )->set_icon_type( 'flag' ); + $icon->set_language( $language ); + if( $this->options->admin_display === 'label' ) { + $icon->set_icon_type( 'label' ); + } else { + $icon->set_icon_type( 'flag' ); + } if ( $post_id = get_the_ID() ) { $icon->set_id( $post_id ); $icon->set_origin_language( 'it_IT' ); } - $arr[] = $icon->get_icon(); + $html .= ' '; } - $columns['mslscol'] = implode( ' ', $arr ); + $columns['mslscol'] = $html; } return $columns; @@ -97,7 +104,9 @@ public function td( $column_name, $item_id ) { $icon->set_href( $mydata->$language ); } - echo $icon->get_a(); + echo ' '; restore_current_blog(); } diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php index 7ee92960..9dcd7da7 100644 --- a/includes/MslsMetaBox.php +++ b/includes/MslsMetaBox.php @@ -183,12 +183,16 @@ public function render_select() { switch_to_blog( $blog->userblog_id ); $language = $blog->get_language(); - $icon = MslsAdminIcon::create( $type ) - ->set_language( $language ) - ->set_icon_type( 'flag' ); + $icon = MslsAdminIcon::create()->set_language( $language ); + + if ( $this->options->admin_display === 'label' ) { + $icon->set_icon_type( 'label' ); + } else { + $icon->set_icon_type( 'flag' ); + } if ( $mydata->has_value( $language ) ) { - $icon->set_href( $mydata->$language ); + $icon->set_href( $mydata->$language ); } $selects = ''; @@ -224,10 +228,11 @@ public function render_select() { } $lis .= sprintf( - '