Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Added duplicate option for posts/pages and products

givanzf6fc936cae92
diff --git a/admin/controller/content/posts.php b/admin/controller/content/posts.php
index 205d616..dc56181 100755
--- a/admin/controller/content/posts.php
+++ b/admin/controller/content/posts.php
@@ -29,6 +29,7 @@ use Vvveb\Sql\PostSQL;
use Vvveb\System\Cache;
use Vvveb\System\Images;
use Vvveb\System\User\Admin;
+use function Vvveb\url;
class Posts extends Base {
protected $type = 'post';
@@ -44,6 +45,59 @@ class Posts extends Base {
return parent::init();
}
+ function duplicate() {
+ $post_id = $this->request->post['post_id'] ?? $this->request->get['post_id'] ?? false;
+
+ if ($post_id) {
+ $this->posts = new PostSQL();
+ $data = $this->posts->get(['post_id' => $post_id, 'type' => $this->type]);
+
+ unset($data['post_id']);
+ $id = rand(1, 1000);
+
+ foreach ($data['post_content'] as &$content) {
+ unset($content['post_id']);
+ $content['name'] .= ' [' . __('duplicate') . ']';
+ $content['slug'] .= '-' . __('duplicate') . "-$id";
+ }
+
+ if (isset($data['post_to_taxonomy_item'])) {
+ foreach ($data['post_to_taxonomy_item'] as &$item) {
+ $taxonomy_item[] = $item['taxonomy_item_id'];
+ }
+ }
+
+ if (isset($data['post_to_site'])) {
+ foreach ($data['post_to_site'] as &$item) {
+ $site_id[] = $item['site_id'];
+ }
+ }
+
+ if ($data) {
+ $result = $this->posts->add([
+ 'post' => [
+ 'post_content' => $data['post_content'],
+ 'taxonomy_item' => $taxonomy_item ?? [],
+ ] + $data,
+ 'site_id' => $site_id,
+ ]);
+
+ if ($result && isset($result['post'])) {
+ $post_id = $result['post'];
+ $url = url(['module' => 'content/post', 'post_id' => $post_id, 'type' => $this->type]);
+
+ $success = ucfirst($this->type) . __(' duplicated!');
+ $success .= sprintf(' <a href="%s">%s</a>', $url, __('Edit') . " {$this->type}");
+ $this->view->success[] = $success;
+ } else {
+ $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);
+ }
+ }
+ }
+
+ return $this->index();
+ }
+
function delete() {
$post_id = $this->request->post['post_id'] ?? $this->request->get['post_id'] ?? false;
@@ -108,31 +162,31 @@ class Posts extends Base {
$return[$archive['year'] . '/' . $archive['month']] = $name;
}
-/*
- $return = [];
+ /*
+ $return = [];
- if (isset($archives['archives'])) {
- foreach ($archives['archives'] as $index => &$archive) {
- if (isset($archive['month'])) {
- $monthNum = $archive['month'];
+ if (isset($archives['archives'])) {
+ foreach ($archives['archives'] as $index => &$archive) {
+ if (isset($archive['month'])) {
+ $monthNum = $archive['month'];
- $archive['month_text'] = $monthNum;
+ $archive['month_text'] = $monthNum;
- if ($df) {
- $dt->setDate(0, $archive['month'], 0);
- $archive['month_text'] = ucfirst(datefmt_format($df, $dt));
- }
- }
+ if ($df) {
+ $dt->setDate(0, $archive['month'], 0);
+ $archive['month_text'] = ucfirst(datefmt_format($df, $dt));
+ }
+ }
- $archive['month'] = sprintf('%02d', $archive['month']);
- $name =
- (isset($archive['month']) ? $archive['month_text'] . ' ' : '') .
- (isset($archive['year']) ? $archive['year'] . ' ' : '');
+ $archive['month'] = sprintf('%02d', $archive['month']);
+ $name =
+ (isset($archive['month']) ? $archive['month_text'] . ' ' : '') .
+ (isset($archive['year']) ? $archive['year'] . ' ' : '');
- $return[$archive['year'] . '/' . $archive['month']] = $name;
- }
- }
-*/
+ $return[$archive['year'] . '/' . $archive['month']] = $name;
+ }
+ }
+ */
return $return;
}
@@ -177,16 +231,16 @@ class Posts extends Base {
$post['image'] = Images::image($post['image'], 'post');
}
- $url = ['module' => 'content/post', 'post_id' => $post['post_id'], 'type' => $post['type']];
- $admin_path = \Vvveb\adminPath();
- $template = $post['template'] ? $post['template'] : $defaultTemplate;
- $post['url'] = \Vvveb\url($url);
- $post['edit-url'] = $post['url'];
-
- $post['admin-url'] = \Vvveb\url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
- $post['delete-url'] = \Vvveb\url(['module' => 'content/posts', 'action' => 'delete'] + $url + ['post_id[]' => $post['post_id']]);
- $post['view-url'] = \Vvveb\url("content/{$this->type}/index", $post + $url + ['host' => $this->global['site_url']]);
- $post['design-url'] = \Vvveb\url(['module' => 'editor/editor', 'url' => $post['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
+ $url = ['module' => 'content/post', 'post_id' => $post['post_id'], 'type' => $post['type']];
+ $admin_path = \Vvveb\adminPath();
+ $template = $post['template'] ? $post['template'] : $defaultTemplate;
+ $post['url'] = url($url);
+ $post['edit-url'] = $post['url'];
+ $post['admin-url'] = url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
+ $post['delete-url'] = url(['module' => 'content/posts', 'action' => 'delete'] + $url + ['post_id[]' => $post['post_id']]);
+ $post['duplicate-url'] = url(['module' => 'content/posts', 'action' => 'duplicate'] + $url + ['post_id' => $post['post_id']]);
+ $post['view-url'] = url("content/{$this->type}/index", $post + $url + ['host' => $this->global['site_url']]);
+ $post['design-url'] = url(['module' => 'editor/editor', 'url' => $post['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
}
}
@@ -203,7 +257,7 @@ class Posts extends Base {
$view->filter = $this->filter;
$view->limit = $options['limit'];
$view->type = $this->type;
- $view->addUrl = \Vvveb\url(['module' => 'content/post', 'type' => $this->type]);
+ $view->addUrl = url(['module' => 'content/post', 'type' => $this->type]);
$view->type_name = humanReadable(__($this->type));
$view->type_name_plural = humanReadable(__($view->type . 's'));
}
diff --git a/admin/controller/editor/editor.php b/admin/controller/editor/editor.php
index 072e535..2de9121 100755
--- a/admin/controller/editor/editor.php
+++ b/admin/controller/editor/editor.php
@@ -87,7 +87,7 @@ class Editor extends Base {
private function loadTemplateList($theme = null) {
$list = $this->themeConfig['pages'] ?? [];
- $pages = $list + Cache::getInstance()->cache(APP,'template-list.' . $theme,
+ $pages = $list + Cache::getInstance()->cache(APP, 'template-list.' . $theme,
function () use ($theme) {
return \Vvveb\getTemplateList($theme);
}, 604800);
@@ -97,6 +97,10 @@ class Editor extends Base {
return $pages;
}
+ private function clearTemplateListCache($theme = null) {
+ return Cache::getInstance()->delete(APP, 'template-list.' . $theme);
+ }
+
private function loadEditorData() {
$data = [];
@@ -328,7 +332,6 @@ class Editor extends Base {
$post_id = $this->request->post['post_id'] ?? false;
$file = sanitizeFileName($this->request->post['file']);
$themeFolder = $this->getThemeFolder();
- //echo $themeFolder . DS . $file;
if ($post_id) {
$type = 'page';
@@ -375,7 +378,7 @@ class Editor extends Base {
}
$currentFile = $themeFolder . DS . $file;
- $targetFile = $themeFolder . DS . $newfile;
+ $targetFile = dirname($currentFile) . DS . basename($newfile); //save in same folder
$message = ['success' => false, 'message' => __('Error!')];
@@ -386,15 +389,61 @@ class Editor extends Base {
$slug = slugify($name);
$this->posts = new PostSQL();
- $options = [
- 'post_id' => $post_id,
- 'post_content' => [
- 'name' => $name,
- 'slug' => $slug,
- ],
- ] + $this->global;
+ $data = $this->posts->get(['post_id' => $post_id]);
if ($duplicate === 'true') {
+ $data = $this->posts->get(['post_id' => $post_id]);
+
+ if ($data) {
+ unset($data['post_id']);
+ $id = rand(1, 1000);
+
+ foreach ($data['post_content'] as &$content) {
+ unset($content['post_id']);
+
+ if ($content['language_id'] == $this->global['language_id']) {
+ $content['name'] = $name;
+ $content['slug'] = $slug;
+ } else {
+ $content['name'] .= ' [' . __('duplicate') . ']';
+ $content['slug'] .= '-' . __('duplicate') . "-$id";
+ }
+ }
+
+ if (isset($data['post_to_taxonomy_item'])) {
+ foreach ($data['post_to_taxonomy_item'] as &$item) {
+ $taxonomy_item[] = $item['taxonomy_item_id'];
+ }
+ }
+
+ if (isset($data['post_to_site'])) {
+ foreach ($data['post_to_site'] as &$item) {
+ $site_id[] = $item['site_id'];
+ }
+ }
+
+ $startTemplateUrl = $data['template'] ?? "content/$type.html";
+ $template = "content/$slug.html";
+
+ if (!@copy($themeFolder . DS . $startTemplateUrl, $themeFolder . DS . $template)) {
+ $template = $data['template'] ?? '';
+ }
+
+ $result = $this->posts->add([
+ 'post' => [
+ 'post_content' => $data['post_content'],
+ 'taxonomy_item' => $taxonomy_item ?? [],
+ 'template' => $template,
+ ] + $data,
+ 'site_id' => $site_id,
+ ]);
+
+ if ($result && isset($result['post'])) {
+ $message = ['success' => true, 'url' => url('content/page/index', ['slug' => $slug]), 'message' => ucfirst($type) . __(' duplicated!')];
+ } else {
+ $message = ['success' => false, 'message' => sprintf(__('Error duplicating %s!'), $type)];
+ }
+ }
} else {
$result = $this->posts->editContent($options);
}
@@ -402,13 +451,13 @@ class Editor extends Base {
if ($result && isset($result['post_content'])) {
$message = ['success' => true, 'url' => url('content/page/index', ['slug' => $slug]), 'message' => ucfirst($type) . __(' renamed!')];
} else {
- $message = ['success' => false, 'message' => sprintf(__('Error deleting %s!'), $type)];
+ $message = ['success' => false, 'message' => sprintf(__('Error renaming %s!'), $type)];
}
}
} else {
if ($duplicate === 'true') {
- if (copy($currentFile, $targetFile)) {
- $message = ['success' => true, 'newfile' => $newfile, 'message' => __('File copied!')];
+ if (@copy($currentFile, $targetFile)) {
+ $message = ['success' => true, 'newfile' => $newfile, 'message' => __('File copied!'), 'url' => $newfile];
} else {
$message = ['success' => false, 'message' => __('Error copying file!')];
}
@@ -421,6 +470,7 @@ class Editor extends Base {
}
}
+ $this->clearTemplateListCache(sanitizeFileName($this->request->get['theme'] ?? false));
$this->response->setType('json');
$this->response->output($message);
}
@@ -520,13 +570,13 @@ class Editor extends Base {
$startTemplate = $themeFolder . DS . $startTemplateUrl;
if (file_exists($startTemplate)) {
- if (! ($html = @file_get_contents($startTemplate)) ) {
+ if (! ($html = @file_get_contents($startTemplate))) {
$text .= sprintf(__('%s is not readable!'), $startTemplate);
}
} else {
$text .= sprintf(__('%s does not exist!'), $startTemplate);
}
-
+
$html = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $html);
}
@@ -546,7 +596,16 @@ class Editor extends Base {
}
}
- if (! $startTemplateUrl) {
+ //if plugins template use public path
+ $isPlugin = false;
+ if (substr_compare($file,'/plugins/', 0, 9) === 0) {
+ $fileName = DIR_PUBLIC . DS . ($folder ? $folder . DS : '') . $file;
+ $isPlugin = true;
+ } else {
+ $fileName = $themeFolder . DS . ($folder ? $folder . DS : '') . $file;
+ }
+
+ if (! $startTemplateUrl && !$isPlugin) {
$backupFolder = $themeFolder . DS . 'backup' . DS;
if (is_writable($backupFolder)) {
@@ -581,13 +640,6 @@ class Editor extends Base {
}
}
- //if plugins template use public path
- if (substr_compare($file[0],'/plugins/', 0, 9) === 0) {
- $fileName = DIR_PUBLIC . DS . ($folder ? $folder . DS : '') . $file;
- } else {
- $fileName = $themeFolder . DS . ($folder ? $folder . DS : '') . $file;
- }
-
if ($html) {
if (@file_put_contents($fileName, $html)) {
$globalOptions = [];
diff --git a/admin/controller/product/products.php b/admin/controller/product/products.php
index e3c2e94..e07ea58 100755
--- a/admin/controller/product/products.php
+++ b/admin/controller/product/products.php
@@ -45,6 +45,69 @@ class Products extends Base {
return parent::init();
}
+ function duplicate() {
+ $product_id = $this->request->product['product_id'] ?? $this->request->get['product_id'] ?? false;
+
+ if ($product_id) {
+ $this->products = new ProductSQL();
+ $data = $this->products->get(['product_id' => $product_id, 'type' => $this->type]);
+
+ unset($data['product_id']);
+ $id = rand(1, 1000);
+
+ foreach ($data['product_content'] as &$content) {
+ unset($content['product_id']);
+ $content['name'] .= ' [' . __('duplicate') . ']';
+ $content['slug'] .= '-' . __('duplicate') . "-$id";
+ }
+
+ if (isset($data['product_to_taxonomy_item'])) {
+ foreach ($data['product_to_taxonomy_item'] as &$item) {
+ $taxonomy_item[] = $item['taxonomy_item_id'];
+ }
+ }
+
+ if (isset($data['product_to_site'])) {
+ foreach ($data['product_to_site'] as &$item) {
+ $site_id[] = $item['site_id'];
+ }
+ }
+
+ if ($data) {
+ $result = $this->products->add([
+ 'product' => [
+ 'product_content' => $data['product_content'],
+ 'taxonomy_item' => $taxonomy_item ?? [],
+ ] + $data,
+ 'site_id' => $site_id,
+ ]);
+
+ if ($result && isset($result['product'])) {
+ $product_id = $result['product'];
+
+ if ($data['product_image']) {
+ $product_image = [];
+
+ foreach ($data['product_image'] as $image) {
+ $product_image[] = $image['image'];
+ }
+ $images = $this->products->productImage(['product_image' => $product_image, 'product_id' => $product_id]);
+ }
+
+ $url = url(['module' => 'product/product', 'product_id' => $product_id, 'type' => $this->type]);
+
+ $success = ucfirst($this->type) . __(' duplicated!');
+ $success .= sprintf(' <a href="%s">%s</a>', $url, __('Edit') . " {$this->type}");
+ $this->view->success[] = $success;
+ } else {
+ $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);
+ }
+ }
+ }
+
+ return $this->index();
+ }
+
function delete() {
$product_id = $this->request->post['product_id'] ?? $this->request->get['product_id'] ?? false;
@@ -72,9 +135,14 @@ class Products extends Base {
$products = new ProductSQL();
$this->filter = array_filter($this->request->get['filter'] ?? []);
-
- if (isset($this->filter['vendor_id'])) $this->filter['vendor_id'] = [$this->filter['vendor_id']];
- if (isset($this->filter['manufacturer_id'])) $this->filter['manufacturer_id'] = [$this->filter['manufacturer_id']];
+
+ if (isset($this->filter['vendor_id'])) {
+ $this->filter['vendor_id'] = [$this->filter['vendor_id']];
+ }
+
+ if (isset($this->filter['manufacturer_id'])) {
+ $this->filter['manufacturer_id'] = [$this->filter['manufacturer_id']];
+ }
$options = [
'type' => $this->type,
@@ -106,13 +174,14 @@ class Products extends Base {
}
}
- $template = (isset($product['template']) && $product['template']) ? $product['template'] : $defaultTemplate;
- $product['url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
- $product['edit-url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
- $product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete', 'product_id[]' => $product['product_id'], 'type' => $product['type']]);
- $product['view-url'] = url('product/product/index', $product + ['host' => $this->global['site_url']]);
- $admin_path = \Vvveb\config('admin.path', 'admin') . '/';
- $product['design-url'] = url(['module' => 'editor/editor', 'url' => $product['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
+ $template = (isset($product['template']) && $product['template']) ? $product['template'] : $defaultTemplate;
+ $product['url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
+ $product['edit-url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
+ $product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete', 'product_id[]' => $product['product_id'], 'type' => $product['type']]);
+ $product['duplicate-url'] = url(['module' => 'product/products', 'action' => 'duplicate', 'product_id' => $product['product_id'], 'type' => $product['type']]);
+ $product['view-url'] = url('product/product/index', $product + ['host' => $this->global['site_url']]);
+ $admin_path = \Vvveb\adminPath();
+ $product['design-url'] = url(['module' => 'editor/editor', 'url' => $product['view-url'], 'template' => $template, 'host' => $this->global['site_url'] . $admin_path], false, false);
}
}
diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sql
index 80fa448..fb6c207 100755
--- a/admin/sql/mysqli/post.sql
+++ b/admin/sql/mysqli/post.sql
@@ -329,12 +329,16 @@
-- meta
- SELECT `key` as array_key,value as array_value FROM post_meta as _
- WHERE _.post_id = @result.post_id;
+ SELECT `key` as array_key,value as array_value FROM post_meta
+ WHERE post_meta.post_id = @result.post_id;
-- post_to_site
SELECT site_id as array_key, site_id FROM post_to_site
- WHERE post_to_site.post_id = @result.post_id;
+ WHERE post_to_site.post_id = @result.post_id;
+
+ -- post_to_taxonomy_item
+ SELECT taxonomy_item_id as array_key, taxonomy_item_id FROM post_to_taxonomy_item
+ WHERE post_to_taxonomy_item.post_id = @result.post_id;
END
@@ -343,9 +347,9 @@
CREATE PROCEDURE add(
IN post ARRAY,
IN site_id ARRAY,
- OUT insert_id
- OUT insert_id
- OUT insert_id
+ OUT insert_id,
+ OUT insert_id,
+ OUT insert_id,
OUT insert_id
)
BEGIN
diff --git a/admin/sql/mysqli/product.sql b/admin/sql/mysqli/product.sql
index ffecdf7..2a6c303 100755
--- a/admin/sql/mysqli/product.sql
+++ b/admin/sql/mysqli/product.sql
@@ -411,9 +411,9 @@
@EACH(:product.product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id)
- VALUES ( :each, :product_id, '', '', '' )
+ VALUES ( :each, :product_id)
ON DUPLICATE KEY UPDATE @LIST(:each);
@@ -509,9 +509,9 @@
@EACH(:product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id )
- VALUES ( :each, @result.product, '', '', '' );
+ VALUES ( :each, @result.product );
@EACH(:product_data.taxonomy_item)
INSERT INTO product_to_taxonomy_item
diff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sql
index 16580d9..b0122ca 100755
--- a/admin/sql/pgsql/post.sql
+++ b/admin/sql/pgsql/post.sql
@@ -276,6 +276,10 @@
SELECT site_id as array_key, site_id FROM post_to_site
WHERE post_to_site.post_id = @result.post_id;
+ -- post_to_taxonomy_item
+ SELECT taxonomy_item_id as array_key, taxonomy_item_id FROM post_to_taxonomy_item
+ WHERE post_to_taxonomy_item.post_id = @result.post_id;
+
END
-- Add new post
diff --git a/admin/sql/pgsql/product.sql b/admin/sql/pgsql/product.sql
index 2692202..bea96b5 100755
--- a/admin/sql/pgsql/product.sql
+++ b/admin/sql/pgsql/product.sql
@@ -411,9 +411,9 @@
@EACH(:product.product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id)
- VALUES ( :each, :product_id, '', '', '' )
+ VALUES ( :each, :product_id)
ON CONFLICT("product_id", "language_id") DO UPDATE SET @LIST(:each);
@@ -506,9 +506,9 @@
@EACH(:product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id)
- VALUES ( :each, @result.product, '', '', '' );
+ VALUES ( :each, @result.product );
@EACH(:product_data.taxonomy_item)
INSERT INTO product_to_taxonomy_item
diff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sql
index 333ce58..9195448 100755
--- a/admin/sql/sqlite/post.sql
+++ b/admin/sql/sqlite/post.sql
@@ -271,6 +271,10 @@
SELECT site_id as array_key, site_id FROM post_to_site
WHERE post_to_site.post_id = @result.post_id;
+ -- post_to_taxonomy_item
+ SELECT taxonomy_item_id as array_key, taxonomy_item_id FROM post_to_taxonomy_item
+ WHERE post_to_taxonomy_item.post_id = @result.post_id;
+
END
-- Add new post
diff --git a/admin/sql/sqlite/product.sql b/admin/sql/sqlite/product.sql
index cdb4096..d4ba487 100755
--- a/admin/sql/sqlite/product.sql
+++ b/admin/sql/sqlite/product.sql
@@ -411,9 +411,9 @@
@EACH(:product.product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id)
- VALUES ( :each, :product_id, '', '', '' )
+ VALUES ( :each, :product_id)
ON CONFLICT("product_id", "language_id") DO UPDATE SET @LIST(:each);
@@ -509,9 +509,9 @@
@EACH(:product_content)
INSERT INTO product_content
- ( @KEYS(:each), product_id, meta_title, meta_description, meta_keywords )
+ ( @KEYS(:each), product_id)
- VALUES ( :each, @result.product, '', '', '' );
+ VALUES ( :each, @result.product );
@EACH(:product_data.taxonomy_item)
INSERT INTO product_to_taxonomy_item
diff --git a/public/admin/default b/public/admin/default
index 3677ca8..161aa35 160000
--- a/public/admin/default
+++ b/public/admin/default
@@ -1 +1 @@
-Subproject commit 3677ca8cef3d43d86e9579dfbd1b97d74fded178
+Subproject commit 161aa3580b0fb06ad96f82512a59b8898091c7e2
diff --git a/public/js/admin/controller/backup.js b/public/js/admin/controller/backup.js
index df0da9d..6c59fb2 100755
--- a/public/js/admin/controller/backup.js
+++ b/public/js/admin/controller/backup.js
@@ -95,7 +95,7 @@ class BackupController {
}
})*/
.catch(error => {
- let message = error.clone().text();
+ let message = error.statusText ?? error;
if (typeof error.json === "function") {
error.json().then(jsonError => {
diff --git a/public/js/admin/controller/update.js b/public/js/admin/controller/update.js
index 2272f27..429d3ec 100755
--- a/public/js/admin/controller/update.js
+++ b/public/js/admin/controller/update.js
@@ -87,13 +87,19 @@ class UpdateController {
}
})*/
.catch(error => {
- let message = error.statusText ?? error.clone().text();
+ let message = error?.statusText ?? "Error updating!";
+ displayToast("bg-danger", "Error", message);
+
+ if (err.hasOwnProperty('text')) err.text().then( errorMessage => {
+ let message = errorMessage.substr(0, 200);
+ displayToast("bg-danger", "Error", message);
+ });
if (typeof error.json === "function") {
error.json().then(jsonError => {
message = jsonError;
}).catch(genericError => {
- message = error.statusText + " " + message;
+ message = error?.statusText + " " + message;
});
}
diff --git a/public/js/admin/functions.js b/public/js/admin/functions.js
index bb1d9b2..d984034 100644
--- a/public/js/admin/functions.js
+++ b/public/js/admin/functions.js
@@ -1,16 +1,16 @@
//Tables
-function addTemplate(id, name, parent, element = false) {
+function addTemplate(id, name, parent, element = false, parentElement = "table", container = "tbody", callback) {
// id = attribute-template
// name = product_attribute
// parent = attribute
let template;
let tbody;
if (element) {
- element = element.closest("table");
+ element = element.closest(parentElement);
} else {
element = document;
}
- template = element.querySelector(id).cloneNode(true);
+ template = document.querySelector(id).cloneNode(true);
template.querySelectorAll('[type="date"]', template).forEach(e => e.setAttribute("value", date()));
template.querySelectorAll('[type="datetime-local"]').forEach(e => e.setAttribute("value", datetime()));
@@ -26,7 +26,12 @@ function addTemplate(id, name, parent, element = false) {
replace('id="' + id + '"', '');
let row = generateElements(template)[0];
- element.querySelector(parent + " tbody").append(row);
+ element.querySelector(parent + " " + container).append(row);
+
+ if (callback) {
+ callback(row);
+ }
+
return row;
}
@@ -57,7 +62,7 @@ const slugify = (str) => {
}
-function addTab(element, event) {
+function addTab(element, callback) {
let nav = element.closest(".nav");
let content = element.closest(".row").querySelector(".tab-content");
@@ -77,7 +82,12 @@ function addTab(element, event) {
contentTemplate = contentTemplate.replaceAll('[0]', '[' + newId + ']').replaceAll('-0-', '-' + newId + '-').replaceAll('disabled', '');
nav.append(navTemplate);
- content.append(generateElements(contentTemplate)[0]);
+ let contentElement = generateElements(contentTemplate)[0];
+ content.append(contentElement);
+
+ if (callback) {
+ callback(navTemplate, contentElement);
+ }
document.querySelectorAll("#tab-" + newId +" .product_option_id").forEach(e => {
e.dispatchEvent(new Event("change"));
diff --git a/public/js/admin/heartbeat.js b/public/js/admin/heartbeat.js
index 8a962f2..10da4d2 100755
--- a/public/js/admin/heartbeat.js
+++ b/public/js/admin/heartbeat.js
@@ -55,7 +55,7 @@ let HeartBeat = setInterval(function () {
document.querySelector('.btn-login .loading').classList.add('d-none');
document.querySelector('.btn-login .button-text').classList.remove('d-none');
console.log(error.statusText);
- displayToast("bg-danger", "Revision", "Error!");
+ displayToast("bg-danger", "Login", "Error!");
});
diff --git a/public/js/vvvebjs/builder.js b/public/js/vvvebjs/builder.js
index 79b06a5..34d58d7 100755
--- a/public/js/vvvebjs/builder.js
+++ b/public/js/vvvebjs/builder.js
@@ -1022,7 +1022,7 @@ Vvveb.Builder = {
let type = list.dataset.type;
list.replaceChildren();
- for (group in Vvveb.BlocksGroup) {
+ for (group in Vvveb.StylesGroup) {
list.append(generateElements(
`<li class="header" data-section="${group}" data-search="">
<label class="header" for="${type}_stylehead_${group}">
@@ -1033,7 +1033,7 @@ Vvveb.Builder = {
</li>`)[0]);
let stylesSubList = list.querySelector('li[data-section="' + group + '"] ol');
- styles = Vvveb.BlocksGroup[ group ];
+ styles = Vvveb.StylesGroup[ group ];
for (i in styles) {
styleType = styles[i];
@@ -1804,16 +1804,16 @@ Vvveb.Builder = {
let value = selectedEl.innerHTML.trim();
// uncomment to use outerHTML, not recommended
//let value = selectedEl.outerHTML;
- Vvveb.ModalCodeEditor.show();
- Vvveb.ModalCodeEditor.setValue(value);
+ Vvveb.ModalTranslateEditor.show();
+ Vvveb.ModalTranslateEditor.setValue(value);
let onSave = function(event) {
selectedEl.innerHTML = event.detail;
//selectedEl.outerHTML = value;
};
- window.removeEventListener("vvveb.ModalCodeEditor.save", onSave);
- window.addEventListener("vvveb.ModalCodeEditor.save", onSave);
+ window.removeEventListener("vvveb.ModalTranslateEditor.save", onSave);
+ window.addEventListener("vvveb.ModalTranslateEditor.save", onSave);
event.preventDefault();
return false;
@@ -2215,13 +2215,14 @@ Vvveb.Builder = {
Vvveb.ModalCodeEditor = {
modal: false,
+ modalId: 'codeEditorModal',
editor: false,
init: function(modal = false, editor = false) {
if (modal) {
this.modal = modal;
} else {
- this.modal = document.getElementById('codeEditorModal');
+ this.modal = document.getElementById(this.modalId);
}
if (editor) {
this.editor = editor;
@@ -2264,6 +2265,10 @@ Vvveb.ModalCodeEditor = {
},
}
+//Vvveb.ModalTranslateEditor = structuredClone(Vvveb.ModalCodeEditor);
+Vvveb.ModalTranslateEditor = Object.assign({}, Vvveb.ModalCodeEditor);
+Vvveb.ModalTranslateEditor.modalId = 'translateEditorModal';
+
Vvveb.CodeEditor = {
isActive: false,
@@ -2675,6 +2680,7 @@ Vvveb.StyleManager = {
mobileWidth: '320px',
tabletWidth: '768px',
doc:false,
+ inlineCSS:false,
init: function(doc) {
if (doc) {
@@ -2798,6 +2804,11 @@ Vvveb.StyleManager = {
selector = this.getSelectorForElement(node);
}
+ if (this.inlineCSS) {
+ element.style[styleProp] = value;
+ return element;
+ }
+
media = document.getElementById("canvas").classList.contains("tablet") ? "tablet" : document.getElementById("canvas").classList.contains("mobile") ? "mobile" : "desktop";
//styles[media][selector][styleProp] = value
@@ -3594,14 +3605,14 @@ Vvveb.FileManager = {
let name;
let _self = this;
+ name = element.querySelector('label span')?.textContent.replace('.html', '');
if (post_id) {
- name = element.querySelector('label span')?.textContent;
name = prompt(`Enter new name for "${name}"`, name);
if (name) {
newfile = page.file;
}
} else {
- newfile = prompt(`Enter new file name for "${page.file}"`, page.file);
+ newfile = prompt(`Enter new file name for "${page.file}"`, name.toLowerCase());
}
if (newfile || name) {
@@ -3620,7 +3631,7 @@ Vvveb.FileManager = {
.then((data) => {
let bg = "bg-success";
if (data.success) {
- document.querySelectorAll("#top-panel .save-btn").forEach(e => e.setAttribute("disabled", "true"));
+ //document.querySelectorAll("#top-panel .save-btn").forEach(e => e.setAttribute("disabled", "true"));
} else {
bg = "bg-danger";
}
@@ -3631,10 +3642,18 @@ Vvveb.FileManager = {
let newName = name || friendlyName(newfile.replace(/.*[\/\\]+/, '')).replace('.html', '');
if (duplicate) {
- let data = _self.pages[page.page];
- data["file"] = newfile;
- data["title"] = newName;
- Vvveb.FileManager.addPage(baseName, data);
+ let addPage = _self.pages[page.page];
+ addPage["name"] = baseName;
+ addPage["file"] = newfile;
+ addPage["title"] = newName;
+ addPage["url"] = data.url;
+ if (data.newfile) {
+ //addPage["url"] = Vvveb.themeBaseUrl + addPage["url"]
+ addPage["url"] = page.url.substring(0, page.url.lastIndexOf("/") + 1) + addPage["url"];
+ }
+
+ let newPage = Vvveb.FileManager.addPage(baseName, addPage, page.page);
+ Vvveb.FileManager.scrollToPage(newPage);
} else {
_self.pages[page.page]["file"] = newfile;
_self.pages[page.page]["title"] = newName;
@@ -3651,7 +3670,7 @@ Vvveb.FileManager = {
let message = error.statusText ?? "Error renaming page!";
displayToast("bg-danger", "Error", message);
- err.text().then( errorMessage => {
+ error.text().then( errorMessage => {
let message = errorMessage.substr(0, 200);
displayToast("bg-danger", "Error", message);
})
@@ -3660,7 +3679,7 @@ Vvveb.FileManager = {
}
},
- addPage: function(name, data) {
+ addPage: function(name, data, afterPage = false) {
//allow event to change name or cancel by setting name to false
window.dispatchEvent(new CustomEvent("vvveb.FileManager.addPage", {
@@ -3686,7 +3705,12 @@ Vvveb.FileManager = {
}
let page = generateElements(tmpl("vvveb-filemanager-page", data))[0];
- folder.append(page);
+ if (afterPage && (afterPage = folder.querySelector('[data-page="' + afterPage + '"]'))) {
+ afterPage.after(page);
+ } else {
+ folder.append(page);
+ }
+
return page;
},
diff --git a/public/js/vvvebjs/components/ecommerce/cart.js b/public/js/vvvebjs/components/ecommerce/cart.js
index 80b4f15..656e62d 100755
--- a/public/js/vvvebjs/components/ecommerce/cart.js
+++ b/public/js/vvvebjs/components/ecommerce/cart.js
@@ -165,13 +165,16 @@ let template =
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/categories.js b/public/js/vvvebjs/components/ecommerce/categories.js
index feb759d..1d3ec30 100755
--- a/public/js/vvvebjs/components/ecommerce/categories.js
+++ b/public/js/vvvebjs/components/ecommerce/categories.js
@@ -86,13 +86,16 @@ class CategoriesComponent {
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/checkout.js b/public/js/vvvebjs/components/ecommerce/checkout.js
index a370de2..bbe03db 100755
--- a/public/js/vvvebjs/components/ecommerce/checkout.js
+++ b/public/js/vvvebjs/components/ecommerce/checkout.js
@@ -442,13 +442,16 @@ Place order <i class="la la-arrow-right"></i>
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/filters.js b/public/js/vvvebjs/components/ecommerce/filters.js
index 9a211a1..021e1eb 100755
--- a/public/js/vvvebjs/components/ecommerce/filters.js
+++ b/public/js/vvvebjs/components/ecommerce/filters.js
@@ -218,13 +218,16 @@ class FiltersComponent {
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/manufacturers.js b/public/js/vvvebjs/components/ecommerce/manufacturers.js
index f547b0e..c7b037c 100755
--- a/public/js/vvvebjs/components/ecommerce/manufacturers.js
+++ b/public/js/vvvebjs/components/ecommerce/manufacturers.js
@@ -45,13 +45,16 @@ class ManufacturersComponent {
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/product.js b/public/js/vvvebjs/components/ecommerce/product.js
index ff3111d..729c29d 100755
--- a/public/js/vvvebjs/components/ecommerce/product.js
+++ b/public/js/vvvebjs/components/ecommerce/product.js
@@ -440,13 +440,16 @@ class ProductComponent {
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/productGallery.js b/public/js/vvvebjs/components/ecommerce/productGallery.js
index d28d727..773d96f 100755
--- a/public/js/vvvebjs/components/ecommerce/productGallery.js
+++ b/public/js/vvvebjs/components/ecommerce/productGallery.js
@@ -36,13 +36,16 @@ class ProductGalleryComponent {
init(node)
{
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
+ el.classList.add("d-none");
+ });
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
+
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}
diff --git a/public/js/vvvebjs/components/ecommerce/vendors.js b/public/js/vvvebjs/components/ecommerce/vendors.js
index 73bc8fc..35c2b30 100755
--- a/public/js/vvvebjs/components/ecommerce/vendors.js
+++ b/public/js/vvvebjs/components/ecommerce/vendors.js
@@ -48,14 +48,13 @@ class VendorsComponent {
document.querySelectorAll('.mb-3[data-group]').forEach((el, i) => {
el.classList.add("d-none");
});
+
+ let source = node.dataset.vSource;
+ if (!source) {
+ source = "automatic";
+ }
- if (node.dataset.type != undefined) {
- document.querySelectorAll('.mb-3[data-group="'+ + node.dataset.type + '"]').forEach((el, i) => {
- el.classList.remove("d-none");
- });
- } else {
- document.querySelector('.mb-3[data-group]:first').classList.remove("d-none");
- }
+ document.querySelectorAll('.mb-3[data-group="' + source + '"]').forEach(e => e.classList.remove("d-none"));
}
}