$xn_current_menu[$k] = $new_menu_item; } } else { return false; } } $xn_nav_menus[$slot_name] = $xn_current_menu; } else { // 强制使用新的菜单项 $new_menu = array(); foreach ($menu_item as $k => $v) { $new_menu_item = array(); $new_menu_item['lid'] = isset($v['lid']) ? $v['lid'] : 0; $new_menu_item['icon'] = isset($v['icon']) ? $v['icon'] : ''; $new_menu_item['name'] = isset($v['name']) ? $v['name'] : ''; $new_menu_item['title'] = isset($v['title']) ? $v['title'] : ''; $new_menu_item['desc'] = isset($v['desc']) ? $v['desc'] : ''; $new_menu_item['href'] = isset($v['href']) ? $v['href'] : ''; $new_menu_item['order'] = isset($v['order']) ? $v['order'] : 0; $new_menu_item['class'] = isset($v['class']) ? $v['class'] : ''; $new_menu_item['attr'] = isset($v['attr']) ? $v['attr'] : ''; $new_menu_item['submenu'] = isset($v['submenu']) && in_array($v['submenu'], array_keys(xn_nav_menu_get_available_slots())) ? $v['submenu'] : ''; //如果有新值,就用新值;如果没有新值,就用空字符串 $new_menu[$k] = $new_menu_item; } $xn_nav_menus[$slot_name] = $new_menu; } //var_dump($xn_nav_menus[$slot_name]); setting_set('abs_nav_menus', $xn_nav_menus); return true; } } /** * 删除指定菜单槽位的指定菜单项 * * @param string $slot_name 槽位ID * @param string|array $menu_item 菜单项ID */ function xn_nav_menu_item_del($slot_name, $menu_item) { if (empty($slot_name) || empty($menu_item)) { return false; } global $xn_nav_menus; if (!isset($xn_nav_menus)) { $xn_nav_menus = setting_get('abs_nav_menus'); } $xn_current_menu = array(); if (isset($xn_nav_menus[$slot_name])) { //如果槽位不存在,则结束 $xn_current_menu = $xn_nav_menus[$slot_name]; } else { return false; } $s_lid_arr = array_column($xn_current_menu, 'lid'); if (isset($menu_item[0]) && is_array($menu_item[0])) { //如果$menu_item是数组的话 foreach ($menu_item as $value) { $k = array_search($value, $s_lid_arr); if ($k !== false) { unset($xn_current_menu[$k]); } else { continue; } } } else { if ($menu_item != 0) { $k = array_search($menu_item, $s_lid_arr); if ($k !== false) { unset($xn_current_menu[$k]); } } else { return false; } } $xn_nav_menus[$slot_name] = $xn_current_menu; setting_set('abs_nav_menus', $xn_nav_menus); return true; } //========== 【CURD功能结束】 ==========// //========== 【杂项功能开始】 ==========// /** * 获取可用菜单槽位;请尽量使用$abs_nav_menus_slots全局变量,除非无法直接获取$abs_nav_menus_slots,才用该函数 * @return array */ function xn_nav_menu_get_available_slots() { global $abs_nav_menus_slots; return $abs_nav_menus_slots; } /** * 获取可用魔法菜单项;请尽量使用$abs_nav_menus_magic_href,除非无法直接获取$abs_nav_menus_magic_href,才用该函数 * @return array */ function xn_nav_menu_get_available_magic_href() { global $abs_nav_menus_magic_href; return $abs_nav_menus_magic_href; } /** * 将菜单栏位里的内容转换成字符串,用于备份 * * @param string $slot 槽位 * @return string 序列化的数组 */ function xn_nav_menu_slot_items_to_string($slot_name) { $r = xn_nav_menu_get($slot_name); return base64_encode(serialize($r)); } if (!function_exists('isSerialized')) { /** * 是否为序列化的字符串 * * @param string $str * @return bool */ function isSerialized($str) { try { $r = ($str == serialize(false) || @unserialize($str) !== false); } catch (\Throwable $th) { return false; } return $r; } } //========== 【杂项功能结束】 ==========//PNG  IHDR""gpMPLTEU~ pHYs+rIDATh=0 塠(9%c{6$pHO?ٽ{ ͦ-<幖O0Ԏlypjr/v<}GϕIٸa5OK0/bg.vvi]SUzsMǸvM5"h [ %s b'<$CQB(ze)QBʷE_a yxj wVUfqxSmv#AkiYYCܓ3Y?%0^g7H:Y/2}PsoXM= RE& UITkEB6q 6chN*T+dR,š9:Ӟ1d*FZb_}L\4c3Q$R0 Z\:utO uƁ.]DA]5'(QRE[g;1;FqP4ǫ!/_ӂ)N91HSgnu A)Ґ\E%WmryNHGON{{Vi)ZwMtQto\Iwypw B^:;TX@cRܭP- Lw#P5XrЌ9PvbIENDB`