Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Menu items image support

givanzd4806ff912ec
diff --git a/admin/controller/content/menus.php b/admin/controller/content/menus.php
index e53a750..d2381ee 100644
--- a/admin/controller/content/menus.php
+++ b/admin/controller/content/menus.php
@@ -25,6 +25,7 @@ namespace Vvveb\Controller\Content;
use function Vvveb\__;
use function Vvveb\sanitizeHTML;
use Vvveb\Sql\menuSQL;
+use Vvveb\System\Images;
use Vvveb\System\Sites;
use function Vvveb\url;
@@ -141,8 +142,7 @@ class Menus extends Categories {
$view->success[] = $success;
echo $success;
} else {
- $view->errors = [$menus->error ?? ''];
- echo $menus->error;
+ echo __('No id!');
}
die(0);
@@ -182,6 +182,20 @@ class Menus extends Categories {
}
}
+ if (isset($data['options'])) {
+ foreach ($data['options'] as $name => $value) {
+ if (! $value) {
+ unset($data['options'][$name]);
+ }
+ }
+
+ if ($data['options']) {
+ $data['options'] = json_encode($data['options'], true);
+ } else {
+ $data['options'] = '';
+ }
+ }
+
$response = [];
$success = true;
$menu_item_id = false;
@@ -231,6 +245,7 @@ class Menus extends Categories {
] + $this->global;
$results = $menus->getMenuAllLanguages($options);
+ $placeholder = Images::image('placeholder.svg', 'menu_item');
foreach ($results['categories'] as &$menu) {
$langs = $menu['languages'] ? json_decode($menu['languages'], true) : [];
@@ -243,6 +258,16 @@ class Menus extends Categories {
$menu['name'] = $menu['languages'][$this->global['language_id']]['name'] ?? $langs[0]['name'] ?? '';
$menu['content'] = $menu['languages'][$this->global['language_id']]['content'] ?? $langs[0]['content'] ?? '';
+ if (isset($menu['options']) && $menu['options']) {
+ $menu['options'] = json_decode($menu['options'], true);
+ if (isset($menu['options']['img'])) {
+ $menu['options']['img_url'] = Images::image($menu['options']['img'], 'menu_item');
+ } else {
+ $menu['options']['img_url'] = $menu['options']['img_url'] ?? $placeholder;
+ }
+ } else {
+ $menu['options'] = ['img_url' => $placeholder];
+ }
}
}
diff --git a/admin/template/content/menus/menu.tpl b/admin/template/content/menus/menu.tpl
old mode 100755
new mode 100644
index 0d8b81a..ab45618
--- a/admin/template/content/menus/menu.tpl
+++ b/admin/template/content/menus/menu.tpl
@@ -45,22 +45,54 @@ if ($_categories) {
if (isset($menu[$name]) && ($value == $menu[$name])) {
echo 'selected';
}
+ ?>
+
+
+ @menu input[data-v-options-*] = $menu['options']['@@__data-v-options-(*)__@@']
+ @menu select[data-v-options-*]|before = <?php $name = '@@__data-v-options-(*)__@@';?>
+
+ @menu select[data-v-options-*] option|addNewAttribute = <?php
+ $value = '@@__value__@@';
+ if (isset($menu['options'][$name]) && ($value == $menu['options'][$name])) {
+ echo 'selected';
+ }
?>
@menu|before = <?php
foreach($_categories as $id => $menu) {
$uniq = Vvveb\System\Functions\Str::random(5);
+
+ $menu_id = 'menu-' . $menu['menu_item_id'];
+ $menu_input = "menu-{$menu['menu_item_id']}-input";
+
+ $menu_hash = "#$menu_id";
+ $menu_input_hash = "#$menu_input";
+
if ($menu['parent_id'] == $parent) {?>
//catch all data attributes
@menu [data-v-taxonomy_item-*] = $menu['@@__data-v-taxonomy_item-(*)__@@']
@menu [data-v-taxonomy_item_id] = $menu['menu_item_id']
-
-
+
@menu [data-v-taxonomy_item-url]|href = <?php echo htmlspecialchars(Vvveb\url('post/menu/index', $menu));?>
@menu [data-v-taxonomy_item-img]|src = $menu['images'][0]
-
+
+ @menu [data-v-image] = $menu['options']['img']
+ @menu [data-v-image-src]|src = $menu['options']['img_url']
+ @menu [data-v-image-src]|id = $menu_id
+
+ @menu [data-v-image-src]|data-target-input = $menu_input_hash
+ @menu [data-v-image-src]|data-target-thumb = $menu_hash
+
+ @menu [data-v-image-btn]|data-target-input = $menu_input_hash
+ @menu [data-v-image-btn]|data-target-thumb = $menu_hash
+
+
+ @menu .menu_input = $menu['image']
+ @menu .menu_input|data-target-input = $menu_input_hash
+ @menu .menu_input|id = $menu_input
+
@menu|append = <?php
$generate_menu($menu['menu_item_id'], $_categories);
}?>
@@ -110,4 +142,4 @@ foreach ($languages as $key => $language) {
?>
-import(content/sites.tpl)
+import(content/sites.tpl)
\ No newline at end of file
diff --git a/app/component/menu.php b/app/component/menu.php
index 65b5e4b..632187e 100644
--- a/app/component/menu.php
+++ b/app/component/menu.php
@@ -30,6 +30,7 @@ use Vvveb\Sql\postSQL;
use Vvveb\Sql\productSQL;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use Vvveb\System\Images;
use Vvveb\System\Sites;
use function Vvveb\url;
@@ -38,9 +39,9 @@ class Menu extends ComponentBase {
'start' => 0, //defaut, override from html
'limit' => 10000,
'menu_id' => null, //unset, set from html
+ 'slug' => null, //unset, set from html
'site_id' => null, //unset, set from html
'language_id' => null, //unset, set from html
- 'slug' => null, //unset, set from html
];
function results() {
@@ -76,6 +77,17 @@ class Menu extends ComponentBase {
$category['children'] = 0;
}
+ if (isset($category['options']) && $category['options']) {
+ $category['options'] = json_decode($category['options'], true);
+ } else {
+ $category['options'] = [];
+ }
+
+ $category['img'] = null;
+ if (isset($category['options']['img'])) {
+ $category['img'] = Images::image($category['options']['img'], 'menu_item');
+ }
+
if ($parent_id > 0) {
$parent = &$results['menu_item'][$parent_id];
@@ -205,11 +217,11 @@ class Menu extends ComponentBase {
foreach ($fields as $field) {
$name = $field['name'];
$value = $field['value'];
-
+
$name = str_replace('item-', '', $name);
if ($name == 'name') {
- $menu_item_content[$name] = sanitizeHTML($value);
+ $menu_item_content[$name] = strip_tags($value);
} else {
if ($name == 'content') {
$menu_item_content[$name] = sanitizeHTML($value);
@@ -218,7 +230,7 @@ class Menu extends ComponentBase {
}
}
}
-
+
//$menu_item['menu_item_content']['post_id'] = $id;
$menu_item_content['language_id'] = self :: $global['language_id'];
$menu_item_content['content'] = $menu_item_content['content'] ?? '';