Example #1
0
function check_chat()
{
    global $db, $current_user, $now, $now_f, $globals, $events;
    if (empty($_POST['chat'])) {
        return;
    }
    $comment = trim(preg_replace("/[\r\n\t]/", ' ', $_REQUEST['chat']));
    $comment = clear_whitespace($comment);
    if ($current_user->user_id > 0 && strlen(strip_tags($comment)) > 2) {
        // Sends a message back if the user has a very low karma
        if ($globals['min_karma_for_sneaker'] > 0 && $current_user->user_karma < $globals['min_karma_for_sneaker']) {
            $comment = _('no tienes suficiente karma para comentar en la fisgona') . ' (' . $current_user->user_karma . ' < ' . $globals['min_karma_for_sneaker'] . ')';
            send_chat_warn($comment);
            return;
        }
        $period = $now - 4;
        $counter = intval($db->get_var("select count(*) from chats where chat_time > {$period} and chat_uid = {$current_user->user_id}"));
        if ($counter > 0) {
            $comment = _('tranquilo charlatán') . ' ;-)';
            send_chat_warn($comment);
            return;
        }
        if (check_ban_proxy()) {
            send_chat_warn(_('proxy abierto no permitido'));
            return;
        }
        if (preg_match('/^!/', $comment)) {
            require_once 'sneaker-stats.php';
            if (!($comment = check_stats($comment))) {
                send_chat_warn(_('comando no reconocido'));
            } else {
                send_string($comment);
            }
            return;
        } else {
            $comment = clean_text_with_tags($comment);
            $comment = preg_replace('/(^|[\\s\\.,¿#@])\\/me([\\s\\.,\\?]|$)/', "\$1<i>{$current_user->user_login}</i>\$2", $comment);
            if (mb_strlen($comment) > 255) {
                // Cut text longer that database, to avoid unclosed html tags
                $comment = mb_substr($comment, 0, 1) . mb_substr($comment, -254, 254);
            }
        }
        $from = $now - 1500;
        $db->query("delete from chats where chat_time < {$from}");
        if ((!empty($_REQUEST['admin']) || preg_match('/^#/', $comment)) && $current_user->admin) {
            $room = 'admin';
            $comment = preg_replace('/^# */', '', $comment);
        } elseif (!empty($_REQUEST['friends']) || preg_match('/^@/', $comment)) {
            $room = 'friends';
            $comment = preg_replace('/^@ */', '', $comment);
        } else {
            $room = 'all';
        }
        if (strlen($comment) > 0) {
            $comment = $db->escape(trim(normalize_smileys($comment)));
            $db->query("insert into chats (chat_time, chat_uid, chat_room, chat_user, chat_text) values ({$now_f}, {$current_user->user_id}, '{$room}', '{$current_user->user_login}', '{$comment}')");
        }
    }
}
Example #2
0
 function normalize_content()
 {
     $this->content = clean_lines(clear_whitespace(normalize_smileys($this->content)));
     return $this->content;
 }