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;
protected $_operations = [WebflowOperation::class];
- protected $_pages = [];
- protected $_texts = [];
- protected $_images = [];
-
public function setFields()
{
parent::setFields();
$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()
return parent::onRetrieved();
}
+ public function getEditableData()
+ {
+ Webflow::setToken($this->webflow_api_token);
+ return Webflow::getEditableData($this->webflow);
+ }
+
}
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
{
protected static $_token = null;
+ protected static $_allData = [];
+ protected static $_editableData = [];
+
public static function setToken($token)
{
self::$_token = $token;
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)
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];
}
}
--- /dev/null
+<?php
+
+namespace App\SubForms\Webflow;
+
+use Cubist\Backpack\Magic\Fields\Checkbox;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\Textarea;
+use Cubist\Backpack\Magic\SubForm;
+
+class SEOPage extends SubForm
+{
+ public function init()
+ {
+ parent::init();
+
+ $this->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]]);
+
+ }
+}