mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-21119 lang menu and login info now handled by themes
This commit is contained in:
parent
684b988c94
commit
244a32c617
26 changed files with 155 additions and 187 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&return=1&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&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&switchrole=0&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 .= ' <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&id=1&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);
|
||||
|
|
|
@ -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&return=1&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&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&switchrole=0&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 .= ' <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&id=1&modid=site_errors">'.get_string('logs').'</a>)';
|
||||
}
|
||||
$loggedinas .= '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $loggedinas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the right arrow with text ('next'), and optionally embedded in a link.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue