Example #1
0
function tags_normalize_string($string)
{
    $string = clear_whitespace($string);
    $string = html_entity_decode(trim($string), ENT_COMPAT, 'UTF-8');
    $string = preg_replace('/-+/', '-', $string);
    // Don't allow a sequence of more than a "-"
    $string = preg_replace('/ +,/', ',', $string);
    // Avoid errors like " ,"
    $string = preg_replace('/[\\n\\t\\r]+/s', ' ', $string);
    if (!preg_match('/,/', $string)) {
        // The user didn't put any comma, we add them
        $string = preg_replace('/ +/', ', ', $string);
    }
    $string = preg_replace('/[\\.\\,] *$/', "", $string);
    // Clean strange characteres, there are feed reader (including feedburner) that are just too strict and complain loudly
    $string = preg_replace('/[\\\\<>;"\'\\]\\[&]/', "", $string);
    return htmlspecialchars(mb_substr(mb_strtolower($string, 'UTF-8'), 0, 80), ENT_COMPAT, 'UTF-8');
}
Example #2
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 #3
0
 function normalize_content()
 {
     $this->content = clean_lines(clear_whitespace(normalize_smileys($this->content)));
     return $this->content;
 }
Example #4
0
function clean_text($string, $wrap=0, $replace_nl=true, $maxlength=0) {
	$string = stripslashes(trim($string));
	$string = clear_whitespace($string);
	$string = html_entity_decode($string, ENT_COMPAT, 'UTF-8');
	// Replace two "-" by a single longer one, to avoid problems with xhtml comments
	//$string = preg_replace('/--/', '–', $string);
	if ($wrap>0) $string = wordwrap($string, $wrap, " ", 1);
	if ($replace_nl) $string = preg_replace('/[\n\t\r]+/s', ' ', $string);
	if ($maxlength > 0) $string = mb_substr($string, 0, $maxlength);
	return @htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
}