]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6201 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Aug 2023 14:00:17 +0000 (16:00 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Aug 2023 14:00:17 +0000 (16:00 +0200)
app/Fluidbook/Compiler/Compiler.php
app/Fluidbook/SEO/Page.php
app/Fluidbook/SocialImage.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/SocialImageOperation.php

index 946bac89dfa36a8addb6b5e61ff307fb1a6c0ecc..ac94eb27757782cf81e7e796985dfe4567334a17 100644 (file)
@@ -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 type="text/javascript" charset="utf-8" src="data/datas.js"></script>';
-//            $script .= '<script type="text/javascript" charset="utf-8" src="data/widget.js"></script>';
-//
-//            $style = '<link type="text/css" rel="stylesheet" href="style/widget.css">';
-//            $vars = array('titre', 'style', 'script');
-//            foreach ($vars as $v) {
-//                if (isset($$v)) {
-//                    $whtml = str_replace('<!-- $' . $v . ' -->', $$v, $whtml);
-//                } else {
-//                    $whtml = str_replace('<!-- $' . $v . ' -->', '', $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);
             }
index 1a5d1e0840d3350f38ff1ec3f18b0d0fd0ef5c43..af941e4d6c131972ae377bc9f96c9641010cf880 100644 (file)
@@ -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();
         }
 
index dc9052041192d987c0fbd90962d20a86db8615dc..0d8f70606c38c50689c85013c1c328abee89f2fb 100644 (file)
@@ -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 : ''));
+    }
 }
index bc5e6aa924d5e4b680de5aa09ad06df38b98240f..cb9ae39d108a5d400b8b23ea2f2bb34b861b661c 100644 (file)
@@ -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);
     }
 
     /**