Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Page builder save page css globally to theme/custom.css

givanz56ee611a9e2a
diff --git a/admin/controller/editor/editor.php b/admin/controller/editor/editor.php
index f872ecd..9f909b7 100755
--- a/admin/controller/editor/editor.php
+++ b/admin/controller/editor/editor.php
@@ -369,7 +369,7 @@ class Editor extends Base {
$type = $this->request->post['type'] ?? false;
$addMenu = $this->request->post['add-menu'] ?? false;
$menu_id = $this->request->post['menu_id'] ?? false;
- $theme = sanitizeFileName($this->request->get['theme'] ?? false);
+ $theme = $this->getTheme();
$url = '';
$file = sanitizeFileName(str_replace('.html', '', $file)) . '.html';
@@ -448,7 +448,7 @@ class Editor extends Base {
$success = false;
$text = '';
- $baseUrl = '/themes/' . $this->getTheme() . '/' . ($folder ? $folder . '/' : '');
+ $baseUrl = '/themes/' . $theme . '/' . ($folder ? $folder . '/' : '');
$themeFolder = $this->getThemeFolder();
if ($startTemplateUrl) {
@@ -507,13 +507,25 @@ class Editor extends Base {
$fileName = $themeFolder . DS . ($folder ? $folder . DS : '') . $file;
}
- $this->saveGlobalElements($content);
+ $globalOptions = [];
+ //keep css inline for email templates
+ if (strpos($fileName, '/email/') !== false) {
+ $globalOptions['inline-css'] = true;
+ }
+
+ $content = $this->saveGlobalElements($content, $globalOptions);
if (file_put_contents($fileName, $content)) {
$success = true;
$text .= __('File saved!');
}
+ $cssFile = DS . 'css' . DS . 'custom.css';
+
+ if (! is_writable($themeFolder . $cssFile)) {
+ $text .= '<br/>' . sprintf(__('%s is not writable!'), $theme . $cssFile);
+ }
+
if (CacheManager::clearCompiledFiles('app') && CacheManager::delete()) {
}
diff --git a/admin/controller/editor/global-trait.php b/admin/controller/editor/global-trait.php
index 52659a0..9c4d229 100644
--- a/admin/controller/editor/global-trait.php
+++ b/admin/controller/editor/global-trait.php
@@ -22,26 +22,47 @@
namespace Vvveb\Controller\Editor;
-use Vvveb\System\Core\View;
-
trait GlobalTrait {
- private function saveGlobalElements($content) {
+ private function saveGlobalElements($content, $options = []) {
$document = new \DomDocument();
- $document->preserveWhiteSpace = false;
+ $document->preserveWhiteSpace = true;
$document->recover = true;
$document->strictErrorChecking = false;
+ $document->substituteEntities = false;
$document->formatOutput = false;
$document->resolveExternals = false;
$document->validateOnParse = false;
$document->xmlStandalone = true;
- $view = View::getInstance();
libxml_use_internal_errors(true);
@$document->loadHTML($content);
$xpath = new \DOMXpath($document);
+ $themeFolder = $this->getThemeFolder();
+
+ if (! isset($options['inline-css']) || $options['inline-css'] == false) {
+ //save vvvebjs css to custom.css
+ $style = $xpath->query('//style[ @id="vvvebjs-styles" ]');
+ $cssFile = $themeFolder . DS . 'css' . DS . 'custom.css';
+
+ if ($style && $style->length && is_writable($cssFile)) {
+ $element = $style[0];
+ $content = trim($element->nodeValue);
+
+ if ($content && file_put_contents($cssFile, $element->nodeValue)) {
+ $link = $document->createElement('link');
+ $link->setAttribute('href', 'css/custom.css');
+ $link->setAttribute('rel', 'stylesheet');
+ $link->setAttribute('media', 'screen');
+ $link->setAttribute('id', 'vvvebjs-css');
+ $element->parentNode->replaceChild($link, $element);
+ }
+ }
+ }
+
+ //save common global elements like footer/header
$elements = $xpath->query('//*[ @data-v-save-global ]');
if ($elements && $elements->length) {
@@ -54,8 +75,6 @@ trait GlobalTrait {
$toDocument->validateOnParse = false;
$toDocument->xmlStandalone = true;
- $themeFolder = $this->getThemeFolder();
-
foreach ($elements as $element) {
$attribute = $element->getAttribute('data-v-save-global');
@@ -98,5 +117,9 @@ trait GlobalTrait {
}
}
}
+
+ $content= $document->saveHTML();
+
+ return $content;
}
}
diff --git a/app/template/editor.tpl b/app/template/editor.tpl
index b376c91..04ecb9e 100755
--- a/app/template/editor.tpl
+++ b/app/template/editor.tpl
@@ -5,8 +5,18 @@ $is_admin = \Vvveb\isAdmin();
if ($is_admin && !$vvveb_is_page_edit) {
echo '<link href="' . Vvveb\publicUrlPath() . 'admin/default/css/admin-bar.css" rel="stylesheet">';
}
+if ($is_admin && $vvveb_is_page_edit) {
+ $customCssFile = DIR_THEMES . Vvveb\System\Sites::getTheme() . DS . 'css'. DS . 'custom.css';
+ if (file_exists($customCssFile)) {
+ $css = file_get_contents($customCssFile);//'body {background:red}';
+ echo "<style id=\"vvvebjs-styles\">$css</style>";
+ }
+}
?>
+#vvvebjs-styles|hide = $vvveb_is_page_edit
+
+
body|prepend = <?php
if (isset($is_admin) && $is_admin && !$vvveb_is_page_edit) {
include_once(DIR_ROOT . '/admin/admin-bar.php');
diff --git a/public/admin/default b/public/admin/default
index 4432f05..085aee2 160000
--- a/public/admin/default
+++ b/public/admin/default
@@ -1 +1 @@
-Subproject commit 4432f0513f28820e8d373797b76584ad650d5aac
+Subproject commit 085aee2c3246884dae28c11bcd607dd3616337e5
diff --git a/public/themes/landing b/public/themes/landing
index 7a054dc..6b38256 160000
--- a/public/themes/landing
+++ b/public/themes/landing
@@ -1 +1 @@
-Subproject commit 7a054dc13cc95bd5f2e8ee3416f0102a1e7c774c
+Subproject commit 6b3825630e4bbde5dc57f52e0d782403c58e8fd9