From 277611e0ac6c237bdc6abcafe3afd696bb993722 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 11 Mar 2023 15:14:05 +0100 Subject: [PATCH] Introduce new menu classes and navigation templates --- controllers/HTMLController.php | 2 -- models/AdminMenu.php | 58 +++++++++++++++++++++++++++++++ models/Dispatcher.php | 1 - models/ErrorHandler.php | 1 - models/MainMenu.php | 41 ++++++++++++++++++++++ models/Menu.php | 18 ++++++++++ models/UserMenu.php | 60 ++++++++++++++++++++++++++++++++ public/css/admin.css | 38 --------------------- public/css/default.css | 31 +++-------------- templates/AdminBar.php | 38 --------------------- templates/MainNavBar.php | 51 ++++++++++++++++++++++++++++ templates/MainTemplate.php | 16 ++++----- templates/NavBar.php | 62 ++++++++++++++++++++++++++++++++++ 13 files changed, 302 insertions(+), 115 deletions(-) create mode 100644 models/AdminMenu.php create mode 100644 models/MainMenu.php create mode 100644 models/Menu.php create mode 100644 models/UserMenu.php delete mode 100644 templates/AdminBar.php create mode 100644 templates/MainNavBar.php create mode 100644 templates/NavBar.php diff --git a/controllers/HTMLController.php b/controllers/HTMLController.php index d03bc50..a5d5236 100644 --- a/controllers/HTMLController.php +++ b/controllers/HTMLController.php @@ -22,8 +22,6 @@ abstract class HTMLController if (Registry::get('user')->isAdmin()) { $this->page->appendStylesheet(BASEURL . '/css/admin.css'); - $this->admin_bar = new AdminBar(); - $this->page->adopt($this->admin_bar); } } diff --git a/models/AdminMenu.php b/models/AdminMenu.php new file mode 100644 index 0000000..aae9e0d --- /dev/null +++ b/models/AdminMenu.php @@ -0,0 +1,58 @@ +isAdmin()) + return; + + $this->items[] = [ + 'label' => 'Admin', + 'icon' => 'gear', + 'subs' => [ + [ + 'uri' => '/managealbums/', + 'label' => 'Albums', + ], + [ + 'uri' => '/manageassets/', + 'label' => 'Assets', + ], + [ + 'uri' => '/managetags/', + 'label' => 'Tags', + ], + [ + 'uri' => '/manageusers/', + 'label' => 'Users', + ], + [ + 'uri' => '/manageerrors/', + 'label' => 'Errors', + 'badge' => ErrorLog::getCount(), + ], + ], + ]; + + foreach ($this->items as $i => $item) + { + if (isset($item['uri'])) + $this->items[$i]['url'] = BASEURL . $item['uri']; + + if (!isset($item['subs'])) + continue; + + foreach ($item['subs'] as $j => $subitem) + $this->items[$i]['subs'][$j]['url'] = BASEURL . $subitem['uri']; + } + } +} diff --git a/models/Dispatcher.php b/models/Dispatcher.php index 8280797..3a6b529 100644 --- a/models/Dispatcher.php +++ b/models/Dispatcher.php @@ -86,7 +86,6 @@ class Dispatcher if (Registry::has('user') && Registry::get('user')->isAdmin()) { $page->appendStylesheet(BASEURL . '/css/admin.css'); - $page->adopt(new AdminBar()); } $page->adopt(new DummyBox('Well, this is a bit embarrassing!', '

The page you requested could not be found. Don\'t worry, it\'s probably not your fault. You\'re welcome to browse the website, though!

', 'errormsg')); diff --git a/models/ErrorHandler.php b/models/ErrorHandler.php index da650e9..3139444 100644 --- a/models/ErrorHandler.php +++ b/models/ErrorHandler.php @@ -168,7 +168,6 @@ class ErrorHandler if ($is_admin) { $page->appendStylesheet(BASEURL . '/css/admin.css'); - $page->adopt(new AdminBar()); } } elseif (!$is_sensitive) diff --git a/models/MainMenu.php b/models/MainMenu.php new file mode 100644 index 0000000..e1ccb05 --- /dev/null +++ b/models/MainMenu.php @@ -0,0 +1,41 @@ +items = [ + [ + 'uri' => '/', + 'label' => 'Albums', + ], + [ + 'uri' => '/people/', + 'label' => 'People', + ], + [ + 'uri' => '/timeline/', + 'label' => 'Timeline', + ], + ]; + + foreach ($this->items as $i => $item) + { + if (isset($item['uri'])) + $this->items[$i]['url'] = BASEURL . $item['uri']; + + if (!isset($item['subs'])) + continue; + + foreach ($item['subs'] as $j => $subitem) + $this->items[$i]['subs'][$j]['url'] = BASEURL . $subitem['uri']; + } + } +} diff --git a/models/Menu.php b/models/Menu.php new file mode 100644 index 0000000..cde4de0 --- /dev/null +++ b/models/Menu.php @@ -0,0 +1,18 @@ +items; + } +} diff --git a/models/UserMenu.php b/models/UserMenu.php new file mode 100644 index 0000000..0204322 --- /dev/null +++ b/models/UserMenu.php @@ -0,0 +1,60 @@ +isLoggedIn()) + { + $this->items[] = [ + 'label' => $user->getFirstName(), + 'icon' => 'person-circle', + 'subs' => [ + + [ + 'label' => 'Settings', + 'uri' => '/accountsettings/', + ], + [ + 'label' => 'Log out', + 'uri' => '/logout/', + ], + ], + ]; + } + else + { + $this->items[] = [ + 'label' => 'Log in', + 'icon' => 'person-circle', + 'uri' => '/login/', + ]; + } + + $this->items[] = [ + 'label' => 'Home', + 'icon' => 'house-door', + 'uri' => '/', + ]; + + foreach ($this->items as $i => $item) + { + if (isset($item['uri'])) + $this->items[$i]['url'] = BASEURL . $item['uri']; + + if (!isset($item['subs'])) + continue; + + foreach ($item['subs'] as $j => $subitem) + $this->items[$i]['subs'][$j]['url'] = BASEURL . $subitem['uri']; + } + } +} diff --git a/public/css/admin.css b/public/css/admin.css index 8dd510d..0316b80 100644 --- a/public/css/admin.css +++ b/public/css/admin.css @@ -11,44 +11,6 @@ margin: 0 0 0.2em; } -/* Admin bar styles ----------------------*/ -body { - padding-top: 30px; -} -#admin_bar { - background: #333; - color: #ccc; - left: 0; - position: fixed; - top: 0; - width: 100%; - z-index: 100; -} -#admin_bar ul { - list-style: none; - margin: 0 auto; - max-width: 1280px; - min-width: 900px; - padding: 2px; - width: 95%; -} -#admin_bar ul > li { - display: inline; - border-right: 1px solid #aaa; -} -#admin_bar ul > li:last-child { - border-right: none; -} -#admin_bar li > a { - color: inherit; - display: inline-block; - padding: 4px 6px; -} -#admin_bar li a:hover { - text-decoration: underline; -} - /* (Tag) autosuggest ----------------------*/ diff --git a/public/css/default.css b/public/css/default.css index 450d770..8cd0846 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -19,17 +19,13 @@ body { background: #aaa 0 -50% fixed; } -#wrapper, header { +#wrapper, header .container { width: 95%; min-width: 900px; max-width: 1280px; margin: 0 auto; } -header { - overflow: auto; -} - a { color: #963626; text-decoration: none; @@ -67,27 +63,10 @@ a:hover h1#logo, a:hover h1#logo:before { /* Navigation ---------------*/ -ul#nav { - margin: 55px 10px 0 0; - padding: 0; - float: right; - list-style: none; -} -ul#nav li { - float: left; -} -ul#nav li a { - color: #fff; - display: block; - float: left; - font: 200 20px 'Press Start 2P', sans-serif; - margin: 0 0 0 32px; - padding: 10px 0; - text-decoration: none; - text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7); -} -ul#nav li a:hover { - text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.6); +.nav-divider { + height: 2.5rem; + border-left: .1rem solid rgba(255,255,255, 0.2); + margin: 0 0.5rem; } diff --git a/templates/AdminBar.php b/templates/AdminBar.php deleted file mode 100644 index daa81a8..0000000 --- a/templates/AdminBar.php +++ /dev/null @@ -1,38 +0,0 @@ - - - '; - } - - public function appendItem($url, $caption) - { - $this->extra_items[] = [$url, $caption]; - } -} diff --git a/templates/MainNavBar.php b/templates/MainNavBar.php new file mode 100644 index 0000000..ded5fbb --- /dev/null +++ b/templates/MainNavBar.php @@ -0,0 +1,51 @@ +outerMenuId, '" class="navbar navbar-expand-lg ', $this->navBarClasses, '" aria-label="', $this->ariaLabel, '"> +
+ + HashRU Pics + + + +
+ '; + } +} diff --git a/templates/MainTemplate.php b/templates/MainTemplate.php index b5224fb..d23df69 100644 --- a/templates/MainTemplate.php +++ b/templates/MainTemplate.php @@ -43,15 +43,12 @@ class MainTemplate extends Template , $this->header_html, ' classes) ? ' class="' . implode(' ', $this->classes) . '"' : '', '> -
- -

#pics

-
- +
'; + + $bar = new MainNavBar(); + $bar->html_main(); + + echo '
'; @@ -88,6 +85,7 @@ class MainTemplate extends Template echo '
', strtr($query, "\t", " "), '
'; echo ' + '; } diff --git a/templates/NavBar.php b/templates/NavBar.php new file mode 100644 index 0000000..c625c60 --- /dev/null +++ b/templates/NavBar.php @@ -0,0 +1,62 @@ +'; + + $this->renderMenuItems($items, $navBarClasses); + + echo ' + '; + } + + public function renderMenuItems(array $items) + { + foreach ($items as $menuId => $item) + { + if (isset($item['icon'])) + $item['label'] = ' ' . $item['label']; + + if (isset($item['badge'])) + $item['label'] .= ' ' . $item['badge'] . ''; + + if (empty($item['subs'])) + { + echo ' + '; + continue; + } + + echo ' + '; + } + } +}