Файл: upload/core/ajax/messages/fetch_mes.php
Строк: 41
<?php
require_once ($_SERVER['DOCUMENT_ROOT'] . '/core/core.php');
$userId = intval($_GET['user']);
$peerId = intval($_GET['peer']);
$after = intval($_GET['after']);
$res = dbquery("
SELECT * FROM messages
WHERE (
(sender_id = ? AND receiver_id = ?)
OR
(sender_id = ? AND receiver_id = ?)
)
AND id > ?
ORDER BY id ASC
", [$userId, $peerId, $peerId, $userId, $after]);
while ($row = FetchAssoc($res)) {
$row['k_text'] = chars($row['k_text']);
$row['created_at'] = intval($row['created_at']);
$class = ($row['sender_id'] == $userId) ? 'my-message' : 'other-message';
$time = date('H:i', $row['created_at']);
$ank = FetchAssoc(dbquery("SELECT * FROM users WHERE id = ?", [$row['sender_id']]));
// обработка вложений
$attachments = [];
if (!empty($row['attachment']) && $row['attachment'] !== 'NULL') {
$files = json_decode($row['attachment'], true);
if (!is_array($files)) $files = [$row['attachment']];
foreach ($files as $file) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($ext, ['zip','rar','7z','tar','gz','tgz','bz2','tbz','tbz2','xz','txz','lz','lzma','tlz','z','lz4','zst','zstd'])) {
$attachments[] = [
'type' => 'archive',
'name' => $file,
'ext' => $ext,
'url' => homeLink() . "/down/$file"
];
}
elseif (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
$attachments[] = [
'type' => 'image',
'name' => $file,
'ext' => $ext,
'url' => homeLink() . "/uploads/chats/$file"
];
}
else {
$attachments[] = [
'type' => 'file',
'name' => $file,
'ext' => $ext,
'url' => homeLink() . "/down/$file"
];
}
}
}
echo $view->render('components/messages/chat_message.html', [
'id' => $row['id'],
'class' => $class,
'avatar' => GetAvatar($ank['avatar']),
'login' => $ank['login'],
'text' => bbmes($row['k_text']),
'time' => $time,
'attachments'=> $attachments
]);
}
?>