예제 #1
0
/**
 * Print a standard header
 *
 * @uses $USER
 * @uses $CFG
 * @uses $SESSION
 * @param string  $title Appears at the top of the window
 * @param string  $heading Appears at the top of the page
 * @param array   $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
 * @param string  $focus Indicates form element to get cursor focus on load eg  inputform.password
 * @param string  $meta Meta tags to be added to the header
 * @param boolean $cache Should this page be cacheable?
 * @param string  $button HTML code for a button (usually for module editing)
 * @param string  $menu HTML code for a popup menu
 * @param boolean $usexml use XML for this page
 * @param string  $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
 * @param bool    $return If true, return the visible elements of the header instead of echoing them.
 */
function print_header($title = '', $heading = '', $navigation = '', $focus = '', $meta = '', $cache = true, $button = '&nbsp;', $menu = '', $usexml = false, $bodytags = '', $return = false)
{
    global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE, $PAGE;
    if (gettype($navigation) == 'string' && strlen($navigation) != 0 && $navigation != 'home') {
        debugging("print_header() was sent a string as 3rd ({$navigation}) parameter. " . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code.", DEBUG_DEVELOPER);
    }
    $PAGE->set_state(moodle_page::STATE_PRINTING_HEADER);
    $heading = format_string($heading);
    // Fix for MDL-8582
    if (CLI_SCRIPT) {
        $output = $heading;
        if ($return) {
            return $output;
        } else {
            console_write($output . "\n", '', false);
            return;
        }
    }
    /// Add the required stylesheets
    $stylesheetshtml = '';
    foreach ($CFG->stylesheets as $stylesheet) {
        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
    }
    $meta = $stylesheetshtml . $meta;
    /// Add the meta page from the themes if any were requested
    $metapage = '';
    if (!isset($THEME->standardmetainclude) || $THEME->standardmetainclude) {
        ob_start();
        include_once $CFG->dirroot . '/theme/standard/meta.php';
        $metapage .= ob_get_contents();
        ob_end_clean();
    }
    if ($THEME->parent && (!isset($THEME->parentmetainclude) || $THEME->parentmetainclude)) {
        if (file_exists($CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    if (!isset($THEME->metainclude) || $THEME->metainclude) {
        if (file_exists($CFG->dirroot . '/theme/' . current_theme() . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . current_theme() . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    $meta = $meta . "\n" . $metapage;
    $meta .= "\n" . require_js('', 1);
    $meta .= standard_js_config();
    /// Set up some navigation variables
    if (is_newnav($navigation)) {
        $home = false;
    } else {
        if ($navigation == 'home') {
            $home = true;
            $navigation = '';
        } else {
            $home = false;
        }
    }
    /// This is another ugly hack to make navigation elements available to print_footer later
    $THEME->title = $title;
    $THEME->heading = $heading;
    $THEME->navigation = $navigation;
    $THEME->button = $button;
    $THEME->menu = $menu;
    $navmenulist = isset($THEME->navmenulist) ? $THEME->navmenulist : '';
    if ($button == '') {
        $button = '&nbsp;';
    }
    if (file_exists($CFG->dataroot . '/' . SITEID . '/maintenance.html')) {
        $button = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/maintenance.php">' . get_string('maintenancemode', 'admin') . '</a> ' . $button;
        if (!empty($title)) {
            $title .= ' - ';
        }
        $title .= get_string('maintenancemode', 'admin');
    }
    if (!$menu and $navigation) {
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
            $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
        }
        $menu = user_login_string($COURSE);
    }
    if (isset($SESSION->justloggedin)) {
        unset($SESSION->justloggedin);
        if (!empty($CFG->displayloginfailures)) {
            if (!empty($USER->username) and $USER->username != 'guest') {
                if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                    $menu .= '&nbsp;<font size="1">';
                    if (empty($count->accounts)) {
                        $menu .= get_string('failedloginattempts', '', $count);
                    } else {
                        $menu .= get_string('failedloginattemptsall', '', $count);
                    }
                    if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) {
                        $menu .= ' (<a href="' . $CFG->wwwroot . '/course/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                    }
                    $menu .= '</font>';
                }
            }
        }
    }
    $meta = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n" . $meta . "\n";
    if (!$usexml) {
        @header('Content-Type: text/html; charset=utf-8');
    }
    @header('Content-Script-Type: text/javascript');
    @header('Content-Style-Type: text/css');
    //Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
    $direction = get_html_lang($dir = true);
    if ($cache) {
        // Allow caching on "back" (but not on normal clicks)
        @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
        @header('Pragma: no-cache');
        @header('Expires: ');
    } else {
        // Do everything we can to always prevent clients and proxies caching
        @header('Cache-Control: no-store, no-cache, must-revalidate');
        @header('Cache-Control: post-check=0, pre-check=0', false);
        @header('Pragma: no-cache');
        @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
        @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        $meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
        $meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
    }
    @header('Accept-Ranges: none');
    $currentlanguage = current_language();
    if (empty($usexml)) {
        $direction = ' xmlns="http://www.w3.org/1999/xhtml"' . $direction;
        // See debug_header
    } else {
        $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
        if (!$mathplayer) {
            header('Content-Type: application/xhtml+xml');
        }
        echo '<?xml version="1.0" ?>' . "\n";
        if (!empty($CFG->xml_stylesheets)) {
            $stylesheets = explode(';', $CFG->xml_stylesheets);
            foreach ($stylesheets as $stylesheet) {
                echo '<?xml-stylesheet type="text/xsl" href="' . $CFG->wwwroot . '/' . $stylesheet . '" ?>' . "\n";
            }
        }
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
        if (!empty($CFG->xml_doctype_extra)) {
            echo ' plus ' . $CFG->xml_doctype_extra;
        }
        echo '//' . strtoupper($currentlanguage) . '" "' . $CFG->xml_dtd . '">' . "\n";
        $direction = " xmlns=\"http://www.w3.org/1999/xhtml\"\n                       xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n                       xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n                       {$direction}";
        if ($mathplayer) {
            $meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
            $meta .= '<!--comment required to prevent this becoming an empty tag-->' . "\n";
            $meta .= '</object>' . "\n";
            $meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
        }
    }
    // Clean up the title
    $title = format_string($title);
    // fix for MDL-8582
    $title = str_replace('"', '&quot;', $title);
    // Create class and id for this page
    $pageid = $PAGE->pagetype;
    $pageclass = $PAGE->bodyclasses;
    $bodytags .= ' class="' . $pageclass . '" id="' . $pageid . '"';
    require_once $CFG->libdir . '/editor/htmlEditor.class.php';
    $htmlEditorObject = new htmlEditor();
    $htmlEditor = $htmlEditorObject->configure(NULL, $COURSE->id);
    ob_start();
    include $CFG->header;
    $output = ob_get_contents();
    ob_end_clean();
    // container debugging info
    $THEME->open_header_containers = open_containers();
    // Skip to main content, see skip_main_destination().
    if ($pageid == 'course-view' or $pageid == 'site-index' or $pageid == 'course-index') {
        $skiplink = '<a class="skip" href="#maincontent">' . get_string('tocontent', 'access') . '</a>';
        if (!preg_match('/(.*<div[^>]+id="page"[^>]*>)(.*)/s', $output, $matches)) {
            preg_match('/(.*<body.*?>)(.*)/s', $output, $matches);
        }
        $output = $matches[1] . "\n" . $skiplink . $matches[2];
    }
    $output = force_strict_header($output);
    if (!empty($CFG->messaging)) {
        $output .= message_popup_window();
    }
    // Add in any extra JavaScript libraries that occurred during the header
    $output .= require_js('', 2);
    $output .= print_js_call('moodle_initialise_body', array(), true);
    $PAGE->set_state(moodle_page::STATE_IN_BODY);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
예제 #2
0
파일: send.php 프로젝트: nadavkav/MoodleTAO
     $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />';
 }
 /// Select direction
 if (get_string('thisdirection') == 'rtl') {
     $direction = ' dir="rtl"';
 } else {
     $direction = ' dir="ltr"';
 }
 @header('Content-Type: text/html; charset=utf-8');
 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
 echo "<html {$direction} xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n";
 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
 echo $stylesheetshtml;
 include $CFG->javascript;
 require_once $CFG->libdir . '/editor/htmlEditor.class.php';
 $htmlEditorObject = new htmlEditor();
 echo $htmlEditorObject->configure();
 echo '<title> </title></head>';
 /// Script parameters
 $userid = required_param('id', PARAM_INT);
 $message = optional_param('message', '', PARAM_CLEANHTML);
 $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
 /// Check the user we are talking to is valid
 if (!($user = get_record('user', 'id', $userid))) {
     error("User ID was incorrect");
 }
 /// Check that the user is not blocking us!!
 if ($contact = get_record('message_contacts', 'userid', $user->id, 'contactid', $USER->id)) {
     if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
         print_heading(get_string('userisblockingyou', 'message'));
         exit;