Smiliecode wird in Shoutbox nicht geparst
Forum » Fachdiskussionen / Programmierung und Datenverwaltung » Smiliecode wird in Shoutbox nicht geparst
Started by: Anonymous (193.171.131.x)
On: 1225452624|%e %b %Y, %H:%M %Z|agohover
Number of posts: 1
rss icon RSS: New posts
Smiliecode wird in Shoutbox nicht geparst
Anonymous (193.171.131.x) 1225452624|%e %b %Y, %H:%M %Z|agohover

Ich wollte vor einigen Tagen die Shoutbox aus dem Buch um eine Smilie-Funktion erweitern.

Leider wird der von der PHP-Datei ausgegebene img-Code in der Shoutbox angezeigt und nicht geparst.

Hier ist der PHP-Code:

<?php
if(isset($_POST['name']) and isset($_POST['text']) 
and $_POST['name'] != "" and $_POST['name'] != "Your message?" 
and $_POST['text'] != "" and $_POST['name'] != "Your name?") {
$name = strip_tags($_POST['name']);
$text = strip_tags($_POST['text']);

  # Smilies
$umwandlung1 = str_replace('[Wütend]', '<img src="angry.gif" />', $text);
$umwandlung2 = str_replace('[breites Grinsen]', '<img src="biggrin.gif" />', $umwandlung1);
$umwandlung3 = str_replace('[Hunde Augen]', '<img src="dogeyes.gif" />', $umwandlung2);
$umwandlung4 = str_replace('[Nichts wissen]', '<img src="dontknow.gif" />', $umwandlung3);
$umwandlung5 = str_replace('[Hausaufgaben]', '<img src="homework.gif" />', $umwandlung4);
$umwandlung6 = str_replace('[Idee]', '<img src="idee.gif" />', $umwandlung5);
$umwandlung7 = str_replace('[Augenrollen]', '<img src="rolleyes.gif" />', $umwandlung6);
$umwandlung8 = str_replace('[Schlaumeier]', '<img src="schlaumeier.gif" />', $umwandlung7);
$umwandlung9 = str_replace('[schreiben]', '<img src=schreiben.gif"" />', $umwandlung8);
$text_fertig = str_replace('[Grinsen]', '<img src="smile.gif" />', $umwandlung9);

   $dom = new DOMDocument("1.0", "UTF-8");
   if(!$dom)
      exit("FEHLER(1)!");
   $dom->preserveWhiteSpace = false;
   if(!$dom->load("shoutbox.xml")) {
      $shoutbox = $dom->createElement("shoutbox");
      $dom->appendChild($shoutbox);
   }
   $new_entry_elem = $dom->createElement("entry");
   $new_entry_elem->setAttribute("datetime", date("Y-m-d H:i"));
   $new_name_elem = $dom->createElement("name", 
                    substr($name, 0, 256));
   $new_text_elem = $dom->createElement("text", 
                    substr($text_fertig, 0, 1024));
   $new_entry_elem->appendChild($new_name_elem);
   $new_entry_elem->appendChild($new_text_elem);
   $shoutbox_elem = get_node($dom, '/shoutbox');
   if($shoutbox_elem->firstChild)
      $shoutbox_elem->insertBefore($new_entry_elem, 
                      $shoutbox_elem->firstChild);
   else
      $shoutbox_elem->appendChild($new_entry_elem);
   $i = 0;   
   $entry_elems = $dom->getElementsByTagName('entry');
   if($entry_elems->length > 10)
       $shoutbox_elem->removeChild($shoutbox_elem->lastChild);
   $dom->save("shoutbox.xml");
}
$content = file_get_contents("shoutbox.xml");
header('Content-Type: text/xml');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
echo $content;

function get_node($dom, $xpath) {
   $path = new DOMXPath($dom);
   $nodes = @$path->query($xpath);
   if(!is_object($nodes))
      return(false);
   else
      return($nodes->item(0));

}
?>

Und hier der HTML-Code:

<script type="text/javascript">
var xml_response_handler = function(content, output_id) { 
   var entries = content.getElementsByTagName("entry");
   document.getElementById(output_id).innerHTML = "";
   for(i = 0; i <= entries.length; i++) {
      var entry_name = entries[i].getElementsByTagName("name")[0];
      var entry_text = entries[i].getElementsByTagName("text")[0];
      var p = document.createElement("P");
      var b = document.createElement("B");
      var br = document.createElement("BR");
      var text_1 = 
    document.createTextNode(entries[i].getAttribute("datetime"));
      var text_2 = document.createTextNode(" wrote ");
      var text_3 = 
    document.createTextNode(entry_name.firstChild.nodeValue);
      var text_4 = document.createTextNode(":");
      var text_5 = 
    document.createTextNode(entry_text.firstChild.nodeValue);
      p.appendChild(b);
      b.appendChild(text_1);
      b.appendChild(text_2);
      b.appendChild(text_3);
      b.appendChild(text_4);
      p.appendChild(br);
      p.appendChild(text_5);
      document.getElementById(output_id).appendChild(p);
   }
};

function show_shoutbox() {
   if(!document.getElementById)
      return;
   script_url = "shoutbox.php";
   do_http_get_request("xml", script_url, "shoutbox_entries");
}

function post_to_shoutbox() {
   if(!document.getElementById)
      return;
   script_url = "shoutbox.php";
   post_field_ids = "name+text";
   do_http_post_request("xml", script_url, post_field_ids, 
                        "shoutbox_entries");
}

</script>
  <script type="text/Javascript">
   <!--
    var art;
    function smilie(art){
     document.formular.text.value += "[" + art + "]";
     document.formular.text.focus();
    }
   //-->
  </script>
</head>

<body onload="show_shoutbox(); 
window.setInterval(show_shoutbox, 10000);">

<form action="#" method="post" name="formular" style="">
<div><textarea name="text" rows="3" cols="20" id="text" 
style="width:490px; height: 4em; border: solid 1px silver; 
font-family: Arial,sans-serif; font-size: 11px; padding: 1px">
Your message?
</textarea></div>
<div><input type="text" name="name" id="name" 
style="width:460px; border: solid 1px silver; 
font-family: Arial,sans-serif; font-size: 11px; padding: 1px" 
value="Your name?"> 
<input type="button" name="send" style="width:30px; 
border: solid 1px silver; background-color: #EEE; 
font-family: Arial,sans-serif; font-size: 11px;" value="OK" 
onclick="post_to_shoutbox()"></div>
</form><br>

<div style="border:1px black dashed; width:498px;">
<p align="center">
      <img src=angry.gif" alt="Wütend" title="Wütend" onClick="smilie('Wütend')">
      <img src="biggrin.gif" alt="breites Grinsen" title="breites Grinsen" onClick="smilie('breites Grinsen')">    
      <img src="dogeyes.gif" alt="Hunde Augen" title="Hunde Augen" onClick="smilie('Hunde Augen')">
      <img src="dontknow.gif" alt="Nichts wissen" title="Nichts wissen" onClick="smilie('Nichts wissen')">
      <img src="homework.gif" alt="Hausaufgaben" title="Hausaufgaben" onClick="smilie('Hausaufgaben')">
      <img src="idee.gif" alt="Idee" title="Idee" onClick="smilie('Idee')">
      <img src="rolleyes.gif" alt="Augenrollen" title="Augenrollen" onClick="smilie('Augenrollen')">
      <img src="schlaumeier.gif" alt="Schlaumeier" title="Schlaumeier" onClick="smilie('Schlaumeier')">
      <img src="schreiben.gif" alt="schreiben" title="schreiben" onClick="smilie('schreiben')">
      <img src="smile.gif" alt="Grinsen" title="Grinsen" onClick="smilie('Grinsen')">
</p>
<p align="center">Auf einen Smilie klicken, um ihn hinzuzufügen</p>
</div>

</div>

Was habe ich falsch gemacht, oder wie kann ich das Problem beheben?

New post
page_revision: 2, last_edited: 1208468043|%e %b %Y, %H:%M %Z (%O ago)