namespace App\Jobs;
-use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader;
use App\Models\ToolWebflow;
use App\Models\User;
use App\Notifications\ToolboxNotification;
$wf = ToolWebflow::withoutGlobalScopes()->find($this->id);
$subject = __('Site :name publié', ['name' => $wf->name]);
if ($this->mode === 'webflow') {
- $wf->mirror(false, true)->debug();
+ $wf->mirror(false, rand(1, 10) === 10);
$text = __('Le site vient d\'être républié suite à une mise à jour de webflow');
} else if ($this->mode === 'auto') {
$text = __('Le site vient d\'être républié suite à une mise à jour des contenus');
$text = __('Le site vient d\'être républié suite à une déclenchement manuel');
}
+ $wf->compile();
$actions = [];
foreach ($wf->getLocales() as $locale) {
use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation;
use App\Jobs\WebflowPublish;
use App\Models\Base\ToolboxModel;
-
+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\Textarea;
-use Cubist\Backpack\Magic\Fields\URL;
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
-use Cubist\Util\Files\VirtualDirectory;
use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
// __('!! Outils')
class ToolWebflow extends ToolboxModel
$sites[$k] = $item['label'];
}
$this->addField('upload', SelectFromArray::class, __('Uploader sur'), ['options' => $sites, 'tab' => __('Paramètres')]);
+ $this->addField('js', Code::class, __('Javascript complémentaire'), ['language' => 'js', 'tab' => __('Code')]);
+ $this->addField('css', Code::class, __('CSS complémentaire'), ['language' => 'css', 'tab' => __('Code')]);
//$this->addField('texts');
//$this->addField('images');
//$this->addField('seo');
*/
public function mirror($slow = true, $force = false)
{
- $path = Files::mkdir(protected_path('webflow/mirrors/' . $this->id));
+ $path = Files::mkdir(protected_path('webflow/mirror/' . $this->id));
if ($force) {
$path = Files::emptyDir($path);
}
}
- protected function compile()
+ public function compile()
{
foreach ($this->getLocales() as $locale) {
$this->compileLocale($locale['locale']);
StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id), $this->upload);
}
+ protected function getCustomCSS()
+ {
+ $css = '';
+
+ return $css . "\n\n" . $this->css;
+ }
+
+ protected function getCustomJS()
+ {
+ $js = '';
+
+ return $js . ";\n\n" . $this->js;
+ }
+
protected function compileLocale($locale)
{
- $mirror = Files::mkdir(protected_path('webflow/mirrors/' . $this->id));
+ $mirror = Files::mkdir(protected_path('webflow/mirror/' . $this->id));
$path = Files::mkdir(protected_path('webflow/final/' . $this->id . '/' . $locale));
$rsync = new CommandLine\Rsync($mirror, $path, true);
$rsync->execute();
+
+ file_put_contents(Files::mkdir($path . '/css') . 'custom.css', $this->getCustomCSS());
+ file_put_contents(Files::mkdir($path . '/js') . 'custom.js', $this->getCustomJS());
+
+ foreach (Files::getRecursiveDirectoryIterator($path) as $f) {
+ /** @var $f \SplFileInfo */
+ if ($f->isDir() || $f->getExtension() !== 'html') {
+ continue;
+ }
+ $this->compileHTMLFile($f, $locale);
+ }
+ }
+
+ /**
+ * @param $f \SplFileInfo
+ * @param $locale string
+ * @return void
+ */
+ protected function compileHTMLFile($f, $locale)
+ {
+ $html = file_get_contents($f->getPathname());
+ $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);
+
+ file_put_contents($f->getPathname(), $html);
}
public function onRetrieved(): bool