diff --git a/lib/filterlib.php b/lib/filterlib.php index 926c5b9b304..fcf037a26b3 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -220,6 +220,10 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc $text = str_replace(array_keys($ignoretags),$ignoretags,$text); } +/// Add missing javascript for popus + $text = filter_add_javascript($text); + + return $text; } @@ -302,4 +306,40 @@ function filter_save_tags(&$text,&$tags) { } } +/** + * Add missing openpopup javascript to HTML files. + */ +function filter_add_javascript($text) { + global $CFG; + + if (stripos($text, '') === FALSE) { + return $text; // this is not a html file + } + if (strpos($text, 'onclick="return openpopup') === FALSE) { + return $text; // no popup - no need to add javascript + } + $js =" + "; + if (stripos($text, '') !== FALSE) { + //try to add it into the head element + $text = str_ireplace('', $js.'', $text); + return $text; + } + + //last chance - try adding head element + return preg_replace("//is", "\\0".$js.'', $text); +} ?>