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
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'));
+ });
}
}
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;
$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')]);
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()
--- /dev/null
+<?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'];
+ }
+}