Early stuff, dev env bugged out.
This commit is contained in:
parent
4fcc32c793
commit
6ff77973d8
2 changed files with 148 additions and 0 deletions
|
@ -16,6 +16,7 @@ require_once __DIR__ . '/src/perms.php';
|
||||||
require_once __DIR__ . '/src/tpl.php';
|
require_once __DIR__ . '/src/tpl.php';
|
||||||
require_once __DIR__ . '/src/zalgo.php';
|
require_once __DIR__ . '/src/zalgo.php';
|
||||||
require_once __DIR__ . '/src/Forum/forum.php';
|
require_once __DIR__ . '/src/Forum/forum.php';
|
||||||
|
require_once __DIR__ . '/src/Forum/perms.php';
|
||||||
require_once __DIR__ . '/src/Forum/post.php';
|
require_once __DIR__ . '/src/Forum/post.php';
|
||||||
require_once __DIR__ . '/src/Forum/topic.php';
|
require_once __DIR__ . '/src/Forum/topic.php';
|
||||||
require_once __DIR__ . '/src/Forum/validate.php';
|
require_once __DIR__ . '/src/Forum/validate.php';
|
||||||
|
|
147
src/Forum/perms.php
Normal file
147
src/Forum/perms.php
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
<?php
|
||||||
|
use Misuzu\Database;
|
||||||
|
|
||||||
|
define('MSZ_FORUM_PERMS_GENERAL', 'forum');
|
||||||
|
|
||||||
|
define('MSZ_FORUM_PERM_MODES', [
|
||||||
|
MSZ_FORUM_PERMS_GENERAL,
|
||||||
|
]);
|
||||||
|
|
||||||
|
function forum_perms_get_keys(): array
|
||||||
|
{
|
||||||
|
$perms = [];
|
||||||
|
|
||||||
|
foreach (MSZ_FORUM_PERM_MODES as $mode) {
|
||||||
|
foreach (MSZ_PERM_SETS as $set) {
|
||||||
|
$perms[] = perms_get_key($mode, $set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $perms;
|
||||||
|
}
|
||||||
|
|
||||||
|
function forum_perms_create(): int
|
||||||
|
{
|
||||||
|
$perms = [];
|
||||||
|
|
||||||
|
foreach (forum_perms_get_keys() as $key) {
|
||||||
|
$perms[$key] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $perms;
|
||||||
|
}
|
||||||
|
|
||||||
|
function forum_perms_get_user(string $prefix, ?int $forum, int $user): int
|
||||||
|
{
|
||||||
|
if (!in_array($prefix, MSZ_FORUM_PERM_MODES) || $user < 1) {
|
||||||
|
return 0;
|
||||||
|
} elseif ($user === 1) {
|
||||||
|
return 0x7FFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
$getPerms = Database::prepare("
|
||||||
|
SELECT BIT_OR(`{$prefix}_perms_allow`) &~ BIT_OR(`{$prefix}_perms_deny`)
|
||||||
|
FROM `msz_forum_permissions`
|
||||||
|
WHERE (
|
||||||
|
`forum_id` = :forum_id
|
||||||
|
OR `forum_id` IS NULL
|
||||||
|
)
|
||||||
|
AND (
|
||||||
|
(`user_id` = :user_id_1 AND `role_id` IS NULL)
|
||||||
|
OR (
|
||||||
|
`user_id` IS NULL
|
||||||
|
AND `role_id` IN (
|
||||||
|
SELECT `role_id`
|
||||||
|
FROM `msz_user_roles`
|
||||||
|
WHERE `user_id` = :user_id_2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
");
|
||||||
|
$getPerms->bindValue('forum_id', $forum);
|
||||||
|
$getPerms->bindValue('user_id_1', $user);
|
||||||
|
$getPerms->bindValue('user_id_2', $user);
|
||||||
|
return $getPerms->execute() ? (int)$getPerms->fetchColumn() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function forum_perms_get_role(string $prefix, ?int $forum, int $role): int
|
||||||
|
{
|
||||||
|
if (!in_array($prefix, MSZ_FORUM_PERM_MODES) || $role < 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$getPerms = Database::prepare("
|
||||||
|
SELECT `{$prefix}_perms_allow` &~ `{$prefix}_perms_deny`
|
||||||
|
FROM `msz_forum_permissions`
|
||||||
|
WHERE (
|
||||||
|
`forum_id` = :forum_id
|
||||||
|
OR `forum_id` IS NULL
|
||||||
|
)
|
||||||
|
AND `role_id` = :role_id
|
||||||
|
AND `user_id` IS NULL
|
||||||
|
");
|
||||||
|
$getPerms->bindValue('forum_id', $forum);
|
||||||
|
$getPerms->bindValue('role_id', $role);
|
||||||
|
return $getPerms->execute() ? (int)$getPerms->fetchColumn() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function perms_get_user_raw(?int $forum, int $user): array
|
||||||
|
{
|
||||||
|
$emptyPerms = forum_perms_create();
|
||||||
|
|
||||||
|
if ($user < 1) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
$getPerms = Database::prepare('
|
||||||
|
SELECT
|
||||||
|
`' . implode('`, `', forum_perms_get_keys()) . '`
|
||||||
|
FROM `msz_forum_permissions`
|
||||||
|
WHERE `user_id` = :user_id
|
||||||
|
AND `role_id` IS NULL
|
||||||
|
');
|
||||||
|
$getPerms->bindValue('forum_id', $user);
|
||||||
|
$getPerms->bindValue('user_id', $user);
|
||||||
|
|
||||||
|
if (!$getPerms->execute()) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
$perms = $getPerms->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$perms) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $perms;
|
||||||
|
}
|
||||||
|
|
||||||
|
function perms_get_role_raw(int $role): array
|
||||||
|
{
|
||||||
|
$emptyPerms = perms_create();
|
||||||
|
|
||||||
|
if ($role < 1) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
$getPerms = Database::prepare('
|
||||||
|
SELECT
|
||||||
|
`' . implode('`, `', perms_get_keys()) . '`
|
||||||
|
FROM `msz_permissions`
|
||||||
|
WHERE `user_id` IS NULL
|
||||||
|
AND `role_id` = :role_id
|
||||||
|
');
|
||||||
|
$getPerms->bindValue('role_id', $role);
|
||||||
|
|
||||||
|
if (!$getPerms->execute()) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
$perms = $getPerms->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$perms) {
|
||||||
|
return $emptyPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $perms;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue