Beispiel #1
0
function sc_add_content($room, $name, $idstr, $content)
{
    $name = sc_trip($name);
    $size = 0;
    $fp = fopen(sc_dat_filename($room), "a");
    if (flock($fp, LOCK_EX)) {
        $stat = fstat($fp);
        $size = $stat['size'];
        if ($size == 0) {
            $size = fwrite($fp, sc_dat_encode($room) . "\n");
        }
        $output = serialize(array(sc_dat_encode($name), $idstr, time(), sc_dat_encode($content))) . "\n";
        if ($size + strlen($output) < MAX_DAT_SIZE) {
            $size += fwrite($fp, $output);
        } else {
            $size = -1;
        }
        flock($fp, LOCK_UN);
    }
    fclose($fp);
    return $size;
}
Beispiel #2
0
 public function testScTrip()
 {
     $this->assertEquals("foo", sc_trip("foo"));
     $this->assertEquals("foo#" . base64_encode(sha1('x', true)), sc_trip("foo#x"));
 }