Файл: monst/core/jphp/chat/typing.php
Строк: 35
<?
$HOME = $_SERVER['DOCUMENT_ROOT'];
include $HOME . '/core/in/j.php';
$s = $_POST['s'];
$file = file($HOME . '/core/data/typing.dat');
if ( isset($_SESSION['chat_room']) ) {
    $room = $_SESSION['chat_room'];
} else {
    $_SESSION['chat_room'] = 1;
    $room = $_SESSION['chat_room'];
}
if ( $s == 'add' ) {
    $user_id = (int)$_POST['user_id'];
    if ( $user['id'] != $user_id ) {
        exit;
    }
    $room = $_SESSION['chat_room'];
    $need_add = 1;
    foreach ( $file as $line ) {
        if ( $line ) {
            $array = explode(';', $line);
            $id = $array[0];
            if ( $user_id == $id ) {
                $need_add = 0;
            }
        }
    }
    if ( $need_add ) {
        $fp = fopen($HOME . '/core/data/typing.dat', 'a+');
        fwrite($fp, $user_id.';'.$room.';'.time()."n");
        fclose($fp);
    }
}
if ( $s == 'upd' ) {
    $data = '';
    foreach ( $file as $line ) {
        if ( $line ) {
            $array = explode(';', $line);
            $time = $array[2];
            if (time() - $time < 4) {
                $data .= $line . "n";
            }
        }
    }
    $fp = fopen($HOME . '/core/data/typing.dat', 'w+');
    fwrite($fp, $data);
    fclose($fp);
}
if ( $s == 'GET' ) {
    $data = '';
    $count = 0;
    foreach ( $file as $line ) {
        if ( !empty($line) ) {
            $array = explode(';', $line);
            $id = trim($array[0]);
            if ( !empty($id) ) {
                $room = $array[1];
                if ( $_SESSION['chat_room'] == $room ) {
                    $name = Name($id);
                    if(empty($name)) $name = $id;
                    if ( $count >= 5) {
                        break;
                    }
                    $data .= $name.', ';
                    $count++;
                }
            }
        }
    }
    if ( !empty($data) ) {
        $data = trim($data);
        $data = substr($data, 0, -1);
        print '<span style="color: #5a6879; font-size: 13px">• • •</span> ' . $data;
    }
}