WowPress-Tailwind/theme/wowpress/Frontend/NavWalker.php

99 lines
3.1 KiB
PHP
Raw Normal View History

2024-04-15 16:00:49 +02:00
<?php
2024-06-11 11:17:57 +02:00
2024-05-01 20:29:07 +02:00
namespace WoWPress\Frontend;
2024-06-11 11:17:57 +02:00
2024-04-15 23:07:29 +02:00
use WoWPress\Frontend\Icon;
2024-05-01 20:29:07 +02:00
class NavWalker extends \Walker_Nav_Menu
2024-04-15 16:00:49 +02:00
{
2024-06-11 11:17:57 +02:00
function start_lvl(&$output, $depth = 0, $args = null)
{
2024-04-15 16:00:49 +02:00
$output .= '
2024-04-23 22:43:54 +02:00
<div x-cloak x-show="open" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="block xl:absolute right-0 w-full mt-2 origin-top-right rounded-md shadow-lg xl:w-48">
2024-05-01 20:29:07 +02:00
<div x-cloak class="px-2 py-2 shadow w-full flex flex-col gap-2" style="background-color:var(--color-deepblue)">
2024-04-15 16:00:49 +02:00
';
2024-06-11 11:17:57 +02:00
}
function end_lvl(&$output, $depth = 0, $args = null)
{
2024-04-15 16:00:49 +02:00
2024-06-11 11:17:57 +02:00
$output .= '</div></div>';
}
function end_el(&$output, $item, $depth = 0, $args = \null)
{
2024-04-15 16:00:49 +02:00
if (0 === $depth) {
2024-06-11 11:17:57 +02:00
$output .= '</div>';
2024-04-15 16:00:49 +02:00
}
2024-06-11 11:17:57 +02:00
}
2024-04-15 16:00:49 +02:00
function start_el(&$output, $item, $depth = 0, $args = [], $id = 0)
{
2024-06-11 11:17:57 +02:00
if ($args->walker->has_children) {
2024-04-23 22:43:54 +02:00
$output .= '<div x-cloak @click.away="open = false" class="relative" x-data="{ open: false }">';
2024-04-15 16:00:49 +02:00
$output .= '<button @click="open = !open" class="w-full nav-btn ' . implode(" ", $item->classes) . '">';
2024-06-11 11:17:57 +02:00
} elseif ($item->url && $item->url != '#' && $item->url != "#LOGIN") {
2024-04-15 16:00:49 +02:00
if (0 === $depth) {
$output .= '<div>';
2024-06-11 11:17:57 +02:00
}
2024-04-15 16:00:49 +02:00
$output .= '<a class="nav-btn ' . implode(" ", $item->classes) . '" href="' . $item->url . '">';
2024-06-11 11:17:57 +02:00
} elseif ($item->url && $item->url == "#LOGIN") {
if (!is_user_logged_in()) {
if (0 === $depth) {
$output .= '<div>';
}
$item->classes[] = "btn-red btn-outline";
$output .= '<a class="nav-btn ' . implode(" ", $item->classes) . '" href="/wp-login.php">';
} else {
if (0 === $depth) {
$output .= '<div>';
}
$item->classes[] = "btn-alliance btn-outline";
$output .= '<a class="nav-btn ' . implode(" ", $item->classes) . '" href="/wp-admin/profile.php">';
}
2024-04-15 16:00:49 +02:00
} else {
if (0 === $depth) {
$output .= '<div>';
2024-06-11 11:17:57 +02:00
}
2024-04-15 16:00:49 +02:00
$output .= '<span class="nav-btn ' . implode(" ", $item->classes) . '">';
}
2024-06-11 11:17:57 +02:00
foreach ($item->classes as $class) {
if (str_contains($class, "icon-")) {
$icon_name = substr($class, 5);
$output .= Icon::get($icon_name, "24px");
2024-04-15 16:00:49 +02:00
}
}
2024-06-11 11:17:57 +02:00
if ($item->url && $item->url == "#LOGIN") {
if (is_user_logged_in()) {
$output .= "Profil";
} else {
$output .= "Login";
}
} else {
$output .= $item->title;
}
2024-04-15 16:00:49 +02:00
if ($args->walker->has_children) {
$output .= "
<svg fill= \"currentColor\" viewBox=\"0 0 20 20\" :class=\"{'rotate-180': open, 'rotate-0': !open}\" class=\"inline w-4 h-4 mt-1 ml-1 transition-transform duration-200 transform md:-mt-1\"><path fill-rule=\"evenodd\" d=\"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z\" clip-rule=\"evenodd\"></path></svg>
";
}
2024-06-11 11:17:57 +02:00
if ($args->walker->has_children) {
$output .= "</button>";
} elseif ($item->url && $item->url != '#') {
2024-04-15 16:00:49 +02:00
$output .= '</a>';
} else {
$output .= '</span>';
}
}
}