]> git.mjollnir.org Git - moodle.git/commitdiff
Checking in Eloy's Javascript/smiley fixes from bug 1185 Thanks!
authormoodler <moodler>
Thu, 25 Mar 2004 06:31:44 +0000 (06:31 +0000)
committermoodler <moodler>
Thu, 25 Mar 2004 06:31:44 +0000 (06:31 +0000)
lib/weblib.php

index 11616123a5ea75622ff53d5704c69e78160d521c..6a95f3044909377a3f4c808561f477e8287ede05 100644 (file)
@@ -723,8 +723,30 @@ function replace_smilies(&$text) {
         $runonce = true;
     }
 
+    // Exclude from transformations all the code inside <script> tags
+    // Needed to solve Bug 1185. Thanks to jouse 2001 detecting it. :-)
+    // Based on code from glossary fiter by Williams Castillo.
+    //       - Eloy
+
+    // Detect all the <script> zones to take out
+    $excludes = array();
+    preg_match_all('/<script language(.+?)<\/script>/is',$text,$list_of_excludes);
+
+    // Take out all the <script> zones from text
+    foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
+        $excludes['<+'.$key.'+>'] = $value;
+    }
+    if ($excludes) {
+        $text = str_replace($excludes,array_keys($excludes),$text);
+    }
+
 /// this is the meat of the code - this is run every time
     $text = str_replace($e, $img, $text);
+
+    // Recover all the <script> zones to text
+    if ($excludes) {
+        $text = str_replace(array_keys($excludes),$excludes,$text);
+    }
 }
 
 function text_to_html($text, $smiley=true, $para=true, $newlines=true) {