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
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();
+ }
+
}