Рефакторинг, очистка, работа над ошибками, связанными с базой, отказ от глобальной переменной $user во многих файлах.

Singleton в некоторых местах вместо решения #42.
Новые шаги для решения #16 и #52.
Closes #42.
Closes #32.
Closes #31.
This commit is contained in:
Igor Barkov (iwork)
2022-01-27 01:15:33 +02:00
parent b1ba212c8c
commit 3502904656
82 changed files with 1575 additions and 2015 deletions
+24 -32
View File
@@ -1,7 +1,11 @@
<?php
use Battles\Nick;
use Battles\Template;
use Battles\User;
require_once 'config.php';
$user = \Battles\User::$current;
$sleep = db::c()->query('SELECT `id` FROM `effects` WHERE `owner` = ?i AND `time` > ?i AND `type` = 3', $user['id'], time())->fetch_assoc();
$sleep = db::c()->query('SELECT `id` FROM `effects` WHERE `owner` = ?i AND `time` > ?i AND `type` = 3', User::getInstance()->getId(), time())->fetch_assoc();
$ps = $_GET['page'] ?? 0;
$isModerator = false;
$isAdmin = false;
@@ -72,7 +76,7 @@ function close_dangling_tags($html)
return $html;
}
if (isset($_POST['add']) && isset($user['id'])) {
if (isset($_POST['add']) && User::getInstance()->getId()) {
$icon = htmlentities($_POST['icon'], ENT_NOQUOTES, 'utf8');
$text2 = htmlspecialchars($_POST['title'], ENT_NOQUOTES, 'utf8');
@@ -86,12 +90,8 @@ if (isset($_POST['add']) && isset($user['id'])) {
rtrim($_POST['text']);
if (empty($_POST['text']) || empty($_POST['title'])) {
$error = "Заголовок или текст не могут быть пустыми!";
} elseif (($minmax['min_align'] == 0 && $minmax['max_align'] == 0) || ($user['align'] >= $minmax['min_align'] && $user['align'] <= $minmax['max_align']) || $isAdmin) {
if ($user['invis'] == 1) {
$userPost = '<b>Невидимка</b>';
} else {
$userPost = Nick::id($user['id'])->full(1);
}
} elseif (($minmax['min_align'] == 0 && $minmax['max_align'] == 0) || (User::getInstance()->getAlign() >= $minmax['min_align'] && User::getInstance()->getAlign() <= $minmax['max_align']) || $isAdmin) {
$userPost = Nick::id(User::getInstance()->getId())->full();
if ($isModerator == false) $text1 = strip_tags($text1, '<b><i><u><code><a><br><img><div>');
db::c()->query('INSERT INTO `forum` (`type`, `topic`, `text`, `parent`, `author`, `date`, `min_align`, `max_align`, `icon`) VALUES (2,"?s","?s",?i,"?s","?s","?s","?s","?s")', $text2, $text1, $_GET['conf'], $userPost, date('d.m.y H:i:s'), $min_align, $max_align, $icon);
@@ -105,7 +105,7 @@ if (isset($_POST['add']) && isset($user['id'])) {
unset($_POST['add']);
}
if (isset($_POST['add2']) && isset($user['id'])) {
if (isset($_POST['add2']) && User::getInstance()->getId()) {
$text2 = htmlspecialchars($_POST['title'], ENT_NOQUOTES, 'utf8');
$text1 = parse_bb_code(preg_replace("/\n/", "<br />", $_POST['text']));
@@ -120,12 +120,8 @@ if (isset($_POST['add2']) && isset($user['id'])) {
$error = "Не надо так делать";
}
if (($minmax['min_align'] == 0 && $minmax['max_align'] == 0) || ($user['align'] >= $minmax['min_align'] && $user['align'] <= $minmax['max_align']) && $minmax['close'] == "0" || $isAdmin) {
if ($user['invis'] == 1) {
$userPost = '<b>Невидимка</b>';
} else {
$userPost = Nick::id($user['id'])->full(1);
}
if (($minmax['min_align'] == 0 && $minmax['max_align'] == 0) || (User::getInstance()->getAlign() >= $minmax['min_align'] && User::getInstance()->getAlign() <= $minmax['max_align']) && $minmax['close'] == "0" || $isAdmin) {
$userPost = Nick::id(User::getInstance()->getId())->full();
if ($isModerator == false) {
$text1 = strip_tags($text1, '<b><i><u><code><a><br><img><div>');
@@ -165,11 +161,7 @@ if (isset($_GET['dt']) && $isModerator == true) {
}
if (isset($_GET['com']) && isset($_GET['cpr']) && $isModerator == true) {
if ($user['invis'] == 1) {
$addText = "<br /><b>Невидимка</b>: " . $_GET['cpr'];
} else {
$addText = Nick::id($user['id'])->full(1) . ": " . $_GET['cpr'];
}
$addText = Nick::id(User::getInstance()->getId())->full() . ": " . $_GET['cpr'];
db::c()->query('UPDATE `forum` SET `text` = CONCAT(`text`,"?s") WHERE `id` = ?i', $addText, $_GET['com']);
echo "<script>window.location='?topic=" . $_GET['topic'] . "&rnd'</script>";
exit();
@@ -183,7 +175,7 @@ if (isset($_GET['do']) && $isModerator == true) {
}
if ($_GET['do'] == "close") {
$closeComment = "Обсуждение закрыл " . ($isAdmin) ? "<b>Администратор</b>" : Nick::id($user['id'])->full(1);
$closeComment = "Обсуждение закрыл " . ($isAdmin) ? "<b>Администратор</b>" : Nick::id(User::getInstance()->getId())->full(1);
db::c()->query('UPDATE `forum` SET `close` = 1, `closepal` = "?s" WHERE `id` = "?s"', $closeComment, $_GET['topic']);
echo "<script>window.location='?topic=" . $_GET['topic'] . "&rnd'</script>";
exit();
@@ -201,7 +193,7 @@ if (isset($_GET['do']) && $isModerator == true) {
exit();
}
}
\Battles\Template::header('Форум');
Template::header('Форум');
?>
<link rel="stylesheet" href="css/wysibb/theme/default/wbbtheme.css"/>
<script type="text/javascript" language="JavaScript" src='js/forum.js'></script>
@@ -209,17 +201,17 @@ if (isset($_GET['do']) && $isModerator == true) {
<tr valign="top">
<td width="200">
<br/>
<?php if (isset($user['id'])) echo "Игрок : " . Nick::id($user['id'])->full(1) . "<br />"; ?>
<?php if (User::getInstance()->getId()) { echo "Игрок : " . Nick::id(User::getInstance()->getId())->full(1) . "<br>"; } ?>
<h4>Конференции</h4>
<?php
if ((isset($_GET['conf']) && is_numeric($_GET['conf'])) || (isset($_GET['konftop']) && is_numeric($_GET['konftop'])) || $Movemess == 1) {
$data = db::c()->query('SELECT * FROM `forum` WHERE `parent` = 0 AND `type` = 1 ORDER BY `id` ASC');
while ($row = $data->fetch_assoc()) {
if (($row['min_align'] == 0 && $row['max_align'] == 0) || ($user['align'] >= $row['min_align'] && $user['align'] <= $row['max_align']) || $isAdmin) {
if (($row['min_align'] == 0 && $row['max_align'] == 0) || (User::getInstance()->getAlign() >= $row['min_align'] && User::getInstance()->getAlign() <= $row['max_align']) || $isAdmin) {
$min = $row['min_align'] == 0;
$max = $row['max_align'] == 0;
if (!isset($user['id']) || (($user['align'] < $row['min_align']) || ($user['align'] > $row['max_align']) && !$min && !$max)) {
if (!User::getInstance()->getId() || ((User::getInstance()->getAlign() < $row['min_align']) || (User::getInstance()->getAlign() > $row['max_align']) && !$min && !$max)) {
echo '<nobr><b>&nbsp;&nbsp;📕';
} else {
echo '<nobr><b>&nbsp;&nbsp;📖&nbsp;';
@@ -234,7 +226,7 @@ if (isset($_GET['do']) && $isModerator == true) {
<?php
if (!isset($_GET['conf'])) {
$row = db::c()->query('SELECT * FROM `forum` WHERE `id` = "?s"', $_GET['topic'])->fetch_assoc();
if (($row['min_align'] == 0 && $row['max_align'] == 0) || ($user['align'] >= $row['min_align'] && $user['align'] <= $row['max_align']) || $isAdmin) {
if (($row['min_align'] == 0 && $row['max_align'] == 0) || (User::getInstance()->getAlign() >= $row['min_align'] && User::getInstance()->getAlign() <= $row['max_align']) || $isAdmin) {
$top = $row['parent'];
$parentCat = db::c()->query('SELECT * FROM `forum` WHERE `id` = ?i', $top)->fetch_assoc();
$icons = $row['icon'];
@@ -371,9 +363,9 @@ if (isset($_GET['do']) && $isModerator == true) {
if ($closed == 1) {
echo "<br /><div align=center>" . $closepal . "</div><br /><br />";
} else {
if (!empty($user['block'])) {
if (User::getInstance()->getBlock()) {
$error = "Вы заблокированы!";
} elseif ($user['level'] < 2) {
} elseif (User::getInstance()->getLevel() < 2) {
$error = "Персонажам до 2-го уровня запрещено писать на форуме!";
} elseif (isset($sleep['id'])) {
$error = "Вы молчите!";
@@ -423,7 +415,7 @@ if (isset($_GET['do']) && $isModerator == true) {
}
} else {
if (is_numeric($_GET['conf']) && $row = db::c()->query('SELECT * FROM `forum` WHERE `id` = ?i', $_GET['conf'])->fetch_assoc()) {
if (($row['min_align'] == 0 && $row['max_align'] == 0) || ($user['align'] >= $row['min_align'] && $user['align'] <= $row['max_align']) || $isAdmin) {
if (($row['min_align'] == 0 && $row['max_align'] == 0) || (User::getInstance()->getAlign() >= $row['min_align'] && User::getInstance()->getAlign() <= $row['max_align']) || $isAdmin) {
$confname = 'Конференция «' . $row['topic'] . '»';
$pgs = db::c()->query('SELECT count(`id`) FROM `forum` WHERE `parent` = ?i ORDER BY `fix` DESC, `updated` DESC', $_GET['conf'])->fetch_row();
$pgs = $pgs[0] / 20;
@@ -506,9 +498,9 @@ if (isset($_GET['do']) && $isModerator == true) {
echo $pages_str . "</p>";
if (!empty($user['block'])) {
if (User::getInstance()->getBlock()) {
$error = "Вы заблокированы!";
} elseif ($user['level'] < 2) {
} elseif (User::getInstance()->getLevel() < 2) {
$error = "Персонажам до 2-го уровня запрещено писать на форуме!";
} elseif (isset($sleep['id'])) {
$error = "Вы молчите!";