/** * minichat 2 * Copyright Paul Mutton, 15th August 2002. * http://www.jibble.org/ * * Include this file on a PHP web page to add a mini chat box. * * Features:- * Totally rewritten from scratch. * Much much more efficient than the previous version. * HTML tags are filtered out. * Imposes a max word size to avoid wrapping issues. * Max nick and message lengths are enforced on the server side. * Accidental "refresh" reposting is avoided. * Appends all messages chronologically to the archive file. * Displays latest 20 messages with the most recent at the top. * Now logs I.P. addresses within comments (do what you want with them). * Displays posting time in correct local time. * */ $latest = $DOCUMENT_ROOT . "/temp/minichat2.latest"; $archive = $DOCUMENT_ROOT . "/temp/minichat2.archive"; $size = 40; $nick_size = 40; $message_size = 512; $max_word_size = 40; ?>
// Check to see if the user is trying to post something.
if (isset($minichat_md5) && isset($minichat_nick) && isset($minichat_message)) {
// Replace any new line stuff with a space.
$nick = strtr($nick, "\r\n", " ");
$message = strtr($message, "\r\n", " ");
// Trim leading and trailing whitespace where necessary and remove slashes.
$nick = trim(stripslashes($minichat_nick));
$message = trim(stripslashes($minichat_message));
// Only proceed if the md5 hash of message is not repeated.
if (md5($message) != $minichat_md5) {
// Only proceed if the user actually filled in both fields.
if (strlen($nick) > 0 && strlen($message) > 0) {
// If the fields are too long, then chop them to the limits.
if (strlen($nick) > $nick_size) {
$nick = substr($nick, 0, $nick_size);
}
if (strlen($message) > $message_size) {
$message = substr($message, 0, $message_size);
}
// Remove new line characters from the input.
$nick = str_replace("\n", " ", $nick);
$message = str_replace("\n", " ", $message);
// Enforce the maximum word size by breaking up $message into lines.
$message = preg_replace("/([^\s]{20})/", "$1\n", $message);
// Now we can encode the nick and message into HTML.
$nick = htmlentities($nick);
$message = htmlentities($message);
// Now replace the new line characters in $message.
$message = str_replace("\n", " |