]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Mar 2024 11:02:07 +0000 (12:02 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Mar 2024 11:02:07 +0000 (12:02 +0100)
app/Fields/Webflow/WebflowSEO.php [deleted file]
app/Models/ToolWebflow.php
app/Services/Webflow.php
app/SubForms/Webflow/SEOPage.php

diff --git a/app/Fields/Webflow/WebflowSEO.php b/app/Fields/Webflow/WebflowSEO.php
deleted file mode 100644 (file)
index eaf606f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-namespace App\Fields\Webflow;
-
-use Cubist\Backpack\Magic\Fields\Textarea;
-
-class WebflowSEO extends Textarea
-{
-    protected $_adminType = 'webflow.seo';
-    protected $_viewNamespace = 'fields';
-}
index 96660919d826dbe602803f651ff22dd210380b5a..a081b82e2c4da9433dae001d16b949e2bf2f97f2 100644 (file)
@@ -54,8 +54,8 @@ class ToolWebflow extends ToolboxModel
         $this->addField('upload', SelectFromArray::class, __('Uploader sur'), ['options' => $sites, 'tab' => __('Paramètres')]);
         $this->addField('js', Code::class, __('Javascript complémentaire'), ['language' => 'js', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
         $this->addField('css', Code::class, __('CSS complémentaire'), ['language' => 'css', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
-        $this->addField('texts', WebflowTexts::class, '', ['tab' => __('Textes')]);
-        $this->addField('images', WebflowImages::class, '', ['tab' => __('Images')]);
+        $this->addField('texts', WebflowTexts::class, '', ['tab' => __('Textes'), 'translatable' => true]);
+        $this->addField('images', WebflowImages::class, '', ['tab' => __('Images'), 'translatable' => true]);
         $this->addField('seo', BunchOfFieldsMultiple::class, '', ['allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => SEOPage::class, 'tab' => __('SEO')]);
     }
 
@@ -81,6 +81,13 @@ class ToolWebflow extends ToolboxModel
         return parent::onSaved();
     }
 
+    protected function refreshFormDataFromAPI()
+    {
+        $editable = Webflow::getEditableData($this->webflow);
+        $this->seo = $editable['seo'];
+        $this->saveQuietly();
+    }
+
     /**
      * @param $slow bool
      * @param $force bool
@@ -90,7 +97,8 @@ class ToolWebflow extends ToolboxModel
     {
         Webflow::setToken($this->webflow_api_token);
         Webflow::clearCache();
-        Webflow::getAllData($this->webflow);
+        $this->refreshFormDataFromAPI();
+
 
         $path = $this->getMirrorPath();
         if ($force) {
@@ -199,7 +207,7 @@ class ToolWebflow extends ToolboxModel
         }
         Cache::put('webflow_' . $this->id . '_locales', $locales);
         Webflow::setToken($this->webflow_api_token);
-        Webflow::getAllData($this->webflow);
+        $this->refreshFormDataFromAPI();
         return parent::onRetrieved();
     }
 
index c8785df8c72bfaf6e5aa36dc7c07ebdd27ec96ad..5c5a4d85c7afb7f233bd8201ba2f5717678b4c6e 100644 (file)
@@ -78,7 +78,7 @@ class Webflow
         if ($force) {
             Cache::forget($cacheKey);
         }
-        $res = Cache::tags('webflow_' . static::getToken())->remember($cacheKey, $ttl, function () use ($url, $method, $data) {
+        $res = Cache::tags(['webflow_' . static::getToken()])->remember($cacheKey, $ttl, function () use ($url, $method, $data) {
             while (Cache::get('webflow_' . static::getToken() . '_wait', false)) {
                 sleep(1);
             }
@@ -98,7 +98,7 @@ class Webflow
 
     public static function clearCache()
     {
-        return Cache::tags('webflow_' . static::getToken())->flush();
+        return Cache::tags(['webflow_' . static::getToken()])->flush();
     }
 
     public static function listSites()
@@ -115,8 +115,12 @@ class Webflow
         }
     }
 
-    public static function getPageMeta($shortname, $pageID)
+    public static function getPageMeta($shortname, $pageID, $fromAPI = false)
     {
+        if ($fromAPI) {
+            return self::request('pages/' . $pageID);
+
+        }
         foreach (self::listPages($shortname) as $page) {
             if ($page['id'] == $pageID) {
                 return $page;
@@ -133,6 +137,7 @@ class Webflow
                 'contents' => self::getPageContents($page['id'])
             ];
         }
+
         return $res;
     }
 
@@ -193,7 +198,13 @@ class Webflow
 
     public static function listPages($shortname)
     {
-        return self::paginatedRequest('sites/' . self::getSiteId($shortname) . '/pages', 'pages');
+        $res = self::paginatedRequest('sites/' . self::getSiteId($shortname) . '/pages', 'pages');
+        foreach ($res as $page) {
+            if (null !== $page['parentId'] && !isset($res[$page['parentId']])) {
+                $res[$page['parentId']] = self::getPageMeta($shortname, $page['parentId'], true);
+            }
+        }
+        return $res;
     }
 
     public static function listAssets($shortname)
@@ -209,10 +220,30 @@ class Webflow
             $res = ['texts' => [], 'images' => [], 'seo' => []];
             foreach ($data['pages'] as $pageID => $page) {
                 $details = $page['details'];
-                if ($details['archived']) {
-                    continue;
+
+                $url = trim($details['slug']);
+                $c = $page;
+                while (true) {
+                    if (null === $c['details']['parentId']) {
+                        break;
+                    }
+                    $p = $data['pages'][$c['details']['parentId']];
+                    $url = trim($p['details']['slug']) . '/' . $url;
+                    $c = $p;
+                }
+                if (!$url) {
+                    $url = 'index';
                 }
+                $type = isset($details['publishedPath']) ? 'folder' : 'page';
+                if ($type === 'page') {
+                    $url .= '.html';
+                }
+                $url = '/' . $url;
+
+
                 $seo = [
+                    'url' => $url,
+                    'type' => $type,
                     'slug' => $details['slug'],
                     'draft' => $details['draft'],
                     'seo_title' => $details['seo']['title'],
@@ -248,6 +279,18 @@ class Webflow
                 }
 
             }
+
+            uasort($res['seo'], function ($a, $b) {
+                if ($a['url'] === '/index.html') {
+                    return -1000;
+                }
+                if ($b['url'] === '/index.html') {
+                    return 1000;
+                }
+                return strcmp($a['url'], $b['url']);
+            });
+
+
             self::$_editableData[$key] = $res;
         }
         return self::$_editableData[$key];
index 8d8c98b17d335cc56fca9e02e9293029cedae64c..8e982c3d6cf66a54dea3402e44fe8feb667fe077 100644 (file)
@@ -3,6 +3,8 @@
 namespace App\SubForms\Webflow;
 
 use Cubist\Backpack\Magic\Fields\Checkbox;
+use Cubist\Backpack\Magic\Fields\Hidden;
+use Cubist\Backpack\Magic\Fields\StaticValue;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Fields\Textarea;
 use Cubist\Backpack\Magic\SubForm;
@@ -13,13 +15,15 @@ class SEOPage extends SubForm
     {
         parent::init();
 
-        $this->addField('slug', Text::class, __('URL') . ' (' . __('slug') . ')');
-        $this->addField('seo_title', Text::class, __('Titre'));
-        $this->addField('og_title_copied', Checkbox::class, __('Utiliser le titre ci-dessus pour les réseaux sociaux'));
-        $this->addField('og_title', Text::class, __('Titre pour les réseaux sociaux'), ['when' => ['og_title_copied' => false]]);
-        $this->addField('seo_description', Textarea::class, __('Description'));
-        $this->addField('og_description_copied', Checkbox::class, __('Utiliser la description ci-dessus pour les réseaux sociaux'));
-        $this->addField('og_description', Text::class, __('Description pour les réseaux sociaux'), ['when' => ['og_description_copied' => false]]);
+        $this->addField('url', Hidden::class, __('URL'));
+        $this->addField('type', Hidden::class, __('Type'));
+        $this->addField('slug', Text::class, __('Slug') . ' (' . __('slug') . ')', ['when' => ['url' => ['operator' => 'not', 'value' => '/index.html']]]);
+        $this->addField('seo_title', Text::class, __('Titre'), ['when' => ['type' => 'page']]);
+        $this->addField('og_title_copied', Checkbox::class, __('Utiliser le titre ci-dessus pour les réseaux sociaux'), ['when' => ['type' => 'page']]);
+        $this->addField('og_title', Text::class, __('Titre pour les réseaux sociaux'), ['when' => ['og_title_copied' => false, 'type' => 'page']]);
+        $this->addField('seo_description', Textarea::class, __('Description'), ['when' => ['type' => 'page']]);
+        $this->addField('og_description_copied', Checkbox::class, __('Utiliser la description ci-dessus pour les réseaux sociaux'), ['when' => ['type' => 'page']]);
+        $this->addField('og_description', Text::class, __('Description pour les réseaux sociaux'), ['when' => ['og_description_copied' => false, 'type' => 'page']]);
 
     }
 }