From 323fd21f77d434bc60010cc269d7e57e786308ba Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 11 Mar 2024 18:17:46 +0100 Subject: [PATCH] wip #6775 @1.5 --- app/Models/ToolWebflow.php | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 7ea8d901f..d3c48c012 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -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(); + } + } -- 2.39.5