]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6775 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Mar 2024 19:37:20 +0000 (20:37 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Mar 2024 19:37:20 +0000 (20:37 +0100)
app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php
app/Jobs/WebflowPublish.php
app/Models/ToolWebflow.php

index 80911200d39490f1d811a8cd96e70cf2ad4a3444..e3496b4b8d92715363709ea0dd145f5a5f3dfc40 100644 (file)
@@ -68,6 +68,5 @@ trait StaticSiteUploader
         $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id'];
         $rsync = new Rsync($from, $dest);
         $rsync->execute();
-        $rsync->debug();
     }
 }
index 5750bf02e53368078c03e97c9e3fab9af21f3826..299781d7a37536b3cdef38dbb7fa11d68b4ae4b6 100644 (file)
@@ -46,7 +46,7 @@ class WebflowPublish extends Base
             $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url'];
         }
         if ($this->user === null) {
-            Slack::send($wf->slack, $subject, $text, $actions, false);
+           // Slack::send($wf->slack, $subject, $text, $actions, false);
         } else {
             $this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
         }
index 2bb3132abfc6614483770233fe00f19bb7b47cfb..3cc4ab05a5f48d5864150ee3184bdf736957cb56 100644 (file)
@@ -14,7 +14,6 @@ use Cubist\Backpack\Magic\Fields\Textarea;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Files\Files;
 use Illuminate\Support\Facades\Cache;
-use Illuminate\Support\Facades\Log;
 
 // __('!! Outils')
 class ToolWebflow extends ToolboxModel
@@ -29,6 +28,10 @@ class ToolWebflow extends ToolboxModel
 
     protected $_operations = [WebflowOperation::class];
 
+    protected $_pages = [];
+    protected $_texts = [];
+    protected $_images = [];
+
     public function setFields()
     {
         parent::setFields();
@@ -44,11 +47,44 @@ 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');
+        $this->addField('js', Code::class, __('Javascript complémentaire'), ['language' => 'js', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
+        $this->addField('css', Code::class, __('CSS complémentaire'), ['language' => 'css', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
+        $this->addField('texts', Textarea::class, '', ['tab' => __('Textes')]);
+        $this->addField('images', Textarea::class, '', ['tab' => __('Images')]);
+        $this->addField('seo', Textarea::class, '', ['tab' => __('SEO')]);
+    }
+
+    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()
@@ -75,7 +111,7 @@ class ToolWebflow extends ToolboxModel
      */
     public function mirror($slow = true, $force = false)
     {
-        $path = Files::mkdir(protected_path('webflow/mirror/' . $this->id));
+        $path = $this->getMirrorPath();
         if ($force) {
             $path = Files::emptyDir($path);
         }
@@ -115,6 +151,7 @@ class ToolWebflow extends ToolboxModel
 
     public function compile()
     {
+        $this->_parsePages();
         foreach ($this->getLocales() as $locale) {
             $this->compileLocale($locale['locale']);
         }
@@ -135,9 +172,14 @@ class ToolWebflow extends ToolboxModel
         return $js . ";\n\n" . $this->js;
     }
 
+    public function getMirrorPath()
+    {
+        return Files::mkdir(protected_path('webflow/mirror/' . $this->id));
+    }
+
     protected function compileLocale($locale)
     {
-        $mirror = Files::mkdir(protected_path('webflow/mirror/' . $this->id));
+        $mirror = $this->getMirrorPath();
         $path = Files::mkdir(protected_path('webflow/final/' . $this->id . '/' . $locale));
         $rsync = new CommandLine\Rsync($mirror, $path, true);
         $rsync->execute();