\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 1000 stories. if (file_exists($file)) { $filetext = file($file); $lines = count($filetext); } else { $lines = 0; } if ($lines > 1000) $lines = 1000; $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>", "


", $storytext); $storytext = eregi_replace("<i>", "", $storytext); $storytext = eregi_replace("<ul>", "", $storytext); $storytext = eregi_replace("</b>", "", $storytext); $storytext = eregi_replace("</i>", "", $storytext); $storytext = eregi_replace("</p>", "

", $storytext); $storytext = eregi_replace("<ol>", "
    ", $storytext); $storytext = eregi_replace("</ol>", "
", $storytext); $storytext = eregi_replace("<li>", "
  • ", $storytext); $storytext = eregi_replace("<table", "

    $storytitle

    \n"); fputs($handle, " $subject\n"); fputs($handle, "

    $synopsis

    \n"); if ($storyimg != "") fputs($handle, "

    \n"); fputs($handle, " \n $storytext"); fclose($handle); } // Initializations, Defaults, and Input Validations. $title = "PHP Demo Author's Page"; $cats = file("category.txt"); if ($submit == "Submit") { $status = ""; if (!isset($storyimg)) $storyimg = "$subject.gif"; validate("Subject",$subject,1); validate("Story Title",$storytitle,10); validate("Synopsis",$synopsis,50); validate("Story Text",$storytext,300); if ($status == "") { $status = "complete"; save(); } } ?> <?php echo($title) ?>

    Story Submission Confirmed!

    Thanks for your input!

    Return to Webzine

    Here's Your Submission:

    Story Title: $storytitle

    \n"); echo("

    Synopsis: $synopsis

    \n"); echo("

    Subject: $subject

    \n"); if ($storyimg != "") echo("

    Story Image:

    \n"); echo("

    Story Text:

    \n"); echo("

    $storytext

    \n"); // ****************************************************************** // This part applies if there's still some work to be done. } else { echo("

    Return to Webzine

    \n"); if ($status == "") $status = "Please fill in the items below to create your new story.

    \n" . "

    Click the \"Submit\" button when you are done editing."; echo("

    $status

    "); // The following form permits the author to enter a story... ?>

    Subject:

    Story Title:

    Synopsis:

    Story Image URL:
    "); else echo("

    No image available.

    "); ?>

    Story Text: