From 964c571975c3593aea096b05512dc502e624ba17 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 1 Oct 2009 10:12:29 +0000 Subject: [PATCH] question import/export: MDL-20299 fix regression I introduced yesterday in hotpot import/export --- question/format/hotpot/format.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/question/format/hotpot/format.php b/question/format/hotpot/format.php index 0ac6e6b216..68d9afb2b2 100644 --- a/question/format/hotpot/format.php +++ b/question/format/hotpot/format.php @@ -508,3 +508,29 @@ class qformat_hotpot extends qformat_default { return $str; } } // end class + +function hotpot_convert_relative_urls($str, $baseurl, $filename) { + $tagopen = '(?:(<)|(<)|(&#x003C;))'; // left angle bracket + $tagclose = '(?(2)>|(?(3)>|(?(4)&#x003E;)))'; // right angle bracket (to match left angle bracket) + + $space = '\s+'; // at least one space + $anychar = '(?:[^>]*?)'; // any character + + $quoteopen = '("|"|&quot;)'; // open quote + $quoteclose = '\\5'; // close quote (to match open quote) + + $replace = "hotpot_convert_relative_url('".$baseurl."', '".$filename."', '\\1', '\\6', '\\7')"; + + $tags = array('script'=>'src', 'link'=>'href', 'a'=>'href','img'=>'src','param'=>'value', 'object'=>'data', 'embed'=>'src'); + foreach ($tags as $tag=>$attribute) { + if ($tag=='param') { + $url = '\S+?\.\S+?'; // must include a filename and have no spaces + } else { + $url = '.*?'; + } + $search = "%($tagopen$tag$space$anychar$attribute=$quoteopen)($url)($quoteclose$anychar$tagclose)%ise"; + $str = preg_replace($search, $replace, $str); + } + + return $str; +} -- 2.39.5