AvocadoAmber/AvocadoEdition_Light/classes/menucategory/menucategory.class.php

95 lines
2.6 KiB
PHP
Raw Normal View History

2024-09-21 10:14:04 +09:00
<?php
if (!defined("__ADVDIR__"))
exit();
// if not loaded load directly
include_once __ADVDIR__ . "/classes/menu/menu.class.php";
class MenuCategory extends Menu
{
public $last_menu;
public $key;
public $childmenu;
public $selected;
2024-09-21 10:14:04 +09:00
public function __construct($key, $mid, $name, $url, $display = true, $order = 0, $icon = '', $gnb_grp_div = 0)
{
$this->key = $key;
$this->selected = false;
2024-09-21 10:14:04 +09:00
$this->childmenu = [];
parent::__construct($mid, $name, $url, $display, $order, $icon, $gnb_grp_div);
}
public function addChild($childMenu)
{
$this->last_menu = $childMenu;
$this->childmenu[] = $childMenu;
$this->orderMenu();
}
public function addChildMenu($mid, $name, $url, $display = true, $order = 0, $icon = '', $gnb_grp_div = 0)
{
$menuitem = new Menu($mid, $name, $url, $display, $order, $icon, $gnb_grp_div);
$this->last_menu = $menuitem;
$this->childmenu[] = $menuitem;
$this->orderMenu();
}
public function orderMenu()
{
2024-09-23 14:37:58 +09:00
usort($this->childmenu, function ($a, $b) {
2024-09-21 10:14:04 +09:00
return $a->order - $b->order;
});
}
public function getLastAddedMenu()
{
return $this->last_menu;
}
public function buildHtml()
{
2024-09-30 01:20:40 +09:00
global $is_admin;
2024-09-21 10:14:04 +09:00
2024-09-30 01:20:40 +09:00
$sub_menu = preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, '/adm'], ['', ''], $_SERVER['SCRIPT_NAME']));
$str = '';
$gnb_grp_style = false;
2024-09-21 10:14:04 +09:00
2024-09-30 01:20:40 +09:00
foreach ($this->childmenu as $menu) {
if ($is_admin != 'super' || !$menu->display) {
2024-09-23 14:37:58 +09:00
continue;
2024-09-30 01:20:40 +09:00
}
2024-09-23 14:37:58 +09:00
2024-09-30 01:20:40 +09:00
$gnb_grp_div = (($menu->gnb_grp_div == 1 && !$gnb_grp_style) || ($menu->gnb_grp_div != 1 && $gnb_grp_style)) ? 'gnb_grp_div' : '';
$gnb_grp_style = $menu->gnb_grp_div == 1 ? 'gnb_grp_style' : '';
2024-09-23 14:37:58 +09:00
2024-09-30 01:20:40 +09:00
$menu_url = preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, '/adm'], ['', ''], $menu->url));
$check_gnb_grp_style = '';
2024-09-23 14:37:58 +09:00
if (
$menu_url == $sub_menu || in_array($sub_menu, array_map(function ($url) {
2024-09-30 01:20:40 +09:00
return preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, '/adm'], ['', ''], $url));
2024-09-23 14:37:58 +09:00
}, $menu->suburl))
) {
2024-09-30 01:20:40 +09:00
$check_gnb_grp_style = 'check';
$this->selected = true;
2024-09-21 10:14:04 +09:00
}
2024-09-23 14:37:58 +09:00
2024-09-30 01:20:40 +09:00
$str .= sprintf(
'<li class="gnb_2dli %s"><a href="%s" class="gnb_2da %s %s" data-text="%s" style="--icon:\'%s\'">%s</a></li>',
$check_gnb_grp_style,
$menu->url,
$gnb_grp_style,
$gnb_grp_div,
$menu->name,
$menu->icon,
$menu->name
);
2024-09-29 09:51:50 +09:00
}
2024-09-30 01:20:40 +09:00
$ul_class = $this->selected ? 'gnb_2dul" style="display: block"' : 'gnb_2dul"';
return "<ul class=\"{$ul_class}\">{$str}</ul>";
2024-09-21 10:14:04 +09:00
}
}