Файл: app/minichat/index.php
Строк: 41
<?php
$smarty->header('Мини-чат');
if (filter_has_var(INPUT_POST, 'submit') && isset($user))
{
$filter = [
'text' => filter_has_var(INPUT_POST, 'text')
? filter_input(INPUT_POST, 'text', FILTER_UNSAFE_RAW)
: null
];
if (Filter::strlen ($filter['text']) < 2 || Filter::strlen ($filter['text']) > 5000)
{
$error = 'Неверный формат сообщения.';
}
elseif ($db->query("SELECT `id` FROM `minichat` WHERE `text` = '" . $filter['text'] . "' AND `id_user` = '" . $user['id'] . "' AND `time` > '" . (time() - 60) . "'")->rowCount() != 0)
{
$error = 'Сообщение уже существует.';
}
else
{
$stmt = $db->prepare('INSERT INTO `minichat` (`text`, `time`, `id_user`) VALUES (:text, :time, :id_user)');
$stmt->execute([
':text' => $filter['text'],
':time' => time(),
':id_user' => $user['id']
]);
}
}
$elements = null;
if (isset($user))
{
$elements[] = [
'type' => 'textarea',
'title' => Lang::word('Сообщение'),
'br' => 1,
'info' => [
'name' => 'text'
]
];
$elements[] = [
'type' => 'submit',
'info' => [
'name' => 'submit',
'value' => Lang::word('Отправить')
]
];
}
$all = $db->query("SELECT `id` FROM `minichat` ")->rowCount();
$pages = new Pages($all, $config['pages']);
$query = $db->query("SELECT * FROM `minichat` ORDER BY `id` DESC LIMIT " . $start . ", " . $config['pages']);
while ($list = $query->fetch())
{
$options = null;
if (isset($user) && $user['id'] != $list['id_user'])
{
$options[] = [
'url' => '/minichat/message?id=' . $list['id'],
'title' => Lang::word('Ответить')
];
}
if (isset($user) && $user['level'] >= 1)
{
$options[] = [
'url' => '/minichat/delete?id=' . $list['id'],
'title' => Lang::word('Удалить')
];
}
$posts[] = [
'image' => User::photo($list['id_user']),
'title' => User::login($list['id_user']).($list['id_profile'] != 0 ? ' для ' . User::login($list['id_profile']) : null),
'post' => Filter::output($list['text']),
'time' => Core::time($list['time']),
'options' => $options
];
}
if ($all == 0)
$posts[] = [
'title' => Lang::word('Нет сообщений.')
];
Core::show('error');
$smarty->assign([
'method' => 'POST',
'action' => '?',
'el' => $elements,
'post' => $posts
]);
$smarty->display('form.tpl');
$smarty->display('posts.tpl');
$pages->view('?');
$smarty->footer();