]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Mar 2024 10:29:14 +0000 (11:29 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Mar 2024 10:29:14 +0000 (11:29 +0100)
app/Models/ToolWebflow.php
app/Services/Webflow.php
app/SubForms/Webflow/SEOPage.php [new file with mode: 0644]
resources/views/fields/webflow/seo.blade.php

index 9df3b24767c7c99656b59d72cc7d58c97d501f9d..96660919d826dbe602803f651ff22dd210380b5a 100644 (file)
@@ -10,6 +10,8 @@ use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation;
 use App\Jobs\WebflowPublish;
 use App\Models\Base\ToolboxModel;
 use App\Services\Webflow;
+use App\SubForms\Webflow\SEOPage;
+use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
 use Cubist\Backpack\Magic\Fields\Code;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Fields\Table;
@@ -33,10 +35,6 @@ class ToolWebflow extends ToolboxModel
 
     protected $_operations = [WebflowOperation::class];
 
-    protected $_pages = [];
-    protected $_texts = [];
-    protected $_images = [];
-
     public function setFields()
     {
         parent::setFields();
@@ -58,7 +56,7 @@ class ToolWebflow extends ToolboxModel
         $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('seo', WebflowSEO::class, '', ['tab' => __('SEO')]);
+        $this->addField('seo', BunchOfFieldsMultiple::class, '', ['allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => SEOPage::class, 'tab' => __('SEO')]);
     }
 
     protected function _parsePages()
@@ -205,4 +203,10 @@ class ToolWebflow extends ToolboxModel
         return parent::onRetrieved();
     }
 
+    public function getEditableData()
+    {
+        Webflow::setToken($this->webflow_api_token);
+        return Webflow::getEditableData($this->webflow);
+    }
+
 }
index 148434ab92dbe2a9bb6e7d6513ba096ddc00f019..c8785df8c72bfaf6e5aa36dc7c07ebdd27ec96ad 100644 (file)
@@ -4,11 +4,9 @@ namespace App\Services;
 
 
 use App\Services\Webflow\Excel;
-use hollodotme\FastCGI\Requests\GetRequest;
 use Illuminate\Http\Client\Response;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Http;
-use function Symfony\Component\String\b;
 
 class Webflow
 {
@@ -17,6 +15,9 @@ class Webflow
 
     protected static $_token = null;
 
+    protected static $_allData = [];
+    protected static $_editableData = [];
+
     public static function setToken($token)
     {
         self::$_token = $token;
@@ -150,7 +151,15 @@ class Webflow
 
     public static function getAllData($shortname)
     {
-        return ['pages' => self::getAllPagesContents($shortname), 'cms' => self::getAllCMSContents($shortname), 'assets' => self::listAssets($shortname)];
+        $key = self::getToken() . '_' . $shortname;
+        if (!isset(self::$_allData[$key])) {
+            self::$_allData[$key] = [
+                'pages' => self::getAllPagesContents($shortname),
+                'cms' => self::getAllCMSContents($shortname),
+                'assets' => self::listAssets($shortname)
+            ];
+        }
+        return self::$_allData[$key];
     }
 
     public static function getCMSCollectionDetails($collectionID)
@@ -194,50 +203,53 @@ class Webflow
 
     public static function getEditableData($shortname)
     {
-        $data = self::getAllData($shortname);
-
-        $res = ['texts' => [], 'images' => [], 'seo' => []];
-        foreach ($data['pages'] as $pageID => $page) {
-            $details = $page['details'];
-            if ($details['archived']) {
-                continue;
-            }
-            $seo = [
-                'slug' => $details['slug'],
-                'draft' => $details['draft'],
-                'seo_title' => $details['seo']['title'],
-                'seo_description' => $details['seo']['description'],
-                'og_title' => $details['openGraph']['title'],
-                'og_description' => $details['openGraph']['description'],
-                'og_title_copied' => $details['openGraph']['titleCopied'],
-                'og_description_copied' => $details['openGraph']['descriptionCopied'],
-            ];
-
-            $res['seo'][$pageID] = $seo;
-
-            $texts = [];
-            foreach ($page['contents'] as $node) {
-                if ($node['type'] === 'text') {
-                    if (!$node['text']['text']) {
-                        continue;
-                    }
-                    if (!isset($res['texts'][$node['text']['text']])) {
-                        $res['texts'][$node['text']['text']] = [];
-                    }
-                    $res['texts'][$node['text']['text']][] = ['node' => $node['id'], 'page' => $pageID];
-                } else if ($node['type'] === 'image') {
-                    if(!isset($node['image']['assetId'])){
-                        continue;
-                    }
-                    $assetId = $node['image']['assetId'];
-                    if (isset($res['images'][$assetId])) {
-                        continue;
+        $key = self::getToken() . '_' . $shortname;
+        if (!isset(self::$_editableData[$key])) {
+            $data = self::getAllData($shortname);
+            $res = ['texts' => [], 'images' => [], 'seo' => []];
+            foreach ($data['pages'] as $pageID => $page) {
+                $details = $page['details'];
+                if ($details['archived']) {
+                    continue;
+                }
+                $seo = [
+                    'slug' => $details['slug'],
+                    'draft' => $details['draft'],
+                    'seo_title' => $details['seo']['title'],
+                    'seo_description' => $details['seo']['description'],
+                    'og_title' => $details['openGraph']['title'],
+                    'og_description' => $details['openGraph']['description'],
+                    'og_title_copied' => $details['openGraph']['titleCopied'],
+                    'og_description_copied' => $details['openGraph']['descriptionCopied'],
+                ];
+
+                $res['seo'][$pageID] = $seo;
+
+                $texts = [];
+                foreach ($page['contents'] as $node) {
+                    if ($node['type'] === 'text') {
+                        if (!$node['text']['text']) {
+                            continue;
+                        }
+                        if (!isset($res['texts'][$node['text']['text']])) {
+                            $res['texts'][$node['text']['text']] = [];
+                        }
+                        $res['texts'][$node['text']['text']][] = ['node' => $node['id'], 'page' => $pageID];
+                    } else if ($node['type'] === 'image') {
+                        if (!isset($node['image']['assetId'])) {
+                            continue;
+                        }
+                        $assetId = $node['image']['assetId'];
+                        if (isset($res['images'][$assetId])) {
+                            continue;
+                        }
+                        $res['images'][$assetId] = ['alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']];
                     }
-                    $res['images'][$assetId] = ['alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']];
                 }
-            }
 
+            }
+            self::$_editableData[$key] = $res;
         }
-        return $res;
+        return self::$_editableData[$key];
     }
 }
diff --git a/app/SubForms/Webflow/SEOPage.php b/app/SubForms/Webflow/SEOPage.php
new file mode 100644 (file)
index 0000000..8d8c98b
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\SubForms\Webflow;
+
+use Cubist\Backpack\Magic\Fields\Checkbox;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\Textarea;
+use Cubist\Backpack\Magic\SubForm;
+
+class SEOPage extends SubForm
+{
+    public function init()
+    {
+        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]]);
+
+    }
+}
index 854492ad71551d4d4ba09f47f40194dab207de0f..1a2b4b19a1349c76fbbf7714cb8f8bbdf9a4c9a9 100644 (file)
@@ -1 +1,24 @@
-seo :)
+@php
+    $data=$entry->getEditableData()['seo'];
+    $fields=[
+        'slug'=>['label'=>'URL','type'=>'text']
+    ,'seo_title','seo_description']
+@endphp
+@include('crud::fields.inc.wrapper_start')
+<ul style="position: sticky;top:0px;">
+    @foreach($data as $id=>$page)
+        <li>
+            <a href="#" data-id="{{$id}}">{{$page['slug']?:'index'}}</a>
+        </li>
+        @push('seo_forms')
+            <div class="seo_page" id="seo_page_{{$id}}">
+                @foreach($fields as $name=>$f)
+
+                @endforeach
+            </div>
+        @endpush
+    @endforeach
+</ul>
+@stack('seo_forms')
+
+@include('crud::fields.inc.wrapper_end')