ロールの追加、性別もクラス化、テスト記事忘れた

This commit is contained in:
2025-12-29 17:19:59 +09:00
parent 113e0a00fb
commit c458eecd53
3 changed files with 28 additions and 6 deletions

11
blog/draft-post.md Normal file
View File

@@ -0,0 +1,11 @@
title: 書き込み中・・・
uuid: fd0d879a-20e9-41b1-bee9-2729452c9a4c
author: 諏訪子
date: 2025-12-29 07:50:11
thumbnail:
thumborient: center
draft: true
category: test
----
これは下書きの記事です。\
Roles::ADMINやRoles::STAFFを持っている方以外誰もこの記事をアクセス出来ません。

View File

@@ -44,7 +44,7 @@ class Auth {
}
$user->name = namecolor($user);
$user->regDate = date('Y年m月d日', $user->regDate);
$user->gender = $user->gender === 0 ? '男' : ($user->gender === 1 ? '女' : '不明');
$user->gender = $user->gender === \Gender::MALE ? '男' : ($user->gender === \Gender::FEMALE ? '女' : '不明');
$user->role = $user->role & (\Roles::ADMIN | \Roles::STAFF) ? '管理者' : ($user->role === \Roles::BANNED ? 'BANされた' : 'ユーザー');
$user->avatar = '/static/user/'.($user->avatar === '' ? 'noicon.png' : $user->username.'/'.$user->avatar);
$user->altName = $user->displayname ?: $user->username;
@@ -197,7 +197,7 @@ class Auth {
$user->regDate = time();
$user->namecolor = '';
$user->displayname = '';
$user->gender = -1;
$user->gender = \Gender::UNKNOWN;
$user->role = \Roles::MEMBER;
$user->tokens = [];

View File

@@ -33,8 +33,19 @@ class Roles {
public const int MEMBER = 1 << 0; // 1
public const int NINTENDONDA = 1 << 1; // 2
public const int PLAYSTATIONNDA = 1 << 2; // 4
public const int STAFF = 1 << 3; // 8
public const int ADMIN = 1 << 7; // 128
public const int FULLNDA = 1 << 3; // 8 (NINTENDONDA + PLAYSTATIONNDA)
public const int SUBSCRIBER = 1 << 4; // 16
public const int NSUBSCRIBER = 1 << 5; // 32 (NINTENDNDA + SUBSCRIBER)
public const int PSUBSCRIBER = 1 << 6; // 64 (PLAYSTATIONNDA + SUBSCRIBER)
public const int FSUBSCRIBER = 1 << 7; // 128 (NINTENDNDA + PLAYSTATIONNDA + SUBSCRIBER)
public const int STAFF = 1 << 8; // 256
public const int ADMIN = 1 << 9; // 512
}
class Gender {
public const int UNKNOWN = -1; // 不明
public const int MALE = 0; // 男性
public const int FEMALE = 1; // 女性
}
$colorPalette = [
@@ -296,7 +307,7 @@ function namecolor(\stdClass $userData): string {
$female = "#F185C9";
$ungender = "#7C60B0";
$gender = 'color: '.($userData->gender === 0 ? $male : ($userData->gender === 1 ? $female : $ungender)).';';
$gender = 'color: '.($userData->gender === Gender::MALE ? $male : ($userData->gender === Gender::FEMALE ? $female : $ungender)).';';
$style = $userData->namecolor ?: ($userData->role !== Roles::BANNED ? $gender : 'color: '.$ban.';');
$showname = $userData->displayname ?: $userData->username;
@@ -304,7 +315,7 @@ function namecolor(\stdClass $userData): string {
$color = "<span style=\"{$style}\">{$showname}</span>";
if ($userData->role & (Roles::ADMIN | Roles::STAFF))
$color .= "<span style=\"font-size: x-small; background: #10c074; border: 1px solid #fcfcfc; border-radius: 10px; padding: 0 0.5em;\">✓</span>";
$suffix = $userData->gender === 0 ? 'くん' : ($userData->gender === 1 ? 'ちゃん' : 'さん');
$suffix = $userData->gender === Gender::MALE ? 'くん' : ($userData->gender === Gender::FEMALE ? 'ちゃん' : 'さん');
return $color.$suffix;
}