<?php //forum in Few Lines As Possible
date_default_timezone_set ('UTC');
//<uk3.php.net/manual/en/function.is-dir.php#70005>
chdir ('forum');
if (isset ($_GET['new'])) {
$name = stripslashes ($_POST['name']);
$title = stripslashes ($_POST['title']);
$text = stripslashes ($_POST['text']);
$json = array (array (
'name' => $name,
'time_c' => time (),
'time_m' => time (),
'text' => $text
));
file_put_contents ("$title.json", json_encode ($json));
header ("Location: ?t=". urlencode ($title));
} elseif (isset ($_GET['post'])) {
$file = urldecode (stripslashes ($_GET['t']));
$json = json_decode (file_get_contents ("$file.json"), true);
$name = stripslashes ($_POST['name']);
$text = stripslashes ($_POST['text']);
$json[] = array (
'name' => $name,
'time_c' => time (),
'time_m' => time (),
'text' => $text
);
file_put_contents ("$file.json", json_encode ($json));
clearstatcache ();
header ("Location: ?t=". urlencode ($file));
} elseif (@$_GET['t']) {
$file = urldecode (stripslashes ($_GET['t']));
$json = json_decode (file_get_contents ("$file.json"), true);
echo <<<HTML
<h2>$file</h2>
<table width="100%" border="1"><tbody>
HTML;
foreach ($json as $post=>$fields) {
$date = date ('j M Y G:i e', $fields['time_c']);
echo <<<HTML
<tr>
<td>${fields['name']}<br />$date</td>
<td>
${fields['text']}
</td>
</tr>
HTML;
}
$fileurl = urlencode ($file);
echo <<<HTML
</tbody></table>
<form action="?post&t=$fileurl" method="post"><fieldset>
<legend>Reply:</legend>
<label for="name">Name:</label>
<input id="name" name="name" type="text" size="50" maxlength="50" /><br />
<label for="text">Message:</label><br />
<textarea id="text" name="text" cols="50" rows="8"></textarea><br />
<input type="submit" value="Reply" />
</form>
HTML;
} else {
?>
<h2>Threads:</h2>
<table width="100%" border="1"><thead>
<th>Updated</th>
<th>Title</th>
<th>Created</th>
</thead><tbody>
<?
$forum = array_flip (array_filter (scandir ('.'), 'is_file'));
foreach ($forum as $file=>&$time) $time = filemtime ($file);
arsort ($forum);
foreach ($forum as $file=>$time) {
$date_m = date ('j M Y G:i e', $time);
$date_c = date ('j M Y G:i e', filectime ($file));
$file = pathinfo ($file, PATHINFO_FILENAME);
$fileurl = urlencode ($file);
echo <<<HTML
<tr>
<td>$date_m</td>
<td><a href="?t=$fileurl">$file</a></td>
<td>$date_c</td>
</tr>
HTML;
}
?>
</tbody></table>
<form action="?new" method="post"><fieldset>
<legend>New Thread:</legend>
<label for="name">Name:</label>
<input id="name" name="name" type="text" size="50" maxlength="50" /><br />
<label for="title">Title:</label>
<input id="title" name="title" type="text" size="50" maxlength="50" /><br />
<label for="text">Message:</label><br />
<textarea id="text" name="text" cols="50" rows="8"></textarea><br />
<input type="submit" value="Add" />
</form>
<?php
}
?>