public function handle()
{
- start_measure('Webflow Publish '.$this->id.' '.$this->mode);
+ start_measure('Webflow Publish ' . $this->id . ' ' . $this->mode);
/** @var ToolWebflow $wf */
$wf = ToolWebflow::withoutGlobalScopes()->find($this->id);
$subject = __('Site :name publié', ['name' => $wf->name]);
- if ($this->mode === 'webflow') {
+ $notify = true;
+ if ($this->mode === 'webflow' && $wf->webflow_refresh_on_publish) {
$wf->refreshFormDataFromAPI();
$wf->mirror(false);
$text = __('Le site vient d\'être républié suite à une mise à jour de webflow');
$text = __('Le site vient d\'être républié suite à une mise à jour des contenus');
} else {
$text = __('Le site vient d\'être républié suite à une déclenchement manuel');
+ $notify=false;
}
$wf->compile();
foreach ($wf->getLocales() as $locale) {
$actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url'];
}
- if ($this->user === null) {
- // Slack::send($wf->slack, $subject, $text, $actions, false);
- } else {
- $this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
+ if ($notify) {
+ if ($this->user === null) {
+ Slack::send($wf->slack, $subject, $text, $actions, false);
+ } else {
+ $this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
+ }
}
- stop_measure('Webflow Publish '.$this->id.' '.$this->mode);
+ stop_measure('Webflow Publish ' . $this->id . ' ' . $this->mode);
}
}
use App\SubForms\Webflow\SEOPage;
use Cubist\Azure\Translate\Api;
use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
+use Cubist\Backpack\Magic\Fields\Checkbox;
use Cubist\Backpack\Magic\Fields\Code;
use Cubist\Backpack\Magic\Fields\Hidden;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
protected $_operations = [WebflowOperation::class];
+ protected $_translationsForCompilation = [];
+
public function setFields()
{
parent::setFields();
$this->addField('webflow', Text::class, __('URL du projet webflow'), ['translatable' => false, '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'), ['translatable' => false, 'tab' => __('Paramètres')]);
$this->addField('webflow_api_login', LinkButton::class, __('Récupérer un token'), ['translatable' => false, 'when' => ["webflow_api_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('webflow_refresh_on_publish', Checkbox::class, __('Recharger tous les contenus lors de la publication sur Webflow'), ['default' => true, 'tab' => __('Paramètres')]);
+ $this->addField('publish_on_save', Checkbox::class, __('Publier le site lors de la modification de contenus'), ['default' => true, 'tab' => __('Paramètres')]);
$this->addField('domains', Textarea::class, __('Domaines à télécharger'), ['translatable' => false, 'tab' => __('Paramètres')]);
$this->addField('locales_domains', Table::class, __('Langues'), ['translatable' => false, 'columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]);
$this->addField('slack', Text::class, __('Notification slack'), ['translatable' => false, 'tab' => __('Paramètres')]);
public function onSaved(): bool
{
- $this->onPublish('auto');
+ if ($this->publish_on_save) {
+ $this->onPublish('auto');
+ }
return parent::onSaved();
}
'ajax.googleapis.com',
'uploads-ssl.webflow.com',
'uploads.webflow.com',
+ 'cdn.prod.website-files.com',
+ 'cdn.embedly.com',
] + \Cubist\Util\Text::splitLines($this->domains));
$wget->setArg("domains", implode(',', $domains));
protected function getCustomCSS()
{
- $css = '';
+ $css = '.w-webflow-badge{display:none !important;}';
return $css . "\n\n" . $this->css;
}
protected function getCustomJS()
{
- $js = '';
+ $code = '$(".w-webflow-badge").remove();' . "\n";
+ foreach ($this->getLocales() as $locale) {
+ $code .= '$("a#switch-' . $locale['locale'] . '").attr("href","https://' . $locale['url'] . '");' . "\n";
+ }
+
+ $js = '$(function(){' . $code . '});';
return $js . ";\n\n" . $this->js;
}
$html = str_replace('</head>', '<link href="/css/custom.css" rel="stylesheet">' . "\n" . '</head>', $html);
$html = str_replace('</body>', '<script src="/js/custom.js"></script>' . "\n" . '</body>', $html);
+ $html = preg_replace('/lang=\"[a-zA-Z\-_]{2,6}\"/', 'lang="' . $locale . '"', $html);
+
+ // Texts
+ $texts = $this->getTextTranslationsForCompilation($locale);
+ foreach ($texts as $text => $translation) {
+ $html = str_replace($text, $translation, $html);
+ }
+
+ // Images
+ $images = $this->getTranslation('images', $locale);
+
+ // SEO
+ $html = preg_replace('/<title>[^<]*<\/title>/', '<title>Nimp</title>', $html);
+
file_put_contents($f->getPathname(), $html);
}
+ protected function getTextTranslationsForCompilation($locale)
+ {
+ if (isset($this->_translationsForCompilation[$locale])) {
+ return $this->_translationsForCompilation[$locale];
+ }
+
+ $res = [];
+ $texts = $this->getTranslation('texts', $locale);
+
+ uksort($texts, function ($a, $b) {
+ return mb_strlen($b) - mb_strlen($a);
+ });
+
+ foreach ($texts as $text => $translation) {
+ if (!$translation) {
+ continue;
+ }
+ $text = str_replace("\n", '<br />', htmlspecialchars(base64_decode($text)));
+ $text = str_replace("'", ''', $text);
+ $translation = str_replace("\n", '<br />', $translation);
+ $res[$text] = $translation;
+ $res[str_replace('<br />', ' <br />', $text)] = $translation;
+ }
+
+ $this->_translationsForCompilation[$locale] = $res;
+ return $res;
+ }
+
public function onRetrieved(): bool
{