Skip to content

Commit 5554786

Browse files
committed
Merging restructuring into master
2 parents a193eea + 3afd781 commit 5554786

142 files changed

Lines changed: 2160 additions & 1747 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MultisiteLanguageSwitcher.php

Lines changed: 16 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Multisite Language Switcher Plugin
44
*
55
* Plugin Name: Multisite Language Switcher
6-
* Version: 2.10.1
6+
* Version: 3.0.0
77
* Plugin URI: http://msls.co/
88
* Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation.
99
* Author: Dennis Ploetner
@@ -35,215 +35,33 @@
3535
exit;
3636
}
3737

38-
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
39-
require __DIR__ . '/vendor/autoload.php';
40-
}
41-
4238
/**
4339
* MultisiteLanguageSwitcher
4440
*
4541
* @author Dennis Ploetner <re@lloc.de>
4642
*/
4743
if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) {
48-
define( 'MSLS_PLUGIN_VERSION', '2.10.1' );
44+
define( 'MSLS_PLUGIN_VERSION', '3.0.0' );
4945
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
5046
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
5147

52-
require_once __DIR__ . '/includes/deprectated.php';
53-
54-
/**
55-
* Get the output for using the links to the translations in your code
56-
*
57-
* @package Msls
58-
* @param mixed $attr
59-
* @return string
60-
*/
61-
function msls_get_switcher( $attr ): string {
62-
$arr = is_array( $attr ) ? $attr : array();
63-
$obj = apply_filters( 'msls_get_output', null );
64-
65-
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
48+
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
49+
require __DIR__ . '/vendor/autoload.php';
6650
}
6751

68-
/**
69-
* Output the links to the translations in your template
70-
*
71-
* You can call this function directly like that
72-
*
73-
* if ( function_exists ( 'the_msls' ) )
74-
* the_msls();
75-
*
76-
* or just use it as shortcode [sc_msls]
77-
*
78-
* @package Msls
79-
* @uses get_the_msls
80-
*
81-
* @param string[] $arr
82-
*/
83-
function msls_the_switcher( array $arr = array() ): void {
84-
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
85-
echo msls_get_switcher( $arr );
86-
}
87-
88-
/**
89-
* Gets the URL of the country flag-icon for a specific locale
90-
*
91-
* @param string $locale
92-
*
93-
* @return string
94-
*/
95-
function msls_get_flag_url( string $locale ): string {
96-
return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale );
97-
}
98-
99-
/**
100-
* Gets the description for a blog for a specific locale
101-
*
102-
* @param string $locale
103-
* @param string $preset
104-
*
105-
* @return string
106-
*/
107-
function msls_get_blog_description( string $locale, string $preset = '' ): string {
108-
$blog = msls_blog( $locale );
109-
110-
return $blog ? $blog->get_description() : $preset;
111-
}
52+
add_action(
53+
'plugins_loaded',
54+
function () {
55+
require_once __DIR__ . '/includes/aliases.php';
56+
require_once __DIR__ . '/includes/deprectated.php';
57+
require_once __DIR__ . '/includes/api.php';
11258

113-
/**
114-
* Gets the permalink for a translation of the current post in a given language
115-
*
116-
* @param string $locale
117-
* @param string $preset
118-
*
119-
* @return string
120-
*/
121-
function msls_get_permalink( string $locale, string $preset = '' ): string {
122-
$url = null;
123-
$blog = msls_blog( $locale );
59+
$builder = new DI\ContainerBuilder();
60+
$builder->addDefinitions( require __DIR__ . '/config.php' );
61+
$builder->build();
12462

125-
if ( $blog ) {
126-
$options = \lloc\Msls\MslsOptions::create();
127-
$url = $blog->get_url( $options );
63+
lloc\Msls\Plugin::init();
64+
lloc\Msls\Cli\Cli::init();
12865
}
129-
130-
return $url ?? $preset;
131-
}
132-
133-
/**
134-
* Looks for the MslsBlog instance for a specific locale
135-
*
136-
* @param string $locale
137-
*
138-
* @return \lloc\Msls\MslsBlog|null
139-
*/
140-
function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog {
141-
return msls_blog_collection()->get_blog( $locale );
142-
}
143-
144-
/**
145-
* Gets the MslsBlogCollection instance
146-
*
147-
* @return \lloc\Msls\MslsBlogCollection
148-
*/
149-
function msls_blog_collection(): \lloc\Msls\MslsBlogCollection {
150-
return \lloc\Msls\MslsBlogCollection::instance();
151-
}
152-
153-
/**
154-
* Gets the MslsOptions instance
155-
*
156-
* @return \lloc\Msls\MslsOptions
157-
*/
158-
function msls_options(): \lloc\Msls\MslsOptions {
159-
return \lloc\Msls\MslsOptions::instance();
160-
}
161-
162-
/**
163-
* Gets the MslsContentTypes instance
164-
*
165-
* @return \lloc\Msls\MslsContentTypes
166-
*/
167-
function msls_content_types(): \lloc\Msls\MslsContentTypes {
168-
return \lloc\Msls\MslsContentTypes::create();
169-
}
170-
171-
/**
172-
* Gets the MslsPostType instance
173-
*
174-
* @return \lloc\Msls\MslsPostType
175-
*/
176-
function msls_post_type(): \lloc\Msls\MslsPostType {
177-
return \lloc\Msls\MslsPostType::instance();
178-
}
179-
180-
/**
181-
* Gets the MslsTaxonomy instance
182-
*
183-
* @return \lloc\Msls\MslsTaxonomy
184-
*/
185-
function msls_taxonomy(): \lloc\Msls\MslsTaxonomy {
186-
return \lloc\Msls\MslsTaxonomy::instance();
187-
}
188-
189-
/**
190-
* Gets the MslsOutput instance
191-
*
192-
* @return \lloc\Msls\MslsOutput
193-
*/
194-
function msls_output(): \lloc\Msls\MslsOutput {
195-
return \lloc\Msls\MslsOutput::create();
196-
}
197-
198-
/**
199-
* Retrieves the MslsOptionsPost instance.
200-
*
201-
* @param int $id
202-
* @return \lloc\Msls\MslsOptionsPost
203-
*/
204-
function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
205-
return new \lloc\Msls\MslsOptionsPost( $id );
206-
}
207-
208-
/**
209-
* Retrieves the MslsOptionsTax instance.
210-
*
211-
* Determines the current query based on conditional tags:
212-
* - is_category
213-
* - is_tag
214-
* - is_tax
215-
*
216-
* @param int $id
217-
* @return \lloc\Msls\OptionsTaxInterface
218-
*/
219-
function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface {
220-
return \lloc\Msls\MslsOptionsTax::create( $id );
221-
}
222-
223-
/**
224-
* Retrieves the MslsOptionsQuery instance.
225-
*
226-
* Determines the current query based on conditional tags:
227-
* - is_day
228-
* - is_month
229-
* - is_year
230-
* - is_author
231-
* - is_post_type_archive
232-
*
233-
* @return ?\lloc\Msls\MslsOptionsQuery
234-
*/
235-
function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
236-
return \lloc\Msls\MslsOptionsQuery::create();
237-
}
238-
239-
/**
240-
* Trivial void function for actions that do not return anything.
241-
*
242-
* @return void
243-
*/
244-
function msls_return_void(): void {
245-
}
246-
247-
lloc\Msls\MslsPlugin::init();
248-
lloc\Msls\MslsCli::init();
66+
);
24967
}

build/translations.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": ">=7.4",
99
"composer/installers": "~2.3.0",
10+
"php-di/php-di": "^7.0",
1011
"ext-json": "*"
1112
},
1213
"require-dev": {
@@ -39,7 +40,7 @@
3940
"flags-svg": "php bin/flags-svg.php > assets/css-flags/flags.php",
4041
"git-release": "bin/git-release.sh",
4142
"phpcs": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4-",
42-
"phpstan": "vendor/bin/phpstan analyze --memory-limit=1G",
43+
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G",
4344
"phpunit": "@php vendor/bin/phpunit",
4445
"phpunit:clover": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-clover tests/coverage.xml",
4546
"phpunit:html": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",

config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php declare( strict_types=1 );
2+
3+
return array();
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare( strict_types=1 );
22

3-
namespace lloc\Msls;
3+
namespace lloc\Msls\Admin;
44

55
if ( ! defined( 'ABSPATH' ) ) {
66
exit;
@@ -9,8 +9,11 @@
99
use lloc\Msls\Component\Input\Checkbox;
1010
use lloc\Msls\Component\Input\Group;
1111
use lloc\Msls\Component\Input\Label;
12-
use lloc\Msls\Component\Input\Text;
1312
use lloc\Msls\Component\Input\Select;
13+
use lloc\Msls\Component\Input\Text;
14+
use lloc\Msls\Link\Link;
15+
use lloc\Msls\Plugin;
16+
use lloc\Msls\Registry\Registry;
1417
use WP_Post_Type;
1518

1619
/**
@@ -30,7 +33,7 @@
3033
*
3134
* @package Msls
3235
*/
33-
final class MslsAdmin extends MslsMain {
36+
final class Admin extends Main {
3437

3538
const MSLS_REGISTER_ACTION = 'msls_admin_register';
3639

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

54-
MslsRegistry::set_object( __CLASS__, $obj );
57+
Registry::set_object( __CLASS__, $obj );
5558

5659
/**
5760
* Override the capabilities needed for the plugin's settings
@@ -171,7 +174,7 @@ public function has_problems(): void {
171174
);
172175
}
173176

174-
MslsPlugin::message_handler( $message, 'updated fade' );
177+
Plugin::message_handler( $message, 'updated fade' );
175178
}
176179

177180
/**
@@ -375,7 +378,7 @@ public function blog_language(): void {
375378
*/
376379
public function display(): void {
377380
// phpcs:ignore WordPress.Security.EscapeOutput
378-
echo ( new Select( 'display', MslsLink::get_types_description(), strval( $this->options->display ) ) )->render();
381+
echo ( new Select( 'display', Link::get_types_description(), strval( $this->options->display ) ) )->render();
379382
}
380383

381384
/**
@@ -385,8 +388,8 @@ public function admin_display(): void {
385388
$select = new Select(
386389
'admin_display',
387390
array(
388-
MslsAdminIcon::TYPE_FLAG => __( 'Flag', 'multisite-language-switcher' ),
389-
MslsAdminIcon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ),
391+
Icon::TYPE_FLAG => __( 'Flag', 'multisite-language-switcher' ),
392+
Icon::TYPE_LABEL => __( 'Label', 'multisite-language-switcher' ),
390393
),
391394
$this->options->get_icon_type()
392395
);
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<?php declare( strict_types=1 );
22

3-
namespace lloc\Msls;
3+
namespace lloc\Msls\Admin;
44

55
if ( ! defined( 'ABSPATH' ) ) {
66
exit;
77
}
88

9-
class MslsAdminBar {
9+
use lloc\Msls\Blog\Blog;
10+
use lloc\Msls\Blog\Collection;
11+
use lloc\Msls\Options\Options;
12+
13+
class Bar {
1014

1115
/**
1216
* @var string
1317
*/
1418
protected string $icon_type;
1519

1620
/**
17-
* @var MslsBlogCollection
21+
* @var Collection
1822
*/
19-
protected MslsBlogCollection $blog_collection;
23+
protected Collection $blog_collection;
2024

2125
/**
22-
* @param MslsOptions $options
23-
* @param MslsBlogCollection $blog_collection
26+
* @param Options $options
27+
* @param Collection $blog_collection
2428
*/
25-
public function __construct( MslsOptions $options, MslsBlogCollection $blog_collection ) {
29+
public function __construct( Options $options, Collection $blog_collection ) {
2630
$this->icon_type = $options->get_icon_type();
2731
$this->blog_collection = $blog_collection;
2832
}
@@ -31,7 +35,7 @@ public function __construct( MslsOptions $options, MslsBlogCollection $blog_coll
3135
* @return void
3236
*/
3337
public static function init(): void {
34-
$obj = new MslsAdminBar( msls_options(), msls_blog_collection() );
38+
$obj = new Bar( msls_options(), msls_blog_collection() );
3539

3640
if ( is_admin_bar_showing() ) {
3741
add_action( 'admin_bar_menu', array( $obj, 'update_admin_bar' ), 999 );
@@ -88,12 +92,12 @@ public function add_node( \WP_Admin_Bar $wp_admin_bar, string $node_id, string $
8892
*
8993
* It uses a blavatar icon as prefix if $blavatar is set to true
9094
*
91-
* @param MslsBlog|null $blog
92-
* @param bool $blavatar
95+
* @param Blog|null $blog
96+
* @param bool $blavatar
9397
*
9498
* @return string|null
9599
*/
96-
protected function get_title( ?MslsBlog $blog, bool $blavatar = false ): ?string {
100+
protected function get_title( ?Blog $blog, bool $blavatar = false ): ?string {
97101
if ( is_null( $blog ) ) {
98102
return $blog;
99103
}

0 commit comments

Comments
 (0)