diff --git a/assets/less/manage/classes/container.less b/assets/less/manage/classes/container.less index f3ed90e9..81b7edd9 100644 --- a/assets/less/manage/classes/container.less +++ b/assets/less/manage/classes/container.less @@ -1,4 +1,8 @@ .container { max-width: 1200px; margin: 2px auto; + + &--center { + text-align: center; + } } diff --git a/assets/less/manage/classes/footer.less b/assets/less/manage/classes/footer.less index 6118e8e2..f431c872 100644 --- a/assets/less/manage/classes/footer.less +++ b/assets/less/manage/classes/footer.less @@ -1,6 +1,6 @@ .footer { text-align: center; - padding: 1em; + padding: 2px 0; &__link { text-decoration: none; diff --git a/assets/less/manage/classes/header.less b/assets/less/manage/classes/header.less index e0ca5b90..643ba2b1 100644 --- a/assets/less/manage/classes/header.less +++ b/assets/less/manage/classes/header.less @@ -9,8 +9,7 @@ margin: 0 auto; } - &__logo, - &__link { + &__logo { padding: 8px 10px; color: #fff; text-decoration: none; @@ -31,30 +30,19 @@ flex-shrink: 0; } - &__link { - cursor: pointer; - transition: background-color .2s; - - &:hover { - background-color: #333; - } - - &--active, - &:active { - background-color: #222; - } - } - &__user { flex-grow: 0; flex-shrink: 1; + } + + &__menu { + margin: 0 1px; &__toggle { - background-size: contain; - background-repeat: no-repeat; - background-position: right; - padding-right: 45px; - min-width: 100px; + padding: 8px 10px; + display: block; + cursor: pointer; + min-width: 50px; transition: background-color .2s, min-width .2s; -webkit-touch-callout: none; -webkit-user-select: none; @@ -62,24 +50,39 @@ -moz-user-select: none; -ms-user-select: none; user-select: none; + + &--profile { + background-size: contain; + background-repeat: no-repeat; + background-position: right; + padding-right: 45px; + } + + &:hover { + background-color: #333; + } + + &--active, + &:active { + background-color: #222; + } } &__state { display: none; - &:checked ~ .header__user__toggle { + &:checked ~ .header__menu__toggle { background-color: #333; min-width: 150px; } - &:checked ~ .header__user__menu { + &:checked ~ .header__menu__options { max-height: 250px; } } - &__menu { + &__options { overflow: hidden; - text-align: right; max-height: 0px; width: 100%; position: absolute; @@ -87,6 +90,10 @@ z-index: 1000; transition: max-height .2s; box-shadow: 0 5px 5px 0 fade(#444, 80%); + + &--user { + text-align: right; + } } &__link { diff --git a/assets/less/manage/classes/pagination.less b/assets/less/manage/classes/pagination.less new file mode 100644 index 00000000..b9a6647a --- /dev/null +++ b/assets/less/manage/classes/pagination.less @@ -0,0 +1,45 @@ +.pagination { + display: inline-flex; + list-style: none; + justify-content: center; + box-shadow: 0 1px 5px 0 fade(#444, 80%); + background: #333; + color: #fff; + font-size: 1.2em; + margin: 2px; + + &__option { + transition: box-shadow .2s, background-color .2s; + + &:hover { + background-color: #444; + box-shadow: 0 1px 5px 0 fade(#555, 80%); + } + + &--active, + &:active { + background-color: #444; + } + } + + &__separator { + width: 1px; + background-color: #444; + } + + &__link { + display: flex; + justify-content: center; + align-items: center; + cursor: pointer; + color: inherit; + text-decoration: none; + min-width: 40px; + min-height: 40px; + + &--prev, + &--next { + font-size: 2em; + } + } +} diff --git a/assets/less/manage/classes/user-listing.less b/assets/less/manage/classes/user-listing.less index 75684a44..44a537cf 100644 --- a/assets/less/manage/classes/user-listing.less +++ b/assets/less/manage/classes/user-listing.less @@ -6,5 +6,11 @@ &__entry { min-width: 296px; margin: 2px; + + &__content { + display: flex; + align-items: flex-start; + padding: 2px; + } } } diff --git a/assets/less/manage/main.less b/assets/less/manage/main.less index 44025b15..13e28cda 100644 --- a/assets/less/manage/main.less +++ b/assets/less/manage/main.less @@ -21,5 +21,6 @@ body { @import "classes/footer"; @import "classes/header"; @import "classes/listing"; +@import "classes/pagination"; @import "classes/user-listing"; diff --git a/misuzu.php b/misuzu.php index af98739a..1988ad50 100644 --- a/misuzu.php +++ b/misuzu.php @@ -25,5 +25,18 @@ if (PHP_SAPI !== 'cli') { ob_start('ob_gzhandler'); } + $manage_mode = starts_with($_SERVER['REQUEST_URI'], '/manage'); + $app->startTemplating(); + $app->templating->addPath('mio', __DIR__ . '/views/mio'); + + if ($manage_mode) { + if (Application::getInstance()->getSession() === null) { + http_response_code(403); + echo $app->templating->render('errors.403'); + exit; + } + + $app->templating->addPath('manage', __DIR__ . '/views/manage'); + } } diff --git a/public/manage.php b/public/manage.php deleted file mode 100644 index e7f3126d..00000000 --- a/public/manage.php +++ /dev/null @@ -1,52 +0,0 @@ -getSession(); - -if ($manage_session === null) { - header('Location: /'); - return; -} - -$app->templating->addPath('manage', __DIR__ . '/../views/manage'); - -$manage_user = $manage_session->user; -$manage_modes = [ - 'overview' => [ - 'title' => 'Overview', - ], - 'forums' => [ - 'title' => 'Forums', - ], - 'users' => [ - 'title' => 'Users', - ], - 'roles' => [ - 'title' => 'Roles', - ], -]; -$manage_mode = $_GET['m'] ?? key($manage_modes); - -$app->templating->vars(compact('manage_mode', 'manage_modes', 'manage_user', 'manage_session')); - -if (!array_key_exists($manage_mode, $manage_modes)) { - http_response_code(404); - $app->templating->var('manage_title', 'Not Found'); - echo $app->templating->render('@manage.notfound'); - return; -} - -$app->templating->var('title', $manage_modes[$manage_mode]['title']); - -switch ($manage_mode) { - case 'users': - $users_page = (int)($_GET['p'] ?? 1); - $manage_users = User::paginate(32, ['*'], 'p', $users_page); - $app->templating->vars(compact('manage_users', 'users_page')); - break; -} - -echo $app->templating->render("@manage.{$manage_mode}"); diff --git a/public/manage/index.php b/public/manage/index.php new file mode 100644 index 00000000..c83c017f --- /dev/null +++ b/public/manage/index.php @@ -0,0 +1,4 @@ +templating->render('@manage.general.overview'); diff --git a/public/manage/users-listing.php b/public/manage/users-listing.php new file mode 100644 index 00000000..86b3fff6 --- /dev/null +++ b/public/manage/users-listing.php @@ -0,0 +1,11 @@ +templating->vars(compact('manage_users', 'users_page')); + +echo $app->templating->render('@manage.users.listing'); diff --git a/public/not-found.php b/public/not-found.php new file mode 100644 index 00000000..ed17ef68 --- /dev/null +++ b/public/not-found.php @@ -0,0 +1,4 @@ +templating->render('errors.404'); diff --git a/public/settings.php b/public/settings.php index a1d5788a..36babdd1 100644 --- a/public/settings.php +++ b/public/settings.php @@ -8,8 +8,9 @@ require_once __DIR__ . '/../misuzu.php'; $settings_session = Application::getInstance()->getSession(); -if ($settings_session === null) { - header('Location: /'); +if (Application::getInstance()->getSession() === null) { + http_response_code(403); + echo $app->templating->render('errors.403'); return; } diff --git a/src/Application.php b/src/Application.php index 32fe0f03..54d23811 100644 --- a/src/Application.php +++ b/src/Application.php @@ -175,7 +175,5 @@ class Application extends ApplicationBase $twig->addFunction('csrf_token', 'tmp_csrf_token'); $twig->var('app', $this); - - $twig->addPath('mio', __DIR__ . '/../views/mio'); } } diff --git a/utility.php b/utility.php index 773dc7a1..3f74d746 100644 --- a/utility.php +++ b/utility.php @@ -199,20 +199,7 @@ function crop_image_centred(Imagick $image, int $target_width, int $target_heigh function create_pagination($paginator) { - $window = \Illuminate\Pagination\UrlWindow::make($paginator); - - $pagination = array_map( - function ($str) { - return substr($str, 2); - }, - array_merge( - $window['first'] ?? [], - $window['slider'] ?? [], - $window['last'] ?? [] - ) - ); - - return $pagination; + return \Illuminate\Pagination\UrlWindow::make($paginator); } function is_int_ex($value, int $boundary_low, int $boundary_high): bool diff --git a/views/manage/forums.twig b/views/manage/general/master.twig similarity index 100% rename from views/manage/forums.twig rename to views/manage/general/master.twig diff --git a/views/manage/general/overview.twig b/views/manage/general/overview.twig new file mode 100644 index 00000000..26c2cc23 --- /dev/null +++ b/views/manage/general/overview.twig @@ -0,0 +1 @@ +{% extends '@manage/general/master.twig' %} diff --git a/views/manage/macros.twig b/views/manage/macros.twig index 8db014cc..77dada0f 100644 --- a/views/manage/macros.twig +++ b/views/manage/macros.twig @@ -4,35 +4,67 @@ {% endspaceless %} {% endmacro %} -{% macro pagination(url, pages, current, class, name) %} - {% set pagess = pages|create_pagination %} - {% set separator %}{% if '%3F' in url|default('')|url_encode %}&{% else %}?{% endif %}{% endset %} - {% set current_page = current|default(1) %} - {% set url = url ~ separator ~ name|default('page') ~ "=" %} - - +{% macro pagination_segment(url_window, base_url, currentPage) %} + {% for page, url in url_window %} +
  • + + {{ page }} + +
  • + {% endfor %} +{% endmacro %} + +{% macro paginate(paginator, base_url, className) %} + {% from _self import pagination_segment %} + + {% set url_window = paginator|create_pagination %} + {% set separator = '%3F' in base_url|default('')|url_encode ? '&' : '?' %} + {% set base_url = base_url ~ separator %} + + {% endmacro %} diff --git a/views/manage/master.twig b/views/manage/master.twig index cda32d67..35975c7d 100644 --- a/views/manage/master.twig +++ b/views/manage/master.twig @@ -1,5 +1,91 @@ {% from '@manage/macros.twig' import link %} +{% set menus = [ + { + 'name': 'general', + 'title': 'General', + 'sections': [ + [ + { + 'name': 'overview', + 'title': 'Overview', + 'url': '/manage/index.php', + }, + { + 'name': 'logs', + 'title': 'Logs', + }, + ], + [ + { + 'name': 'emotes', + 'title': 'Emoticons', + }, + { + 'name': 'settings', + 'title': 'Settings', + }, + ], + ], + }, + { + 'name': 'users', + 'title': 'Users', + 'sections': [ + [ + { + 'name': 'listing', + 'title': 'Listing', + }, + ], + [ + { + 'name': 'roles', + 'title': 'Roles', + }, + { + 'name': 'perms', + 'title': 'Permissions', + }, + ], + [ + { + 'name': 'report', + 'title': 'Reports', + }, + { + 'name': 'restrictions', + 'title': 'Restrictions', + }, + { + 'name': 'blacklist', + 'title': 'Blacklisting', + }, + ], + ], + }, + { + 'name': 'forum', + 'title': 'Forum', + 'sections': [ + [ + { + 'name': 'forums', + 'title': 'Listing', + }, + { + 'name': 'perms', + 'title': 'Permissions', + }, + { + 'name': 'settings', + 'title': 'Settings', + }, + ], + ], + }, +] %} + @@ -7,32 +93,47 @@ Flashii Broom Closet +