Code:
<html>
<head>
<title>txtForum</title>
</head>
<body>
<center>
<?
//////////////////////////////////////////////////////////////////////
// //
// txtForum v.0.5 //
// author: Zoran Raskovic //
//
[email protected] //
//
[email protected] //
// icq: 46742125 //
// date: April 6, 2002 //
// //
// You need to set $posts, $httpindex, //
// $row1_color and $row2_color //
// //
// Please drop me a line or two if you find txtForum useful. //
// Also, send me your url where you are using my forum :) //
// Questions, comments and suggestions are welcomed as well. //
// //
// Special thanks to Ted Suzman for fixing up some code //
// and Verdana for the banner. //
// //
//////////////////////////////////////////////////////////////////
//$posts - path to your posts.txt file
$posts = 'C:/web/zoki/txtforum/posts.txt';
//$httpindex - url where your index.php is
$httpindex = 'http://zoki.ath.cx/txtForum/index.php';
//$row1_color - color of alternating row one
$row1_color="#ffffff";
//$row2_color - color of alternating row two
$row2_color="#BCD8E2";
////////////////////////DO NOT EDIT BEYOND THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING!!!!/////////////////////////////
//top part
$topics=0;
$msgs=0;
$fp = fopen ($posts, "rb");
while (!feof ($fp))
{
$buff = fgets($fp, 4096);
if(substr($buff, 0, 10 )=="[new_post]") {
$p=explode('|||^^^|||', "$buff");
if ($p[2]==0) {
$topics++;
$msgs++;
}
else {
$msgs++;
}
}
}
fclose($fp);
$now=date("M-d-Y, H:i:s");
$timezone=date("O");
echo "<table border='0' width='80%'><tr><td align='left'><img src='forum.jpg'><td valign='bottom' align='right'></td></tr><tr><td>$topics topics and $msgs messages<td align='right'>$now $timezone</td></tr></table>";
switch($a)
{
//if there's a reply..
CASE "reply":
//open txt file for reading and writing
$fp = fopen ($posts, "rb");
//get the next post_id
$id=fgets($fp, 4096);
$new_id=$id+1;
//echo "id=$id, new_id=$new_id<p>$contents<p>";
//close file
fclose($fp);
$fp = fopen ($posts, "r+b");
//memorize this id
fwrite($fp, $new_id);
//close file
fclose($fp);
$fp = fopen ($posts, "ab");
fwrite($fp, "\r\n");
//close file
fclose($fp);
//do we have all required info?
if (!$name or !$subject or !$msg) {
header("Location: $httpindex");
}
else {
//write new post in file
$name=htmlspecialchars($name);
$subject=htmlspecialchars($subject);
$msg=htmlspecialchars($msg);
$msg = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$msg);
$datum=date("m-d-Y @ h:i:s");
$fp = fopen ($posts, "ab");
fwrite($fp, "[new_post]|||^^^|||$new_id|||^^^|||$tid|||^^^|||$name|||^^^|||$subject|||^^^|||$datum|||^^^|||$msg|||^^^|||");
//close file
fclose($fp);
}
//forward user to the thread they just posted to
header("Location: {$httpindex}?a=view_thread&tid=$tid");
BREAK;
//are we viewing a thread?
CASE "view_thread":
$fp = fopen ($posts, "rb");
//show the first message
echo "<table border='0' bordercolor='#e2e2e2' width='80%' cellspacing='1' cellpadding='2' bgcolor='#000000'><tr bgcolor='$row2_color' border='1' bordercolor='1'><td width='20%'>Author<td width='80%'>Message</td></tr>";
while(!feof ($fp))
{
$buffer = fgets($fp, 4096);
if (substr($buffer, 0, 10 )=="[new_post]")
{
$p=explode('|||^^^|||', "$buffer");
if ($p[1]==$tid)
{
$subject=$p[4];
$msg1=nl2br($p[6]);
$msg1 = str_replace('[b]', '<b>', $msg1);
$msg1 = str_replace('[/b]', '</b>', $msg1);
$msg1 = str_replace('[i]', '<i>', $msg1);
$msg1 = str_replace('[/i]', '</i>', $msg1);
$msg1 = str_replace('[u]', '<u>', $msg1);
$msg1 = str_replace('[/u]', '</u>', $msg1);
$msg1 = str_replace('[red]', '<font color=red>', $msg1);
$msg1 = str_replace('[/red]', '</font>', $msg1);
$msg1 = str_replace('[link=&quot;javascript', '[link=&quot; javascript', $msg1);
// $msg1 = preg_replace('\[link=&quot;([[:graph:]]+)&quot;\]', '<a href="\1">', $msg1);
$msg1 = str_replace('[/link]', '</a>', $msg1);
echo "<tr bgcolor='$row1_color' border='1' bordercolor='1'><td valign='top'>$p[3]<td>$p[4]<p>$msg1</td></tr><tr bgcolor='$row1_color' border='1' bordercolor='#ffffff'><td>$p[5]<td></td></tr>";
}
}
}
fclose($fp);
//list all messages that have a thread id = $tid
$fp = fopen ($posts, "rb");
$color=0;
while (!feof ($fp))
{
$buffer = fgets($fp, 4096);
if(substr($buffer, 0, 10 )=="[new_post]")
{
$p=explode('|||^^^|||', "$buffer");
if ($p[2]==$tid)
{
$subject=$p[4];
$msg1=nl2br($p[6]);
$msg1 = str_replace('[b]', '<b>', $msg1);
$msg1 = str_replace('[/b]', '</b>', $msg1);
$msg1 = str_replace('[i]', '<i>', $msg1);
$msg1 = str_replace('[/i]', '</i>', $msg1);
$msg1 = str_replace('[u]', '<u>', $msg1);
$msg1 = str_replace('[/u]', '</u>', $msg1);
$msg1 = str_replace('[red]', '<font color=red>', $msg1);
$msg1 = str_replace('[/red]', '</font>', $msg1);
$msg1 = str_replace('[link=&quot;javascript', '[link=&quot; javascript', $msg1);
// $msg1 = preg_replace('\[link=&quot;([[:graph:]]+)&quot;\]', '<a href="\1">', $msg1);
$msg1 = str_replace('[/link]', '</a>', $msg1);
if ($color==0) {
echo "<tr bgcolor='$row2_color' border='1' bordercolor='1'><td valign='top'>$p[3]<td>Re: $p[4]<p>$msg1</td><tr bgcolor='$row2_color' border='1' bordercolor='#ffffff'><td>$p[5]<td></td></tr>";
$color=1;
}
else {
echo "<tr bgcolor='$row1_color' border='1' bordercolor='1'><td valign='top'>$p[3]<td>Re: $p[4]<p>$msg1</td><tr bgcolor='$row1_color' border='1' bordercolor='#ffffff'><td>$p[5]<td></td></tr>";
$color=0;
}
}
}
}
fclose($fp);
echo "</table><p><A HREF='index.php'>Back to list</A>";
//display form for replying
echo "
<form action='index.php?a=reply' method='post'>
<table border='0'>
<tr><td><B>Name</B>: </td><td><INPUT TYPE='text' NAME='name' size='30'></td></tr>
<tr><td><B>Subject</B>: <td>$subject</td></tr>
<tr><td><B>Message</B>: <td><TEXTAREA NAME='msg' ROWS='8' COLS='40'></TEXTAREA></td></tr></table>
<table>
<tr><td>
<INPUT TYPE='hidden' name='tid' value='$tid'>
<input type='hidden' name='subject' value=\"$subject\">
<INPUT TYPE='submit' name='submit_new' value='Reply'></td></tr>
</table>
</form>";
BREAK;
//are we posting a new topic?
CASE "post_new":
//open txt file for reading and writing
$fp = fopen ($posts, "rb");
//get the next post_id
$id=fgets($fp, 4096);
$new_id=$id+1;
//close file
fclose($fp);
$fp = fopen ($posts, "r+b");
//memorize this id
fwrite($fp, $new_id);
//close file
fclose($fp);
$fp = fopen ($posts, "ab");
fwrite($fp, "\r\n");
//close file
fclose($fp);
//do we have all required info?
if (!$name or !$subject or !$msg) {
header("Location: $httpindex");
}
else {
//write new post in file
$name=htmlspecialchars($name);
$subject=htmlspecialchars($subject);
$msg=htmlspecialchars($msg);
$msg = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$msg);
$datum=date("m-d-Y @ h:i:s");
$fp = fopen ($posts, "ab");
fwrite($fp, "[new_post]|||^^^|||$new_id|||^^^|||0|||^^^|||$name|||^^^|||$subject|||^^^|||$datum|||^^^|||$msg|||^^^|||");
//close file
fclose($fp);
}
//forward user to the topic listing
header("Location: $httpindex");
BREAK;
//if nothing else, list all threads here
DEFAULT:
echo "<table border='0' bordercolor='#e2e2e2' width='80%' cellspacing='1' cellpadding='2' bgcolor='#000000'><tr bgcolor='$row2_color' border='1' bordercolor='1' align='center'><td width='60%'>Subject<td width='20%'>Author<td>Replies<td width='20%'>Date</td></tr>";
$fp = fopen ($posts, "rb");
while (!feof ($fp))
{
$buffer = fgets($fp, 4096);
if(substr($buffer, 0, 10 )=="[new_post]")
{
$p=explode('|||^^^|||', "$buffer");
//echo sizeof($p);
if ($p[2]==0)
{
//get number of replies for this thread
$fp1 = fopen ($posts, "rb");
$replies=0;
while (!feof ($fp1))
{
$buffer1 = fgets($fp1, 4096);
if(substr($buffer1, 0, 10 )=="[new_post]")
{
$p1=explode('|||^^^|||', "$buffer1");
if ($p1[2]==$p[1]) {
$replies++;
}
}
}
fclose($fp1);
echo "<tr bgcolor='#ffffff' border='1' bordercolor='1'><td><A HREF='index.php?a=view_thread&tid=$p[1]'>$p[4]</A><td>$p[3]<td align='center'>$replies<td>$p[5]</td></tr>";
}
//echo "<p>";
}
}
fclose ($fp);
echo "</table><p>";
// display form for posting a new topic
echo "Post a new topic
<form action='index.php?a=post_new' method='post'>
<table border='0'>
<tr><td><B>Name</B>: </td><td><INPUT TYPE='text' NAME='name' size='30'></td></tr>
<tr><td><B>Subject</B>: <td><INPUT TYPE='text' NAME='subject' size='30'></td></tr>
<tr><td><B>Message</B>: <td><TEXTAREA NAME='msg' ROWS='8' COLS='40'></TEXTAREA></td></tr></table>
<table>
<tr><td><INPUT TYPE='submit' name='submit_new' value='Post new topic'></td></tr>
</table>
</form>";
BREAK;
}
echo " <p><small>powered by <A HREF='http://zoki.ath.cx/txtForum'>txtForum v.0.5</A></small>";
?>
</center>
</body>
</html>
Obratite paznju da code nije sto posto chist i gotov ali prilicno je doteran.