use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
use Illuminate\Support\Facades\Cache;
-use Illuminate\Support\Facades\Log;
// __('!! Outils')
class ToolWebflow extends ToolboxModel
protected $_operations = [WebflowOperation::class];
+ protected $_pages = [];
+ protected $_texts = [];
+ protected $_images = [];
+
public function setFields()
{
parent::setFields();
$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()
*/
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);
}
public function compile()
{
+ $this->_parsePages();
foreach ($this->getLocales() as $locale) {
$this->compileLocale($locale['locale']);
}
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();