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

97 lines
2.8 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()
{
global $g5, $is_admin, $auth, $menu, $auth_menu;
2024-09-23 14:37:58 +09:00
$sub_menu = preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, "/adm"], ["", ""], $_SERVER["SCRIPT_NAME"]));
2024-09-21 10:14:04 +09:00
2024-09-29 09:51:50 +09:00
$str = "";
2024-09-23 14:37:58 +09:00
foreach ($this->childmenu as $key => $menu) {
2024-09-21 10:14:04 +09:00
if ($is_admin != 'super')
continue;
2024-09-23 14:37:58 +09:00
if (!$menu->display)
continue;
2024-09-21 10:14:04 +09:00
if (($menu->gnb_grp_div == 1 && $gnb_grp_style == false) || ($menu->gnb_grp_div != 1 && $gnb_grp_style == true))
$gnb_grp_div = 'gnb_grp_div';
else
$gnb_grp_div = '';
2024-09-23 14:37:58 +09:00
2024-09-21 10:14:04 +09:00
if ($menu->gnb_grp_div == 1)
$gnb_grp_style = 'gnb_grp_style';
else
$gnb_grp_style = '';
2024-09-23 14:37:58 +09:00
2024-09-21 10:14:04 +09:00
$check_gnb_grp_style = "";
2024-09-23 14:37:58 +09:00
$menu_url = preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, "/adm"], ["", ""], $menu->url));
if (
$menu_url == $sub_menu || in_array($sub_menu, array_map(function ($url) {
return preg_replace('/^.*\/([^\/]+\.php)$/', '/$1', str_replace([G5_ADMIN_URL, "/adm"], ["", ""], $url));
}, $menu->suburl))
) {
2024-09-21 10:14:04 +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-22 10:46:52 +09:00
$str .= '<li class="gnb_2dli ' . $check_gnb_grp_style . '"><a href="' . $menu->url . '" class="gnb_2da ' . $gnb_grp_style . ' ' . $gnb_grp_div . '" data-text="' . $menu->name . '" style="--icon:\'' . $menu->icon . '\'">' . $menu->name . '</a></li>';
2024-09-21 10:14:04 +09:00
}
$str .= "</ul>";
2024-09-23 14:37:58 +09:00
2024-09-29 09:51:50 +09:00
if ($this->selected) {
$str = "<ul class=\"gnb_2dul\" style=\"display: block\">{$str}";
} else {
$str = "<ul class=\"gnb_2dul\">{$str}";
}
2024-09-21 10:14:04 +09:00
return $str;
}
}