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.

69 lines
1.7 KiB
PHTML

<?php
/**
* Returns Message id array
*
* @return array|false
*/
8 years ago
function Message_ids()
{
return sql_select("SELECT `id` FROM `Messages`");
}
/**
* Returns message by id.
*
* @param int $message_id message ID
* @return array|false|null
*/
8 years ago
function Message($message_id)
{
$message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1");
if ($message_source === false) {
return false;
}
if (count($message_source) > 0) {
return $message_source[0];
}
return null;
}
/**
* TODO: use validation functions, return new message id
* TODO: global $user con not be used in model!
* send message
*
* @param int $receiver_user_id User ID of Reciever
* @param string $text Text of Message
* @return bool
*/
8 years ago
function Message_send($receiver_user_id, $text)
{
global $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("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id));
8 years ago
if (
($text != "" && is_numeric($receiver_user_id))
&& (sql_num_query("
SELECT *
FROM `User`
WHERE `UID`='" . sql_escape($receiver_user_id) . "'
AND NOT `UID`='" . sql_escape($user['UID']) . "'
LIMIT 1
") > 0)
) {
sql_query("
INSERT INTO `Messages`
SET `Datum`='" . sql_escape(time()) . "',
`SUID`='" . sql_escape($user['UID']) . "',
`RUID`='" . sql_escape($receiver_user_id) . "',
`Text`='" . sql_escape($text) . "'
");
8 years ago
return true;
}
8 years ago
8 years ago
return false;
}