From 8b0882da89f8f0e97277d0ed5049256583ce8f21 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 21 Aug 2023 16:00:17 +0200 Subject: [PATCH] wip #6201 @0:20 --- app/Fluidbook/Compiler/Compiler.php | 34 ++++--------------- app/Fluidbook/SEO/Page.php | 4 +-- app/Fluidbook/SocialImage.php | 9 +++-- .../Services/SocialImageOperation.php | 6 ++-- 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 946bac89d..ac94eb277 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -1064,7 +1064,7 @@ class Compiler extends Base implements CompilerInterface $dim = SocialImage::getSocialImageSize($this->getFluidbook()); if ($dim) { - $socialImage = backpack_url('services/socialimage/' . $this->getFluidbook()->cid . '/' . time()); + $socialImage = SocialImage::socialImageURL($this->getFluidbook()->cid); $socialImageWidth = $dim[0]; $socialImageHeight = $dim[1]; @@ -1238,27 +1238,6 @@ class Compiler extends Base implements CompilerInterface } } - protected function writeWidget() - { - // Write widget html -// if ($this->widget) { -// $whtml = file_get_contents($this->assets . '/widget.html'); -// $script = ''; -// $script .= ''; -// -// $style = ''; -// $vars = array('titre', 'style', 'script'); -// foreach ($vars as $v) { -// if (isset($$v)) { -// $whtml = str_replace('', $$v, $whtml); -// } else { -// $whtml = str_replace('', '', $whtml); -// } -// } -// $this->vdir->file_put_contents('widget.html', $whtml); -// } - } - function writeSEO() { foreach ($this->seoArticles as $seoArticle) { @@ -1269,13 +1248,12 @@ class Compiler extends Base implements CompilerInterface } $a = $seoArticle; unset($a['image']); - $a['imageurl'] = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->getFluidbook()->cid . '&j=' . time(); - if ($seoArticle['image']) { - $a['imageurl'] .= '&image=' . $seoArticle['image']; + $a['imageurl'] = SocialImage::socialImageURL($this->getFluidbook()->cid, $seoArticle['image']); + $dim = SocialImage::getSocialImageSize($this->getFluidbook(), $seoArticle['image']); + if (null !== $dim) { + $a['imagewidth'] = $dim[0]; + $a['imageheight'] = $dim[1]; } - $dim = Image::getimagesize($a['imageurl']); - $a['imagewidth'] = $dim[0]; - $a['imageheight'] = $dim[1]; foreach ($a as $k => $v) { $html = str_replace('$' . $k, $v, $html); } diff --git a/app/Fluidbook/SEO/Page.php b/app/Fluidbook/SEO/Page.php index 1a5d1e084..af941e4d6 100644 --- a/app/Fluidbook/SEO/Page.php +++ b/app/Fluidbook/SEO/Page.php @@ -40,10 +40,10 @@ class Page if (!$this->canonical) { $this->canonical = $this->getURL(); } - if (!$this->next && isset($this->_container->pages[$this->page + 1]) && $this->_container->pages[$this->page + 1] instanceof wsHTML5SeoPage) { + if (!$this->next && isset($this->_container->pages[$this->page + 1]) && $this->_container->pages[$this->page + 1] instanceof Page) { $this->next = $this->_container->pages[$this->page + 1]->getURL(); } - if (!$this->prev && isset($this->_container->pages[$this->page - 1]) && $this->_container->pages[$this->page - 1] instanceof wsHTML5SeoPage) { + if (!$this->prev && isset($this->_container->pages[$this->page - 1]) && $this->_container->pages[$this->page - 1] instanceof Page) { $this->prev = $this->_container->pages[$this->page - 1]->getURL(); } diff --git a/app/Fluidbook/SocialImage.php b/app/Fluidbook/SocialImage.php index dc9052041..0d8f70606 100644 --- a/app/Fluidbook/SocialImage.php +++ b/app/Fluidbook/SocialImage.php @@ -69,9 +69,9 @@ class SocialImage * @return array * @throws \Exception */ - public static function getSocialImageSize($fluidbook) + public static function getSocialImageSize($fluidbook, $image=null) { - $socialImage = self::socialImagePath($fluidbook->id); + $socialImage = self::socialImagePath($fluidbook->id,$image); if (!file_exists($socialImage)) { return null; } @@ -88,4 +88,9 @@ class SocialImage { return Files::mkdir(protected_path('fluidbookpublication/socialimage')) . $id . '.' . $ext; } + + public static function socialImageURL($cid, $image = null) + { + return backpack_url('services/socialimage/' . $cid . '/' . time() . ($image !== null ? '/' . $image : '')); + } } diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/SocialImageOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/SocialImageOperation.php index bc5e6aa92..cb9ae39d1 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/SocialImageOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/SocialImageOperation.php @@ -16,7 +16,7 @@ trait SocialImageOperation protected function setupSocialimageRoutes($segment, $routeName, $controller) { foreach (['services', 's'] as $segment) { - Route::match(['get'], $segment . '/socialimage/{cid?}/{time?}', $controller . '@socialImage')->withoutMiddleware([CheckIfAdmin::class])->name('social_image'); + Route::match(['get'], $segment . '/socialimage/{cid?}/{time?}/{image?}', $controller . '@socialImage')->withoutMiddleware([CheckIfAdmin::class])->name('social_image'); Route::match(['get'], $segment . '/socialimage', $controller . '@ws2SocialImage')->withoutMiddleware([CheckIfAdmin::class]); Route::match(['get'], $segment . '/facebook_thumbnail', $controller . '@ws2SocialImage')->withoutMiddleware([CheckIfAdmin::class]); } @@ -36,13 +36,13 @@ trait SocialImageOperation abort(404); } - public function socialImage($cid = null, $time = null) + public function socialImage($cid = null, $time = null, $image = null) { $publication = FluidbookPublication::where('cid', $cid)->first(); if (null === $publication) { abort(404); } - return $this->_socialImage($publication); + return $this->_socialImage($publication, $image); } /** -- 2.39.5