Skip to content
203 changes: 6 additions & 197 deletions MultisiteLanguageSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Multisite Language Switcher Plugin
*
* Plugin Name: Multisite Language Switcher
* Version: 2.10.1
* Version: 3.0.0
* Plugin URI: http://msls.co/
* Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation.
* Author: Dennis Ploetner
Expand Down Expand Up @@ -45,205 +45,14 @@
* @author Dennis Ploetner <re@lloc.de>
*/
if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) {
define( 'MSLS_PLUGIN_VERSION', '2.10.1' );
define( 'MSLS_PLUGIN_VERSION', '3.0.0' );
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
define( 'MSLS_PLUGIN__FILE__', __FILE__ );

require_once __DIR__ . '/includes/aliases.php';
require_once __DIR__ . '/includes/deprectated.php';
require_once __DIR__ . '/includes/api.php';

/**
* Get the output for using the links to the translations in your code
*
* @package Msls
* @param mixed $attr
* @return string
*/
function msls_get_switcher( $attr ): string {
$arr = is_array( $attr ) ? $attr : array();
$obj = apply_filters( 'msls_get_output', null );

return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
}

/**
* Output the links to the translations in your template
*
* You can call this function directly like that
*
* if ( function_exists ( 'the_msls' ) )
* the_msls();
*
* or just use it as shortcode [sc_msls]
*
* @package Msls
* @uses get_the_msls
*
* @param string[] $arr
*/
function msls_the_switcher( array $arr = array() ): void {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo msls_get_switcher( $arr );
}

/**
* Gets the URL of the country flag-icon for a specific locale
*
* @param string $locale
*
* @return string
*/
function msls_get_flag_url( string $locale ): string {
return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale );
}

/**
* Gets the description for a blog for a specific locale
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_blog_description( string $locale, string $preset = '' ): string {
$blog = msls_blog( $locale );

return $blog ? $blog->get_description() : $preset;
}

/**
* Gets the permalink for a translation of the current post in a given language
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_permalink( string $locale, string $preset = '' ): string {
$url = null;
$blog = msls_blog( $locale );

if ( $blog ) {
$options = \lloc\Msls\MslsOptions::create();
$url = $blog->get_url( $options );
}

return $url ?? $preset;
}

/**
* Looks for the MslsBlog instance for a specific locale
*
* @param string $locale
*
* @return \lloc\Msls\MslsBlog|null
*/
function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog {
return msls_blog_collection()->get_blog( $locale );
}

/**
* Gets the MslsBlogCollection instance
*
* @return \lloc\Msls\MslsBlogCollection
*/
function msls_blog_collection(): \lloc\Msls\MslsBlogCollection {
return \lloc\Msls\MslsBlogCollection::instance();
}

/**
* Gets the MslsOptions instance
*
* @return \lloc\Msls\MslsOptions
*/
function msls_options(): \lloc\Msls\MslsOptions {
return \lloc\Msls\MslsOptions::instance();
}

/**
* Gets the MslsContentTypes instance
*
* @return \lloc\Msls\MslsContentTypes
*/
function msls_content_types(): \lloc\Msls\MslsContentTypes {
return \lloc\Msls\MslsContentTypes::create();
}

/**
* Gets the MslsPostType instance
*
* @return \lloc\Msls\MslsPostType
*/
function msls_post_type(): \lloc\Msls\MslsPostType {
return \lloc\Msls\MslsPostType::instance();
}

/**
* Gets the MslsTaxonomy instance
*
* @return \lloc\Msls\MslsTaxonomy
*/
function msls_taxonomy(): \lloc\Msls\MslsTaxonomy {
return \lloc\Msls\MslsTaxonomy::instance();
}

/**
* Gets the MslsOutput instance
*
* @return \lloc\Msls\MslsOutput
*/
function msls_output(): \lloc\Msls\MslsOutput {
return \lloc\Msls\MslsOutput::create();
}

/**
* Retrieves the MslsOptionsPost instance.
*
* @param int $id
* @return \lloc\Msls\MslsOptionsPost
*/
function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
return new \lloc\Msls\MslsOptionsPost( $id );
}

/**
* Retrieves the MslsOptionsTax instance.
*
* Determines the current query based on conditional tags:
* - is_category
* - is_tag
* - is_tax
*
* @param int $id
* @return \lloc\Msls\OptionsTaxInterface
*/
function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface {
return \lloc\Msls\MslsOptionsTax::create( $id );
}

/**
* Retrieves the MslsOptionsQuery instance.
*
* Determines the current query based on conditional tags:
* - is_day
* - is_month
* - is_year
* - is_author
* - is_post_type_archive
*
* @return ?\lloc\Msls\MslsOptionsQuery
*/
function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
return \lloc\Msls\MslsOptionsQuery::create();
}

/**
* Trivial void function for actions that do not return anything.
*
* @return void
*/
function msls_return_void(): void {
}

lloc\Msls\MslsPlugin::init();
lloc\Msls\MslsCli::init();
lloc\Msls\Plugin::init();
lloc\Msls\Cli\Cli::init();
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"flags-svg": "php bin/flags-svg.php > assets/css-flags/flags.php",
"git-release": "bin/git-release.sh",
"phpcs": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4-",
"phpstan": "vendor/bin/phpstan analyze --memory-limit=1G",
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G",
"phpunit": "@php vendor/bin/phpunit",
"phpunit:clover": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-clover tests/coverage.xml",
"phpunit:html": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
Expand Down
21 changes: 12 additions & 9 deletions includes/MslsAdmin.php → includes/Admin/Admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare( strict_types=1 );

namespace lloc\Msls;
namespace lloc\Msls\Admin;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -9,8 +9,11 @@
use lloc\Msls\Component\Input\Checkbox;
use lloc\Msls\Component\Input\Group;
use lloc\Msls\Component\Input\Label;
use lloc\Msls\Component\Input\Text;
use lloc\Msls\Component\Input\Select;
use lloc\Msls\Component\Input\Text;
use lloc\Msls\Link\Link;
use lloc\Msls\Plugin;
use lloc\Msls\Registry\Registry;
use WP_Post_Type;

/**
Expand All @@ -30,7 +33,7 @@
*
* @package Msls
*/
final class MslsAdmin extends MslsMain {
final class Admin extends Main {

const MSLS_REGISTER_ACTION = 'msls_admin_register';

Expand All @@ -47,11 +50,11 @@ final class MslsAdmin extends MslsMain {
* @codeCoverageIgnore
*/
public static function init(): void {
$obj = MslsRegistry::get_object( __CLASS__ );
$obj = Registry::get_object( __CLASS__ );
if ( ! $obj ) {
$obj = new self( msls_options(), msls_blog_collection() );

MslsRegistry::set_object( __CLASS__, $obj );
Registry::set_object( __CLASS__, $obj );

/**
* Override the capabilities needed for the plugin's settings
Expand Down Expand Up @@ -171,7 +174,7 @@ public function has_problems(): void {
);
}

MslsPlugin::message_handler( $message, 'updated fade' );
Plugin::message_handler( $message, 'updated fade' );
}

/**
Expand Down Expand Up @@ -375,7 +378,7 @@ public function blog_language(): void {
*/
public function display(): void {
// phpcs:ignore WordPress.Security.EscapeOutput
echo ( new Select( 'display', MslsLink::get_types_description(), strval( $this->options->display ) ) )->render();
echo ( new Select( 'display', Link::get_types_description(), strval( $this->options->display ) ) )->render();
}

/**
Expand All @@ -385,8 +388,8 @@ public function admin_display(): void {
$select = new Select(
'admin_display',
array(
MslsAdminIcon::TYPE_FLAG => __( 'Flag', 'multisite-language-switcher' ),
MslsAdminIcon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ),
Icon::TYPE_FLAG => __( 'Flag', 'multisite-language-switcher' ),
Icon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ),
),
$this->options->get_icon_type()
);
Expand Down
26 changes: 15 additions & 11 deletions includes/MslsAdminBar.php → includes/Admin/Bar.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
<?php declare( strict_types=1 );

namespace lloc\Msls;
namespace lloc\Msls\Admin;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

class MslsAdminBar {
use lloc\Msls\Blog\Blog;
use lloc\Msls\Blog\Collection;
use lloc\Msls\Options\Options;

class Bar {

/**
* @var string
*/
protected string $icon_type;

/**
* @var MslsBlogCollection
* @var Collection
*/
protected MslsBlogCollection $blog_collection;
protected Collection $blog_collection;

/**
* @param MslsOptions $options
* @param MslsBlogCollection $blog_collection
* @param Options $options
* @param Collection $blog_collection
*/
public function __construct( MslsOptions $options, MslsBlogCollection $blog_collection ) {
public function __construct( Options $options, Collection $blog_collection ) {
$this->icon_type = $options->get_icon_type();
$this->blog_collection = $blog_collection;
}
Expand All @@ -31,7 +35,7 @@ public function __construct( MslsOptions $options, MslsBlogCollection $blog_coll
* @return void
*/
public static function init(): void {
$obj = new MslsAdminBar( msls_options(), msls_blog_collection() );
$obj = new Bar( msls_options(), msls_blog_collection() );

if ( is_admin_bar_showing() ) {
add_action( 'admin_bar_menu', array( $obj, 'update_admin_bar' ), 999 );
Expand Down Expand Up @@ -88,12 +92,12 @@ public function add_node( \WP_Admin_Bar $wp_admin_bar, string $node_id, string $
*
* It uses a blavatar icon as prefix if $blavatar is set to true
*
* @param MslsBlog|null $blog
* @param bool $blavatar
* @param Blog|null $blog
* @param bool $blavatar
*
* @return string|null
*/
protected function get_title( ?MslsBlog $blog, bool $blavatar = false ): ?string {
protected function get_title( ?Blog $blog, bool $blavatar = false ): ?string {
if ( is_null( $blog ) ) {
return $blog;
}
Expand Down
Loading
Loading