]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Mar 2024 08:46:43 +0000 (09:46 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Mar 2024 08:46:43 +0000 (09:46 +0100)
.env.prod
app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php
app/Models/ToolWebflow.php
app/Services/Webflow.php [new file with mode: 0644]

index 511707f1954c3b13f69957ce43ebe07b62391d17..81cc9357a1292f17b3055054ec6a6e6b585cd2dc 100644 (file)
--- 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
index 13bd222639a698f2f5cc300185cfcdf02e09b3f3..2599a746000851be2afa1fd3ecc306069764600e 100644 (file)
@@ -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'));
+        });
     }
 
 }
index 3cc4ab05a5f48d5864150ee3184bdf736957cb56..58987cefb9b6756632725f87b5b668a03a89a2a9 100644 (file)
@@ -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 (file)
index 0000000..cdbf2a7
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Services;
+
+use Illuminate\Support\Facades\Http;
+
+class Webflow
+{
+    public static function getToken($code, $data = [])
+    {
+        $response = Http::post('https://api.webflow.com/oauth/access_token',
+            array_merge(
+                [
+                    'client_id' => env('WEBFLOW_CLIENT_ID'),
+                    'client_secret' => env('WEBFLOW_CLIENT_SECRET'),
+                    'code' => $code,
+                    'grant_type' => 'authorization_code',
+
+                ], $data)
+        );
+
+        return $response->json()['access_token'];
+    }
+}