Sturgis High School Class of '78 Guest Book
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PHP Guestbook 1.0 (Feb. 2002)
by Harald Meyer (webmaster@harrym.nu)
Feel free to use it, but don't delete these lines.
PHP FXP is Freeware.
Based on another Guestbook.
Please send me modified versions!
If you use it on your page, a link back to its homepage would
be highly appreciated.
Homepage: http://tools.harrym.nu/php_guestbook.php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
//*********************************************************************************************//
// To change: //
//*********************************************************************************************//
// File that contains the data
$filelocation="gbook_data.php";
//Name of this document here
$boardname="guestbook.php";
// The message to display when someone entered data $name is the name then
$thanksmessage="
Thanks for your message, $name!
";
// The message to display, if there is an error
$errormessage="
You must enter your name and a message!
";
// Defines, if special characters should be converted to their html equivalents like > to >
// 1 enables and 0 disables this feature
$specialchars=1;
// Defines, if Ascii linebreaks (people pressing enter while filling the form should become
// html linebreaks
// 1 enables and 0 disables this feature
$linebreaks=1;
// Entrytext, displayed every time the guestbooks gets loaded
$entrytext = "";
// Maximal length of the words, to prevent someone killing your layout
$maxwordlength = 30;
// Rules, displayed when you enter some text...
$rules = "";
//Captions
$cap_submit="Submit";
$cap_msg="Message:";
$cap_noenty="Kein Eintrag bis jetzt!";
//Colors, Styles
$col_tb="#CCCCCC";
/*-----------------------------------------------------------------------------------------------
Adding a new entry to the data file
------------------------------------------------------------------------------------------------*/
if ($edit == "yes"){
// test if someone forgot to enter spaces.
$spaces = explode(" ",$message);
for ($i=0;$i $maxwordlength) $bozo="yes";
}
$spaces = explode(" ",$name);
for ($i=0;$i $maxwordlength) $bozo="yes";
}
// When there is missing data, display the errormessage and reprint the form
if ($name == "" || $message =="" || $bozo == "yes"){
echo "
$errormessage \n";
if ($bozo = "yes") echo "";
echo "
";
}
// If all the entries are correct, display thanksmessage add to datafile
else {
echo " $thanksmessage\n";
// Change % and # to percent and no, to avoid wrong splitting of the data.
$message = eregi_replace("#","no.",$message);
$message = eregi_replace("%","percent",$message);
$name = eregi_replace("#","no.",$name);
$name = eregi_replace("%","percent",$name);
// When specialchars are to be replaced...
if ($specialchars==1){
$message=htmlentities($message);
$name=htmlentities($name);
}
// When ASCII Linebreaks should become
s
if ($linebreaks==1){$message = nl2br($message);}
// When there is no datafile yet, create a new one
if (!file_exists($filelocation)) {
$newfile = fopen($filelocation,"w+");
fclose($newfile);
}
// Add the data to the end of the datafile
$newfile = fopen($filelocation,"a+");
$add = "%".$name."#".$email."#".$url."#".date("F jS Y")."#".$message."\n";
fwrite($newfile, $add);
fclose($newfile);
}
}
/*-----------------------------------------------------------------------------------------------
Introduction Screen when there is no data from the form
------------------------------------------------------------------------------------------------*/
if ($action != "view" && $action !="new"){
if ($edit=="yes"){
}
else {
echo $entrytext;
}
}
/*-----------------------------------------------------------------------------------------------
Display the guestbook
------------------------------------------------------------------------------------------------*/
if ($action=="view"){
echo $entrytext;
// When there is no data file, create a new one and say there are no entries.
if (!file_exists($filelocation)) {
$newfile = fopen($filelocation,"w+");
fclose($newfile);
echo $cap_noentry;
}
// Open the datafile and read the content
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
// Remove the slashes PHP automatically puts before special characters
$content=stripslashes($content);
// Put the entries into the array lines
$lines = explode("%",$content);
// Define and fill the reverse array (showing the last entry first)
$rev=array();
for ($i=sizeof($lines)-1;$i>0;$i--){array_push($rev,$lines[$i]);}
$lines=$rev;
// Display all the entries of the guestbook
while(list($key)= each ($lines)){
/*
/ split the data lines into a user array
/ user[0] is the name, [1] is the email, [2] is the url [3] is the date and [4] the message
*/
$urladd="";
$mailadd="";
$user = explode("#",$lines[$key]);
// if there is an email, display an email link
if ($user[1] != ""){$mailadd="email";}
// if there is a url, display a link
if ($user[2] != ""){
// if people were dumb enough not to add http:// do so
if (substr($user[2],0,7)!= "http://"){
$user[2]="http://".$user[2];
}
$urladd="Homepage";
}
echo "
";
echo "$user[0] $mailadd $urladd ($user[3])";
echo " |
|
";
// Display the entries, here you can tweak HTML
echo "
$user[4]\n";
echo "
|
";
}
}
/*-----------------------------------------------------------------------------------------------
Add a new entry to the guestbook, display the rules and show the form.
------------------------------------------------------------------------------------------------*/
if ($action == "new"){
echo "$rules
\n
";
}
?>