09. juli 2001 - 23:38
#20
<?
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(\"j. F 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))));
mail(\"[sin mail],\"Forum\",\"Der er skrevet i forum ved [dit site]:
Navn: $name\\nE-mail: $email\\nEmne: $title\\n\\n$body\",\"From: [din mail]\");
$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.php?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 \"<h3>\".$data[3].\"</h3>\";
}
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 width=70%>\";
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 width=70%>\";
}
}
fclose($fp);
}
}
function showpost() {
global $parent, $post;
echo \"<hr width=70%><table width=100%><tr><td width=100></td><td align=left>\";
$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)!=\"Svar: \") $reply=\"Svar: \".$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>postet af $name , $time</i><br> <br></td></tr></table>\";
} else {
echo \"<br>Denne post er slettet.<br> <br></td></tr></table>\";
}
return $reply;
}
function replypost() {
global $post;
if ($post != \"threads\") {
$fp=fopen(\"body.$post\",\"r\");
$t=fread($fp, 20000);
fclose($fp);
if ($t!=\"\") {
echo \" -- Tidligere besked -- \\n: \";
echo str_replace(\"<br>\\n\", \": \", $t);
}
}
}
if (isset($name)) insert($post, $name, $mail, $title, $body);
$reply = \"\";
if ($post != \"threads\") $replytitle = showpost();
showthreads();
?><h3>Post en besked</h3>
<center><table><tr><td>
<form method=post>
Navn:<br>
<input type=text name=\"name\" size=40 maxlength=30><p>
E-mail:<br>
<input type=text name=\"mail\" size=40 maxlength=50><p>
Emne:<br>
<input type=text name=\"title\" size=60 maxlength=100 value=\"<?echo $replytitle;?>\">
<p>
Besked (max 5k):<br>
<textarea cols=60 rows=16 name=\"body\" wrap=virtual><?replypost();?></textarea>
<p>
<center>
<input type=submit name=\"post_message\" value=\"Post beskeden\">
</center>
</form>
HUSK OG ÆNDRE [din mail] OG [din site]
Filen skal hedde index.php