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 revisions for theme templates

givanz23d6dad35e17
diff --git a/admin/controller/editor/revisions.php b/admin/controller/editor/revisions.php
new file mode 100644
index 0000000..8821425
--- /dev/null
+++ b/admin/controller/editor/revisions.php
@@ -0,0 +1,79 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Vvveb\Controller\Editor;
+
+use Vvveb\Controller\Base;
+use function Vvveb\friendlyDate;
+use function Vvveb\sanitizeFileName;
+use Vvveb\System\Sites;
+
+class Revisions extends Base {
+ private function backupFolder() {
+ $theme = $this->request->get['theme'] ?? Sites::getTheme() ?? 'default';
+
+ return DIR_THEMES . DS . $theme . DS . 'backup' . DS;
+ }
+
+ function delete() {
+ }
+
+ function load() {
+ $template = $this->request->get['template'] ?? false;
+
+ $this->view->text = $text;
+ $this->response->setType('text');
+ }
+
+ function preview() {
+ }
+
+ function revisions() {
+ $template = $this->request->get['template'] ?? false;
+ $backupFolder = $this->backupFolder();
+ $revisions = [];
+
+ if ($template) {
+ $template = str_replace(['/', '.html'], ['-', ''], sanitizeFileName($template));
+
+ $glob = glob("$backupFolder/$template|*.html");
+
+ foreach ($glob as &$file) {
+ $file = basename($file, '.html');
+ list($name, $date) = explode('|', $file);
+ $date = str_replace('_', ' ', $date);
+ $date_friendly = friendlyDate($date);
+ /*
+ $time = date_parse_from_format($this->revisionDateFormat, $date);
+ unset($time['warnings'], $time['warning_count'], $time['errors'], $time['error_count']);
+ */
+ $revisions[] = compact(['file', 'date', 'date_friendly', 'name'/*, 'time'*/]);
+ }
+ }
+
+ $this->response->setType('json');
+ $this->response->output($revisions);
+ }
+
+ function index() {
+ }
+}
diff --git a/public/js/admin/revisions.js b/public/js/admin/revisions.js
index de7f619..2fb20b7 100644
--- a/public/js/admin/revisions.js
+++ b/public/js/admin/revisions.js
@@ -49,12 +49,13 @@ $(".revisions").on("click", ".btn-delete", function (e) {
let item = $(this).parents("[data-v-revision]")
let count = $(item).parents(".tab-pane").find("[data-v-" + data.type + "-content-revision_count]");
- revisionAction("delete", data, function (data, text) {
- displayToast("bg-success", "Revision", "Revision deleted!");
- item.remove();
- count.html(Math.max(count.html() - 1, 0));
- });
-
+ if (confirm('Are you sure?')) {
+ revisionAction("delete", data, function (data, text) {
+ displayToast("bg-success", "Revision", "Revision deleted!");
+ item.remove();
+ count.html(Math.max(count.html() - 1, 0));
+ });
+ }
//e.preventDefault()
return false;
});