]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 11 Mar 2024 17:17:46 +0000 (18:17 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 11 Mar 2024 17:17:46 +0000 (18:17 +0100)
app/Models/ToolWebflow.php

index 7ea8d901f9ee26d3f235e2ac1b48456876ca607e..d3c48c0129573a82dee8e1c015310f9e37d9165a 100644 (file)
@@ -7,6 +7,9 @@ use App\Models\Base\ToolboxModel;
 use Cubist\Backpack\Magic\Fields\Table;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Fields\URL;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Cache;
 
 // __('!! Outils')
 class ToolWebflow extends ToolboxModel
@@ -26,11 +29,56 @@ class ToolWebflow extends ToolboxModel
         parent::setFields();
 
         $this->addField('name', Text::class, __('Projet'), ['column' => true, 'tab' => __('Paramètres')]);
-        $this->addField('webflow', URL::class, __('URL du projet webflow'), ['column' => true, 'hint' => __('ex : :url', ['url' => 'https://projet.webflow.io']), 'tab' => __('Paramètres')]);
+        $this->addField('webflow', Text::class, __('URL du projet webflow'), ['prefix' => 'https://', 'suffix' => '.webflow.io', 'column' => true, 'hint' => __('ex : :url', ['url' => 'https://projet.webflow.io']), 'tab' => __('Paramètres')]);
         $this->addField('locales', Table::class, __('Langues'), ['columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]);
         //$this->addField('texts');
         //$this->addField('images');
         //$this->addField('seo');
     }
 
+    public function getLocales()
+    {
+        return Cache::get('webflow_' . $this->id . '_locales', []);
+    }
+
+    public function mirror($slow = true)
+    {
+        $path = Files::mkdir(protected_path('webflow/' . $this->id));
+        $wget = new CommandLine('wget');
+        $wget->setArg('mirror');
+        $wget->setArg('convert-links');
+        $wget->setArg('adjust-extension');
+        $wget->setArg('page-requisites');
+        $wget->setArg('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0');
+        $wget->setArg("directory-prefix", $path);
+        $wget->setArg("span-hosts");
+        if ($slow) {
+            $wget->setArg("w", 10);
+            $wget->setArg("random-wait");
+        }
+        $domains = [$this->webflow . '.webflow.io',
+            'assets-global.website-files.com',
+            'cdn.jsdelivr.net',
+            'unpkg.com',
+            'cdnjs.cloudflare.com',
+            'ajax.googleapis.com',
+        ];
+        $wget->setArg("domains", implode(',', $domains));
+        $wget->setArg("compression", 'auto');
+        $wget->setArg(null, 'https://' . $this->webflow . '.webflow.io');
+        $wget->execute();
+
+    }
+
+    protected function _parseHtml()
+    {
+
+    }
+
+    public function onRetrieved(): bool
+    {
+        Cache::put('webflow_' . $this->id . '_locales', $this->locales);
+        return parent::onRetrieved();
+    }
+
 }