Esempio n. 1
0
File: get.php Progetto: hgwr/stechat
        $_GET[$key] = stripslashes($_GET[$key]);
    }
    $o[$key] = trim($_GET[$key]);
}
if (!isset($o['room']) || strlen($o['room']) >= MAX_ROOM_LEN) {
    exit;
}
foreach (array('m', 's', 'e') as $key) {
    if (isset($o[$key]) && is_numeric($o[$key])) {
        $o[$key] = (int) $o[$key];
        if ($o[$key] <= 0) {
            $o[$key] = 1;
        }
    }
}
if (isset($_GET['last'])) {
    $contents = sc_get_last_contents($o['room'], $o['m']);
} else {
    $contents = sc_get_contents($o['room'], $o['s'], $o['e'], true);
}
$len_contents = sizeof($contents) - 1;
if ($len_contents == 0) {
    ini_set('zlib.output_compression', 'Off');
}
session_name("stechat");
session_start();
sc_set_idstr();
header("Content-type: text/javascript");
if ($len_contents > 0) {
    print json_encode($contents);
}
Esempio n. 2
0
 public function testScGetLastContents()
 {
     $room = 'njiSeDkea2';
     $name = 'foo';
     $idstr = '123';
     $content = 'Hello <b>world</b>';
     $dat_filename = sc_dat_filename($room);
     if (file_exists($dat_filename)) {
         unlink($dat_filename);
     }
     for ($i = 1; $i <= 20; $i++) {
         sc_add_content($room, $name, $idstr, $i);
     }
     $contents = sc_get_last_contents($room, 0);
     $this->assertEquals(21, sizeof($contents));
     $this->assertEquals(1, $contents[0][1]);
     $this->assertEquals(20, $contents[0][2]);
     $chat = $contents[1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("1", $chat[3]);
     $chat = $contents[sizeof($contents) - 1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("20", $chat[3]);
     for ($i = 21; $i <= MAX_MSGS_LEN + 20; $i++) {
         sc_add_content($room, $name, $idstr, $i);
     }
     $contents = sc_get_last_contents($room, 0);
     $this->assertEquals(MAX_MSGS_LEN + 1, sizeof($contents));
     $this->assertEquals(21, $contents[0][1]);
     $this->assertEquals(MAX_MSGS_LEN + 20, $contents[0][2]);
     $chat = $contents[1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("21", $chat[3]);
     $chat = $contents[sizeof($contents) - 1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("" . (MAX_MSGS_LEN + 20), $chat[3]);
 }