示例#1
0
function live_chat_load_events($options)
{
    $tail['filename'] = LIVE_CHAT_STORAGE_PATH . $options['type'] . '/' . $options['reference_id'];
    $tail['line_count'] = LIVE_CHAT_MAX_READ_LINES;
    $tail['buffer_length'] = LIVE_CHAT_STORAGE_BUFFER_LENGTH;
    $options['min_id'] = isset($options['min_id']) ? $options['min_id'] : 0;
    $rows = tail($tail);
    $events = array();
    foreach ($rows as $row) {
        $event = unserialize(trim($row));
        if ($event['id'] > $options['min_id']) {
            $event['message'] = clickable_links($event['message']);
            $event['message'] = setsmilies($event['message']);
            $events[] = $event;
        }
    }
    return $events;
}
/**
 *
 * Gets new messages from users
 *
 */
function fetchMessages()
{
    global $db;
    global $response;
    global $userid;
    global $messages;
    global $last_message;
    global $block_chats;
    global $heart_beat;
    $time_it = time();
    $result = $db->execute("\n\t\t\tSELECT arrowchat.id, arrowchat.from, arrowchat.to, arrowchat.message, arrowchat.sent, arrowchat.read, arrowchat.user_read \n\t\t\tFROM arrowchat \n\t\t\tWHERE arrowchat.to = '" . $db->escape_string($userid) . "' \n\t\t\t\tAND (arrowchat.read != 1 \n\t\t\t\t\tOR arrowchat.user_read != 1\n\t\t\t\t\tOR (arrowchat.sent + " . $db->escape_string($heart_beat) . " + 1) > " . $time_it . ") \n\t\t\tORDER BY arrowchat.id ASC\n\t\t");
    $id_check = 0;
    $messages_test = false;
    if (!is_array($_SESSION['tab_alert'])) {
        $_SESSION['tab_alert'] = array();
    }
    while ($chat = $db->fetch_array($result)) {
        $self = 0;
        $old = 0;
        if ($chat['from'] == $userid) {
            $chat['from'] = $chat['to'];
            $self = 1;
            $old = 1;
        }
        if ($chat['user_read'] == 1 and $chat['read'] == 1) {
            $old = 1;
        }
        $chatid = $chat['from'];
        if (!empty($last_message)) {
            if (preg_match("#:{$chatid}/[0-9,a-z]+#", $last_message, $matches)) {
                $matches2 = explode("/", $matches[0]);
                $num = (int) $matches2[1];
                $time_check = time();
                if ($num < $time_check and $chat['read'] != 1 and $chat['user_read'] != 1) {
                    $last_message = str_replace($matches[0], ":" . $chatid . "/" . time() . "", $last_message);
                } else {
                    $last_message = $last_message;
                }
            } else {
                $last_message .= ":" . $chatid . "/" . time();
            }
        } else {
            $last_message = ":" . $chatid . "/" . time();
        }
        $chat_message = $chat['message'];
        $chat_message = str_replace("\\'", "'", $chat_message);
        $chat_message = str_replace('\\"', '"', $chat_message);
        $chat_message = clickable_links($chat_message);
        $block_chats_unserialized = unserialize($block_chats);
        if (!is_array($block_chats_unserialized)) {
            $block_chats_unserialized = array();
        }
        if (!in_array($chat['id'], $_SESSION['tab_alert']) or $chat['sent'] + $heart_beat > $time_it and in_array($chat['id'], $_SESSION['tab_alert'])) {
            if ($old != 1) {
                if (!in_array($chat['from'], $block_chats_unserialized)) {
                    $messages[] = array('id' => $chat['id'], 'from' => $chat['from'], 'message' => $chat_message, 'self' => $self, 'old' => $old, 'sent' => $chat['sent']);
                    $messages_test = true;
                    $_SESSION['tab_alert'][] = $chat['id'];
                }
            }
        }
        $id_check = $chat['id'];
    }
    if ($messages_test) {
        $response['messages'] = $messages;
        $db->execute("\n\t\t\t\tUPDATE arrowchat \n\t\t\t\tSET arrowchat.read = '1' \n\t\t\t\tWHERE arrowchat.to = '" . $db->escape_string($userid) . "' \n\t\t\t\t\tAND arrowchat.id <= '" . $db->escape_string($id_check) . "'\n\t\t\t\t\tAND arrowchat.read = '0'\n\t\t\t");
        $db->execute("\n\t\t\t\tUPDATE arrowchat_status \n\t\t\t\tSET last_message = '" . $db->escape_string($last_message) . "' \n\t\t\t\tWHERE userid = '" . $db->escape_string($userid) . "'\n\t\t\t");
    }
}
    $response['chat_users'] = $chat_users;
}
// ################### START CHATROOM HISTORY RECEIVE ####################
if (logged_in($userid)) {
    $history_length = $chatroom_history_length * 60;
    $result = $db->execute("\n\t\t\tSELECT id, username, message, sent, user_id, global_message\n\t\t\tFROM arrowchat_chatroom_messages\n\t\t\tWHERE (chatroom_id = '" . $db->escape_string($chatroom_id) . "'\n\t\t\t\tAND sent + " . $history_length . " > " . $time . ")\n\t\t\tORDER BY sent DESC\n\t\t\tLIMIT 30\n\t\t");
    while ($chatroom_history = $db->fetch_array($result)) {
        $temp_array[] = $chatroom_history;
    }
    $temp_array = array_reverse($temp_array);
    foreach ($temp_array as $chatroom_history) {
        $fetchid = $chatroom_history['user_id'];
        $chat_message = $chatroom_history['message'];
        $chat_message = str_replace("\\'", "'", $chat_message);
        $chat_message = str_replace('\\"', '"', $chat_message);
        $chat_message = clickable_links($chat_message);
        if (array_key_exists($fetchid, $user_cache)) {
            $avatar = $user_cache[$fetchid];
        } else {
            $sql = get_user_details($fetchid);
            $result2 = $db->execute($sql);
            $user = $db->fetch_array($result2);
            $avatar = get_avatar($user['avatar'], $fetchid);
            $user_cache[$fetchid] = $avatar;
        }
        $chat_history[] = array('id' => $chatroom_history['id'], 'n' => $db->escape_string(strip_tags($chatroom_history['username'])), 'm' => $chat_message, 't' => $chatroom_history['sent'], 'a' => $avatar, 'userid' => $fetchid, 'global' => $chatroom_history['global_message']);
    }
    $response['chat_history'] = $chat_history;
}
header('Content-type: application/json; charset=utf-8');
echo json_encode($response);
示例#4
0
function discussion_forum_parse_output($text, $options = array())
{
    // BBcode part
    $bbcode_ruleset = array('' => array('type' => BBCODE_TYPE_ROOT), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'img' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<img src="', 'close_tag' => '" class="forum_post_image" />', 'childs' => ''), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'), 'spoiler' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<div class="spoiler"><span>Spoiler: <button class="spoiler_control">Visa</button></span><span class="spoiler_content">', 'close_tag' => '</span></div>', 'childs' => ''));
    $text = clickable_links($text);
    if (isset($options['search_highlight'])) {
        $options['search_highlight'] = is_array($options['search_highlight']) ? $options['search_highlight'] : explode(' ', $options['search_highlight']);
        $safe_wordlist = array_map('preg_quote', $options['search_highlight']);
        $pattern = '/(' . str_replace('/', '\\/', implode('|', $safe_wordlist)) . ')/';
        echo $pattern . "\n";
        $replacement = '<strong class="search_highlight">$1</strong>';
        $text = preg_replace($pattern, $replacement, $text);
    }
    $text = nl2br($text);
    $text = str_replace(array("\n", "\r"), '', $text);
    $bbcode_handler = bbcode_create($bbcode_ruleset);
    $text = bbcode_parse($bbcode_handler, $text);
    $pattern = '/\\[svar:(.+?):([0-9]+?)\\](.*?)(\\[\\/svar\\])/';
    $replacement = '<div class="answer" id="forum_answer_to_$2"><strong>Svar till <a href="/traffa/quicksearch.php?username=$1">$1</a></strong> [<a href="/diskussionsforum/gaa_till_post.php?post_id=$2">Gå till post</a>]: $3</div>';
    $text = preg_replace($pattern, $replacement, $text);
    $pattern = '/\\[svar:(.+?)\\](.+?)(\\[\\/svar\\])/';
    $replacement = '<div class="answer"><a href="?$1">$1</a>: $2</div>';
    $text = preg_replace($pattern, $replacement, $text);
    $pattern = '/\\[poll:(.+?)\\]/';
    $text = preg_replace_callback($pattern, 'discussion_forum_insert_poll', $text);
    $pattern = '/\\@(.+?)\\@/';
    $replacement = '<span class="forum_answer" id="$1">Svar till $1</span>';
    $text = preg_replace($pattern, $replacement, $text);
    $pattern = '/\\[tillagg:(.+?):(.+?)\\](.*?)(\\[\\/tillagg\\])/';
    $replacement = '<div class="answer" id="forum_answer_to_$2">Tilläg av <a href="/traffa/quicksearch.php?username=$1">$1</a> klockan $2<br />$3</div>';
    $text = preg_replace_callback($pattern, 'discussion_forum_tillagg_callback', $text);
    $code_languages = array('php', 'html', 'javascript', 'css', 'C#', 'asp', 'joar');
    // Note: The pattern modifier /i makes the pattern case-insensitive.
    $pattern = '/\\[code:(' . implode('|', $code_languages) . ')\\](.*?)(\\[\\/code\\])/i';
    $text = preg_replace_callback($pattern, 'discussion_forum_code_tag_callback', $text);
    // Note: See above for explanation on /i, /e evaluates (an escaped version) of the search string.
    $pattern = '/\\[code\\](.*?)\\[\\/code\\]/ie';
    //$text = preg_replace($pattern, 'discussion_forum_code_tag_callback(array(1 => "", 2 => "$1"))', $text);
    //		$text = ($_SESSION['preferences']['forum_enable_smilies'] == 1) ? setSmilies($text) : $text;
    if (isset($options['post']['quality_level']) && $options['post']['quality_level'] <= 3 && $_SESSION['preferences']['forum_enable_smilies'] == 1) {
        $text = setSmilies($text);
    }
    return $text;
}
示例#5
0
function profile_presentation_link_tag_callback($matches)
{
    $type = substr($matches[1], 0, strpos($matches[1] . ']', ']'));
    //profile, webb, photos, guestbook, ..., ...
    switch ($type) {
        case 'profile':
            return '<a href="/traffa/quicksearch.php?username='******'">' . $matches[2] . '</a>';
        case 'webb':
            return clickable_links(unset_smilies($matches[3]));
        case 'photos':
            return '<a href="/traffa/photos.php?user=%USERID%">fotoalbum</a>';
        case 'guestbook':
            return '<a href="/traffa/guestbook.php?userid=%USERID%">gästbok</a>';
    }
}