| 1 |
<?php |
| 2 |
// no direct access |
| 3 |
defined('ABSPATH') || die(); |
| 4 |
|
| 5 |
/** @var LSD_Menus_Dashboard $this */ |
| 6 |
/** @var string $title */ |
| 7 |
/** @var string $page */ |
| 8 |
/** @var string|null $url */ |
| 9 |
/** @var array $menus */ |
| 10 |
$can_manage_options = current_user_can('manage_options'); |
| 11 |
$announcements = $can_manage_options ? LSD_Announcements::instance() : null; |
| 12 |
$active_announcements = $announcements ? $announcements->active() : []; |
| 13 |
$dismissed_announcements = $announcements ? $announcements->dismissed() : []; |
| 14 |
$announcements_count = count($active_announcements); |
| 15 |
$announcement_icon_urls = [ |
| 16 |
'info' => $this->lsd_asset_url('img/announcement-gear.svg'), |
| 17 |
'success' => $this->lsd_asset_url('img/announcement-checkmark.svg'), |
| 18 |
'warning' => $this->lsd_asset_url('img/announcement-exclamation.svg'), |
| 19 |
'danger' => $this->lsd_asset_url('img/announcement-exclamation.svg'), |
| 20 |
'error' => $this->lsd_asset_url('img/announcement-exclamation.svg'), |
| 21 |
]; |
| 22 |
|
| 23 |
$render_announcement = function (array $announcement, string $tab) use ($announcement_icon_urls): void |
| 24 |
{ |
| 25 |
$id = sanitize_key((string) ($announcement['id'] ?? '')); |
| 26 |
if ($id === '') return; |
| 27 |
|
| 28 |
$severity = sanitize_key((string) ($announcement['severity'] ?? 'info')); |
| 29 |
if (!isset($announcement_icon_urls[$severity])) $severity = 'info'; |
| 30 |
|
| 31 |
$severity_class = $severity === 'error' ? 'danger' : $severity; |
| 32 |
$created_at = (int) ($announcement['created_at'] ?? 0); |
| 33 |
$created_label = $created_at > 0 ? sprintf(esc_html__('%s ago', 'listdom'), human_time_diff($created_at, time())) : ''; |
| 34 |
$url = esc_url((string) ($announcement['url'] ?? '')); |
| 35 |
$cta_label = trim((string) ($announcement['cta_label'] ?? '')); |
| 36 |
if ($url && $cta_label === '') $cta_label = esc_html__('Learn More', 'listdom'); |
| 37 |
?> |
| 38 |
<article class="lsd-announcement-item lsd-announcement-item-<?php echo esc_attr($severity_class); ?>" data-lsd-announcement-id="<?php echo esc_attr($id); ?>" data-lsd-announcement-created-at="<?php echo esc_attr($created_at); ?>"> |
| 39 |
<div class="lsd-announcement-item-content"> |
| 40 |
<div class="lsd-announcement-item-heading"> |
| 41 |
<h3> |
| 42 |
<span class="lsd-announcement-item-icon" aria-hidden="true"> |
| 43 |
<img alt="" src="<?php echo esc_url($announcement_icon_urls[$severity]); ?>"> |
| 44 |
</span> |
| 45 |
<?php echo esc_html((string) ($announcement['title'] ?? '')); ?> |
| 46 |
</h3> |
| 47 |
<?php if ($created_label): ?> |
| 48 |
<span class="lsd-announcement-item-date"><?php echo esc_html($created_label); ?></span> |
| 49 |
<?php endif; ?> |
| 50 |
</div> |
| 51 |
<?php if (!empty($announcement['description'])): ?> |
| 52 |
<div class="lsd-announcement-item-description"><?php echo wp_kses_post((string) $announcement['description']); ?></div> |
| 53 |
<?php endif; ?> |
| 54 |
<?php if ($url || $tab === LSD_Announcements::STATE_ACTIVE): ?> |
| 55 |
<div class="lsd-announcement-item-actions"> |
| 56 |
<?php if ($url): ?> |
| 57 |
<a class="lsd-announcement-item-cta lsd-primary-button" href="<?php echo esc_url($url); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html($cta_label); ?></a> |
| 58 |
<?php endif; ?> |
| 59 |
<?php if ($tab === LSD_Announcements::STATE_ACTIVE): ?> |
| 60 |
<button type="button" class="lsd-announcement-item-dismiss lsd-text-button" data-lsd-announcement-dismiss="<?php echo esc_attr($id); ?>"><?php echo esc_html__('Dismiss', 'listdom'); ?></button> |
| 61 |
<?php endif; ?> |
| 62 |
</div> |
| 63 |
<?php endif; ?> |
| 64 |
</div> |
| 65 |
</article> |
| 66 |
<?php |
| 67 |
}; |
| 68 |
?> |
| 69 |
<div class="lsd-dashboard-top-bar"> |
| 70 |
<div class="lsd-logo-section"> |
| 71 |
<a href="<?php echo esc_url($url ?: admin_url('admin.php?page=' . $page)); ?>"> |
| 72 |
<img class="lsd-logo" alt="<?php esc_attr__('logo', 'listdom') ?>" src="<?php echo esc_url($this->lsd_asset_url('img/listdom-logo.svg')); ?>"> |
| 73 |
<span><?php echo LSD_Kses::element($title); ?></span> |
| 74 |
</a> |
| 75 |
</div> |
| 76 |
|
| 77 |
<div class="lsd-header-icons"> |
| 78 |
<?php echo lsd_ads('header-links-start'); ?> |
| 79 |
|
| 80 |
<?php if ($can_manage_options): ?> |
| 81 |
<button type="button" class="lsd-text-button lsd-header-announcements-button" aria-label="<?php echo esc_attr__('Announcements', 'listdom'); ?>" aria-expanded="false" aria-controls="lsd-announcements-panel"> |
| 82 |
<span class="lsd-header-announcements-icon-wrap"> |
| 83 |
<img class="lsd-header-announcements-icon" alt="" src="<?php echo esc_url($this->lsd_asset_url('img/announcements.svg')); ?>"> |
| 84 |
<?php if ($announcements_count > 0): ?> |
| 85 |
<span class="lsd-header-announcements-badge" data-lsd-announcements-header-badge><?php echo esc_html($announcements_count); ?></span> |
| 86 |
<?php endif; ?> |
| 87 |
</span> |
| 88 |
</button> |
| 89 |
<?php endif; ?> |
| 90 |
|
| 91 |
<a href="<?php echo esc_url(admin_url('admin.php?page=listdom-connect&tab=addons')); ?>" class="lsd-text-button lsd-header-addons-button"> |
| 92 |
<i class="webilia-icon wbli-add-plus-circle"></i> |
| 93 |
<span><?php echo esc_html__('Addons', 'listdom'); ?></span> |
| 94 |
</a> |
| 95 |
|
| 96 |
<?php if ($can_manage_options): ?> |
| 97 |
<?php |
| 98 |
$connect_connected = LSD_Webilia_Connect::enabled() && LSD_Webilia_Connect::isConnected(); |
| 99 |
$connect_return_url = admin_url('admin.php?page=listdom-connect&tab=connect'); |
| 100 |
$connect_url = $connect_connected ? $connect_return_url : LSD_Webilia_Connect::connectUrl($connect_return_url); |
| 101 |
?> |
| 102 |
<a href="<?php echo esc_url($connect_url); ?>" class="lsd-primary-button lsd-header-connect-button<?php echo $connect_connected ? ' lsd-header-connect-button-connected' : ''; ?>"> |
| 103 |
<i class="webilia-icon <?php echo $connect_connected ? 'wbli-checkmark-circle' : 'wbli-link-square'; ?>" aria-hidden="true"></i> |
| 104 |
<span><?php echo $connect_connected ? esc_html__('Connected to Webilia', 'listdom') : esc_html__('Connect Now', 'listdom'); ?></span> |
| 105 |
</a> |
| 106 |
<?php endif; ?> |
| 107 |
|
| 108 |
<?php echo lsd_ads('header-links-end'); ?> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
<?php if ($can_manage_options): ?> |
| 112 |
<div class="lsd-announcements-overlay" data-lsd-announcements-close hidden></div> |
| 113 |
<aside id="lsd-announcements-panel" class="lsd-announcements-panel" role="dialog" aria-modal="true" aria-hidden="true" aria-labelledby="lsd-announcements-title" hidden> |
| 114 |
<div class="lsd-announcements-panel-header"> |
| 115 |
<div class="lsd-announcements-panel-heading"> |
| 116 |
<div class="lsd-announcements-panel-subject"> |
| 117 |
<h2 id="lsd-announcements-title" class="lsd-admin-title"><?php echo esc_html__('Notifications', 'listdom'); ?></h2> |
| 118 |
<span class="lsd-announcements-panel-badge" data-lsd-announcements-count><?php echo esc_html($announcements_count); ?></span> |
| 119 |
</div> |
| 120 |
<button type="button" class="lsd-announcements-panel-close" aria-label="<?php echo esc_attr__('Close', 'listdom'); ?>" data-lsd-announcements-close> |
| 121 |
<img alt="" src="<?php echo esc_url($this->lsd_asset_url('img/close.svg')); ?>"> |
| 122 |
</button> |
| 123 |
</div> |
| 124 |
<ul class="lsd-announcements-panel-tabs lsd-level-3-menu lsd-sub-tabs" role="tablist" aria-label="<?php echo esc_attr__('Announcement views', 'listdom'); ?>"> |
| 125 |
<li class="lsd-announcements-panel-tab lsd-sub-tabs-active" role="presentation"> |
| 126 |
<a href="#lsd-announcements-active-panel" id="lsd-announcements-active-tab" role="tab" aria-selected="true" aria-controls="lsd-announcements-active-panel" tabindex="0" data-lsd-announcements-tab="active"> |
| 127 |
<?php echo esc_html__('Active', 'listdom'); ?> |
| 128 |
</a> |
| 129 |
</li> |
| 130 |
<li class="lsd-announcements-panel-tab" role="presentation"> |
| 131 |
<a href="#lsd-announcements-dismissed-panel" id="lsd-announcements-dismissed-tab" role="tab" aria-selected="false" aria-controls="lsd-announcements-dismissed-panel" tabindex="-1" data-lsd-announcements-tab="dismissed"> |
| 132 |
<?php echo esc_html__('Dismissed', 'listdom'); ?> |
| 133 |
</a> |
| 134 |
</li> |
| 135 |
</ul> |
| 136 |
</div> |
| 137 |
<div class="lsd-announcements-panel-content"> |
| 138 |
<div id="lsd-announcements-active-panel" class="lsd-announcements-panel-list" role="tabpanel" aria-labelledby="lsd-announcements-active-tab" data-lsd-announcements-list="active"> |
| 139 |
<?php foreach ($active_announcements as $announcement) $render_announcement($announcement, LSD_Announcements::STATE_ACTIVE); ?> |
| 140 |
<p class="lsd-announcements-empty<?php echo count($active_announcements) ? ' lsd-util-hide' : ''; ?>" <?php echo count($active_announcements) ? 'hidden="hidden"' : ''; ?>><?php echo esc_html__('No active notifications.', 'listdom'); ?></p> |
| 141 |
</div> |
| 142 |
<div id="lsd-announcements-dismissed-panel" class="lsd-announcements-panel-list" role="tabpanel" aria-labelledby="lsd-announcements-dismissed-tab" data-lsd-announcements-list="dismissed" hidden> |
| 143 |
<?php foreach ($dismissed_announcements as $announcement) $render_announcement($announcement, LSD_Announcements::STATE_DISMISSED); ?> |
| 144 |
<p class="lsd-announcements-empty<?php echo count($dismissed_announcements) ? ' lsd-util-hide' : ''; ?>" <?php echo count($dismissed_announcements) ? 'hidden="hidden"' : ''; ?>><?php echo esc_html__('No dismissed notifications.', 'listdom'); ?></p> |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
</aside> |
| 148 |
<?php endif; ?> |
| 149 |
<?php if (is_array($menus) && count($menus)): ?> |
| 150 |
<div class="lsd-header-submenu"> |
| 151 |
<?php foreach ($menus as $menu): if (!isset($menu['title']) || !isset($menu['url'])) continue; ?> |
| 152 |
<?php $badge = isset($menu['badge']) ? (int) $menu['badge'] : 0; ?> |
| 153 |
<a href="<?php echo esc_url($menu['url']); ?>" class="lsd-submenu-item<?php echo isset($menu['selected']) && $menu['selected'] ? ' selected' : ''; ?>"> |
| 154 |
<?php if (!empty($menu['icon'])): ?><i class="webilia-icon <?php echo esc_attr($menu['icon']); ?>" aria-hidden="true"></i><?php endif; ?> |
| 155 |
<?php echo esc_html($menu['title']); ?> |
| 156 |
<?php if ($badge > 0): ?><span class="update-plugins count-<?php echo esc_attr($badge); ?>"><span class="update-count"><?php echo esc_html($badge); ?></span></span><?php endif; ?> |
| 157 |
</a> |
| 158 |
<?php endforeach; ?> |
| 159 |
</div> |
| 160 |
<?php endif; |
| 161 |
?> |
| 162 |
|