Skip to content

Commit

Permalink
Don't save page template if html is empty and show error message
Browse files Browse the repository at this point in the history
  • Loading branch information
givanz committed Jun 23, 2024
1 parent 397849c commit ffa4f96
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions admin/controller/editor/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ function save() {
}
}

$content = $this->request->post['html'] ?? false;
$html = $this->request->post['html'] ?? false;
$elements = $this->request->post['elements'] ?? false;
$setTemplate = $this->request->post['setTemplate'] ?? false;

Expand All @@ -517,8 +517,8 @@ function save() {
$themeFolder = $this->getThemeFolder();

if ($startTemplateUrl) {
$content = file_get_contents($themeFolder . DS . $startTemplateUrl);
$content = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $content);
$html = file_get_contents($themeFolder . DS . $startTemplateUrl);
$html = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $html);
}

if (! $url) {
Expand Down Expand Up @@ -572,21 +572,25 @@ function save() {
$fileName = $themeFolder . DS . ($folder ? $folder . DS : '') . $file;
}

$globalOptions = [];
//keep css inline for email templates
if (strpos($fileName, '/email/') !== false) {
$globalOptions['inline-css'] = true;
}
if ($html) {
if (file_put_contents($fileName, $html)) {
$globalOptions = [];
//keep css inline for email templates
if (strpos($fileName, '/email/') !== false) {
$globalOptions['inline-css'] = true;
}

$content = $this->saveGlobalElements($content, $globalOptions);
$html = $this->saveGlobalElements($html, $globalOptions);

if (file_put_contents($fileName, $content)) {
$success = true;
$text .= __('File saved!');
} else {
if (!is_writable($fileName)) {
$text .= sprintf(__('%s is not writable!'), $fileName);
$success = true;
$text .= __('File saved!');
} else {
if (! is_writable($fileName)) {
$text .= sprintf(__('%s is not writable!'), $fileName);
}
}
} else {
$text .= sprintf(__('Page html empty!'), $fileName);
}

$cssFile = DS . 'css' . DS . 'custom.css';
Expand Down

0 comments on commit ffa4f96

Please sign in to comment.