From: Vincent Vanwaelscappel Date: Fri, 15 Mar 2024 10:29:14 +0000 (+0100) Subject: wip #6775 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=04bf9b6a1c10da73c85d56517adaaff9919968ed;p=fluidbook-toolbox.git wip #6775 @2 --- diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 9df3b2476..96660919d 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -10,6 +10,8 @@ use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation; use App\Jobs\WebflowPublish; use App\Models\Base\ToolboxModel; use App\Services\Webflow; +use App\SubForms\Webflow\SEOPage; +use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple; use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Backpack\Magic\Fields\Table; @@ -33,10 +35,6 @@ class ToolWebflow extends ToolboxModel protected $_operations = [WebflowOperation::class]; - protected $_pages = []; - protected $_texts = []; - protected $_images = []; - public function setFields() { parent::setFields(); @@ -58,7 +56,7 @@ class ToolWebflow extends ToolboxModel $this->addField('css', Code::class, __('CSS complémentaire'), ['language' => 'css', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]); $this->addField('texts', WebflowTexts::class, '', ['tab' => __('Textes')]); $this->addField('images', WebflowImages::class, '', ['tab' => __('Images')]); - $this->addField('seo', WebflowSEO::class, '', ['tab' => __('SEO')]); + $this->addField('seo', BunchOfFieldsMultiple::class, '', ['allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => SEOPage::class, 'tab' => __('SEO')]); } protected function _parsePages() @@ -205,4 +203,10 @@ class ToolWebflow extends ToolboxModel return parent::onRetrieved(); } + public function getEditableData() + { + Webflow::setToken($this->webflow_api_token); + return Webflow::getEditableData($this->webflow); + } + } diff --git a/app/Services/Webflow.php b/app/Services/Webflow.php index 148434ab9..c8785df8c 100644 --- a/app/Services/Webflow.php +++ b/app/Services/Webflow.php @@ -4,11 +4,9 @@ namespace App\Services; use App\Services\Webflow\Excel; -use hollodotme\FastCGI\Requests\GetRequest; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; -use function Symfony\Component\String\b; class Webflow { @@ -17,6 +15,9 @@ class Webflow protected static $_token = null; + protected static $_allData = []; + protected static $_editableData = []; + public static function setToken($token) { self::$_token = $token; @@ -150,7 +151,15 @@ class Webflow public static function getAllData($shortname) { - return ['pages' => self::getAllPagesContents($shortname), 'cms' => self::getAllCMSContents($shortname), 'assets' => self::listAssets($shortname)]; + $key = self::getToken() . '_' . $shortname; + if (!isset(self::$_allData[$key])) { + self::$_allData[$key] = [ + 'pages' => self::getAllPagesContents($shortname), + 'cms' => self::getAllCMSContents($shortname), + 'assets' => self::listAssets($shortname) + ]; + } + return self::$_allData[$key]; } public static function getCMSCollectionDetails($collectionID) @@ -194,50 +203,53 @@ class Webflow public static function getEditableData($shortname) { - $data = self::getAllData($shortname); - - $res = ['texts' => [], 'images' => [], 'seo' => []]; - foreach ($data['pages'] as $pageID => $page) { - $details = $page['details']; - if ($details['archived']) { - continue; - } - $seo = [ - 'slug' => $details['slug'], - 'draft' => $details['draft'], - 'seo_title' => $details['seo']['title'], - 'seo_description' => $details['seo']['description'], - 'og_title' => $details['openGraph']['title'], - 'og_description' => $details['openGraph']['description'], - 'og_title_copied' => $details['openGraph']['titleCopied'], - 'og_description_copied' => $details['openGraph']['descriptionCopied'], - ]; - - $res['seo'][$pageID] = $seo; - - $texts = []; - foreach ($page['contents'] as $node) { - if ($node['type'] === 'text') { - if (!$node['text']['text']) { - continue; - } - if (!isset($res['texts'][$node['text']['text']])) { - $res['texts'][$node['text']['text']] = []; - } - $res['texts'][$node['text']['text']][] = ['node' => $node['id'], 'page' => $pageID]; - } else if ($node['type'] === 'image') { - if(!isset($node['image']['assetId'])){ - continue; - } - $assetId = $node['image']['assetId']; - if (isset($res['images'][$assetId])) { - continue; + $key = self::getToken() . '_' . $shortname; + if (!isset(self::$_editableData[$key])) { + $data = self::getAllData($shortname); + $res = ['texts' => [], 'images' => [], 'seo' => []]; + foreach ($data['pages'] as $pageID => $page) { + $details = $page['details']; + if ($details['archived']) { + continue; + } + $seo = [ + 'slug' => $details['slug'], + 'draft' => $details['draft'], + 'seo_title' => $details['seo']['title'], + 'seo_description' => $details['seo']['description'], + 'og_title' => $details['openGraph']['title'], + 'og_description' => $details['openGraph']['description'], + 'og_title_copied' => $details['openGraph']['titleCopied'], + 'og_description_copied' => $details['openGraph']['descriptionCopied'], + ]; + + $res['seo'][$pageID] = $seo; + + $texts = []; + foreach ($page['contents'] as $node) { + if ($node['type'] === 'text') { + if (!$node['text']['text']) { + continue; + } + if (!isset($res['texts'][$node['text']['text']])) { + $res['texts'][$node['text']['text']] = []; + } + $res['texts'][$node['text']['text']][] = ['node' => $node['id'], 'page' => $pageID]; + } else if ($node['type'] === 'image') { + if (!isset($node['image']['assetId'])) { + continue; + } + $assetId = $node['image']['assetId']; + if (isset($res['images'][$assetId])) { + continue; + } + $res['images'][$assetId] = ['alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']]; } - $res['images'][$assetId] = ['alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']]; } - } + } + self::$_editableData[$key] = $res; } - return $res; + return self::$_editableData[$key]; } } diff --git a/app/SubForms/Webflow/SEOPage.php b/app/SubForms/Webflow/SEOPage.php new file mode 100644 index 000000000..8d8c98b17 --- /dev/null +++ b/app/SubForms/Webflow/SEOPage.php @@ -0,0 +1,25 @@ +addField('slug', Text::class, __('URL') . ' (' . __('slug') . ')'); + $this->addField('seo_title', Text::class, __('Titre')); + $this->addField('og_title_copied', Checkbox::class, __('Utiliser le titre ci-dessus pour les réseaux sociaux')); + $this->addField('og_title', Text::class, __('Titre pour les réseaux sociaux'), ['when' => ['og_title_copied' => false]]); + $this->addField('seo_description', Textarea::class, __('Description')); + $this->addField('og_description_copied', Checkbox::class, __('Utiliser la description ci-dessus pour les réseaux sociaux')); + $this->addField('og_description', Text::class, __('Description pour les réseaux sociaux'), ['when' => ['og_description_copied' => false]]); + + } +} diff --git a/resources/views/fields/webflow/seo.blade.php b/resources/views/fields/webflow/seo.blade.php index 854492ad7..1a2b4b19a 100644 --- a/resources/views/fields/webflow/seo.blade.php +++ b/resources/views/fields/webflow/seo.blade.php @@ -1 +1,24 @@ -seo :) +@php + $data=$entry->getEditableData()['seo']; + $fields=[ + 'slug'=>['label'=>'URL','type'=>'text'] + ,'seo_title','seo_description'] +@endphp +@include('crud::fields.inc.wrapper_start') + +@stack('seo_forms') + +@include('crud::fields.inc.wrapper_end')