June 25, 2015

Universal Forum Version 5

The last update I made to my Universal Forum Script was on March 5, 2013. This updated version 5 is greatly improved, albeit more advanced and hence less 'universal'. My script is unique in that it solves three fundamental problems in atypical ways:

1. Entire forum is contained in a single PHP file, including all the code that makes it work.
This is done using fwrite to append form data to the end of the source file.

2. The forum automatically refreshes the page after each comment is made.
If else rules are exploited to execute a non-recursive meta refresh.

3. Posts are displayed in reverse-chronological order!
Recursive CSS transform flipping makes the impossible possible.


These are mainly very typical forum attributes, the thing that makes them unique is that they are all accomplished using extremely light-weight and elegant functions. The entire script is only 2428 characters. Those are the main new improvements, above and beyond that the styles have been adjusted to improve legibility and scale every element dynamically to fit any viewport.

Please play with the source code to explore all its features:



<?php
date_default_timezone_set('America/Los_Angeles');
error_reporting (E_ALL ^ E_NOTICE);
echo "<!doctype html><html><head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'><title>Universal Forum v5</title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<style>

body
{
background-color: whitesmoke;
margin: 0%;
padding: 0%;
}

.flip
{
transform: scaleY(-1);
margin: 0%;
padding: 0%;
}

.form
{
margin: 1%;
font-family: 'Source Sans Pro';
font-size: calc(100vw / 50);
}

#textarea
{
font-family: 'Source Sans Pro';
font-size: calc(100vw / 50);
}

#button
{
height: calc(100vw / 12);
width: calc(100vw / 12);
padding: 1%;
vertical-align: top;
text-shadow: 1px 1px white;
font-family: 'Source Sans Pro';
font-size: calc(100vw / 50);
}

.bubble
{
background-color: white;
transform: scaleY(-1);
margin: 1%;
padding: 1%;
border-radius: 6px;
box-shadow: 1px 1px 3px lightgray;
font-family: 'Source Sans Pro';
font-size: calc(100vw / 50);
}

.timestamp
{
margin-left: 40%;
margin-right: 40%;
background: radial-gradient(circle, rgba(245,245,245,1) 0%, rgba(245,245,245,1) 50%, rgba(0,0,0,0) 100%);
margin-top: -2%;
color: red;
font-family: 'Source Sans Pro';
font-size: calc(100vw / 75);
}

</style>
</head>
<body>
<div class='form'>
<form action='index.php' method='post'>
<textarea autofocus rows='3' cols='50' wrap='virtual' name='comment' placeholder='comment' id='textarea'></textarea>
<input type='submit' value='POST' id='button'>
</form>
</div>
<div class='flip'>
";
$file = "index.php";
$name = fopen($file, 'a') or die("fail");
if ($_POST["comment"]=="")
echo "";
else
{
echo "";

fwrite($name, $string);
$string = "<div class='bubble'>";

fwrite($name, $string);
$string = "<div class='timestamp'><center>";

fwrite($name, $string);
$string = date("y.m.d", time());

fwrite($name, $string);
$string = " · ";

fwrite($name, $string);
$string = date("H:i:s", time());

fwrite($name, $string);
$string = "</center></div>";

fwrite($name, $string);
$string = strip_tags($_POST["comment"]);

fwrite($name, $string);
$string = "</div>";

fwrite($name, $string);
$string = "

";

fwrite($name, $string);
fclose($name);

if ($_POST["comment"]=="")
echo "";

else
{
echo('<meta http-equiv="refresh" content="1">');
}
}
?>