$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);
readstring_accel($output, $mimetype, false);
$options->noclean = true;
$options->nocache = true; // temporary workaround for MDL-5136
$text = $stored_file->get_content();
- $text = file_modify_html_header($text);
$output = format_text($text, FORMAT_HTML, $options, $COURSE->id);
readstring_accel($output, $mimetype, false);
}
}
-/**
- * add includes (js and css) into uploaded files
- * before returning them, useful for themes and utf.js includes
- *
- * @global stdClass $CFG
- * @param string $text text to search and replace
- * @return string text with added head includes
- * @todo MDL-21120
- */
-function file_modify_html_header($text) {
- // first look for <head> tag
- global $CFG;
-
- $stylesheetshtml = '';
-/*
- foreach ($CFG->stylesheets as $stylesheet) {
- //TODO: MDL-21120
- $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />'."\n";
- }
-*/
- // TODO The code below is actually a waste of CPU. When MDL-29738 will be implemented it should be re-evaluated too.
-
- preg_match('/\<head\>|\<HEAD\>/', $text, $matches);
- if ($matches) {
- $replacement = '<head>'.$stylesheetshtml;
- $text = preg_replace('/\<head\>|\<HEAD\>/', $replacement, $text, 1);
- return $text;
- }
-
- // if not, look for <html> tag, and stick <head> right after
- preg_match('/\<html\>|\<HTML\>/', $text, $matches);
- if ($matches) {
- // replace <html> tag with <html><head>includes</head>
- $replacement = '<html>'."\n".'<head>'.$stylesheetshtml.'</head>';
- $text = preg_replace('/\<html\>|\<HTML\>/', $replacement, $text, 1);
- return $text;
- }
-
- // if not, look for <body> tag, and stick <head> before body
- preg_match('/\<body\>|\<BODY\>/', $text, $matches);
- if ($matches) {
- $replacement = '<head>'.$stylesheetshtml.'</head>'."\n".'<body>';
- $text = preg_replace('/\<body\>|\<BODY\>/', $replacement, $text, 1);
- return $text;
- }
-
- // if not, just stick a <head> tag at the beginning
- $text = '<head>'.$stylesheetshtml.'</head>'."\n".$text;
- return $text;
-}
-
/**
* Tells whether the filename is executable.
*