| px | top | add code | search | signup | login | help |
<!-- needs three files chat.php3, thread.php3 and messages.txt -->
<!-- start of chat.php3 -->
<?php
//////////////////////////////////////////////////
// A php only message board. //
// All source written by Ian Hickman. Aug 2000. //
// Use with thread.php3 and message.txt //
// Feel free to use this. //
//////////////////////////////////////////////////
// open message file
$message_array = file( "messages.txt" );
$number_of_threads=0;
// store the last entry to avoid duplicates
list( $fnumber, $fsubject, $fname, $femail, $fdate, $ftext, $flinkurl, $flinktitle, ) = split("::", $message_array[0] );
// if something has been entered and it is not the same as the last one
if( $name!="" && $subject!="" && $message!="" && ( $name!=$fname || $subject!=$fsubject ) ){
// load all old messages
for( $counter=0; $counter<100; $counter++ ){
// split message field up
if( $message_array[$counter] ){
list( $pnumber, $psubject, $pname, $pemail, $pdate, $ptext, $plinkurl, $plinktitle ) = split("::", $message_array[$counter] );
// check for vality should be as all messages are valid when entered
if( $pnumber && $psubject && $ptext && $pname ){
// count the number of messages
if( $pnumber > $number_of_threads ){
$number_of_threads=intval($pnumber);
}
// add all the old messages into old_messages string
$old_messages .= $message_array[$counter];
}
}
}
// create new message...
// add date in format hh:mm:ss dd/mm/yy
$date=date("H:i:s d/m/y");
// replace newlines with <br>'s
$message=ereg_replace( "\n", "<br>", $message );
// format the new message
$new_message = ($number_of_threads+1)."::$subject::$name::$email::$date::$message";
//strip html chars
$new_message = htmlspecialchars( $new_message );
if( $linkurl && !(ereg( "^http:\/\/", $linkurl )) ){
$linkurl = "http://".$linkurl;
}
$new_message .= "::$linkurl::$linktitle\n";
// open message file
$open_file = fopen( "messages.txt", "w");
// add message and old messages to file
// new message will be at the top of the board
fputs($open_file, stripslashes( $new_message ));
fputs($open_file, $old_messages);
fclose($open_file);
}
// indent is used to align are the message threads
$indent=0;
// open message file
$message_array = file( "messages.txt" );
// loop through message file lines
for( $counter=0; $counter<100; $counter++ ){
// split the message field
list( $pnumber, $psubject, $pname, $pemail, $pdate, $ptext ) = split("::", $message_array[$counter] );
// check that it is valid, should be due to validy check on message post
if( $pnumber && $psubject && $ptext && $pname ){
// indent if message is a reply
if( intval($pnumber)!=$pnumber && $indent==0){
$print_titles .= "<ul>\n";
$indent=1;
}
if( intval($pnumber)==$pnumber && $indent==1){
$print_titles .= "</ul>\n";
$indent=0;
}
// add the titles to the print_titles string
$print_titles .= "<li><a href=\"thread.php3#$pnumber?thread=$pnumber\">$psubject</a> ";
// if an email address is supplied link to it
if( $pemail ){
$print_titles .= "- <a href=\"mailto:$pemail\">$pname</a> $pdate\n";
} else {
$print_titles .= "- $pname $pdate\n";
}
}
}
// print the title array
echo( "<ul>\n" );
echo( $print_titles );
echo( "</ul>\n" );
// check that there are no lists open
if( $indent==1 ){
echo( "</ul>\n" );
}
?>
<hr>
<form action="chat.php3" method="post">
<table border="0">
<tr>
<td>Name : </td>
<td><input size="50" type="text" name="name"></td>
</tr>
<tr>
<td>Email (Optional) : </td>
<td><input size="50" type="text" name="email"></td>
</tr>
<tr>
<td>Subject : </td>
<td><input size="50" type="text" name="subject"></td>
</tr>
<tr>
<td>Message : </td>
<td><textarea cols=55 rows=10 name="message" wrap="virtual"></textarea></td>
</tr>
<tr>
<td>Link URL (Optional) : </td>
<td><input size="50" type="text" name="linkurl"></td>
</tr>
<tr>
<td>Link Title (Optional) : </td>
<td><input size="50" type="text" name="linktitle"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Post new message"><input type="reset"></td>
</tr>
</table>
<!--end of chat.php3-->
<!--start of thread.php3-->
<?php
//////////////////////////////////////////////////
// A php only message board. //
// All source written by Ian Hickman. Aug 2000. //
// Use with chat.php3 and message.txt //
// Feel free to use this. //
//////////////////////////////////////////////////
// open message file
$message_array = file( "messages.txt" );
$threadnumber=0;
// store the last entry to avoid duplicates
list( $fnumber, $fsubject, $fname, $femail, $fdate, $ftext, $flinkurl, $flinktitle ) = split("::", $message_array[0] );
// if something has been entered and it is not the same as the last one
if( $name!="" && $subject!="" && $message!="" && ( $name!=$fname || $subject!=$fsubject ) ){
// loop through all old messages
for( $counter=0; $counter<100; $counter++ ){
// check message line exists
if( $message_array[$counter] ){
// split message field up
list( $pnumber, $psubject, $pname, $pemail, $pdate, $ptext, $flinkurl, $flinktitle ) = split("::", $message_array[$counter] );
// check for validy of message field. Should be valid as messages entered are validated
if( $pnumber && $psubject && $ptext && $pname ){
// find out where to put the new message
if( intval($pnumber) < $thread ){
$old_messages .= $message_array[$counter];
}
if( intval($pnumber) == $thread ){
$messages_after .= $message_array[$counter];
$threadnumber=$pnumber+0.01;
}
if( intval($pnumber) > $thread ){
$messages_after .= $message_array[$counter];
}
}
}
}
// create new message
$date=date("H:i:s d/m/y");
$message=ereg_replace( "\n", "<br>", $message );
$new_message = "$threadnumber::$subject::$name::$email::$date::$message";
// strip html chars
$new_message = htmlspecialchars( $new_message );
if( $linkurl && !(ereg( "^http:\/\/", $linkurl )) ){
$linkurl = "http://".$linkurl;
}
$new_message .= "::$linkurl::$linktitle\n";
// open message file
$open_file = fopen( "messages.txt", "w");
// strip html stuff and add message to file
fputs($open_file, $messages_after);
fputs($open_file, stripslashes( $new_message ));
fputs($open_file, $old_messages);
fclose($open_file);
}
// loop through all messages copying the title and messages into separate arrays
$message_array = file( "messages.txt" );
for( $counter=0; $counter<100; $counter++ ){
// split the message field
list( $pnumber, $psubject, $pname, $pemail, $pdate, $ptext, $plinkurl, $plinktitle ) = split("::", $message_array[$counter] );
// check that it is valid although it should be due to earlier validity checks
// also check to see if the message is the thread (or followup) that we want
if( intval($pnumber)==intval($thread) && $psubject && $ptext && $pname ){
// add the message to print_messages string
$print_messages .= "<h3><a name=$pnumber>$psubject</a></h3>\n";
// if an email address is supplied link to it
if( $pemail ){
$print_messages .= "<p>Posted by <a href=\"mailto:$pemail\">$pname</a> on $pdate</p>\n<p>$ptext</p>";
} else {
$print_messages .= "<p>Posted by $pname on $pdate</p>\n<p>$ptext</p>";
}
// if a url has been submitted draw it up
if( $plinkurl && $plinktitle ){
$print_messages .= "<p><a href=\"$plinkurl\" target=\"_blank\">$plinktitle</a></p>\n";
} else {
$print_messages .= "\n";
}
}
}
// print the messages
echo( $print_messages );
?>
<hr>
<form action="thread.php3" method="post">
<?php
// pass the thread value when submitted
echo( "<input type=\"hidden\" name=\"thread\" value=\"$thread\">\n" );
?>
<table border="0">
<tr>
<td>Name : </td>
<td><input size="50" type="text" name="name"></td>
</tr>
<tr>
<td>Email (Optional) : </td>
<td><input size="50" type="text" name="email"></td>
</tr>
<tr>
<td>Subject : </td>
<td><input size="50" type="text" name="subject"></td>
</tr>
<tr>
<td>Message : </td>
<td><textarea cols=55 rows=10 name="message" wrap="virtual"></textarea></td>
</tr>
<tr>
<td>Link URL (Optional) : </td>
<td><input size="50" type="text" name="linkurl"></td>
</tr>
<tr>
<td>Link Title (Optional) : </td>
<td><input size="50" type="text" name="linktitle"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Post Followup"><input type="reset"></td>
</tr>
</table>
<hr>
<center>
[ <a href="chat.php3">Main Board</a> ]
</center>
<hr>
<!--end of thread.php3-->
<!--all of messages.txt should be on one line-->
<!--start of messages.txt-->
1::Greets::Ian::ian@neverin.com::12:40:23 04/08/00::Hello from Ian, thankyou for using my message board::http://www.neverin.com::neverin
<!--end of messages.txt-->
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.