MDL-21119 lang menu and login info now handled by themes

This commit is contained in:
Petr Skoda 2009-12-29 17:26:29 +00:00
parent 684b988c94
commit 244a32c617
26 changed files with 155 additions and 187 deletions

View file

@ -21,17 +21,6 @@ httpsrequired();
/// Define variables used in page
$site = get_site();
if (empty($CFG->langmenu)) {
$langmenu = "";
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language')));
$langmenu = '<div class="langmenu">'.$OUTPUT->select($select).'</div>';
}
$loginsite = get_string("loginsite");
$loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : '';
@ -82,7 +71,6 @@ httpsrequired();
$PAGE->set_title("$site->fullname: $loginsite");
$PAGE->set_heading($site->fullname);
$PAGE->set_focuscontrol('idp');
$PAGE->set_headingmenu($langmenu);
echo $OUTPUT->header();
include("index_form.html");

View file

@ -95,7 +95,6 @@ $PAGE->navbar->add($strcalendar, $viewcalendarurl);
$PAGE->navbar->add($title);
$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
$PAGE->set_heading($strcalendar);
$PAGE->set_headingmenu(user_login_string($site));
echo $OUTPUT->header();
echo $OUTPUT->box_start('eventlist');

View file

@ -207,7 +207,6 @@ $PAGE->navbar->add($strcalendar, $link);
$PAGE->navbar->add($title);
$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
$PAGE->set_heading($strcalendar);
$PAGE->set_headingmenu(user_login_string($site));
echo $OUTPUT->header();

View file

@ -133,7 +133,6 @@ $PAGE->navbar->add($pagetitle);
$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$pagetitle);
$PAGE->set_heading($strcalendar);
$PAGE->set_headingmenu(user_login_string($site));
$PAGE->set_button($prefsbutton);
$PAGE->set_focuscontrol('eventform.name');

View file

@ -68,7 +68,6 @@ $PAGE->navbar->add($strpreferences, new moodle_url($CFG->wwwroot.'/calendar/view
$PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
$PAGE->set_heading($strcalendar);
$PAGE->set_headingmenu(user_login_string($site));
echo $OUTPUT->header();

View file

@ -152,7 +152,6 @@ $prefsbutton = calendar_preferences_button();
// Print title and header
$PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
$PAGE->set_heading($strcalendar);
$PAGE->set_headingmenu(user_login_string($site));
$PAGE->set_button($prefsbutton);
$PAGE->requires->yui2_lib('animation');

View file

@ -38,7 +38,6 @@
$PAGE->set_heading('Course info');
$PAGE->set_course($course);
$PAGE->navbar->add(get_string('summary'));
$PAGE->set_headingmenu(user_login_string());
echo $OUTPUT->header();
echo $OUTPUT->heading('<a href="view.php?id='.$course->id.'">'.format_string($course->fullname) . '</a><br />(' . format_string($course->shortname) . ')');

View file

@ -198,8 +198,6 @@
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
$PAGE->set_button($buttons);
//TODO: MDL-21123 this should be done in course page layout, not here with this ugly hack!
//$PAGE->set_headingmenu(user_login_string($course, $USER));
echo $OUTPUT->header();
if ($completion->is_enabled() && ajaxenabled()) {

View file

@ -123,7 +123,6 @@ $PAGE->navbar->add($straddgroupstogroupings);
/// Print header
$PAGE->set_title("$course->shortname: $strgroups");
$PAGE->set_heading($course->fullname);
$PAGE->set_headingmenu(user_login_string($course, $USER));
echo $OUTPUT->header();
?>

View file

@ -85,7 +85,6 @@ $PAGE->navbar->add($stradduserstogroup);
/// Print header
$PAGE->set_title("$course->shortname: $strgroups");
$PAGE->set_heading($course->fullname);
$PAGE->set_headingmenu(user_login_string($course, $USER));
echo $OUTPUT->header();
?>

View file

@ -69,18 +69,6 @@
$PAGE->set_pagetype('site-index');
$PAGE->set_course($SITE);
if (empty($CFG->langmenu)) {
$langmenu = '';
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$select = html_select::make_popup_form($CFG->wwwroot .'/index.php', 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language')));
//TODO: MDL-21123
$langmenu = '<div class="langmenu">'.$OUTPUT->select($select).'</div>';
}
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
$PAGE->set_url('');
$PAGE->set_docs_path('');
@ -88,8 +76,7 @@
$editing = $PAGE->user_is_editing();
$PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_headingmenu($langmenu);
echo $OUTPUT->header($langmenu);
echo $OUTPUT->header();
/// Print Section
if ($SITE->numsections > 0) {

View file

@ -2169,6 +2169,23 @@ function print_footer($course = NULL, $usercourse = NULL, $return = false) {
}
}
/**
* Returns text to be displayed to the user which reflects their login status
*
* @global object
* @global object
* @global object
* @global object
* @uses CONTEXT_COURSE
* @param course $course {@link $COURSE} object containing course information
* @param user $user {@link $USER} object containing user information
* @return string HTML
*/
function user_login_string($course='ignored', $user='ignored') {
debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
return '';
}
/**
* Prints a nice side block with an optional header. The content can either
* be a block of HTML or a list of text with optional icons.

View file

@ -556,10 +556,6 @@ class html_select extends labelled_html_component {
$selectedurl = $baseurl->out(false, array($name => $selected), false);
}
if (!($baseurl instanceof moodle_url)) {
$baseurl = new moodle_url($baseurl);
}
// Replace real value by formatted URLs
foreach ($options as $value => $label) {
$options[$baseurl->out(false, array($name => $value), false)] = $label;

View file

@ -458,8 +458,80 @@ class core_renderer extends renderer_base {
* @return string HTML fragment.
*/
public function login_info() {
global $USER;
return user_login_string($this->page->course, $USER);
global $USER, $CFG, $DB;
if (during_initial_install()) {
return '';
}
$course = $this->page->course;
if (session_is_loggedinas()) {
$realuser = session_get_realuser();
$fullname = fullname($realuser, true);
$realuserinfo = " [<a $CFG->frametarget
href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
} else {
$realuserinfo = '';
}
$loginurl = get_login_url();
if (empty($course->id)) {
// $course->id is not defined during installation
return '';
} else if (!empty($USER->id)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$fullname = fullname($USER, true);
$username = "<a $CFG->frametarget href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a>";
if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
$username .= " from <a $CFG->frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
}
if (isset($USER->username) && $USER->username == 'guest') {
$loggedinas = $realuserinfo.get_string('loggedinasguest').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
} else if (!empty($USER->access['rsw'][$context->path])) {
$rolename = '';
if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
$rolename = ': '.format_string($role->name);
}
$loggedinas = get_string('loggedinas', 'moodle', $username).$rolename.
" (<a $CFG->frametarget
href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
} else {
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
}
} else {
$loggedinas = get_string('loggedinnot', 'moodle').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
}
$loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
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)) {
$loggedinas .= '&nbsp;<div class="loginfailures">';
if (empty($count->accounts)) {
$loggedinas .= get_string('failedloginattempts', '', $count);
} else {
$loggedinas .= get_string('failedloginattemptsall', '', $count);
}
if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) {
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php'.
'?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
}
}
}
}
return $loggedinas;
}
/**
@ -668,6 +740,35 @@ class core_renderer extends renderer_base {
return $this->opencontainers->pop_all_but_last($shouldbenone);
}
/**
* Returns lang menu or '', this method also checks forcing of languages in courses.
* @return string
*/
public function lang_menu() {
global $CFG;
if (empty($CFG->langmenu)) {
return '';
}
if ($this->page->course != SITEID and !empty($this->page->course->lang)) {
// do not show lang menu if language forced
return '';
}
$currlang = current_language();
$langs = get_list_of_languages();
if (count($langs) < 2) {
return '';
}
$select = html_select::make_popup_form($this->page->url, 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language')));
return '<div class="langmenu">'.$this->select($select).'</div>';
}
/**
* Output the row of editing icons for a block, as defined by the controls array.
* @param array $controls an array like {@link block_contents::$controls}.
@ -1028,7 +1129,7 @@ class core_renderer extends renderer_base {
* @param moodle_action_icon $icon A moodle_action_icon object
* @return string HTML fragment
*/
public function action_icon($icon) {
public function action_icon(moodle_action_icon $icon) {
$icon = clone($icon);
$icon->prepare($this, $this->page, $this->target);
$imageoutput = $this->image($icon->image);

View file

@ -498,6 +498,7 @@ class moodle_url {
$uri .= $this->host ? $this->host : '';
$uri .= $this->port ? ':'.$this->port : '';
$uri .= $this->path ? $this->path : '';
if (!$omitquerystring) {
$querystring = $this->get_query_string($overrideparams, $escaped);
if ($querystring) {
@ -1906,101 +1907,6 @@ function send_headers($contenttype, $cacheable = true) {
@header('Accept-Ranges: none');
}
/**
* Returns text to be displayed to the user which reflects their login status
*
* @global object
* @global object
* @global object
* @global object
* @uses CONTEXT_COURSE
* @param course $course {@link $COURSE} object containing course information
* @param user $user {@link $USER} object containing user information
* @return string HTML
*/
function user_login_string($course=NULL, $user=NULL) {
global $USER, $CFG, $SITE, $DB;
if (during_initial_install()) {
return '';
}
if (empty($user) and !empty($USER->id)) {
$user = $USER;
}
if (empty($course)) {
$course = $SITE;
}
if (session_is_loggedinas()) {
$realuser = session_get_realuser();
$fullname = fullname($realuser, true);
$realuserinfo = " [<a $CFG->frametarget
href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
} else {
$realuserinfo = '';
}
$loginurl = get_login_url();
if (empty($course->id)) {
// $course->id is not defined during installation
return '';
} else if (!empty($user->id)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$fullname = fullname($user, true);
$username = "<a $CFG->frametarget href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a>";
if (is_mnet_remote_user($user) and $idprovider = $DB->get_record('mnet_host', array('id'=>$user->mnethostid))) {
$username .= " from <a $CFG->frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
}
if (isset($user->username) && $user->username == 'guest') {
$loggedinas = $realuserinfo.get_string('loggedinasguest').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
} else if (!empty($user->access['rsw'][$context->path])) {
$rolename = '';
if ($role = $DB->get_record('role', array('id'=>$user->access['rsw'][$context->path]))) {
$rolename = ': '.format_string($role->name);
}
$loggedinas = get_string('loggedinas', 'moodle', $username).$rolename.
" (<a $CFG->frametarget
href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
} else {
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
}
} else {
$loggedinas = get_string('loggedinnot', 'moodle').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
}
$loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
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)) {
$loggedinas .= '&nbsp;<div class="loginfailures">';
if (empty($count->accounts)) {
$loggedinas .= get_string('failedloginattempts', '', $count);
} else {
$loggedinas .= get_string('failedloginattemptsall', '', $count);
}
if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) {
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php'.
'?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
}
}
}
}
return $loggedinas;
}
/**
* Return the right arrow with text ('next'), and optionally embedded in a link.
*

View file

@ -61,20 +61,10 @@ httpsrequired();
$PAGE->set_url("$CFG->httpswwwroot/login/index.php");
/// Define variables used in page
$site = get_site();
if (empty($CFG->langmenu)) {
$langmenu = "";
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language')));
$langmenu = $OUTPUT->select($select);
}
$loginsite = get_string("loginsite");
$PAGE->navbar->add($loginsite);
@ -221,7 +211,6 @@ if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) { /
$days2expire = $userauth->password_expire($USER->username);
$PAGE->set_title("$site->fullname: $loginsite");
$PAGE->set_heading("$site->fullname");
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>");
if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
@ -325,7 +314,6 @@ if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_i
$PAGE->set_title("$site->fullname: $loginsite");
$PAGE->set_heading("$site->fullname");
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>");
$PAGE->set_focuscontrol($focus);
echo $OUTPUT->header();

View file

@ -69,23 +69,12 @@ if ($mform_signup->is_cancelled()) {
$newaccount = get_string('newaccount');
$login = get_string('login');
if (empty($CFG->langmenu)) {
$langmenu = '';
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$select = html_select::make_popup_form("$CFG->wwwroot/login/signup.php", 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$langmenu = $OUTPUT->select($select);
}
$PAGE->navbar->add($login);
$PAGE->navbar->add($newaccount);
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/signup.php'));
$PAGE->set_title($newaccount);
$PAGE->set_heading($newaccount);
$PAGE->set_focuscontrol($mform_signup->focus());
$PAGE->set_headingmenu("<div class=\"langmenu\">$langmenu</div>");
echo $OUTPUT->header();
$mform_signup->display();

View file

@ -48,12 +48,10 @@
$heading = $course->fullname;
$button = '<div style="font-size:0.75em;">'.$button.'</div>';
$loggedinas = '<span class="logininfo">'.user_login_string($course, $USER).'</span>';
$PAGE->set_title($title);
$PAGE->set_heading($heading);
$PAGE->set_button($button);
$PAGE->set_headingmenu($loggedinas);
$time = time();
$hppassword = optional_param('hppassword', '', PARAM_RAW);

View file

@ -44,23 +44,10 @@
$header = $SITE->shortname . ': ' . $strmymoodle;
$PAGE->navbar->add($strmymoodle);
$loggedinas = user_login_string();
if (empty($CFG->langmenu)) {
$langmenu = '';
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$select = html_select::make_popup_form($CFG->wwwroot .'/my/index.php', 'lang', $langs, 'chooselang', $currlang);
$select->nothinglabel = false;
$select->set_label(get_accesshide(get_string('language')));
$langmenu = $OUTPUT->select($select);
}
$PAGE->set_title($strmymoodle);
$PAGE->set_heading($header);
$PAGE->set_button($button);
$PAGE->set_headingmenu($loggedinas . $langmenu);
echo $OUTPUT->header();
/// The main overview in the middle of the page

View file

@ -66,6 +66,7 @@ $THEME->layouts = array(
'file' => 'general.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post',
'options' => array('langmenu'=>true),
),
'coursecategory' => array(
'theme' => 'base',
@ -100,6 +101,7 @@ $THEME->layouts = array(
'file' => 'general.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post',
'options' => array('langmenu'=>true),
),
// My public page
'mypublic' => array(
@ -112,6 +114,7 @@ $THEME->layouts = array(
'theme' => 'base',
'file' => 'general.php',
'regions' => array(),
'options' => array('langmenu'=>true),
),
// Pages that appear in pop-up windows - no navigation, no blocks, no header.

View file

@ -24,11 +24,9 @@ echo $OUTPUT->doctype() ?>
<div id="header-home" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php
if ($PAGE->headingmenu) {
echo $PAGE->headingmenu;
} else {
echo $OUTPUT->login_info();
}
echo $OUTPUT->lang_menu();
echo $PAGE->headingmenu;
?></div>
</div>
<!-- END OF HEADER -->

View file

@ -23,7 +23,13 @@ echo $OUTPUT->doctype() ?>
<?php if ($PAGE->heading) { ?>
<div id="header" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php echo $PAGE->headingmenu ?></div>
<div class="headermenu"><?php
echo $OUTPUT->login_info();
if (!empty($PAGE->layout_options['langmenu'])) {
echo $OUTPUT->lang_menu();
}
echo $PAGE->headingmenu
?></div>
</div>
<?php } ?>

View file

@ -97,6 +97,7 @@ $THEME->layouts = array(
'file' => 'normal.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post',
'options' => array('langmenu'=>true),
),
'coursecategory' => array(
'theme' => 'base',
@ -131,6 +132,7 @@ $THEME->layouts = array(
'file' => 'normal.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post',
'options' => array('langmenu'=>true),
),
// My public page
'mypublic' => array(
@ -143,6 +145,7 @@ $THEME->layouts = array(
'theme' => 'standard',
'file' => 'normal.php',
'regions' => array(),
'options' => array('langmenu'=>true),
),
// Pages that appear in pop-up windows - no navigation, no blocks, no header.

View file

@ -13,7 +13,13 @@
<?php if ($PAGE->heading) { ?>
<div id="header" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php echo $PAGE->headingmenu ?></div>
<div class="headermenu"><?php
echo $OUTPUT->login_info();
if (!empty($PAGE->layout_options['langmenu'])) {
echo $OUTPUT->lang_menu();
}
echo $PAGE->headingmenu
?></div>
</div>
<?php } ?>

View file

@ -14,10 +14,9 @@
<div id="header-home" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php
echo $OUTPUT->login_info();
if ($PAGE->headingmenu) {
echo $OUTPUT->login_info();
echo $OUTPUT->lang_menu();
echo $PAGE->headingmenu;
}
?></div>
</div>
<hr />

View file

@ -13,7 +13,13 @@
<?php if ($PAGE->heading) { ?>
<div id="header" class="clearfix">
<h1 class="headermain"><?php echo $PAGE->heading ?></h1>
<div class="headermenu"><?php echo $PAGE->headingmenu ?></div>
<div class="headermenu"><?php
echo $OUTPUT->login_info();
if (!empty($PAGE->layout_options['langmenu'])) {
echo $OUTPUT->lang_menu();
}
echo $PAGE->headingmenu
?></div>
</div>
<?php } ?>