kathrine: possibility to add custom menu categories

This commit is contained in:
slawkens
2025-07-19 07:48:01 +02:00
parent 2fe9924437
commit ec11c14024
5 changed files with 57 additions and 36 deletions

View File

@@ -1,12 +1,18 @@
<?php <?php
$config['menu_default_links_color'] = '#ffffff'; $config['menu_default_links_color'] = '#ffffff';
$config['menu_categories'] = array( // max 7 menus for kathrine
MENU_CATEGORY_NEWS => array('id' => 'news', 'name' => 'Latest News'), $config['menu_categories'] = [
MENU_CATEGORY_ACCOUNT => array('id' => 'account', 'name' => 'Account'), MENU_CATEGORY_NEWS => ['id' => 'news', 'name' => 'Latest News'],
MENU_CATEGORY_COMMUNITY => array('id' => 'community', 'name' => 'Community'), // you can add custom menu by uncommenting this
MENU_CATEGORY_LIBRARY => array('id' => 'library', 'name' => 'Library'), // after doing it, go to admin panel -> Menus and add your entries for this category
MENU_CATEGORY_SHOP => array('id' => 'shops', 'name' => 'Shop') // tip: you can move it up/down to show it on specific position
); //7 => array('id' => 'testing', 'name' => 'Test Menu 1'),
//8 => array('id' => 'testing2', 'name' => 'Test Menu 2'),
MENU_CATEGORY_ACCOUNT => ['id' => 'account', 'name' => 'Account'],
MENU_CATEGORY_COMMUNITY => ['id' => 'community', 'name' => 'Community'],
MENU_CATEGORY_LIBRARY => ['id' => 'library', 'name' => 'Library'],
MENU_CATEGORY_SHOP => ['id' => 'shops', 'name' => 'Shop']
];
$config['menus'] = require __DIR__ . '/menus.php'; $config['menus'] = require __DIR__ . '/menus.php';

View File

@@ -1,42 +1,40 @@
<?php <?php
$menus = get_template_menus(); function get_template_pages($category): array
{
function get_template_pages($category) {
global $menus; global $menus;
$ret = array(); $ret = array();
foreach($menus[$category] as $menu) { foreach($menus[$category] ?? [] as $menu) {
$ret[] = $menu['link']; $ret[] = $menu['link'];
} }
return $ret; return $ret;
} }
?> ?>
var category = '<?php let category = '<?php
if(strpos(URI, 'subtopic=') !== false) { if(str_contains(URI, 'subtopic=')) {
$tmp = array($_REQUEST['subtopic']); $tmp = [$_REQUEST['subtopic']];
} }
else { else {
$tmp = URI; $tmp = URI;
if(empty($tmp)) { if(empty($tmp)) {
$tmp = array('news'); $tmp = ['news'];
} }
else { else {
$tmp = explode('/', URI); $tmp = explode('/', URI);
} }
} }
if(in_array($tmp[0], get_template_pages(MENU_CATEGORY_NEWS))) foreach (config('menu_categories') as $id => $info) {
echo 'news'; $templatePages = get_template_pages($id);
elseif(in_array($tmp[0], get_template_pages(MENU_CATEGORY_LIBRARY)))
echo 'library'; if ($id == MENU_CATEGORY_ACCOUNT) {
elseif(in_array($tmp[0], get_template_pages(MENU_CATEGORY_COMMUNITY))) $templatePages = array_merge($templatePages, ['account']);
echo 'community'; }
elseif(in_array($tmp[0], array_merge(get_template_pages(MENU_CATEGORY_ACCOUNT), array('account'))))
echo 'account'; if (in_array($tmp[0], $templatePages)) {
elseif(in_array($tmp[0], get_template_pages(MENU_CATEGORY_SHOP))) echo $info['id'];
echo 'shops'; break;
else { }
echo 'news';
} }
?>'; ?>';

View File

@@ -1,10 +1,10 @@
var list = new Array(); var list = new Array();
{% set i = 0 %} {% set i = 0 %}
{% for cat in categories %} {% for id, cat in config('menu_categories') %}
{% if cat.id != 'shops' or setting('core.gifts_system') %} {% if (cat.id != 'shops' or setting('core.gifts_system')) and menus[id]|length > 0 %}
list[{{ i }}] = '{{ cat.id }}'; list[{{ i }}] = '{{ cat.id }}';
{% set i = i + 1 %}
{% endif %} {% endif %}
{% set i = i + 1 %}
{% endfor %} {% endfor %}
function initMenu() function initMenu()

View File

@@ -27,11 +27,13 @@ body
#tabs #tabs
{ {
width: 580px; width: 99%;
height: 32px; height: 32px;
background: url('images/tabs-bg.png') no-repeat; background: url('images/tabs-bg.png') no-repeat;
float: left;
padding-left: 200px; padding-left: 200px;
position: relative;
display: inline-flex;
right: 0;
} }
#tabs .tab #tabs .tab

View File

@@ -8,7 +8,9 @@ defined('MYAAC') or die('Direct access not allowed!');
<link rel="stylesheet" href="<?php echo $template_path; ?>/style.css" type="text/css" /> <link rel="stylesheet" href="<?php echo $template_path; ?>/style.css" type="text/css" />
<script type="text/javascript"> <script type="text/javascript">
<?php <?php
$twig->display('menu.js.html.twig', array('categories' => $config['menu_categories'])); $menus = get_template_menus();
$twig->display('menu.js.html.twig', ['menus' => $menus]);
?> ?>
</script> </script>
<script type="text/javascript" src="tools/basic.js"></script> <script type="text/javascript" src="tools/basic.js"></script>
@@ -28,11 +30,24 @@ defined('MYAAC') or die('Direct access not allowed!');
<div id="header"></div> <div id="header"></div>
<!-- End --> <!-- End -->
<!-- Custom Style for #tabs -->
<?php
$menusCount = count($menus);
$tabsStyle = '';
if ($menusCount > 6) {
$tabsStyle .= 'padding-left: 4px;';
$tabsStyle .= 'padding-right: 12px;';
}
elseif ($menusCount > 5) {
$tabsStyle .= 'padding-left: 90px;';
}
?>
<!-- Menu Section --> <!-- Menu Section -->
<div id="tabs"> <div id="tabs" style="<?= $tabsStyle; ?>">
<?php <?php
foreach($config['menu_categories'] as $id => $cat) { foreach($config['menu_categories'] as $id => $cat) {
if($id != MENU_CATEGORY_SHOP || $config['gifts_system']) { ?> if (($id != MENU_CATEGORY_SHOP || $config['gifts_system']) && isset($menus[$id])) { ?>
<span id="<?php echo $cat['id']; ?>" onclick="menuSwitch('<?php echo $cat['id']; ?>');"><?php echo $cat['name']; ?></span> <span id="<?php echo $cat['id']; ?>" onclick="menuSwitch('<?php echo $cat['id']; ?>');"><?php echo $cat['name']; ?></span>
<?php <?php
} }