<?php
###############################################################################
# A PHP ShoutboxScript with smileys
#
###############################################################################
# Dieses Programm ist freie Software. Sie können es weitergeben und/oder 
# nach Ihren Anforderungen modifizieren
#
############### Einstellungen ##################################################
#
$showcomments 5;                //Anzahl der anzuzeigenden Kommentare
$file "/var/www/shoutbox/shouts.txt";        //Name der Shoutsdatei, muss vorhanden sein
$maxlength_name "20";                //Maximallänge für den Namen
$maxlength_comment "150";            //Maximallänge für das Kommentar
$length "16";                    //Länge des Eingabefeldes
$break_name "16";                //Zeilenumbruch nach wieviel Zeichen im Namen?
$break_comment "18";                //Zeilenumbruch nach wieviel Zeichen im Kommentar?
$smilies_ort "/imgage";            //Odner von den smilies
$size "10pt";                    //Schriftgröße
$sizecoment "9pt";                //Schriftgröße der Kommentare
$color "Navy";                //Schriftfarbe    (HTML stil)
$colorcoment "Navy";                //Schriftfarbe der Kommentare (HTML stil)
$bgcolor "#B4B4B4";                //Hintergrundfarbe der tabelle (HTML stil)
$tablewidth 145;                //Breite der Tabelle
#
# Smileys kann mann hinzufügen  zb. ":das-zeichen-für-die-darstellung:","das-bildgif", 
$smilies_ubb_array = array(
    
";)","wink2.gif",
    
":firefox:","MSI-vs-FF.gif",
    
":rofl:","rofl.gif",
    
":shock:","schock.gif",
    
":o","schock.gif",
    
":gut:","thumb.gif",
    
":crazy:","crazy.gif",
    
":bad:","mad.gif",
    
":)","smile.gif",
    
":(","traurig.gif",
    
":D","grin.gif",
    
":p","tongue.gif",
    
":buh","thumbd.gif",
    );
######################################################################################

$show = ($_GET['show']);
$zeit=date('H:i');
$datum date(' d.m.y');
$wann "$zeit $datum";
$input_comment $_POST['input_comment'];
$input_name $_POST['input_name'];

//Eingabefeld erzeugen
?>
<html>
    <HEAD> 
    <TITLE>Shoutbox</TITLE></HEAD> 
    <body style="background-color:#B4B4B4; margin:0;"> 
    <script language="JavaScript"> 
    function smilie(zeichen) { 
    shoutbox.input_comment.value = shoutbox.input_comment.value + zeichen; 
    } 
    </script>

<?php
echo <<<BOX 
    
<table style='background-color: $bgcolor; font-size: $size pt; color : $color;' width='$tablewidth' cellspacing='0' cellpadding='2' border='0'>
    <
form action='$SCRIPT_NAME?show=$show' method='post' name='shoutbox'>
    <
tr><td>
    <
a href="javascript:smilie(' :) ')"><img src="$smilies_ort/smile.gif" alt="." width="15" height="15" border="0" ></a>
    <
a href="javascript:smilie(' ;) ')"><img src="$smilies_ort/wink2.gif" alt="." width="15" height="15" border="0"></a>
    <
a href="javascript:smilie(' :D ')"><img src="$smilies_ort/grin.gif" alt="." width="15" height="15" border="0"></a>
    <
a href="javascript:smilie(' :( ')"><img src="$smilies_ort/traurig.gif" alt="." width="15" height="15" border="0"></a>
    <
a href="javascript:smilie(' :p ')"><img src="$smilies_ort/tongue.gif" alt="." width="15" height="15" border="0"></a>
    <
a href="javascript:smilie(' :bad: ')"><img src="$smilies_ort/mad.gif" alt="." width="15" height="15" border="0"></a>
    <
a href="javascript:smilie(' :shock: ')"><img src="$smilies_ort/schock.gif" alt="." width="15" height="15" border="0" ></a>
    <
a href="javascript:smilie(' :gut: ')"><img src="$smilies_ort/thumb.gif" alt="." width="30" height="18" border="0"></a>
    <
a href="javascript:smilie(' :rofl: ')"><img src="$smilies_ort/rofl.gif" alt="." width="30" height="18" border="0" ></a>
    <
a href="javascript:smilie(' :crazy: ')"><img src="$smilies_ort/crazy.gif" alt="." width="30" height="18" border="0" ></a>
    <
a href="javascript:smilie(' :buh: ')"><img src="$smilies_ort/thumbd.gif" alt="." width="22" height="22" border="0"></a>
    </
td></tr>
    <
tr><td>&nbsp;<input type='text' value='Name' name='input_name' size='$length' maxlength='$maxlength_name'
    
onFocus="javascript:if(document.shoutbox.input_name.value=='Name')document.shoutbox.input_name.value='';"></td></tr>
    <
tr><td>&nbsp;<input type='text' value='Kommentar' name='input_comment' id='input_comment' size='$length' maxlength='$maxlength_comment'
     
onFocus="javascript:if(document.shoutbox.input_comment.value=='Kommentar')document.shoutbox.input_comment.value='';"></td></tr>
    <
tr><td>&nbsp;<input type='submit' value='Go!'></td></tr>
    <
tr><td colspan='2'><hr>&nbsp;<font style='font-size : $size; color: $color;'><a href='javascript:location.reload()'>reload</a></font><hr
BOX;
   if(
$_GET['show'] == "all"){
    echo 
"&nbsp;<font style='font-size : $size; color: $color;'><a href='$SCRIPT_NAME?show='>Normale Ansicht</a></font><hr>\n\n";
   }
   else {
    echo 
"&nbsp;<font style='font-size : $size; color: $color;'><a href='$SCRIPT_NAME?show=all'>Alle Shouts zeigen</a></font> <hr>\n\n";
   }

//eingaben prüfen
  
if($input_name != "Name" && $input_name != "" && $input_comment != "Kommentar" && $input_comment != ""){

    
$tmp fopen($file,"r");
    while(!
feof($tmp)){
      
$row fgets($tmp,999999);
      list(
$tmpwann,$tmpname,$tmpcomment) = split("\|",$row);
      if(
$tmpname != "" && $tmpcomment != ""){
        
$name $tmpname;
        
$comment $tmpcomment;
        
$comment str_replace("\n","",$comment);
      }
    }
    
fclose($tmp);

$input_comment eregi_replace("http://www.""www."$input_comment);
$input_comment eregi_replace("www.""http://www."$input_comment);

//wenn "http://"  im text vorkommt
  
if (preg_match('@^(?:http://)?([^/]+)@i'$input_comment$treffer)){
    
$input_name htmlentities($input_name ,ENT_QUOTES);
    
$input_name stripslashes($input_name);
    
$input_name trim($input_name);
    
$input_name wordwrap$input_name$break_name"<br>&nbsp;",TRUE);
    
$input_comment htmlentities($input_comment ,ENT_QUOTES);
    
$input_comment stripslashes($input_comment);
    
$input_comment trim($input_comment);
    
$input_comment wordwrap$input_comment$break_comment"<br>&nbsp;");
    
$host $treffer[1];
//urls in links umwandeln
$input_comment preg_replace('#(http\:\/\/[a-zA-Z0-9\/\.\#\-\_\?\&\%\=]+)#'
                
"<a href=\"$1\" title=\"$1\" target=\"_blank\">$host</a>" ,$input_comment);

//Smileys:
//str_replace("altes-zeichen","neues-zeichen","zeichenkette");
   
$smilie_rep_count 0;
   while(
$smilies_ubb_array[$smilie_rep_count]!=""){
       
$smilie_rep_count2 $smilie_rep_count 1;
       
$input_comment str_replace("$smilies_ubb_array[$smilie_rep_count]",
        
" <image src=\"$smilies_ort/$smilies_ubb_array[$smilie_rep_count2]\" alt=\".\" border=\"0\"> ",$input_comment);
       
$smilie_rep_count+=2;
       } 

   }

//wenn nicht, dann nicht ;-)
  
else {
    
$input_name htmlentities($input_name ,ENT_QUOTES);
    
$input_name stripslashes($input_name);
    
$input_name trim($input_name);
    
$input_name wordwrap$input_name$break_name"<br>&nbsp;",TRUE);
    
$input_comment htmlentities($input_comment ,ENT_QUOTES);
    
$input_comment stripslashes($input_comment);
    
$input_comment trim($input_comment);
    
$input_comment wordwrap$input_comment$break_comment"<br>&nbsp;",TRUE);

//Smileys:
//str_replace("altes-zeichen","neues-zeichen","zeichenkette");
   
$smilie_rep_count 0;
   while(
$smilies_ubb_array[$smilie_rep_count]!=""){
       
$smilie_rep_count2 $smilie_rep_count 1;
       
$input_comment str_replace("$smilies_ubb_array[$smilie_rep_count]",
        
"<image src=\"$smilies_ort/$smilies_ubb_array[$smilie_rep_count2]\" alt=\".\" border=\"0\">",$input_comment);
       
$smilie_rep_count+=2;
       }
   }

//reload sperre
    
if($name != $input_name || $comment != $input_comment){
      
$tmp fopen($file"a");
      
fputs($tmp,"$wann|$input_name|$input_comment\n");
      
fclose($tmp);
        }
}

//einträge in ein arry laden,
  
$wanns = array();
  
$names = array();
  
$comments = array();
  
$tmp fopen($file,"r");
  while(!
feof($tmp)){
    
$row fgets($tmp,999999);
    list(
$wann,$name,$comment) = split("\|",$row);
    if(
$name != ""){
      
array_push($wanns,$wann);
      
array_push($names,$name);
      
array_push($comments,$comment);
    }
  }
  
fclose($tmp);

//die letzen einträge nach vorne holen
  
$wanns array_reverse($wanns);
  
$names array_reverse($names);
  
$comments array_reverse($comments);

  if(
$show == "all")
    
$max count($names);
  else
    
$max $showcomments;

//und anzeigen
  
for($i=0$i<$max$i++)
    echo 
"<div style='background-color:#E3E0E0;' >&nbsp;<font style='font-size : $sizecoment; color: $colorcoment;'>$wanns[$i]<br>".
    
" &nbsp;<b>$names[$i]</b> schrieb:<br> &nbsp;$comments[$i]</font><br><br>\n\n";

  echo (
"</td>".
    
"</tr>".
    
"</form>".
    
"<tr><td></td></tr>".
    
"</table>".
    
"</body></html>");
?>