From 6d8ca3f6084f00e87923254a4dd8bc60566623d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81onard=20Phoumpakka?= Date: Thu, 12 Nov 2020 09:25:41 +0100 Subject: [PATCH 1/4] replace domain only for current site --- mercator-domain-replacements.php | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mercator-domain-replacements.php b/mercator-domain-replacements.php index 27735d9..37746c4 100644 --- a/mercator-domain-replacements.php +++ b/mercator-domain-replacements.php @@ -32,7 +32,7 @@ class Mapping { /** @var array $domains */ - private $domains = array(); + private $domains = []; /** * Mapping constructor. @@ -78,13 +78,19 @@ public function translate_network_url() { return; } - $domain_internal = untrailingslashit( 'https://' . $current_network->domain . $current_network->path ); - $domain_mapped = mangle_url( untrailingslashit( $current_site->siteurl ), '', '', $current_site->id ); - if ( $domain_internal === $domain_mapped ) { - return; + $network_domain_internal = untrailingslashit( 'https://' . $current_network->domain . $current_network->path ); + $domain_internal = untrailingslashit( 'https://' . $current_site->domain . $current_site->path ); + $domain_mapped = mangle_url( untrailingslashit( $current_site->siteurl ), '', '', $current_site->id ); + + // Site domain URL + if ( $domain_internal !== $domain_mapped ) { + $this->domains[ $domain_internal ] = $domain_mapped; } - $this->domains[ $domain_internal ] = $domain_mapped; + // Network domain URL + if ( $network_domain_internal !== $domain_mapped ) { + $this->domains[ $network_domain_internal . '/content/uploads/' ] = $domain_mapped . '/content/uploads/'; + } } /** @@ -92,13 +98,13 @@ public function translate_network_url() { */ public function translate_sites_url() { $site_query = new \WP_Site_Query( - array( + [ 'fields' => 'ids', 'number' => 500, 'public' => '1', 'order' => 'ASC', 'orderby' => 'id', - ) + ] ); $sites = $site_query->get_sites(); @@ -148,10 +154,10 @@ public function translate_sites_url() { * https://monsite.com > https://mondomain.com * https:\/\/monsite.com > https:\/\/mondomain.com localized in JS * - * @return string - * * @param string $buffer * + * @return string + * * @author Alexandre Sadowski */ public function replace_urls( $buffer ) { @@ -177,10 +183,10 @@ public function replace_urls( $buffer ) { /** * Add backslashes for JS * - * @return string|string[] - * * @param string $content * + * @return string|string[] + * * @author Alexandre Sadowski */ private function replace_slashes( $content ) { @@ -190,10 +196,10 @@ private function replace_slashes( $content ) { /** * Transform also URL with ://, without defined scheme * - * @return string|string[] - * * @param string $content * + * @return string|string[] + * * @author Alexandre Sadowski */ private function replace_scheme( $content ) { From ccda18b9b9c02a2e7cc81f6bc4210994f5ef5ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81onard=20Phoumpakka?= Date: Fri, 13 Nov 2020 08:50:32 +0100 Subject: [PATCH 2/4] replace static upload dir by upload_dir() --- mercator-domain-replacements.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mercator-domain-replacements.php b/mercator-domain-replacements.php index 37746c4..5d1ebd1 100644 --- a/mercator-domain-replacements.php +++ b/mercator-domain-replacements.php @@ -1,7 +1,7 @@ domains[ $network_domain_internal . '/content/uploads/' ] = $domain_mapped . '/content/uploads/'; + $upload_mapped_url = wp_upload_dir()['baseurl']; + $upload_path = str_replace( $domain_mapped, '', $upload_mapped_url ); + $this->domains[ $network_domain_internal . $upload_path ] = $domain_mapped . $upload_path; } } From dab28b2468fa4a735337bd8a49ec679aba84490b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81onard=20Phoumpakka?= Date: Tue, 17 Nov 2020 10:51:38 +0100 Subject: [PATCH 3/4] fix psalm errors --- mercator-domain-replacements.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mercator-domain-replacements.php b/mercator-domain-replacements.php index 5d1ebd1..e53e657 100644 --- a/mercator-domain-replacements.php +++ b/mercator-domain-replacements.php @@ -131,7 +131,7 @@ public function translate_sites_url() { $domain_internal = untrailingslashit( $current_site->siteurl ); foreach ( $mappings as $mapping ) { - /** @var $mapping \Mercator\Mapping */ + /** @var \Mercator\Mapping $mapping */ if ( ! $mapping->is_active() ) { continue; } @@ -187,7 +187,7 @@ public function replace_urls( $buffer ) { * * @param string $content * - * @return string|string[] + * @return string * * @author Alexandre Sadowski */ @@ -200,7 +200,7 @@ private function replace_slashes( $content ) { * * @param string $content * - * @return string|string[] + * @return string * * @author Alexandre Sadowski */ From 511c7b6c6941c018d4131146347cd6f88eabeb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81onard=20Phoumpakka?= Date: Tue, 17 Nov 2020 11:17:59 +0100 Subject: [PATCH 4/4] add changelog --- README.md | 6 ++++++ mercator-domain-replacements.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index afd7493..4222d03 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,9 @@ If you really like what we do or want to thank us for our quick work, feel free ## License Mercator Domain Replacements is licensed under the [GPLv3 or later](LICENSE.md). + +## Changelog + +### 1.0.2 + +* Fixed: replace by active current mapped domain only for current sub-site (not use the network domain) \ No newline at end of file diff --git a/mercator-domain-replacements.php b/mercator-domain-replacements.php index e53e657..2d7ee45 100644 --- a/mercator-domain-replacements.php +++ b/mercator-domain-replacements.php @@ -1,7 +1,7 @@