From f2b657baeb8e7c29ab0ad12d8f54be89ec64f4c6 Mon Sep 17 00:00:00 2001 From: Tam Date: Fri, 18 Aug 2023 11:32:02 +0100 Subject: [PATCH] Fixed absolute URL including token query parameter Fixes #457 --- CHANGELOG.md | 5 +++++ src/models/data/SeoData.php | 14 ++++++++++++++ src/templates/_seo/meta.twig | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edbe635..26401d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.2.0 - 2023-08-18 +### Fixed +- Fixed absolute URL including token query parameter (Fixes #457) +- Fixed error on Shopify plugin products (#456 via @ttempleton) + ## 4.1.2 - 2023-05-15 ### Fixed - Fix robots always injecting no-index (Fixes #432) diff --git a/src/models/data/SeoData.php b/src/models/data/SeoData.php index eb413b1..69dcfe8 100644 --- a/src/models/data/SeoData.php +++ b/src/models/data/SeoData.php @@ -383,6 +383,20 @@ public function getCanonical () return UrlHelper::siteUrl($this->advanced['canonical']); } + public function getAbsolute () + { + $url = Craft::$app->getRequest()->getAbsoluteUrl(); + $query = parse_url($url, PHP_URL_QUERY); + parse_str($query, $parts); + + if (empty($parts)) return $url; + + // Remove token param + unset($parts['token']); + + return preg_replace('/\?([^#]*)/m', '?' . http_build_query($parts), $url); + } + // Helpers // ========================================================================= diff --git a/src/templates/_seo/meta.twig b/src/templates/_seo/meta.twig index a5dad32..7716336 100644 --- a/src/templates/_seo/meta.twig +++ b/src/templates/_seo/meta.twig @@ -13,7 +13,7 @@ {% set fb = seo.social.facebook -%} - + @@ -29,7 +29,7 @@ {% set tw = seo.social.twitter -%} - +