diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index f8b815c49a8..36d90270333 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -1504,18 +1504,18 @@ class hotpot_xml_tree { // remove white space between , and parts // (so it doesn't get converted to
) $htmltags = '(' - . 'TABLE|/?CAPTION|/?COL|/?COLGROUP|/?TBODY|/?TFOOT|/?THEAD|/?TD|/?TH|/?TR' - . '|OL|UL|/?LI' - . '|DL|/?DT|/?DD' - . '|EMBED|OBJECT|APPLET|/?PARAM' - //. '|SELECT|/?OPTION' - //. '|FIELDSET|/?LEGEND' - //. '|FRAMESET|/?FRAME' + . 'TABLE|\\/?CAPTION|\\/?COL|\\/?COLGROUP|\\/?TBODY|\\/?TFOOT|\\/?THEAD|\\/?TD|\\/?TH|\\/?TR' + . '|OL|UL|\\/?LI' + . '|DL|\\/?DT|\\/?DD' + . '|EMBED|OBJECT|APPLET|\\/?PARAM' + //. '|SELECT|\\/?OPTION' + //. '|FIELDSET|\\/?LEGEND' + //. '|FRAMESET|\\/?FRAME' . ')' ; - $space = '(\s|(]*>))+'; - $search = '#(<'.$htmltags.'[^>]*'.'>)'.$space.'(?='.'<)#is'; + $space = '(?:\s|(?:]*>))+'; + $search = '/(<'.$htmltags.'[^>]*'.'>)'.$space.'(?='.'<)/is'; $value = preg_replace($search, '\\1', $value); // replace remaining newlines with
@@ -1532,11 +1532,14 @@ class hotpot_xml_tree { // F0 - FF : 1st byte of 4-byte char // if the string doesn't match the above, it might be // 80 - FF : single-byte, non-ascii char - $search = '#('.'[\xc0-\xdf][\x80-\xbf]'.'|'.'[\xe0-\xef][\x80-\xbf]{2}'.'|'.'[\xf0-\xff][\x80-\xbf]{3}'.'|'.'[\x80-\xff]'.')#se'; - $value = preg_replace($search, "hotpot_utf8_to_html_entity('\\1')", $value); + $search = '/'.'[\xc0-\xdf][\x80-\xbf]'.'|'.'[\xe0-\xef][\x80-\xbf]{2}'.'|'.'[\xf0-\xff][\x80-\xbf]{3}'.'|'.'[\x80-\xff]'.'/'; + $value = preg_replace_callback($search, array(&$this, 'xml_value_callback'), $value); } return $value; } + function xml_value_callback(&$matches) { + return hotpot_utf8_to_html_entity($matches[0]); + } function xml_values($tags) { $i = 0; $values = array(); @@ -1550,14 +1553,6 @@ class hotpot_xml_tree { } function encode_cdata(&$str, $tag) { - // conversion tables - static $HTML_ENTITIES = array( - ''' => "'", - '"' => '"', - '<' => '<', - '>' => '>', - '&' => '&', - ); static $ILLEGAL_STRINGS = array( "\r\n" => '<br />', "\r" => '<br />', @@ -1576,13 +1571,22 @@ class hotpot_xml_tree { // if there are any ampersands in "open text" // surround them by CDATA start and end markers // (and convert HTML entities to plain text) - $search = '/>([^<]*&[^<]*) "'", + '"' => '"', + '<' => '<', + '>' => '>', + '&' => '&', + ); + return ''; + } } class hotpot_xml_quiz extends hotpot_xml_tree { @@ -1680,31 +1684,26 @@ class hotpot_xml_quiz extends hotpot_xml_tree { $this->html = &$this->source; // relative URLs in stylesheets - $search = '|'.'(]*>)'.'(.*?)'.'()'.'|ise'; - $replace = "hotpot_stripslashes('\\1').hotpot_convert_stylesheets_urls('".$this->get_baseurl()."','".$this->reference."','\\2'.'\\3')"; - $this->source = preg_replace($search, $replace, $this->source); + $search = '/'.'(]*>)'.'(.*?)'.'(<\/style>)'.'/is'; + $this->source = preg_replace_callback($search, array(&$this, 'callback_stylesheets_urls'), $this->source); // relative URLs in "PreloadImages(...);" - $search = '|'.'(?<='.'PreloadImages'.'\('.')'."([^)]+?)".'(?='.'\);'.')'.'|se'; - $replace = "hotpot_convert_preloadimages_urls('".$this->get_baseurl()."','".$this->reference."','\\1')"; - $this->source = preg_replace($search, $replace, $this->source); + $search = '/'.'(?<='.'PreloadImages'.'\('.')'."([^)]+?)".'(?='.'\);'.')'.'/is'; + $this->source = preg_replace_callback($search, array(&$this, 'callback_preloadimages_urls'), $this->source); // relative URLs in