You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB
PHTML

<?php
use Engelsystem\Database\DB;
/**
* Returns Message id array
*
* @return array
*/
8 years ago
function Message_ids()
{
return DB::select('SELECT `id` FROM `Messages`');
}
/**
* Returns message by id.
*
* @param int $message_id message ID
* @return array|null
*/
8 years ago
function Message($message_id)
{
$message = DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
return empty($message) ? null : $message;
}
/**
* TODO: use validation functions, return new message id
* send message
*
7 years ago
* @param int $receiver_user_id User ID of Receiver
* @param string $text Text of Message
* @return bool
*/
8 years ago
function Message_send($receiver_user_id, $text)
{
$user = auth()->user();
8 years ago
8 years ago
$text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text));
$receiver_user_id = preg_replace('/([^\d]{1,})/ui', '', strip_tags($receiver_user_id));
8 years ago
if (
($text != '' && is_numeric($receiver_user_id))
&& count(DB::select('
SELECT `id`
FROM `users`
WHERE `id` = ?
AND NOT `id` = ?
8 years ago
LIMIT 1
', [$receiver_user_id, $user->id])) > 0
8 years ago
) {
return DB::insert('
INSERT INTO `Messages` (`Datum`, `SUID`, `RUID`, `Text`)
VALUES(?, ?, ?, ?)
',
[
time(),
$user->id,
$receiver_user_id,
$text
]
);
8 years ago
}
8 years ago
8 years ago
return false;
}