Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Text type for menu item for mega menu feature

givanz2cb82bbc036d
diff --git a/admin/controller/content/menus.php b/admin/controller/content/menus.php
index d998544..871a926 100755
--- a/admin/controller/content/menus.php
+++ b/admin/controller/content/menus.php
@@ -22,8 +22,10 @@
namespace Vvveb\Controller\Content;
-use \Vvveb\Sql\menuSQL;
use function Vvveb\__;
+use function Vvveb\sanitizeHTML;
+use Vvveb\Sql\menuSQL;
+use Vvveb\System\Sites;
class Menus extends Categories {
function deleteMenu() {
@@ -93,11 +95,26 @@ class Menus extends Categories {
$menus = new menuSQL();
+ if (isset($data['item_id']) && ! is_numeric($data['item_id'])) {
+ unset($data['item_id']);
+ }
+
+ if (isset($data['menu_item_content'])) {
+ foreach ($data['menu_item_content'] as &$lang) {
+ $lang['content'] = sanitizeHTML($lang['content']);
+
+ // if autocomplete set text as default name for languages
+ if (isset($data['item_id_text'])) {
+ $lang['name'] = $data['item_id_text'];
+ }
+ }
+ }
+
if (isset($data['menu_item_id']) && $data['menu_item_id']) {
$results = $menus->editMenuItem(['menu_item' => $data, 'menu_item_id' => $data['menu_item_id']]);
if ($results) {
- echo __('Item edited!');
+ echo __('Item saved!');
}
} else {
$results = $menus->addMenuItem(['menu_item' => $data]);
@@ -123,7 +140,8 @@ class Menus extends Categories {
if ($menuId) {
$options = [
- 'menu_id' => $menuId, //menus
+ 'menu_id' => $menuId,
+ 'limit' => 100000,
] + $this->global;
$results = $menus->getMenuAllLanguages($options);
@@ -137,7 +155,8 @@ class Menus extends Categories {
$menu['languages'][$lang['language_id']] = $lang;
}
- $menu['name'] = $menu['languages'][$this->global['language_id']]['name'] ?? $langs[0]['name'] ?? '';
+ $menu['name'] = $menu['languages'][$this->global['language_id']]['name'] ?? $langs[0]['name'] ?? '';
+ $menu['content'] = $menu['languages'][$this->global['language_id']]['content'] ?? $langs[0]['content'] ?? '';
}
}
@@ -172,6 +191,14 @@ class Menus extends Categories {
$view->set($results);
+ $admin_path = \Vvveb\adminPath();
+ $controllerPath = $admin_path . 'index.php?module=media/media';
+ $view->scanUrl = "$controllerPath&action=scan";
+ $view->uploadUrl = "$controllerPath&action=upload";
+ $theme = Sites::getTheme() ?? 'default';
+ $view->themeCss = PUBLIC_PATH . "themes/$theme/css/admin-post-editor.css";
+ //$view->themeCss = PUBLIC_PATH . "themes/$theme/css/style.css";
+
//return 'content/menus/menu.html';
}
diff --git a/admin/template/content/menus/menu.tpl b/admin/template/content/menus/menu.tpl
index c854dd5..5cb095b 100755
--- a/admin/template/content/menus/menu.tpl
+++ b/admin/template/content/menus/menu.tpl
@@ -29,8 +29,23 @@ if ($_categories) {
?>
@menu|data-v-id = $menu['menu_item_id']
- @menu [data-v-url] = $menu['url']
- @menu [data-v-sort_order] = $menu['sort_order']
+ @menu input[data-v-menu-*] = $menu['@@__data-v-menu-(*)__@@']
+ @menu input[data-v-menu-item_id]|data-text = <?php
+ $type = '@@__data-type__@@';
+ if ($menu['type'] == $type) {
+ $langtext = reset($menu['languages']);
+ echo $langtext['name'] ?? '';
+ } else echo ' ';
+ ?>
+
+ @menu select[data-v-menu-*]|before = <?php $name = '@@__data-v-menu-(*)__@@';?>
+
+ @menu select[data-v-menu-*] option|addNewAttribute = <?php
+ $value = '@@__value__@@';
+ if (isset($menu[$name]) && ($value == $menu[$name])) {
+ echo 'selected';
+ }
+ ?>
@menu|before = <?php
diff --git a/admin/template/menu.tpl b/admin/template/menu.tpl
index 931480a..a3747e4 100755
--- a/admin/template/menu.tpl
+++ b/admin/template/menu.tpl
@@ -4,8 +4,8 @@
@submenumenu_item = [data-v-menu] [data-v-menu-item] [data-v-submenu]
-@menu_item|deleteAllButFirst
-@submenumenu_item [data-v-submenu-item]|deleteAllButFirst
+@menu_item|deleteAllButFirstChild
+@submenumenu_item [data-v-submenu-item]|deleteAllButFirstChild
@menu_item|before = <?php
diff --git a/app/component/menu.php b/app/component/menu.php
index 793a8c3..e202c80 100755
--- a/app/component/menu.php
+++ b/app/component/menu.php
@@ -22,9 +22,13 @@
namespace Vvveb\Component;
+use function Vvveb\sanitizeHTML;
use Vvveb\Sql\menuSQL;
+use Vvveb\Sql\postSQL;
+use Vvveb\Sql\productSQL;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use function Vvveb\url;
class Menu extends ComponentBase {
public static $defaultOptions = [
@@ -45,8 +49,12 @@ class Menu extends ComponentBase {
$menuSql = new menuSQL();
$results = $menuSql->getMenus($options);
$current_category_slug = false;
+
//count the number of child menus (subcategories) for each category
if (isset($results['menus'])) {
+ $productIds = [];
+ $postIds = [];
+
foreach ($results['menus'] as $taxonomy_item_id => &$category) {
$parent_id = $category['parent_id'] ?? false;
@@ -68,6 +76,66 @@ class Menu extends ComponentBase {
} else {
$parent['children'] = 1;
}
+
+ if ($category['type'] == 'text') {
+ $parent['has-text'] = true;
+ }
+ }
+
+ if ($category['type'] == 'product') {
+ $productIds[$taxonomy_item_id] = $category['item_id'];
+ }
+
+ if ($category['type'] == 'post' || $category['type'] == 'page') {
+ $postIds[$taxonomy_item_id] = $category['item_id'];
+ }
+ }
+
+ //get product items
+ if ($productIds) {
+ $productOptions = [
+ 'product_id' => $productIds,
+ 'language_id' => $options['language_id'],
+ 'site_id' => $options['site_id'],
+ ];
+
+ $productSql = new productSql();
+ $products = $productSql->getAll($productOptions);
+
+ if (isset($products['products']) && $products['products']) {
+ $productTaxonomy = array_flip($productIds);
+
+ foreach ($products['products'] as $product) {
+ $taxonomy_item_id = $productTaxonomy[$product['product_id']];
+ $category = &$results['menus'][$taxonomy_item_id];
+ $route = "product/{$category['type']}/index";
+ $category['url'] = url($route, ['slug'=> $product['slug']]);
+ $category['name'] = $product['name'];
+ }
+ }
+ }
+
+ //get post items
+ if ($postIds) {
+ $postOptions = [
+ 'post_id' => $postIds,
+ 'language_id' => $options['language_id'],
+ 'site_id' => $options['site_id'],
+ ];
+
+ $postSql = new postSql();
+ $posts = $postSql->getAll($postOptions);
+
+ if (isset($posts['posts']) && $posts['posts']) {
+ $postTaxonomy = array_flip($postIds);
+
+ foreach ($posts['posts'] as $post) {
+ $taxonomy_item_id = $postTaxonomy[$post['post_id']];
+ $category = &$results['menus'][$taxonomy_item_id];
+ $route = "content/{$category['type']}/index";
+ $category['url'] = url($route, ['slug'=> $post['slug']]);
+ $category['name'] = $post['name'];
+ }
}
}
}
@@ -91,7 +159,7 @@ class Menu extends ComponentBase {
$menu_item_content[$name] = strip_tags($value);
} else {
if ($name == 'content') {
- $menu_item_content[$name] = $value;
+ $menu_item_content[$name] = sanitizeHTML($value);
} else {
$menu_item[$name] = $value;
}
diff --git a/install/sql/insert/menu/menu_item.sql b/install/sql/insert/menu/menu_item.sql
index f5df12f..4764e83 100755
--- a/install/sql/insert/menu/menu_item.sql
+++ b/install/sql/insert/menu/menu_item.sql
@@ -1,73 +1,74 @@
-INSERT INTO `menu_item` VALUES
-(1,3,'','',0,null,1,1),
-(2,3,'','',1,null,2,1),
-(3,3,'','',0,null,3,1),
-(4,3,'','',0,null,5,1),
-(5,3,'','',0,null,2,1),
-(6,3,'','',0,null,4,1),
-(7,3,'','',3,null,3,1),
-(8,3,'','',1,null,3,1),
-(9,3,'','',3,null,3,1),
-(10,3,'','',3,null,3,1),
-(11,3,'','',3,null,3,1),
-(12,3,'','',3,null,3,1),
-(13,3,'','',0,null,6,1),
-(14,3,'','',0,null,7,1),
-(15,3,'','',7,null,0,1),
-(16,3,'','',7,null,0,1),
-(17,3,'','',14,null,0,1),
-(18,3,'','',14,null,0,1),
-(19,3,'','',14,null,0,1),
-(20,3,'','',14,null,0,1),
-(21,3,'','',14,null,0,1),
-(22,3,'','',14,null,0,1),
-(23,3,'','',14,null,0,1),
-(24,3,'','',14,null,0,1),
-(25,3,'','',5,null,0,1),
-(26,3,'','',5,null,0,1),
-(27,3,'','',14,null,0,1),
-(28,3,'','',14,null,0,1),
-(29,3,'','',14,null,0,1),
-(30,3,'','',14,null,0,1),
-(31,3,'','',14,null,0,1),
-(32,3,'','',14,null,0,1),
-(33,3,'','',14,null,0,1),
-(34,3,'','',14,null,0,1),
-(35,3,'','',14,null,0,1),
-(36,3,'','',14,null,0,1),
-(37,3,'','',0,null,1,1),
-(38,3,'','',32,null,0,1),
+INSERT INTO `menu_item` (`menu_item_id`, `menu_id`, `type`, `url`, `parent_id`, `item_id`, `sort_order`, `status`) VALUES
+(1,3,'link','',0,null,1,1),
+(2,3,'link','',1,null,2,1),
+(3,3,'link','',0,null,3,1),
+(4,3,'link','',0,null,5,1),
+(5,3,'link','',0,null,2,1),
+(6,3,'link','',0,null,4,1),
+(7,3,'link','',3,null,3,1),
+(8,3,'link','',1,null,3,1),
+(9,3,'link','',3,null,3,1),
+(10,3,'link','',3,null,3,1),
+(11,3,'link','',3,null,3,1),
+(12,3,'link','',3,null,3,1),
+(13,3,'link','',0,null,6,1),
+(14,3,'link','',0,null,7,1),
+(15,3,'link','',7,null,0,1),
+(16,3,'link','',7,null,0,1),
+(17,3,'link','',14,null,0,1),
+(18,3,'link','',14,null,0,1),
+(19,3,'link','',14,null,0,1),
+(20,3,'link','',14,null,0,1),
+(21,3,'link','',14,null,0,1),
+(22,3,'link','',14,null,0,1),
+(23,3,'link','',14,null,0,1),
+(24,3,'link','',14,null,0,1),
+(25,3,'link','',5,null,0,1),
+(26,3,'link','',5,null,0,1),
+(27,3,'link','',14,null,0,1),
+(28,3,'link','',14,null,0,1),
+(29,3,'link','',14,null,0,1),
+(30,3,'link','',14,null,0,1),
+(31,3,'link','',14,null,0,1),
+(32,3,'link','',14,null,0,1),
+(33,3,'link','',14,null,0,1),
+(34,3,'link','',14,null,0,1),
+(35,3,'link','',14,null,0,1),
+(36,3,'link','',14,null,0,1),
+(37,3,'link','',0,null,1,1),
+(38,3,'link','',32,null,0,1),
-- tags
-(39,2,'','',0,null,0,1),
-(40,2,'','',0,null,0,1),
-(41,2,'','',0,null,0,1),
+(39,2,'link','',0,null,0,1),
+(40,2,'link','',0,null,0,1),
+(41,2,'link','',0,null,0,1),
-- menu
-(42,1,'','/',0,null,0,1),
-(43,1,'','/shop',0,null,3,1),
--- (44,1,'','//docs.*.*',0,null,2,1),
--- (45,1,'','//docs.*.*',44,null,0,1),
-(46,1,'','/blog',0,null,5,1),
--- (47,1,'','//github.com/givanz/Vvveb/discussions',44,null,0,1),
--- (48,1,'','//dev.*.*',44,null,3,1),
+(42,1,'link','/',0,null,0,1),
+(43,1,'link','/shop',0,null,3,1),
+-- (44,1,'link','//docs.*.*',0,null,2,1),
+-- (45,1,'link','//docs.*.*',44,null,0,1),
+(46,1,'link','/blog',0,null,5,1),
+-- (47,1,'link','//github.com/givanz/Vvveb/discussions',44,null,0,1),
+-- (48,1,'link','//dev.*.*',44,null,3,1),
-(49,1,'','/page/contact',0,null,6,1),
-(59,1,'','/page/about',0,null,1,1),
--- (60,1,'','/page/contact',59,null,0,1),
--- (61,1,'','/page/contact',59,null,3,1),
--- (62,1,'','/page/contact',59,null,2,1),
-
-(63,1,'','/page/contact',0,null,4,1),
-(64,1,'','/page/pricing',63,null,0,1),
-(65,1,'','/page/services',63,null,0,1),
-(66,1,'','/page/portfolio',63,null,0,1),
+(49,1,'link','/page/contact',0,null,6,1),
+(59,1,'link','/page/about',0,null,1,1),
+-- (60,1,'link','/page/contact',59,null,0,1),
+-- (61,1,'link','/page/contact',59,null,3,1),
+-- (62,1,'link','/page/contact',59,null,2,1),
+(63,1,'link','/page/contact',0,null,4,1),
+(64,1,'link','/page/pricing',63,null,0,1),
+(65,1,'link','/page/services',63,null,0,1),
+(66,1,'link','/page/portfolio',63,null,0,1),
+(67,1,'text','/page/about',0,NULL,3, 0),
+(68,1,'text','/page/about',67,NULL,0,0),
-- footer
-(50,5,'','',0,null,0,1),
-(51,5,'','/',50,null,0,1),
-(52,5,'','/shop',50,null,0,1),
-(53,5,'','//docs.*.*',0,null,0,1),
-(54,5,'','//dev.*.*',53,null,0,1),
-(55,5,'','//docs.*.*',53,null,0,1),
-(56,5,'','//github.com/givanz/VvvebJs',57,null,0,1),
-(57,5,'','/contact.html',0,null,0,1),
-(58,5,'','/blog',57,null,0,1);
+(50,5,'link','',0,null,0,1),
+(51,5,'link','/',50,null,0,1),
+(52,5,'link','/shop',50,null,0,1),
+(53,5,'link','//docs.*.*',0,null,0,1),
+(54,5,'link','//dev.*.*',53,null,0,1),
+(55,5,'link','//docs.*.*',53,null,0,1),
+(56,5,'link','//github.com/givanz/VvvebJs',57,null,0,1),
+(57,5,'link','/contact.html',0,null,0,1),
+(58,5,'link','/blog',57,null,0,1);
diff --git a/install/sql/insert/menu/menu_item_content.sql b/install/sql/insert/menu/menu_item_content.sql
index 0686516..2954e21 100755
--- a/install/sql/insert/menu/menu_item_content.sql
+++ b/install/sql/insert/menu/menu_item_content.sql
@@ -92,32 +92,48 @@ INSERT INTO `menu_item_content` VALUES
(40,1, 'Tag 2', 'Tag 2', 'tag 2'),
(41,1, 'Tag 3', 'Tag 3', 'tag 3'),
-- menu
-(42,1, 'Home', 'Home', 'home'),
-(43,1, 'Shop', 'Shop', 'shop'),
+(42,1, 'Home', 'Home', ''),
+(43,1, 'Shop', 'Shop', ''),
-- (44,1, 'Support', 'Tag 3', 'tag 3'),
-- (45,1, 'User documentation', 'Tag 3', 'tag 3'),
-(46,1, 'Blog', 'Blog', 'Blog'),
+(46,1, 'Blog', 'Blog', ''),
-- (47,1, 'Forums', 'Forums', 'Forums'),
-- (48,1, 'Developer guide', 'Developer', 'Developer'),
-(49,1, 'Contact', 'Contact', 'Contact'),
-(59,1, 'About', 'About', 'About'),
+(49,1, 'Contact', 'Contact', ''),
+(59,1, 'About', 'About', ''),
-- (60,1, 'Support Vvveb', 'Support Vvveb', 'Support Vvveb'),
-- (61,1, 'Contribute', 'Contribute', 'Contribute'),
-- (62,1, 'Translations', 'Translations', 'Translations'),
-(63,1, 'Services', 'Services', 'Services'),
-(64,1, 'Pricing', 'Pricing', 'Pricing'),
-(65,1, 'Services', 'Services', 'Services'),
-(66,1, 'Portfolio', 'Portfolio', 'Portfolio'),
+(63,1, 'Services', 'Services', ''),
+(64,1, 'Pricing', 'Pricing', ''),
+(65,1, 'Services', 'Services', ''),
+(66,1, 'Portfolio', 'Portfolio', ''),
+(67,1, 'Mega menu', '', '<p><img src="/media/vvveb.svg" height="24" alt="" class="me-2">Mega menu</p>'),
+(68,1, 'Features', '', '<div class="row">
+ <div class="col-6 align-self-center"><img src="/media/posts/4.jpg" alt="Post" width="250" loading="lazy" class="rounded"></div>
+ <div class="col-6">
+ <h4>Features</h4>
+ <p class="text-muted">Just a few mentions, but there is more</p>
+ <ul class="list-unstyled">
+ <li class="text-primary">Page builder</li>
+ <li class="text-primary">Mega menu</li>
+ <li class="text-primary">Multi language</li>
+ <li class="text-primary">Advanced SEO</li>
+ <li class="text-primary">Ecommerce</li>
+ </ul>
+ </div>
+</div>'),
+
-- footer
-(50,1, 'Vvveb', 'Vvveb', 'Vvveb'),
-(51,1, 'Home', 'Home', 'home'),
-(52,1, 'Shop', 'Shop', 'shop'),
-(53,1, 'Resources', 'Tag 3', 'tag 3'),
+(50,1, 'Vvveb', 'Vvveb', ''),
+(51,1, 'Home', 'Home', ''),
+(52,1, 'Shop', 'Shop', ''),
+(53,1, 'Resources', 'Tag 3', ''),
(54,1, 'Developer documentation', 'Developer documentation', 'Developer documentation'),
-(55,1, 'User documentation', 'Tag 3', 'tag 3'),
-(56,1, 'Github', 'Tag 3', 'tag 3'),
-(57,1, 'Contact', 'Tag 3', 'tag 3'),
-(58,1, 'Blog', 'Blog', 'Blog');
+(55,1, 'User documentation', 'Tag 3', ''),
+(56,1, 'Github', 'Tag 3', ''),
+(57,1, 'Contact', 'Tag 3', ''),
+(58,1, 'Blog', 'Blog', '');
diff --git a/install/sql/mysqli/schema/menu/menu_item.sql b/install/sql/mysqli/schema/menu/menu_item.sql
index ff5554c..cc74954 100755
--- a/install/sql/mysqli/schema/menu/menu_item.sql
+++ b/install/sql/mysqli/schema/menu/menu_item.sql
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS `menu_item`;
CREATE TABLE `menu_item` (
`menu_item_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`menu_id` INT UNSIGNED NOT NULL,
+ `type` varchar(191) NOT NULL DEFAULT 'link',
`image` varchar(191) NOT NULL DEFAULT '',
`url` varchar(191) NOT NULL DEFAULT '',
`parent_id` INT UNSIGNED NOT NULL DEFAULT '0',
diff --git a/install/sql/mysqli/schema/menu/menu_item_content.sql b/install/sql/mysqli/schema/menu/menu_item_content.sql
index 66790d1..bcf12a1 100755
--- a/install/sql/mysqli/schema/menu/menu_item_content.sql
+++ b/install/sql/mysqli/schema/menu/menu_item_content.sql
@@ -3,7 +3,7 @@ DROP TABLE IF EXISTS `menu_item_content`;
CREATE TABLE `menu_item_content` (
`menu_item_id` INT UNSIGNED NOT NULL,
`language_id` INT UNSIGNED NOT NULL,
- `name` varchar(191) NOT NULL,
+ `name` varchar(191) NOT NULL DEFAULT '',
`slug` varchar(191) NOT NULL DEFAULT '',
`content` text NOT NULL,
PRIMARY KEY (`menu_item_id`,`language_id`),
diff --git a/install/sql/pgsql/schema/menu/menu_item.sql b/install/sql/pgsql/schema/menu/menu_item.sql
index bc07074..aeac6f8 100755
--- a/install/sql/pgsql/schema/menu/menu_item.sql
+++ b/install/sql/pgsql/schema/menu/menu_item.sql
@@ -7,6 +7,7 @@ CREATE SEQUENCE menu_item_seq;
CREATE TABLE menu_item (
"menu_item_id" int check ("menu_item_id" > 0) NOT NULL DEFAULT NEXTVAL ('menu_item_seq'),
"menu_id" int check ("menu_id" > 0) NOT NULL,
+ "type" varchar(191) NOT NULL DEFAULT 'link',
"image" varchar(191) NOT NULL DEFAULT '',
"url" varchar(191) NOT NULL DEFAULT '',
"parent_id" int check ("parent_id" >= 0) NOT NULL DEFAULT 0,
diff --git a/install/sql/pgsql/schema/menu/menu_item_content.sql b/install/sql/pgsql/schema/menu/menu_item_content.sql
index 913293b..c7dd5f0 100755
--- a/install/sql/pgsql/schema/menu/menu_item_content.sql
+++ b/install/sql/pgsql/schema/menu/menu_item_content.sql
@@ -2,7 +2,7 @@ DROP TABLE IF EXISTS menu_item_content;
CREATE TABLE menu_item_content (
"menu_item_id" int check ("menu_item_id" > 0) NOT NULL,
"language_id" int check ("language_id" > 0) NOT NULL,
- "name" varchar(191) NOT NULL,
+ "name" varchar(191) NOT NULL DEFAULT '',
"slug" varchar(191) NOT NULL DEFAULT '',
"content" text NOT NULL,
PRIMARY KEY ("menu_item_id","language_id")
diff --git a/install/sql/sqlite/schema/menu/menu_item.sql b/install/sql/sqlite/schema/menu/menu_item.sql
index 3060d37..faaa016 100755
--- a/install/sql/sqlite/schema/menu/menu_item.sql
+++ b/install/sql/sqlite/schema/menu/menu_item.sql
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS `menu_item`;
CREATE TABLE `menu_item` (
`menu_item_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`menu_id` INT NOT NULL,
+`type` TEXT NOT NULL DEFAULT 'link',
`image` TEXT NOT NULL DEFAULT '',
`url` TEXT NOT NULL DEFAULT '',
`parent_id` INT NOT NULL DEFAULT '0',
diff --git a/install/sql/sqlite/schema/menu/menu_item_content.sql b/install/sql/sqlite/schema/menu/menu_item_content.sql
index 0c7ea39..8365a7f 100755
--- a/install/sql/sqlite/schema/menu/menu_item_content.sql
+++ b/install/sql/sqlite/schema/menu/menu_item_content.sql
@@ -3,10 +3,10 @@ DROP TABLE IF EXISTS `menu_item_content`;
CREATE TABLE `menu_item_content` (
`menu_item_id` INT NOT NULL,
`language_id` INT NOT NULL,
-`name` TEXT NOT NULL,
-`slug` TEXT NOT NULL DEFAULT '',
+`name` TEXT NOT NULL DEFAULT '',
+`slug` TEXT DEFAULT '',
`content` text NOT NULL,
PRIMARY KEY (`menu_item_id`,`language_id`)
);
-CREATE INDEX `menu_item_content_name` ON `menu_item_content` (`name`);
+CREATE INDEX `menu_item_content_name` ON `menu_item_content` (`name`);
\ No newline at end of file