]> git.mjollnir.org Git - moodle.git/commitdiff
fix "Force Plugins" behavior to correctly detect media players in JavaScript
authorgbateson <gbateson>
Sat, 15 Apr 2006 08:17:30 +0000 (08:17 +0000)
committergbateson <gbateson>
Sat, 15 Apr 2006 08:17:30 +0000 (08:17 +0000)
mod/hotpot/lib.php

index 2708929409f9f4e992b7272cc7a3ead267c1b21d..f56b408083e4eed6b27c7275e7c5a3f3d2ea7ca1 100644 (file)
@@ -1638,42 +1638,42 @@ class hotpot_xml_quiz extends hotpot_xml_tree {
                        include_once "$CFG->dirroot/filter/mediaplugin/filter.php";\r
 \r
                        // exclude swf files from the filter\r
-                       $CFG->filter_mediaplugin_ignore_swf = true;\r
+                       //$CFG->filter_mediaplugin_ignore_swf = true;\r
 \r
-                       $s = '\s+'; // at least one space\r
-                       $n = '[^>]*'; // any character inside a tag\r
                        $q = '["'."']?"; // single, double, or no quote\r
-                       $Q = '[^"'."' >]*"; // any charater inside a quoted string\r
 \r
                        // patterns to media files types and paths\r
-                       $filetype = "avi|mpeg|mpg|mp3|mov|wmv";\r
-                       $filepath = "$Q\.($filetype)";\r
+                       $filetype = "avi|mpeg|mpg|mp3|mov|swf|wmv";\r
+                       $filepath = ".*?\.($filetype)";\r
 \r
-                       // pattern to match <param> tags which contain the file path\r
-                       //      wmp             : url\r
+                       $tagopen = '(?:(<)|(\\\\u003C))'; // left angle-bracket (uses two parenthese)\r
+                       $tagclose = '(?(1)>|(?(2)\\\\u003E))'; // right angle-bracket (to match the left one)\r
+                       $tagreopen = '(?(1)<|(?(2)\\\\u003C))'; // another left angle-bracket (to match the first one)\r
+\r
+                       // pattern to match <PARAM> tags which contain the file path\r
+                       //      wmp          : url\r
                        //      quicktime  : src\r
                        //      realplayer : src\r
-                       //      flash     : movie (doesn't need replacing)\r
-                       $param_url = "/<param$s{$n}name=$q(src|url)$q$s{$n}value=$q($filepath)$q$n>/is";\r
+                       //      flash      : movie (doesn't need replacing)\r
+                       $param_url = "/{$tagopen}PARAM\s+.*?NAME=$q(?:movie|src|url)$q\s+.*?VALUE=$q($filepath)$q.*?$tagclose/is";\r
 \r
-                       // pattern to match <a> tags which link to multimedia files (not swf)\r
-                       $link_url = "/<a$s{$n}href=$q($filepath)$q$n>(.*?)<\/a>/is";\r
+                       // pattern to match <a> tags which link to multimedia files\r
+                       $link_url = "/{$tagopen}A\s.*?HREF=$q($filepath)$q.*?$tagclose.*?$tagreopen\/A$tagclose/is";\r
 \r
-                       // extract <object> tags\r
-                       preg_match_all("|<object$n>(.*?)</object>|is", $this->html, $objects);\r
+                       // extract <OBJECT> tags\r
+                       preg_match_all("/{$tagopen}OBJECT\s+.*?{$tagclose}(.*?){$tagreopen}\/OBJECT{$tagclose}/is", $this->html, $objects);\r
 \r
                        $i_max = count($objects[0]);\r
                        for ($i=0; $i<$i_max; $i++) {\r
 \r
+                               // extract URL from <PARAM> or <A> \r
                                $url = '';\r
-                               if (preg_match($param_url, $objects[1][$i], $matches)) {\r
-                                       $url = $matches[2];\r
-                               } else if (preg_match($link_url, $objects[1][$i], $matches)) {\r
-                                       $url = $matches[1];\r
+                               if (preg_match($param_url, $objects[3][$i], $matches) || preg_match($link_url, $objects[3][$i], $matches)) {\r
+                                       $url = $matches[3];\r
                                }\r
 \r
                                if ($url) {\r
-                                       $txt = trim(strip_tags($objects[1][$i]));\r
+                                       $txt = preg_replace("/$tagopen.*?$tagclose/", '', $objects[3][$i]);\r
 \r
                                        // if url is in the query string, remove the leading characters\r
                                        $url = preg_replace('/^[^?]*\?([^=]+=[^&]*&)*[^=]+=([^&]*)$/', '$2', $url, 1);\r