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 'Add new' dialog changed to add also post/page/product

givanz03bc34b5ba4f
diff --git a/admin/controller/editor/editor.php b/admin/controller/editor/editor.php
index 1a2eda0..d4b8de4 100755
--- a/admin/controller/editor/editor.php
+++ b/admin/controller/editor/editor.php
@@ -22,8 +22,10 @@
namespace Vvveb\Controller\Editor;
+use \Vvveb\Sql\menuSQL;
use function Vvveb\__;
use Vvveb\Controller\Base;
+use function Vvveb\getUrl;
use function Vvveb\sanitizeFileName;
use function Vvveb\slugify;
use Vvveb\Sql\PostSQL;
@@ -34,6 +36,8 @@ use Vvveb\System\Event;
use Vvveb\System\Sites;
class Editor extends Base {
+ protected $revisionDateFormat = 'Y-m-d_H:i:s';
+
private $themeConfig = [];
private $skipFolders = ['src', 'source', 'backup', 'import'];
@@ -46,6 +50,18 @@ class Editor extends Base {
return parent::init();
}
+ function oEmbedProxy() {
+ $url = $this->request->get['url'];
+
+ if (! $url) {
+ return;
+ }
+ $result = getUrl($url, false);
+
+ $this->response->setType('json');
+ $this->response->output($result);
+ }
+
function getThemeFolder() {
$theme = $this->request->get['theme'] ?? Sites::getTheme() ?? 'default';
@@ -143,19 +159,26 @@ class Editor extends Base {
$view->pages = [$name => $current_page] + $view->pages;
}
- $admin_path = \Vvveb\adminPath();
- $mediaControllerPath = $admin_path . 'index.php?module=media/media';
- $controllerPath = $admin_path . 'index.php?module=editor/editor';
-
- $this->view->scanUrl = "$mediaControllerPath&action=scan";
- $this->view->uploadUrl = "$mediaControllerPath&action=upload";
- $this->view->saveUrl = "$controllerPath&action=save";
- $this->view->deleteUrl = "$controllerPath&action=delete";
- $this->view->renameUrl = "$controllerPath&action=rename";
- $this->view->saveReusableUrl = "$controllerPath&action=saveReusable";
- $view->templates = \Vvveb\getTemplateList();
- $view->folders = \Vvveb\getThemeFolderList();
- $view->data = $this->loadEditorData();
+ $admin_path = \Vvveb\adminPath();
+ $mediaControllerPath = $admin_path . 'index.php?module=media/media';
+ $controllerPath = $admin_path . 'index.php?module=editor/editor';
+ $revisionsPath = $admin_path . 'index.php?module=editor/revisions';
+
+ $this->view->scanUrl = "$mediaControllerPath&action=scan";
+ $this->view->uploadUrl = "$mediaControllerPath&action=upload";
+ $this->view->saveUrl = "$controllerPath&action=save";
+ $this->view->deleteUrl = "$controllerPath&action=delete";
+ $this->view->renameUrl = "$controllerPath&action=rename";
+ $this->view->saveReusableUrl = "$controllerPath&action=saveReusable";
+ $this->view->oEmbedProxyUrl = "$controllerPath&action=oEmbedProxy";
+
+ $this->view->revisionsUrl = "$revisionsPath&action=revisions";
+ $this->view->revisionLoadUrl = "$revisionsPath&action=revisionLoad";
+ $this->view->revisionDeleteUrl = "$revisionsPath&action=revisionDelete";
+
+ $view->templates = \Vvveb\getTemplateList();
+ $view->folders = \Vvveb\getThemeFolderList();
+ $view->data = $this->loadEditorData();
}
function getComponent($html, $options) {
@@ -165,8 +188,8 @@ class Editor extends Base {
$themeFolder = $this->getThemeFolder() . DS;
$backupFolder = $themeFolder . 'backup' . DS;
$page = str_replace('.html', '', sanitizeFileName($page));
- $backupName = str_replace(DS, '-', $page) . '|' . date('Y-m-d_H:i:s') . '.html';
- $file = $themeFolder . $page . '.html';
+ $backupName = str_replace(DS, '-', $page) . '|' . date($this->revisionDateFormat) . '.html';
+ $file = $themeFolder . $page . '.html';
if (is_dir($backupFolder)) {
if (file_exists($file)) {
@@ -252,7 +275,6 @@ class Editor extends Base {
$file = sanitizeFileName($this->request->post['file']);
$themeFolder = $this->getThemeFolder();
//echo $themeFolder . DS . $file;
- header('Content-type: application/json; charset=utf-8');
if (unlink($themeFolder . DS . $file)) {
$message = ['success' => true, 'message' => __('File deleted!')];
@@ -260,9 +282,8 @@ class Editor extends Base {
$message = ['success' => false, 'message' => __('Error deleting file!')];
}
- echo json_encode($message);
-
- die();
+ $this->response->setType('json');
+ $this->response->output($message);
}
function rename() {
@@ -271,7 +292,6 @@ class Editor extends Base {
$duplicate = $this->request->post['duplicate'] ?? false;
$themeFolder = $this->getThemeFolder();
- header('Content-type: application/json; charset=utf-8');
$currentFile = $themeFolder . DS . $file;
$targetFile = $themeFolder . DS . $newfile;
@@ -289,9 +309,8 @@ class Editor extends Base {
}
}
- echo json_encode($message);
-
- die();
+ $this->response->setType('json');
+ $this->response->output($message);
}
function saveReusable() {
@@ -303,8 +322,6 @@ class Editor extends Base {
$folder = $themeFolder . DS . $type . 's' . DS . 'reusable' . DS;
$file = "$name.html";
- header('Content-type: application/json; charset=utf-8');
-
@mkdir($folder);
if (file_put_contents($folder . $file, $html)) {
@@ -313,33 +330,107 @@ class Editor extends Base {
$message = ['success' => false, 'message' => __('Error saving!')];
}
- echo json_encode($message);
-
- die();
+ $this->response->setType('json');
+ $this->response->output($message);
}
function save() {
- $page = sanitizeFileName($_POST['file']);
+ $file = $this->request->post['file'] ?? '';
+ $startTemplateUrl = $this->request->post['startTemplateUrl'] ?? '';
+ $name = $this->request->post['name'] ?? '';
+ $content = $this->request->post['content'] ?? 'Lorem ipsum';
+ $type = $this->request->post['type'] ?? false;
+ $addMenu = $this->request->post['add-menu'] ?? false;
+ $menu_id = $this->request->post['menu_id'] ?? false;
+ $url = '';
+
+ $file = sanitizeFileName(slugify(str_replace('.html', '', $file))) . '.html';
+
+ if ($type && $name) {
+ $slug = slugify($name);
+ $success = false;
+
+ switch ($type) {
+ case 'page':
+ case 'post':
+ $file = sanitizeFileName("content/$slug.html");
+ $startTemplateUrl = "content/$type.html";
+ $post = new PostSQL();
+ $result = $post->add([
+ 'post' => [
+ 'template' => $file,
+ 'type' => $type,
+ 'image' => 'posts/2.jpg', //'placeholder.svg'
+ 'post_content' => [[
+ 'slug' => $slug,
+ 'name' => $name,
+ 'content' => $content,
+ 'language_id' => $this->global['language_id'],
+ ]],
+ ] + $this->global, ] + $this->global);
+
+ if ($result['post']) {
+ $success = true;
+ $route = "content/{$type}/index";
+ $url = \Vvveb\url($route, ['slug'=> $slug]);
+ }
+
+ break;
+
+ case 'product':
+ $file = sanitizeFileName("product/$slug.html");
+ $startTemplateUrl = "product/$type.html";
+ $price = $this->request->post['price'] ?? 0;
+ $product = new ProductSQL();
+ $result = $product->add([
+ 'product' => [
+ 'model' => '',
+ 'image' => 'posts/2.jpg', //'placeholder.svg'
+ 'status' => 1, //active
+ 'template' => $file,
+ 'price' => $price,
+ 'product_content' => [[
+ 'slug' => $slug,
+ 'name' => $name,
+ 'name' => $name,
+ 'content' => $content,
+ 'language_id' => $this->global['language_id'],
+ ]],
+ ] + $this->global, ] + $this->global);
+
+ if ($result['product']) {
+ $success = true;
+ $route = "product/{$type}/index";
+ $url = \Vvveb\url($route, ['slug'=> $slug]);
+ }
+
+ break;
+ }
+ }
- $content = $this->request->post['html'] ?? false;
- $startTemplateUrl = $this->request->post['startTemplateUrl'] ?? false;
- $elements = $this->request->post['elements'] ?? false;
- $setTemplate = $this->request->post['setTemplate'] ?? false;
+ $content = $this->request->post['html'] ?? false;
+ $elements = $this->request->post['elements'] ?? false;
+ $setTemplate = $this->request->post['setTemplate'] ?? false;
- header('Content-type: application/json; charset=utf-8');
$view = View::getInstance();
$view->noJson = true;
$success = false;
$text = '';
$themeFolder = $this->getThemeFolder();
+ $baseUrl = '/themes/' . (Sites::getTheme() ?? 'default') . '/';
- if ($startTemplateUrl && ! $content) {
- $baseUrl = '/themes/' . (Sites::getTheme() ?? 'default') . '/';
+ if ($startTemplateUrl) {
$content = file_get_contents($themeFolder . DS . $startTemplateUrl);
$content = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $content);
}
+ if (! $url) {
+ $url = "$baseUrl/$file";
+ }
+
+ $data = compact('file', 'name', 'url', 'startTemplateUrl');
+
if ($elements) {
if ($this->saveElements($elements)) {
$success = true;
@@ -351,18 +442,38 @@ class Editor extends Base {
}
if (! $startTemplateUrl) {
- if ($this->backup($page)) {
+ if ($this->backup($file)) {
} else {
$success = false;
$text .= __('Error saving backup!') . "\n";
}
}
+ if ($addMenu && $menu_id) {
+ $menuData = ['menu_item' => [
+ 'menu_id' => $menu_id,
+ 'url' => $url,
+ 'menu_item_content' => [[
+ 'name' => $name,
+ 'slug' => $slug,
+ 'language_id' => $this->global['language_id'],
+ 'content' => '',
+ ]],
+ ]] + $this->global;
+
+ $menus = new menuSQL();
+ $results = $menus->addMenuItem($menuData);
+
+ if ($results) {
+ $text .= "\n" . __('Menu item added!');
+ }
+ }
+
//if plugins template use public path
- if (substr_compare($page[0],'/plugins/', 0, 9) === 0) {
- $fileName = DIR_PUBLIC . DS . $page;
+ if (substr_compare($file[0],'/plugins/', 0, 9) === 0) {
+ $fileName = DIR_PUBLIC . DS . $file;
} else {
- $fileName = $themeFolder . DS . $page;
+ $fileName = $themeFolder . DS . $file;
}
if (file_put_contents($fileName, $content)) {
@@ -373,11 +484,9 @@ class Editor extends Base {
if (CacheManager::clearCompiledFiles('app') && CacheManager::delete()) {
}
- $message = ['success' => $success, 'message' => $text];
- echo json_encode($message);
-
- die();
+ $data += ['success' => $success, 'message' => $text];
- return false;
+ $this->response->setType('json');
+ $this->response->output($data);
}
}
diff --git a/admin/template/editor/editor.tpl b/admin/template/editor/editor.tpl
index 79816f6..227b4a7 100755
--- a/admin/template/editor/editor.tpl
+++ b/admin/template/editor/editor.tpl
@@ -40,7 +40,7 @@ if(isset($this->themeBlocks) && is_array($this->themeBlocks))
foreach ($this->themeBlocks as $id => $file) {?>
[data-v-theme-blocks]|src = $file
- [data-v-theme-blocks]|id = $id
+ [data-v-theme-blocks]|id = <?php echo "theme-$id";?>
[data-v-theme-blocks]|after = <?php
}
@@ -55,7 +55,7 @@ if(isset($this->themeSections) && is_array($this->themeSections))
foreach ($this->themeSections as $id => $file) {?>
[data-v-theme-sections]|src = $file
- [data-v-theme-sections]|id = $id
+ [data-v-theme-sections]|id = <?php echo "theme-$id";?>
[data-v-theme-sections]|after = <?php
}
@@ -70,7 +70,7 @@ if(isset($this->themeJs) && is_array($this->themeJs))
foreach ($this->themeJs as $id => $file) {?>
[data-v-theme-js]|src = $file
- [data-v-theme-js]|id = $id
+ [data-v-theme-js]|id = <?php echo "theme-$id";?>"
[data-v-theme-js]|after = <?php
}
diff --git a/install/sql/mysqli/schema/product/product.sql b/install/sql/mysqli/schema/product/product.sql
index 05a11af..d163cc4 100755
--- a/install/sql/mysqli/schema/product/product.sql
+++ b/install/sql/mysqli/schema/product/product.sql
@@ -4,23 +4,23 @@ CREATE TABLE `product` (
`product_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`admin_id` INT unsigned NOT NULL DEFAULT '0',
`parent_id` INT UNSIGNED NOT NULL DEFAULT 0,
- `model` varchar(64) NOT NULL,
- `sku` varchar(64) NOT NULL,
- `upc` varchar(12) NOT NULL,
- `ean` varchar(14) NOT NULL,
- `jan` varchar(13) NOT NULL,
- `isbn` varchar(17) NOT NULL,
- `mpn` varchar(64) NOT NULL,
- `location` varchar(128) NOT NULL,
+ `model` varchar(64) NOT NULL DEFAULT '',
+ `sku` varchar(64) NOT NULL DEFAULT '',
+ `upc` varchar(12) NOT NULL DEFAULT '',
+ `ean` varchar(14) NOT NULL DEFAULT '',
+ `jan` varchar(13) NOT NULL DEFAULT '',
+ `isbn` varchar(17) NOT NULL DEFAULT '',
+ `mpn` varchar(64) NOT NULL DEFAULT '',
+ `location` varchar(128) NOT NULL DEFAULT '',
`stock_quantity` int(4) NOT NULL DEFAULT '0',
- `stock_status_id` INT UNSIGNED NOT NULL,
- `image` varchar(191) NOT NULL,
+ `stock_status_id` INT UNSIGNED NOT NULL DEFAULT 1,
+ `image` varchar(191) NOT NULL DEFAULT '',
`manufacturer_id` INT UNSIGNED NOT NULL DEFAULT 0,
`vendor_id` INT UNSIGNED NOT NULL DEFAULT 0,
`requires_shipping` tinyint NOT NULL DEFAULT '1',
`price` decimal(15,4) NOT NULL DEFAULT 0.0000,
`points` int(8) NOT NULL DEFAULT '0',
- `tax_type_id` INT UNSIGNED NOT NULL,
+ `tax_type_id` INT UNSIGNED NOT NULL DEFAULT 0,
`weight` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`weight_type_id` INT UNSIGNED NOT NULL DEFAULT '0',
`length` decimal(15,8) NOT NULL DEFAULT '0.00000000',
diff --git a/install/sql/pgsql/schema/product/product.sql b/install/sql/pgsql/schema/product/product.sql
index d7a694f..499d9f9 100755
--- a/install/sql/pgsql/schema/product/product.sql
+++ b/install/sql/pgsql/schema/product/product.sql
@@ -7,23 +7,23 @@ CREATE SEQUENCE product_seq;
CREATE TABLE product (
"product_id" int check ("product_id" > 0) NOT NULL DEFAULT NEXTVAL ('product_seq'),
"admin_id" int check ("admin_id" >= 0) NOT NULL DEFAULT 0,
- "model" varchar(64) NOT NULL,
- "sku" varchar(64) NOT NULL,
- "upc" varchar(12) NOT NULL,
- "ean" varchar(14) NOT NULL,
- "jan" varchar(13) NOT NULL,
- "isbn" varchar(17) NOT NULL,
- "mpn" varchar(64) NOT NULL,
- "location" varchar(128) NOT NULL,
+ "model" varchar(64) NOT NULL DEFAULT '',
+ "sku" varchar(64) NOT NULL DEFAULT '',
+ "upc" varchar(12) NOT NULL DEFAULT '',
+ "ean" varchar(14) NOT NULL DEFAULT '',
+ "jan" varchar(13) NOT NULL DEFAULT '',
+ "isbn" varchar(17) NOT NULL DEFAULT '',
+ "mpn" varchar(64) NOT NULL DEFAULT '',
+ "location" varchar(128) NOT NULL DEFAULT '',
"stock_quantity" int NOT NULL DEFAULT 0,
- "stock_status_id" int check ("stock_status_id" >= 0) NOT NULL,
- "image" varchar(191) NOT NULL,
+ "stock_status_id" int check ("stock_status_id" >= 0) NOT NULL DEFAULT 0,
+ "image" varchar(191) NOT NULL DEFAULT '',
"manufacturer_id" int check ("manufacturer_id" >= 0) NOT NULL DEFAULT 0,
"vendor_id" int check ("vendor_id" >= 0) NOT NULL DEFAULT 0,
"requires_shipping" smallint NOT NULL DEFAULT 1,
"price" decimal(15,4) NOT NULL DEFAULT 0.0000,
"points" int NOT NULL DEFAULT 0,
- "tax_type_id" int check ("tax_type_id" >= 0) NOT NULL,
+ "tax_type_id" int check ("tax_type_id" >= 0) NOT NULL DEFAULT 0,
"weight" decimal(15,8) NOT NULL DEFAULT 0.00000000,
"weight_type_id" int check ("weight_type_id" >= 0) NOT NULL DEFAULT 0,
"length" decimal(15,8) NOT NULL DEFAULT 0.00000000,
diff --git a/install/sql/sqlite/schema/product/product.sql b/install/sql/sqlite/schema/product/product.sql
index b38e8a4..509d52b 100755
--- a/install/sql/sqlite/schema/product/product.sql
+++ b/install/sql/sqlite/schema/product/product.sql
@@ -3,37 +3,37 @@ DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
`product_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`admin_id` INT NOT NULL DEFAULT 0,
-`model` TEXT NOT NULL,
-`sku` TEXT NOT NULL,
-`upc` TEXT NOT NULL,
-`ean` TEXT NOT NULL,
-`jan` TEXT NOT NULL,
-`isbn` TEXT NOT NULL,
-`mpn` TEXT NOT NULL,
-`location` TEXT NOT NULL,
-`stock_quantity` INTEGER NOT NULL DEFAULT '0',
-`stock_status_id` INT NOT NULL,
-`image` TEXT NOT NULL,
+`model` TEXT NOT NULL DEFAULT '',
+`sku` TEXT NOT NULL DEFAULT '',
+`upc` TEXT NOT NULL DEFAULT '',
+`ean` TEXT NOT NULL DEFAULT '',
+`jan` TEXT NOT NULL DEFAULT '',
+`isbn` TEXT NOT NULL DEFAULT '',
+`mpn` TEXT NOT NULL DEFAULT '',
+`location` TEXT NOT NULL DEFAULT '',
+`stock_quantity` INTEGER NOT NULL DEFAULT 0,
+`stock_status_id` INT NOT NULL DEFAULT 1,
+`image` TEXT NOT NULL DEFAULT '',
`manufacturer_id` INT NOT NULL DEFAULT 0,
`vendor_id` INT NOT NULL DEFAULT 0,
-`requires_shipping` TINYINT NOT NULL DEFAULT '1',
+`requires_shipping` TINYINT NOT NULL DEFAULT 1,
`price` decimal(15,4) NOT NULL DEFAULT 0.0000,
-`points` INTEGER NOT NULL DEFAULT '0',
-`tax_type_id` INT NOT NULL,
+`points` INTEGER NOT NULL DEFAULT 0,
+`tax_type_id` INT NOT NULL DEFAULT 0,
`weight` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`weight_type_id` INT NOT NULL DEFAULT '0',
`length` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`width` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`height` decimal(15,8) NOT NULL DEFAULT '0.00000000',
-`length_type_id` INT NOT NULL DEFAULT '0',
+`length_type_id` INT NOT NULL DEFAULT 0,
`date_available` date NOT NULL DEFAULT '1000-01-01',
`template` TEXT NOT NULL DEFAULT '',
-`views` INTEGER NOT NULL DEFAULT '0',
-`subtract_stock` TINYINT NOT NULL DEFAULT '1',
-`minimum_quantity` INT NOT NULL DEFAULT '1',
+`views` INTEGER NOT NULL DEFAULT 0,
+`subtract_stock` TINYINT NOT NULL DEFAULT 1,
+`minimum_quantity` INT NOT NULL DEFAULT 1,
`type` TEXT NOT NULL DEFAULT 'product',
-`status` TINYINT NOT NULL DEFAULT '0',
-`sort_order` INT NOT NULL DEFAULT '0',
+`status` TINYINT NOT NULL DEFAULT 0,
+`sort_order` INT NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
-- PRIMARY KEY (`product_id`)