From 51afe2babf40669c55253c1b5403f97d51d0d2f2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 19 Jul 2024 20:31:56 +0200 Subject: [PATCH] wait #7014 @4 --- app/Jobs/FluidbookImagesPreprocess.php | 2 +- app/Models/ToolWebflow.php | 51 ++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/Jobs/FluidbookImagesPreprocess.php b/app/Jobs/FluidbookImagesPreprocess.php index d26f0f7c5..ab027f7d9 100644 --- a/app/Jobs/FluidbookImagesPreprocess.php +++ b/app/Jobs/FluidbookImagesPreprocess.php @@ -119,7 +119,7 @@ class FluidbookImagesPreprocess extends Base if ($job->isError()) { Log::error('This file failed ' . $job->getPath()); } - Log::error('This file is stuck ' . $job->getPath()); + //Log::error('This file is stuck ' . $job->getPath()); } return true; } diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 35c02a545..7329eac7d 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -43,6 +43,8 @@ class ToolWebflow extends ToolboxTranslatableModel protected $_translationsForCompilation = []; + protected $_urlMaps = null; + public function setFields() { parent::setFields(); @@ -416,7 +418,7 @@ class ToolWebflow extends ToolboxTranslatableModel { $code = '$(".w-webflow-badge").remove();' . "\n"; foreach ($this->getLocales() as $locale) { - $code .= '$("a#switch-' . $locale['locale'] . '").attr("href","https://' . $locale['url'] . '");' . "\n"; + $code .= 'if($("html").attr("lang")=="' . $locale['locale'] . '"){$("a#switch-' . $locale['locale'] . '").attr("href",null).attr("nohref","");}else{$("a#switch-' . $locale['locale'] . '").attr("href",SWITCH_URL_' . $locale['locale'] . ');}' . "\n"; } $js = '$(function(){' . $code . '});'; @@ -479,9 +481,13 @@ class ToolWebflow extends ToolboxTranslatableModel * @param $locale string * @return void */ - protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo, $urlmap) + protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo) { + $urlmaps = $this->getURLMaps(); + $urlmap = $urlmaps[$locale]; + $origRelative = $relative; + $html = file_get_contents($f->getPathname()); $regex = '/("https:\/\/' . $this->webflow . '.webflow.io\/\\\\")(.*)(\\\\"")/'; $html = preg_replace($regex, '\"$2\"', $html); @@ -500,8 +506,25 @@ class ToolWebflow extends ToolboxTranslatableModel } } + // Replace URL + foreach ($urlmap as $k => $v) { + $html = str_replace(ltrim($k, '/'), ltrim($v, '/'), $html); + } + + + $localeURL = ""; + $html = str_replace('', '' . "\n" . '', $html); - $html = str_replace('', '' . "\n" . '', $html); + $html = str_replace('', $localeURL . '' . "\n" . '', $html); $html = preg_replace('/\s+lang=\"[a-zA-Z\-_]{2,6}\"/', ' lang="' . $locale . '"', $html); @@ -512,11 +535,6 @@ class ToolWebflow extends ToolboxTranslatableModel // Images - // Replace URL - foreach ($urlmap as $k => $v) { - $html = str_replace(ltrim($k, '/'), ltrim($v, '/'), $html); - } - // SEO if (!$isMainLocale || $htmlPage) { foreach ($seo as $s) { @@ -546,7 +564,24 @@ class ToolWebflow extends ToolboxTranslatableModel file_put_contents($dest . ($urlmap[$relative] ?? $relative), $html); } + public function getURLMaps() + { + + if (null === $this->_urlMaps) { + $this->_urlMaps = []; + foreach ($this->getLocalesCodes() as $locale) { + $this->_urlMaps[$locale] = $this->_getURLMap($locale); + } + } + return $this->_urlMaps; + } + public function getURLMap($locale) + { + return $this->getURLMaps()[$locale]; + } + + protected function _getURLMap($locale) { if ($locale === $this->getMainLocale()) { return []; -- 2.39.5