From dac8ffef5d977fa492f638d9ed1759105bf8e556 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Fri, 8 Dec 2023 18:56:26 +0200 Subject: [PATCH] Refactor _mod.php by stripping out conditional moderator statements. The update centralizes authorization checks for various moderation actions such as blocking users and appointing new moderators. It also optimizes several lines in the code by suppressing unnecessary components. The old method of using 'admin' has been replaced by an object-oriented 'm' class to streamline and improve code maintenance. --- modules_data/_mod.php | 269 ++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 143 deletions(-) diff --git a/modules_data/_mod.php b/modules_data/_mod.php index bfba842d..5ac79f06 100644 --- a/modules_data/_mod.php +++ b/modules_data/_mod.php @@ -15,16 +15,6 @@ if (!$m->isModerator) { return; } -$rang = 'Модератор'; - -if (isset($_GET['remod'])) { - if ($_GET['remod'] == 1) { - $_SESSION['remod'] = 3; - } else { - $_SESSION['remod'] = 1; - } -} - $merror = ''; $uer = ''; @@ -50,23 +40,23 @@ if (!empty($_POST['logingo'])) { $moderation->depersonalize($_POST['time']); } elseif (!empty($_POST['undepersonalize'])) { $moderation->undepersonalize(); - } elseif (!empty($_POST['ban'])) { + } elseif (!empty($_POST['ban']) && $m->canBlockUsers) { $moderation->ban(); - } elseif (!empty($_POST['unban'])) { + } elseif (!empty($_POST['unban']) && $m->canBlockUsers) { $moderation->unban(); - } elseif (!empty($_POST['addmoderator'])) { + } elseif (!empty($_POST['addmoderator']) && $m->isAdmin) { $administration->addmoderator(); - } elseif (!empty($_POST['deletemoderator'])) { + } elseif (!empty($_POST['deletemoderator']) && $m->isAdmin) { $administration->removemoderator(); - } elseif (!empty($_POST['changegender'])) { + } elseif (!empty($_POST['changegender']) && $m->isAdmin) { $administration->changegender(); - } elseif (!empty($_POST['changelogin']) && !empty($_POST['newLogin'])) { + } elseif (!empty($_POST['changelogin']) && !empty($_POST['newLogin']) && $m->isAdmin) { $administration->changelogin($_POST['newLogin']); - } elseif (!empty($_POST['giveitem']) && !empty($_POST['itemId'])) { + } elseif (!empty($_POST['giveitem']) && !empty($_POST['itemId']) && $m->isAdmin) { $administration->additem((int)$_POST['itemId']); - } elseif (!empty($_POST['kickfrombattle'])) { + } elseif (!empty($_POST['kickfrombattle']) && $m->isAdmin) { $administration->kickfrombattle(); - } elseif (!empty($_POST['toggleinvisibility'])) { + } elseif (!empty($_POST['toggleinvisibility']) && $m->isAdmin) { $administration->toggleinvisibility(); } @@ -93,7 +83,7 @@ if (isset($_GET['go'])) { $go = round($_GET['go']); } -if ($go == 3 && $u->info['admin'] > 0) { +if ($go == 3 && $m->isAdmin) { ?> @@ -227,11 +217,11 @@ if ($go == 3 && $u->info['admin'] > 0) {
info['admin'] > 0) { +} elseif ($go == 2 && $m->isAdmin) { if (isset($_POST['q_name'])) { $qd = []; /* Array ([q_act_atr_1] => 0 [q_act_val_1] => [q_tr_atr_1] => 0 [q_tr_val_1] => [q_ng_atr_1] => 0 [q_ng_val_1] => [q_nk_atr_NaN] => 0 - [q_nk_val_NaN] => [q_info] => test описание [q_line1] => 1 [q_line2] => 1 [q_fast] => 1 [q_fast_city] => capitalcity [q_align1] => 1 [q_align2] => 1 [q_align3] => 1 ) */ + [q_nk_val_NaN] => [q_info] => test описание [q_line1] => 1 [q_line2] => 1 [q_fast] => 1 [q_align1] => 1 [q_align2] => 1 [q_align3] => 1 ) */ $qd['name'] = $_POST['q_name']; $qd['lvl'] = explode('-', $_POST['q_lvl']); $qd['info'] = $_POST['q_info']; @@ -239,7 +229,6 @@ if ($go == 3 && $u->info['admin'] > 0) { $qd['line'] = $_POST['q_line2']; } if ($_POST['q_fast'] == 1) { - $qd['city'] = $_POST['q_fast_city']; $gd['fast'] = 1; } if ($_POST['align1'] == 1) { @@ -257,7 +246,7 @@ if ($go == 3 && $u->info['admin'] > 0) { } } else { $i = -2; - $qd['act_date'] = trim($qd['act_date'], ':|:'); + $qd['act_date'] = trim($qd['act_date'], ':|'); } $i++; } @@ -269,7 +258,7 @@ if ($go == 3 && $u->info['admin'] > 0) { } } else { $i = -2; - $qd['tr_date'] = trim($qd['tr_date'], ':|:'); + $qd['tr_date'] = trim($qd['tr_date'], ':|'); } $i++; } @@ -281,7 +270,7 @@ if ($go == 3 && $u->info['admin'] > 0) { } } else { $i = -2; - $qd['win_date'] = trim($qd['win_date'], ':|:'); + $qd['win_date'] = trim($qd['win_date'], ':|'); } $i++; } @@ -293,7 +282,7 @@ if ($go == 3 && $u->info['admin'] > 0) { } } else { $i = -2; - $qd['lose_date'] = trim($qd['lose_date'], ':|:'); + $qd['lose_date'] = trim($qd['lose_date'], ':|'); } $i++; } @@ -397,18 +386,43 @@ if ($go == 3 && $u->info['admin'] > 0) { Текстовое поле + + - - +

Редактор заданий

+

Редактор заданий

- - +
@@ -422,58 +436,55 @@ if ($go == 3 && $u->info['admin'] > 0) { Панель добавления новых заданий:
- + +
- - + - + - - + + - - + + - - + + - - + + - + - - - - -
+
Действия[+] добавитьДействия[+] добавить
Условия[+] добавитьУсловия[+] добавить
Награда[+] добавитьНаграда[+] добавить
Неудача[+] добавитьНеудача[+] добавить
- + - +
- + -
+
- +
info['admin'] > 0) { padding: 10px; } - -