From: Vincent Vanwaelscappel Date: Thu, 14 Mar 2024 08:46:43 +0000 (+0100) Subject: wip #6775 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1c05f7d74d73f4730b660069043673dcbeedd0a4;p=fluidbook-toolbox.git wip #6775 @2 --- diff --git a/.env.prod b/.env.prod index 511707f19..81cc9357a 100644 --- a/.env.prod +++ b/.env.prod @@ -71,3 +71,6 @@ TIMEZONE=Europe/Paris VAPID_PUBLIC_KEY=BNtDSMlXpG39rcsC-nwW_wfsVpfnpzGpM6hW3YpPFt1xERu7ux8Ve1BH3nYVE-Y-3VCO_n_WTHk8X4ak6j6gpRA VAPID_PRIVATE_KEY=GYvIMn542hv5XERqkz61aC923Lm76luB5O33jeayjD8 + +WEBFLOW_CLIENT_ID=34e42c1b564bafed681ff256b38525dcdcf9d3b0e8ceff7b052406b992ad9e09 +WEBFLOW_CLIENT_SECRET=3884a44cc09f576428589032182c6b36c6a478e3b477f44749b2a9a7dfbad8db diff --git a/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php b/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php index 13bd22263..2599a7460 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php +++ b/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Operations\Tools; use App\Http\Middleware\CheckIfAdmin; use App\Http\Middleware\VerifyCsrfToken; use App\Models\ToolWebflow; +use App\Services\Webflow; use Illuminate\Support\Facades\Route; trait WebflowOperation @@ -14,6 +15,14 @@ trait WebflowOperation Route::match(['get', 'post'], 'webhook/webflow/{id}', function ($id) { ToolWebflow::withoutGlobalScopes()->find($id)->onPublish('webflow'); })->withoutMiddleware([VerifyCsrfToken::class, CheckIfAdmin::class]); + + Route::match(['get'], 'webflow/auth', function () { + $id = request()->get('state'); + $wf = ToolWebflow::withoutGlobalScopes()->find($id); + $wf->webflow_api_token = Webflow::getToken(request()->get('code')); + $wf->save(); + return redirect(backpack_url('tool-webflow/' . $id . '/edit')); + }); } } diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 3cc4ab05a..58987cefb 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -10,6 +10,7 @@ use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Backpack\Magic\Fields\Table; use Cubist\Backpack\Magic\Fields\Text; +use Cubist\Backpack\Magic\Fields\LinkButton; use Cubist\Backpack\Magic\Fields\Textarea; use Cubist\Util\CommandLine; use Cubist\Util\Files\Files; @@ -38,6 +39,8 @@ class ToolWebflow extends ToolboxModel $this->addField('name', Text::class, __('Projet'), ['column' => true, '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('webflow_api_token', Text::class, __('Token de l\'API Webflow'), ['tab' => __('Paramètres')]); + $this->addField('webflow_api_login', LinkButton::class, __('Récupérer un token'), ['tab' => __('Paramètres'), 'value' => 'https://webflow.com/oauth/authorize?response_type=code&client_id=' . env('WEBFLOW_CLIENT_ID') . '&state=$id&scope=assets%3Aread%20assets%3Awrite%20authorized_user%3Aread%20cms%3Aread%20cms%3Awrite%20custom_code%3Aread%20custom_code%3Awrite%20forms%3Aread%20forms%3Awrite%20pages%3Aread%20pages%3Awrite%20sites%3Aread%20sites%3Awrite']); $this->addField('domains', Textarea::class, __('Domaines à télécharger'), ['tab' => __('Paramètres')]); $this->addField('locales', Table::class, __('Langues'), ['columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]); $this->addField('slack', Text::class, __('Notification slack'), ['tab' => __('Paramètres')]); @@ -56,35 +59,7 @@ class ToolWebflow extends ToolboxModel protected function _parsePages() { - $mirror = $this->getMirrorPath(); - foreach (Files::getRecursiveDirectoryIterator($mirror) as $f) { - /** @var $f \SplFileInfo */ - if ($f->isDir() || $f->getExtension() !== 'html') { - continue; - } - - $relativeURL = str_replace($mirror, '', $f->getPathname()); - - $this->_pages[$relativeURL] = ['title' => '']; - - $html = file_get_contents($f->getPathName()); - $doc = new \DOMDocument(); - $doc->loadHTML($html, LIBXML_NOERROR); - $xpath = new \DOMXpath($doc); - $title = $xpath->query("//title"); - /** @var \DOMElement $e */ - foreach ($title as $e) { - $this->_pages[$relativeURL]['title'] = (string)$e->nodeValue; - } - $img = $xpath->query("//img"); - foreach ($img as $e) { - $src=str_replace('../',$e->getAttribute('src')); - $this->_images[$src] = $e->getAttribute('alt'); - } - - } - dd($this->_images); } public function getLocales() diff --git a/app/Services/Webflow.php b/app/Services/Webflow.php new file mode 100644 index 000000000..cdbf2a7d0 --- /dev/null +++ b/app/Services/Webflow.php @@ -0,0 +1,24 @@ + env('WEBFLOW_CLIENT_ID'), + 'client_secret' => env('WEBFLOW_CLIENT_SECRET'), + 'code' => $code, + 'grant_type' => 'authorization_code', + + ], $data) + ); + + return $response->json()['access_token']; + } +}