| px | top | add code | search | signup | login | help |
<?
if (!isset($post)) $post = "threads";
function deletethread($thread, $parent = "threads") {
$fp = @fopen("header.$parent", "r");
while ($data = @fgets($fp, 1000))
if (substr($data, 0, strpos($data, "|")) != $thread) $read[] = $data;
@fclose($fp);
$fp = fopen("header.$parent", "w");
for ($i=0; $i<count($read); $i++) fputs($fp, $read[$i]);
fclose($fp);
deletepost($thread);
}
function deletepost($post) {
@unlink("body.$post");
$fp = @fopen("header.$post", "r");
while ($data = @fgetcsv($fp, 1000, "|")) deletepost($data[0]);
@fclose($fp);
@unlink("header.$post");
}
function insert($dest, $name, $mail, $title, $body) {
$time=date("F j Y H:i");
if (strpos($title, "(nt)")) {
$body="";
$title=substr($title, 0, strpos($title, "(nt)"));
}
$name=str_replace("|", "", htmlentities(trim(stripslashes($name))));
$email=str_replace("|", "", htmlentities(trim(stripslashes($mail))));
$title=str_replace("|", "", htmlentities(trim(stripslashes($title))));
$body=substr(nl2br(trim(stripslashes($body))), 0, 5000);
if ($title=="") $title="(no subject)";
if ($body=="") $title.=" (nt)";
if ($name=="") $name="anon";
$next = uniqid("");
$fp = fopen("body.$next", "a");
fputs($fp, $body);
fclose($fp);
if ($dest == "threads") {
$fp = @fopen("header.threads", "r");
while ($read[] = @fgets($fp, 1000));
@fclose($fp);
$fp = fopen("header.threads", "w");
fputs($fp, "$next|$name|$mail|$title|$time\n");
for ($i=0; $i<count($read); $i++) {
if ($i < 30) fputs($fp, $read[$i]);
else deletethread(substr($read[$i], 0, strpos($read[$i], "|")));
}
fclose($fp);
} else {
$fp = fopen("header.$dest", "a+");
fputs($fp, "$next|$name|$mail|$title|$time\n");
fclose($fp);
}
}
function showheader($data, $p = "", $t = "") {
global $thread, $parent, $post;
if ($t == "") $t = $thread;
if ($p == "") $p = $parent;
if ($data[0] == $post) echo "<i>";
echo "<b><a href=index.php3?thread=$t&parent=$p&post=".$data[0].">".$data[3]."</a></b> - ";
if ($data[2]!="") echo "<a href=mailto:".$data[2].">".$data[1]."</a>";
else echo $data[1];
echo " - <i>".$data[4]."</i>";
if ($data[0] == $post) echo "</i>";
}
function showtitle($data) {
echo "<h2>".$data[3]."</h2>";
}
function showposts($post, $p = "", $t = "") {
global $thread;
if ($t == "") $t = $thread;
if ($p == "") $p = $parent;
if (file_exists("header.$post")) {
echo "<ul>";
$fp = fopen("header.$post", "r");
while ($data = fgetcsv($fp, 1000, "|")) {
echo "<li>";
showheader($data, $post, $t);
showposts($data[0], $post, $t);
}
fclose($fp);
echo "</ul>";
}
}
function showthreads() {
global $thread;
echo "<hr>";
if (file_exists("header.threads")) {
$fp = fopen("header.threads", "r");
$i = 0;
while ($data = fgetcsv($fp, 1000, "|")) {
$i++;
if ($thread == "" | $thread == $data[0]) {
echo "<ul><li>";
showheader($data, "threads", $data[0]);
showposts($data[0], "threads", $data[0]);
echo "</ul><hr>";
}
}
fclose($fp);
}
}
function showpost() {
global $parent, $post;
echo "<hr>";
$fp = fopen("header.$parent", "r");
while ($data = fgetcsv($fp, 1000, "|")) {
if ($data[0] == $post) {
showtitle($data);
$reply = $data[3];
if ($reply != "") {
if (strpos($reply, "(nt)")) $reply=substr($reply, 0, strpos($reply, "(nt)"));
if (substr($reply, 0, 4)!="Re: ") $reply="Re: ".$reply;
$name=$data[1]; $mail=$data[2]; $time=$data[4];
}
}
}
fclose($fp);
if (file_exists("body.$post")) {
$fp=fopen("body.$post", "r");
$t=fread($fp, 20000);
fclose($fp);
if ($t != "") {
if (substr($t, 0, 2) == ": ") $t="<font color=darkblue>$t";
else $t="<font>$t";
$t=str_replace("<br>\n: ", "</font><br><font color=darkblue>", $t);
$t=str_replace("<br>\n", "</font><br><font>", $t);
echo "$t</font><br>\n <br>";
}
echo "<i>posted by $name on $time</i><br> <br>";
} else {
echo "<br>This post has been deleted.<br> <br>";
}
return $reply;
}
function replypost() {
global $post;
if ($post != "threads") {
$fp=fopen("body.$post","r");
$t=fread($fp, 20000);
fclose($fp);
if ($t!="") {
echo "--Previous Message--\n: ";
echo str_replace("<br>\n", ": ", $t);
}
}
}
if (isset($name)) insert($post, $name, $mail, $title, $body);
$reply = "";
if ($post != "threads") $replytitle = showpost();
showthreads();
?><h2>Post a message</h2>
<center><table><tr><td>
<form method=post>
Your name:<br>
<input type=text name="name" size=40 maxlength=30><p>
Your e-mail address:<br>
<input type=text name="mail" size=40 maxlength=50><p>
Subject:<br>
<input type=text name="title" size=60 maxlength=100 value="<?echo $replytitle;?>">
<p>
Message (max 5k):<br>
<textarea cols=60 rows=16 name="body" wrap=virtual><?replypost();?></textarea>
<p>
<center>
<input type=submit name="post_message" value="Post">
</center>
</form>
</td></tr></table></center><hr>
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.