\n";
$status = $status . $problem;
}
// Validate the length and existence of an input value.
function validate($name, $string, $length) {
if ($string == "") complain("$name was not entered, and is required.");
else {
$slen = strlen($string);
if ($slen < $length)
complain("$name is too short, must be at least $length characters, is only $slen.");
}
}
// Add a new line to the start of an existing file.
function prepend($file,$string) {
// TO DO - use database to make this algorithm more scaleable.
// Current limit is 100 stories.
if (file_exists($file)) {
$filetext = file($file);
$lines = count($filetext);
} else {
$lines = 0;
}
if ($lines > 100) $lines = 100;
$handle = fopen($file,"w");
fputs ($handle, "$string\n");
for ($i=0; $i<$lines; $i++)
fputs ($handle, $filetext[$i]);
fclose ($handle);
}
// Return the next available story number.
function getstorynum() {
// TO DO - add synchronization to prevent multi-user conflicts.
if (file_exists("filenum.txt"))
$storynum = file("filenum.txt");
else
$storynum[0] = 0;
$snum = $storynum[0] + 1;
$handle = fopen("filenum.txt","w");
fputs($handle, $snum);
fclose ($handle);
return $snum;
}
// Save the user's input to the appropriate files.
function save() {
global $storytitle;
global $storyimg;
global $synopsis;
global $storytext;
global $subject;
$storynum = getstorynum();
$entry = "$storynum^$storytitle^$storyimg^$synopsis";
prepend("Main.txt",$entry);
$topicfile = "$subject.txt";
prepend($topicfile,$entry);
// Selective Security! Convert most HTML tags to text.
//$storytext = eregi_replace("&", "&", $storytext);
$storytext = eregi_replace("<", "<", $storytext);
$storytext = eregi_replace("\"", """, $storytext);
$storytext = eregi_replace("\n", "
\n", $storytext);
$storytext = eregi_replace("
\n
", "
", $storytext); //$storytext = eregi_replace('$', "$", $storytext); $storytext = eregi_replace("<b>", "", $storytext); $storytext = eregi_replace("<p>", "
", $storytext);
$storytext = eregi_replace("<br>", "
", $storytext);
$storytext = eregi_replace("<hr>", "
$storytitle | \n");
fputs($handle, " $subject |
$synopsis \n"); if ($storyimg != "") fputs($handle, " | |
| $storytext |