' . $matches[1] . '';
}
function chatOut( $status = null, $chat = null ) {
if ( $status !== null ) {
$lastMod = filemtime( DBFILE );
if ( $lastMod === false ) $lastMod = 0;
echo( "{$status}:$lastMod\n" );
}
if ( $chat === null ) {
if ( CHATTRIM ) {
$f = fopen( DBFILE, "r" );
fseek( $f, -CHATTRIM, SEEK_END );
$chat = fread( $f, CHATTRIM );
fclose( $f );
$p = mb_strpos( $chat, '
?@\\[\\]^_`{|}~0-9a-zа-яё]\x07iu", "", $str );
$str = preg_replace( "~&~u", "&", $str );
$str = preg_replace( "~<~u", "<", $str );
$str = preg_replace( "~>~u", ">", $str );
$str = mb_substr( $str, 0, MAXUSERTEXTLEN );
$str = preg_replace( "~\n~u", "
", $str );
return $str;
}
$exit = false;
$name = @$_POST["name"] ? $_POST["name"] : null;
$text = @$_POST["text"];
$mode = null;
switch( @$_POST["mode"] ) {
case "post":
$mode = "post";
break;
case "list":
$mode = "list";
break;
}
$cookieName = @$_COOKIE["userName"] ? $_COOKIE["userName"] : null;
if ( $cookieName ) $cookieName = cleanName( $cookieName );
if ( !$name ) $name = $cookieName;
if ( $text ) $text = cleanText( $text );
if ( $mode == "post" ) {
if ( !$name || !$text ) {
header( 'HTTP/1.1 400 Bad Request' );
exit( 0 );
}
if ( !@empty( $_SERVER[ "HTTP_CLIENT_IP" ] ) ) $id = $_SERVER[ "HTTP_CLIENT_IP" ];
elseif ( !@empty( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) $id = $_SERVER["HTTP_X_FORWARDED_FOR"];
else $id = @$_SERVER["REMOTE_ADDR"];
$exit = true;
if ( $name != $cookieName ) setcookie( "userName", $name, mktime( 0, 0, 0, 12, 31, 3000 ), COOKIEPATH );
$text = preg_replace_callback( "\x07((?:[a-z]+://(?:www\\.)?)[_.+!*'(),/:@~=?&$%a-z0-9\\-]+)\x07iu", "makeURL", $text );
$msg = '
' . $name . '' . date( "d.m.Y H:i:s" ) . ' (' . $id . ')
' . $text . '
' . "\n\n";
file_put_contents( DBFILE, $msg, FILE_APPEND );
$mode = "list";
}
if ( $mode == "list" ) {
$exit = true;
$rlm = preg_match( "~^\\d+$~u", @$_POST["lastMod"] ) ? (int)$_POST["lastMod"] : 0;
$lastMod = filemtime( DBFILE );
if ( $lastMod === false ) $lastMod = 0;
if ( $rlm == $lastMod ) chatOut( "NONMODIFIED", "" );
else chatOut( "OK", null );
}
if ( $exit ) exit( 0 );
$lastMod = filemtime( DBFILE );
if ( $lastMod === false ) $lastMod = 0;
?>
ProtoChat