From: toyomoyo Date: Fri, 17 Aug 2007 04:57:52 +0000 (+0000) Subject: merged fix for MDL-10856, mp3 filter does not work for uploaded html files X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3ace5ee45666f9fff803936a7d7b8cad123dfa41;p=moodle.git merged fix for MDL-10856, mp3 filter does not work for uploaded html files --- diff --git a/lib/filelib.php b/lib/filelib.php index 55154261cd..e9f199a491 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -383,6 +383,8 @@ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring= $options->noclean = true; $options->nocache = true; // temporary workaround for MDL-5136 $text = $pathisstring ? $path : implode('', file($path)); + + $text = file_modify_html_header($text); $output = format_text($text, FORMAT_HTML, $options, $COURSE->id); if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) { //cookieless mode - rewrite links @@ -646,4 +648,56 @@ function byteserving_send_file($filename, $mimetype, $ranges) { } } +/** + * add includes (js and css) into uploaded files + * before returning them, useful for themes and utf.js includes + * @param string text - text to search and replace + * @return string - text with added head includes + */ +function file_modify_html_header($text) { + // first look for tag + global $CFG; + + $stylesheetshtml = ''; + foreach ($CFG->stylesheets as $stylesheet) { + $stylesheetshtml .= ''."\n"; + } + + $filters = explode(",", $CFG->textfilters); + if (in_array('filter/mediaplugin', $filters)) { + // this script is needed by most media filter plugins. + $ufo = "\n".''."\n"; + } else { + $ufo = ''; + } + + preg_match('/\|\/', $text, $matches); + if ($matches) { + $replacement = ''.$ufo.$stylesheetshtml; + $text = preg_replace('/\|\/', $replacement, $text, 1); + return $text; + } + + // if not, look for tag, and stick right after + preg_match('/\|\/', $text, $matches); + if ($matches) { + // replace tag with includes + $replacement = '."\n".'.$ufo.$stylesheetshtml.''; + $text = preg_replace('/\|\/', $replacement, $text, 1); + return $text; + } + + // if not, look for tag, and stick before body + preg_match('/\|\/', $text, $matches); + if ($matches) { + $replacement = ''.$ufo.$stylesheetshtml.'."\n".'; + $text = preg_replace('/\|\/', $replacement, $text, 1); + return $text; + } + + // if not, just stick a tag at the beginning + $text = ''.$ufo.$stylesheetshtml.''."\n".$text; + return $text; +} + ?>