Beispiel #1
0
/**
 * add includes (js and css) into uploaded files
 * before returning them, useful for themes and utf.js includes
 *
 * @global object
 * @param string $text text to search and replace
 * @return string text with added head includes
 */
function file_modify_html_header($text)
{
    // first look for <head> tag
    global $CFG;
    $stylesheetshtml = '';
    foreach ($CFG->stylesheets as $stylesheet) {
        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
    }
    $ufo = '';
    if (filter_is_enabled('filter/mediaplugin')) {
        // this script is needed by most media filter plugins.
        $ufo = ajax_get_link_to_script($CFG->wwwroot . '/lib/ufo.js');
    }
    preg_match('/\\<head\\>|\\<HEAD\\>/', $text, $matches);
    if ($matches) {
        $replacement = '<head>' . $ufo . $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>' . $ufo . $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>' . $ufo . $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>' . $ufo . $stylesheetshtml . '</head>' . "\n" . $text;
    return $text;
}
Beispiel #2
0
 public function get_html()
 {
     return ajax_get_link_to_script($this->url);
 }