<?php
class Post{
var $name;
var $email;
var $message;
var $date;
var $post_id;
var $ip_addr;
var $show_email;
var $show_message;
var $approved;
var $post_array;
function Post($post_array){
$this->SetThisVarsFromPostArray($post_array);
}
function SetThisVarsFromPostArray($post_array){
foreach ($post_array as $key=>$val){
$string='$this->'.$key.'='.$val.';';
eval ($string);
}
$this->post_array=$post_array;
}
function PrintFields(){
foreach ($this->post_array as $key=>$value)
{
echo "<B>".$key."</B>: ".$this->DecodeMessage($value)." <P>\n";
}
}
function EncodeMessage($message){
$message=preg_split('/;/',$message);
$message=implode("##semicolon##",$message);
$message=preg_split("/'/",$message);
$message=implode("##prime##",$message);
$message=preg_split('/"/',$message);
$message=implode("##apostrophe##",$message);
$message=preg_split('/:/',$message); // added0.52
$message=implode("##colon##",$message);
$message=preg_split('/$/',$message);
$message=implode("##dollarsign##",$message);
return ($message);
}
function DecodeMessage ($message){
$message=preg_split('/##semicolon##/',$message);
$message=implode(";",$message);
$message=preg_split('/##prime##/',$message);
$message=implode("'",$message);
$message=preg_split('/##apostrophe##/',$message);
$message=implode('"',$message);
$message=preg_split('/##colon##/',$message);
$message=implode(':',$message); // added0.52
$message=preg_split('/##dollarsign##/',$message);
$message=implode('$',$message);
return ($message);
}
# a function to replace new lines with breaks
function ConvertToHtml ($message){
$fmess1=preg_split('/\\r\\n|\\n|\\r/',$message);
$fmess=implode("<BR>",$fmess1);
$fmess2=stripslashes($fmess);
return ($fmess2);
}
function RemoveBreaks($message){
$fmess1=preg_split('/<BR>/',$message);
$fmess=implode("\n",$fmess1);
$fmess1=preg_split('/<P>/',$message);
$fmess=implode("\n\n",$fmess1);
$fmess2=stripslashes($fmess);
return ($fmess2);
}
function CleanName($name){
$name = trim($name);
$name=preg_split('/;/',$name);
$name=implode("",$name);
$name=preg_split('/"/',$name);
$name=implode("",$name);
$name=preg_split('/\'/',$name);
$name=implode("",$name);
$name=preg_split('/:/',$name);
$name=implode("",$name);
$name=stripslashes($name);
return $name;
}
function SetVariablesFromPostArray(){ //returns a string to be evaluated for the variables to be set
$string='';
foreach ($this->post_array as $key => $val)
{
$string=$string.'$'.$key.'="'.$val.'";';
}
return $string;
}
function MailLogLine($var="mail"){
$used_language="include/lang/eng/lang.php";
include $used_language;
$post_array=$this->post_array;
$post_log='';
$temp=array();
foreach ($post_array as $key=>$val){
if ($key==message){$temp["message"]=$this->RemoveBreaks($val);}
elseif ($key!="approved"){$temp["$key"]=$val;}
}
foreach ($temp as $key=>$val){
$post_log=$post_log.$key.": ".$val."\n";
}
if ($var==log){$post_log="\n<entry>".$post_log."</entry>\n";}
$post_log=trim($this->DecodeMessage(stripslashes($post_log)));
#$post_log=$this->DecodeMessage(stripslashes("\n<ENTRY>\n$name_lang: ".$this->name."\n$email_lang: ".$this->email."\n$message_lang: ".$this->message."\n$date_lang ".$this->date."\n$from_ip_lang: ".$this->ip_addr."\n</ENTRY>\n")); # formatting for the log file
return $post_log;
}
}
class Guestbook{
var $conf_file="include/conf.php";
var $gbook_url;
var $gbook_name;
var $admin_pass;
var $gbook_title;
var $admin_email;
var $gbook_email;
var $reserved_name;
var $activate_res_name;
var $posts_per_page;
var $sendmail_onpost;
var $enable_image_verification_step;
var $additional_pages_name;
var $menu_spacer;
//$forbidden_strings=array();
//$banned_ips=array("123.221.331.21","111.122");
var $used_language;
var $p_template;
var $posts_file;
var $logfile_name;
var $moderation_active;
var $posts_array;
var $header;
var $footer;
var $last_message_to_top;
var $powby;
var $pwb2;
function Guestbook(){
$this->SetGBVars();
$this->posts_array=$this->FlatfileToArray();
$this->header=$this->GetHeader();
$this->footer=$this->GetFooter();
$this->last_message_to_top=1;
}
function SetGBVars(){
include $this->conf_file;
include "include/mixvar.php";
$this->gbook_url=$gbook_url;
$this->gbook_name=$gbook_name;
$this->admin_pass=$admin_pass;
$this->gbook_title=$gbook_title;
$this->admin_email=$admin_email;
$this->gbook_email=$gbook_email;
$this->pwb2=$powby;
$this->reserved_name=$reserved_name;
$this->activate_res_name=$activate_res_name;
$this->posts_per_page=$posts_per_page;
$this->sendmail_onpost=$sendmail_onpost;
$this->enable_image_verification_step=$enable_image_verification_step;
$this->additional_pages_name=$additional_pages_name;
$this->menu_spacer=$menu_spacer;
$this->used_language=$used_language;
$p_template=preg_split('/##prime##/',$p_template);
$p_template=implode("'",$p_template);
$p_template=preg_split('/##apostrophe##/',$p_template);
$p_template=implode('\"',$p_template);
$this->p_template=$p_template;
$this->posts_file=$posts_file;
$this->logfile_name=$logfile;
$this->moderation_active=$moderation_active;
$this->powby="<a class=\"powby\" href=\"http://www.cellbiol.com/scripts/free_php_guestbook/free_php_guestbook.html\" target=\"_blank\">Powered by the The Easy PHP Guestbook ®</a>";
}
function BuildMenus(){
$app=$this->GetApproved();
$msgnum=count($app);
#echo "there are $msgnum posts in the guestbook <P>";
#echo "the number of posts per page is $this->posts_per_page <P>";
$pagesnum=$msgnum/$this->posts_per_page;
if ((int)$pagesnum<$pagesnum){$pagesnum=(int)$pagesnum+1;}
#echo "there are $pagesnum pages in the guestbook <P>";
$apn=$this->additional_pages_name;
$ms=$this->menu_spacer;
$i=1;
$menus=array();
$max_lp=6; //max linked pages in the menu on each side of the current page
while ($i<=$pagesnum){
$nx=$i+1; # number of next page
$pv=$i-1; # number of previous page
$string='';
$j=1;
if ($i==1 AND $pagesnum!=1){ # first page menus if there is more than one page total
$string="<b>1</b>";
$j=2;
while ($j<=$pagesnum AND $j<=$max_lp){
$string=$string.$ms."<a href=$apn"."$j.html>$j</a>";
$j=$j+1;
}
$string=$string.$ms."<a href=$apn".$nx.".html>next></a>".$ms."<a href=$apn".$pagesnum.".html>last>></a>";
$menus[]=$string;
$i=$i+1;
}
elseif ($i==1 AND $pagesnum==1){$menus[]=''; $i=$i+1;} # if there is only one page in total
elseif ($i==$pagesnum AND $i!=1){ # last page menus
if ($pagesnum==2) { # if there are 2 pages total, this will be applied to the second page
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$this->gbook_name><previous</a>";
# in this case first and previous both lead to the first guestbook page
}
else {
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$apn".$pv.".html><previous</a>";
}
$inpag=$i-$max_lp; //initial page to be linked
if ($inpag<1){$inpag=1;}
$j=$inpag;
while ($j<=$pagesnum){
if ($j==$i){$string=$string.$ms."<b>".$i."</b>";}
elseif ($j==1){$string=$string.$ms."<a href=$this->gbook_name>$j</a>";}
elseif ($j!=$i AND $j!=1){$string=$string.$ms."<a href=$apn"."$j.html>$j</a>";}
$j=$j+1;
}
$menus[]=$string;
$i=$i+1;
}
elseif ($i>1 AND $i<$pagesnum) { # middle page menus
######### code below was modified to fix the "previous" link bug in the second page ################
if ($i==2) { # if there are 2 pages total, this will be applied to the second page
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$this->gbook_name><previous</a>";
# in the case of the second page, first and previous both lead to the first guestbook page
}
else {
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$apn".$pv.".html><previous</a>";
}
######### end modified code ################
$inpag=$i-$max_lp; //initial page to be linked
if ($inpag<1){$inpag=1;}
$lastpag=$i+$max_lp; //last page to be linked
if ($lastpag>$pagesnum){$lastpag=$pagesnum;}
######### code below was modified to fix the "previous" link bug in the second page ################
if ($i==2) { # if there are 2 pages total, this will be applied to the second page
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$this->gbook_name><previous</a>";
# in the case of the second page, first and previous both lead to the first guestbook page
}
else {
$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$apn".$pv.".html><previous</a>";
}
######### end modified code ################
#$string="<a href=$this->gbook_name><<first</a>".$ms."<a href=$apn".$pv.".html><previous</a>";
$j=$inpag;
while ($j<=$lastpag){
if ($j==$i){$string=$string.$ms."<b>".$i."</b>";}
elseif ($j==1 AND $j!=$i){$string=$string.$ms."<a href=$this->gbook_name>$j</a>";}
elseif ($j!=$i){$string=$string.$ms."<a href=$apn"."$j.html>$j</a>";}
$j=$j+1;
}
$string=$string.$ms."<a href=$apn"."$nx".".html>next></a>".$ms."<a href=$apn".$pagesnum.".html>last>></a>";
$menus[]=$string;
$i=$i+1;
}
}
#foreach ($menus as $menu){echo $menu."<P>";}
return $menus;
}
function FlatfileToArray(){
$posts=file($this->posts_file);
$post_array=array();
$posts2=array();
foreach ($posts as $post)
{
$post2=preg_split('/;/',$post);
foreach ($post2 as $post_item)
{
$temp=preg_split('/:/',$post_item);
$post_array[$temp[0]]=trim($temp[1]);
}
$posts2[]=$post_array;
}
return $posts2;
}
function ArrayToFlatfile(){
$tofile='';
foreach ($this->posts_array as $post)
{
$line=PostArrayToLine($post);
$tofile=$tofile.$line;
}
$fp = fopen($this->posts_file, "w");
$write = fputs($fp, $tofile);
fclose($fp);
}
function AddPost($post_array){//former AddPostToFlatfile
$posts_array=$this->posts_array;
$posts_array[]=$post_array;
$this->posts_array=$posts_array;
$this->ArrayToFlatfile();
$this->UpdateHTMLFile();
//$this->posts_array=$this->FlatfileToArray();
}
function GetPost($post_id){//former GetPostFromFlatfile
foreach ($this->posts_array as $post)
{
if ($post["post_id"]==$post_id){$post_array=$post;break;}
}
return $post_array;
}
function ReplacePost($post_array){//former ReplacePostInFlatfile
$post_id=$post_array["post_id"];
$temp=array();
foreach ($this->posts_array as $post)
{
if ($post["post_id"]!=$post_id){$temp[]=$post;}
else {$temp[]=$post_array;}
}
$this->posts_array=$temp;
$this->ArrayToFlatfile();
$this->UpdateHTMLFile();
//$this->posts_array=$this->FlatfileToArray();
}
function DeletePost($post_id){//former DeletePostFromFlatfile
srand((double)microtime()*1000000);
$string = md5(rand(0,9999));
$new_string = substr($string, 17, 5);
$temp_file_name="posts/temp$new_string.txt";
$file = fopen($this->posts_file,"r");
$temp_file= fopen("$temp_file_name","w");
while(! feof($file))
{
$line=fgets($file);
if ($line==''){break;}
$post_array=$this->PostLineToArray($line);
if ($post_array['post_id']==$post_id){continue;}
else
{
$write = fputs($temp_file, $line);
}
}
fclose($file);fclose($temp_file);
$file = fopen($this->posts_file,"w");
$temp_file= fopen("$temp_file_name","r");
while(! feof($temp_file))
{
$line=fgets($temp_file);
$write = fputs($file, $line);
}
fclose($file);fclose($temp_file);unlink($temp_file_name);
$this->posts_array=$this->FlatfileToArray();
$this->UpdateHTMLFile();
}
function GetApproved(){//former GetApprovedMessages
$approved_msgs=array();
foreach ($this->posts_array as $post_array){
if ($post_array["approved"]!="no"){$approved_msgs[]=$post_array;}
}
return $approved_msgs;
}
function GetHeader(){
$g_content=file_get_contents($this->gbook_name); # getting the whole html guestbook contents
$comstart_reg="/<!-- COMMENTS-START -->.*\\n/";
$chars = preg_split($comstart_reg, $g_content); # we split in 2 the html guestbook file bu using the comments start regular expression
$header=$chars[0];
return ($header);
}
function GetFooter(){
$g_content=file_get_contents($this->gbook_name); # getting the whole html guestbook contents
$comend_reg="/<!-- COMMENTS-END -->.*\\n/";
$comstart_reg="/<!-- COMMENTS-START -->.*\\n/";
$chars = preg_split($comstart_reg, $g_content); # we split in 2 the html guestbook file by using the comments start regular expression
$chars2 = preg_split($comend_reg, $chars[1]); # we split the second part (posts+footer) in two by using the comend regular expression
$len_c2=count($chars2); # this will be =1 if the comments end tag is not there, or = 2 if it is there
if($len_c2==1){$footer=$chars2[0];}# maybe the end tag is not there (upgrade from old version of the script), in this case everything after the start tag is treated like a footer
elseif($len_c2==2){$footer = $chars2[1];} # this is the footer of the guestbook page
$menu_start_reg="/<menu>/";
$menu_end_reg="/<\/menu>/";
$temp1 = preg_split($menu_end_reg, $footer);
if (count($temp1)==1)
{
$footer=$footer;
}
elseif (count($temp1)==2)
{
$footer=$temp1[1];
}
return ($footer);
}
function PostLineToArray($line){
$post_array=array();
$temp_arr=preg_split('/;/',$line);
foreach ($temp_arr as $post_item)
{
$temp=preg_split('/:/',$post_item);
$post_array[$temp[0]]=trim($temp[1]);
}
return $post_array;
}
function DirList ($directory){
$results = array();
$handler = opendir($directory);
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..'){$results[] = $file;}
}
closedir($handler);
return $results;
}
function PostArrayToPost($post_array){
$post=new Post();
$post->SetThisVarsFromPostArray($post_array);
$setvars=$post->SetVariablesFromPostArray();
eval ($setvars);
if ($show_email == "no")
{
#$email="<a class=maillink href=php_guestbook.php?task=ShowPrivatePost&post_id=$post_id>Private</a>";
$email="";
}
$date=$post->DecodeMessage($date);
if ($show_message == "yes")
{
$message=$post->DecodeMessage($message);
}
else {$message="<a class=\"priv_msg_link\" href=php_guestbook.php?task=ShowPrivatePost&post_id=$post_id>Private</a>";}
include $this->used_language;
eval("\$f_post = \"$this->p_template\";");
return $f_post;
}
function PostLineToPost($line){
$post_array=$this->PostLineToArray($line);
$formatted_post=$this->PostArrayToPost($post_array);
return $formatted_post;
}
function BuildArchive($posts_number){
$posts_folder="posts";
$all_posts_files=$this->DirList($posts_folder);
$existing_archives=array();
foreach ($all_posts_files as $file){
if (preg_match('/archive/',$file))
{
$existing_archives[]=$file;
}
}
$indexes=array();
if (count($existing_archives)==0)
{
$archive_name="archive1.html";
}
else{
foreach ($existing_archives as $archive){
$temp=preg_split ('/archive/',$archive);
$temp=preg_split ('/\.html/',$temp[1]);
$index=$temp[0];
$indexes[]=$index;
}
sort($indexes);
$archive_name="archive".(end($indexes)+1).".html";
}
srand((double)microtime()*1000000);
$string = md5(rand(0,9999));
$new_string = substr($string, 17, 5);
$temp_file_name="posts/temp$new_string.txt";
$fp = fopen($archive_name, "w");
$temp_file = fopen($temp_file_name, "w");
$write = fputs($fp, $this->header);
$file = fopen($this->posts_file,"r");
$pta=array();//posts to archive
$i=0;
while(! feof($file))
{
$line=fgets($file);
if ($line==''){break;}
if ($i<$posts_number) //if the line is in the group that is to be archived, we add it to the pta array
{
$pta[]=$line;
}
else //else we store it in a temporary file from which we will rebuild the posts file in the code below
{
$write = fputs($temp_file, $line);
}
$i=$i+1;
}
fclose($file);fclose($temp_file);
$pta=array_reverse($pta);
foreach ($pta as $line){
$ready_post=PostLineToPost($line);
$write = fputs($fp, $ready_post);
}
$write = fputs($fp, $this->footer);
fclose($fp);
#code to remove the archived posts from the posts file
$file = fopen($this->posts_file,"w");
$temp_file= fopen("$temp_file_name","r");
while(! feof($temp_file))
{
$line=fgets($temp_file);
$write = fputs($file, $line);
}
fclose($file);fclose($temp_file);unlink($temp_file_name);
$this->posts_array=$this->FlatfileToArray();
$this->UpdateHTMLFile();
}
function UpdateHTMLFile(){//former UpdateHTMLguestbookPaginate
$temp=$this->GetApproved();
if ($this->last_message_to_top==1){$temp=array_reverse($temp);}
$posts2=array();
$subdposts=array(); #subdivided posts array. Will end up containing a number of arrays, each with the number of posts set in the $posts_per_page variable in the conf file
$i=0;
$comstart="<!-- COMMENTS-START -->\n";
$comend="<!-- COMMENTS-END -->\n";
if (count($temp)==0){ //if there are no approved posts
$contents=$this->header.$comstart.$comend.$this->footer; # we re-build the guestbook html page by putting together all the pieces
$fp = fopen($this->gbook_name, "w");
$write = fputs($fp, $contents); # and then write this to the guestbook file
fclose($fp);
}
# we now take the posts one by one, add them to an array until we reach the number of posts set in the $posts_per_page variable in the
# conf file and then add this array as element of a final array called subdivided posts array ($subdposts)
foreach($temp as $post_array)
{
if ($i<$this->posts_per_page)
{
$posts2[]=$post_array;
$i=$i+1;
}
elseif ($i==$this->posts_per_page)
{
$subdposts[]=$posts2; # we add the array containing a number of $posts_per_page posts to the final subdposts array
$posts2=array(); # we empty the posts2 array to start over
$posts2[]=$post_array;
$i=1;
}
}
if (count($posts2)!=0){$subdposts[]=$posts2;}
$pages_number=count($subdposts);
$i=1;
$menus=$this->BuildMenus();
$pvar=0;
if ($this->pwb2!=$this->powby){$pvar=1;}
foreach ($subdposts as $posts_group)
{
$page_number=i;
$index=$i-1;
$page_menu=$menus[$index];
//Code to build the navigation menu
if ($i==1) //first page
{
if ($pages_number!=1){
$menu_index="<menu><br><center><table width=90% border=0 cellpadding=15><tr><td><center>".$page_menu."</center></td></tr></table></center></menu>";
}
else {$menu_index="";}
$fp = fopen($this->gbook_name, "w");
//$write = fputs($fp, $contents); # and then write this to the guestbook file
$write = fputs($fp, $this->header);$write = fputs($fp, $comstart);$write = fputs($fp, $menu_index);
foreach($posts_group as $post_array){
if ($pvar==0){
$f_post=DecodeMessage($this->PostArrayToPost($post_array));
$write = fputs($fp, $f_post);
}
else {die();}
}
$write = fputs($fp, $comend);$write = fputs($fp, $menu_index);$write = fputs($fp, $this->footer);
fclose($fp);
$i=$i+1;
}
elseif ($i!=1){ //page beyond the first one
$menu_index="<menu><br><center><table width=90% border=0 cellpadding=15><tr><td><center>".$page_menu."</center></td></tr></table></center></menu>\n";
$pagename=$this->additional_pages_name.$i.".html";
$fp = fopen($pagename, "w");
$write = fputs($fp, $this->header);$write = fputs($fp, $comstart);$write = fputs($fp, $menu_index);
foreach($posts_group as $post_array){
$f_post=DecodeMessage($this->PostArrayToPost($post_array));
$write = fputs($fp, $f_post);
}
$write = fputs($fp, $comend);$write = fputs($fp, $menu_index);$write = fputs($fp, $this->footer);
fclose($fp);
$i=$i+1;
}
}
} //end function definition UpdateHTMLguestbookPaginate
function GetNextAvailableId(){
if (count($this->posts_array)==0){return "1";exit;}
else{
$max_id=0;
foreach ($this->posts_array as $post)
{
$post_id=$post["post_id"];
if ($post_id>$max_id){$max_id=$post_id;}
}
$nai=$max_id+1; //next available id
return $nai;
}
}
# A function to show a single post, intended for admin only, to see private fields and IP
function ShowPrivatePost($post_id){
$post_array=$this->GetPost($post_id);
if (count($post_array)==0){echo "A post with id $post_id is not present in the database"; exit;}
else
{
$post= new Post;
$post->SetThisVarsFromPostArray($post_array);
echo "<center><a href=$this->gbook_url>Back to the guestbook</A> | <a href=php_guestbook.php?task=show>Admin Home</A> | <a href=php_guestbook.php?task=adm_logout>Logout</A></center><P>";
echo '<center><table width=1024 cellpadding=0 cellspacing=10><TR bgcolor=red><TD><center><H1><font color=white>Admin view for message number '.$post_id.'</font></H1></center></TD></TR></TABLE></center>';
echo '<center><table width=1024 cellpadding=10 cellspacing=10><TR bgcolor=#FFCC66><TD>';
#foreach ($post_array as $key=>$value)
#{
#echo "<B>".$key."</B>: ".DecodeMessage($value)." <P>\n";
#}
$post->PrintFields();
echo '</td></tr></table></center>';
}
}
function CreateDelEditPage (){//tolto $posted_pass come argomento e tolto anche alla form $admin_template in mix_html
include "include/html/forms.php";
include "include/html/mix_html.php";
include $this->used_language;
$adm_pag1='';
$gbook_url=$this->gbook_url;
$gbook_title=$this->gbook_title;
//$myposts_array=array_reverse($this->posts_array);
#echo $doctype_header.$open_html_and_head.$admin_title.$link_admin_css.$close_head_open_body;
#echo '<span class="admin_style"><center> <a href="php_guestbook.php?task=show">Admin home</a> | <a href="php_guestbook.php?task=configure">Configure</a> | <a href="php_guestbook.php?task=del_edit">Edit/Delete</a> | <a href="php_guestbook.php?task=ShowPendingMessages">Pending</a> | <a href="'.$this->gbook_url.'"target="_blank">Guestbook</a> | <a href="http://www.cellbiol.com/scripts/free_php_guestbook/free_php_guestbook.html" target="_blank">Check for updates</a> | <a href="php_guestbook.php?task=adm_logout">Logout</a></center></span>';
echo $del_edit_header1;
echo '<span class="admin_style"><center> <a href="php_guestbook.php?task=show">Admin home</a> | <a href="php_guestbook.php?task=configure">Configure</a> | <a href="php_guestbook.php?task=del_edit">Edit/Delete</a> | <a href="php_guestbook.php?task=ShowPendingMessages">Pending</a> | <a href="'.$this->gbook_url.'"target="_blank">Guestbook</a> | <a href="http://www.cellbiol.com/scripts/free_php_guestbook/free_php_guestbook.html" target="_blank">Check for updates</a> | <a href="php_guestbook.php?task=adm_logout">Logout</a></center></span>';
echo $del_edit_header2;
#echo $adm_pag1;
$file = fopen($this->posts_file,"r");
#echo "<P>the posts file is $this->posts_file <P>";
while(! feof($file))
{
$line=fgets($file);
if ($line==''){break;}
$post_array=$this->PostLineToArray($line);
$post=new Post();
$post->SetThisVarsFromPostArray($post_array);
$setvars=$post->SetVariablesFromPostArray();
eval ($setvars);
$email=$post->DecodeMessage($email);
$date=$post->DecodeMessage($date);
$message=$post->DecodeMessage($message);
$message=$this->Truncate(htmlspecialchars($message));
eval("\$adm_pag = \"$admin_template\";");
echo $adm_pag;
}fclose($file);
echo $del_edit_footer;
echo $close_body_and_html;
}
# fuction to write to the log file
function writelog($filename,$text){
$fp = fopen($filename, "a");
$write = fputs($fp, $text);
fclose($fp);
} # end function definition writelog
function Truncate ($str, $length=300, $trailing='.....'){
// take off chars for the trailing
$length-=strlen($trailing);
if (strlen($str) > $length)
{
// string exceeded length, truncate and add trailing dots
return substr($str,0,$length).$trailing;
}
else
{
// string was already short enough, return the string
$res = $str;
}
return $res;
}
} //end Guestbook class definition
?>