mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
themes MDL-21489 Added support for a legacy theme used with old browsers. Thanks Brendan for the patch
Admin can now select a theme for modern browsers and old browsers, the user then sees the modern theme with modern browsers and legacy theme with old browsers. Currenlty IE6 (or less) are considered old browsers.
This commit is contained in:
parent
cdb34efc83
commit
ee8df661dc
@ -939,6 +939,8 @@ $string['lastyear'] = 'Last year';
|
||||
$string['latestlanguagepack'] = 'Check for latest language pack on moodle.org';
|
||||
$string['layouttable'] = 'Layout table';
|
||||
$string['leavetokeep'] = 'Leave blank to keep current password';
|
||||
$string['legacythemeinuse'] = 'This site is being displayed to you in compatibility mode because your browser is too old.';
|
||||
$string['legacythemesaved'] = 'New legacy theme saved';
|
||||
$string['license'] = 'License';
|
||||
$string['liketologin'] = 'Would you like to log in now with a full user account?';
|
||||
$string['list'] = 'List';
|
||||
@ -1708,6 +1710,8 @@ $string['uploadusers'] = 'Upload users';
|
||||
$string['url'] = 'URL';
|
||||
$string['used'] = 'Used';
|
||||
$string['usedinnplaces'] = 'Used in {$a} places';
|
||||
$string['useformaintheme'] = 'Use for modern browsers';
|
||||
$string['useforlegacytheme'] = 'Use for old browsers';
|
||||
$string['usemessageform'] = 'or use the form below to send a message to the selected students';
|
||||
$string['user'] = 'User';
|
||||
$string['userconfirmed'] = 'Confirmed {$a}';
|
||||
|
@ -347,6 +347,10 @@ class core_renderer extends renderer_base {
|
||||
// but some of the content won't be known until later, so we return a placeholder
|
||||
// for now. This will be replaced with the real content in {@link footer()}.
|
||||
$output = self::PERFORMANCE_INFO_TOKEN;
|
||||
if ($this->page->legacythemeinuse) {
|
||||
// The legacy theme is in use print the notification
|
||||
$output .= html_writer::tag('div', get_string('legacythemeinuse'), array('class'=>'legacythemeinuse'));
|
||||
}
|
||||
if (!empty($CFG->debugpageinfo)) {
|
||||
$output .= '<div class="performanceinfo">This page is: ' . $this->page->debug_summary() . '</div>';
|
||||
}
|
||||
|
@ -68,6 +68,7 @@
|
||||
* @property-read string $heading The main heading that should be displayed at the top of the <body>.
|
||||
* @property-read string $headingmenu The menu (or actions) to display in the heading
|
||||
* @property-read array $layout_options Returns arrays with options for layout file.
|
||||
* @property-read bool $legacythemeinuse Returns true if the legacy theme is being used.
|
||||
* @property-read navbar $navbar Returns the navbar object used to display the navbar
|
||||
* @property-read global_navigation $navigation Returns the global navigation structure
|
||||
* @property-read xml_container_stack $opencontainers Tracks XHTML tags on this page that have been opened but not closed.
|
||||
@ -205,6 +206,19 @@ class moodle_page {
|
||||
*/
|
||||
protected $_legacypageobject = null;
|
||||
|
||||
/**
|
||||
* Associative array of browser shortnames (as used by check_browser_version)
|
||||
* and their minimum required versions
|
||||
* @var array
|
||||
*/
|
||||
protected $_legacybrowsers = array('MSIE' => 6.0);
|
||||
|
||||
/**
|
||||
* Is set to true if the chosen legacy theme is in use. False by default.
|
||||
* @var bool
|
||||
*/
|
||||
protected $_legacythemeinuse = false;
|
||||
|
||||
/// Magic getter methods =============================================================
|
||||
/// Due to the __get magic below, you normally do not call these as $PAGE->magic_get_x
|
||||
/// methods, but instead use the $PAGE->x syntax.
|
||||
@ -493,6 +507,14 @@ class moodle_page {
|
||||
return $this->_theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Please do not call this method directly, use the ->legacythemeinuse syntax. {@link __get()}.
|
||||
* @return bool
|
||||
*/
|
||||
protected function magic_get_legacythemeinuse() {
|
||||
return ($this->_legacythemeinuse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Please do not call this method directly use the ->periodicrefreshdelay syntax
|
||||
* {@link __get()}
|
||||
@ -1168,13 +1190,34 @@ class moodle_page {
|
||||
case 'site':
|
||||
if ($mnetpeertheme) {
|
||||
return $mnetpeertheme;
|
||||
} else if(!empty($CFG->themelegacy) && $this->browser_is_outdated()) {
|
||||
$this->_legacythemeinuse = true;
|
||||
return $CFG->themelegacy;
|
||||
} else {
|
||||
return $CFG->theme;
|
||||
return $CFG->theme;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current browser should
|
||||
* default to the admin-selected legacy theme
|
||||
*
|
||||
* @return true if legacy theme should be used, otherwise false
|
||||
*
|
||||
*/
|
||||
protected function browser_is_outdated() {
|
||||
foreach($this->_legacybrowsers as $browser => $version) {
|
||||
// Check the browser is valid first then that its version is suitable
|
||||
if(check_browser_version($browser, '0') &&
|
||||
!check_browser_version($browser, $version)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ->pagetype from the script name. For example, if the script that was
|
||||
* run is mod/quiz/view.php, ->pagetype will be set to 'mod-quiz-view'.
|
||||
@ -1275,6 +1318,10 @@ class moodle_page {
|
||||
if (!empty($CFG->blocksdrag)) {
|
||||
$this->add_body_class('drag');
|
||||
}
|
||||
|
||||
if ($this->_legacythemeinuse) {
|
||||
$this->add_body_class('legacytheme');
|
||||
}
|
||||
}
|
||||
|
||||
protected function load_activity_record() {
|
||||
|
@ -23,6 +23,7 @@ require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$choose = optional_param('choose', '', PARAM_SAFEDIR);
|
||||
$chooselegacy = optional_param('chooselegacy', '', PARAM_SAFEDIR);
|
||||
$reset = optional_param('reset', 0, PARAM_BOOL);
|
||||
|
||||
admin_externalpage_setup('themeselector');
|
||||
@ -32,25 +33,26 @@ unset($SESSION->theme);
|
||||
if ($reset and confirm_sesskey()) {
|
||||
theme_reset_all_caches();
|
||||
|
||||
} else if ($choose and confirm_sesskey()) {
|
||||
// The user has chosen one theme from the list of all themes, show a
|
||||
// 'You have chosen a new theme' confirmation page.
|
||||
} else if (($choose || $chooselegacy) && confirm_sesskey()) {
|
||||
|
||||
$theme = theme_config::load($choose);
|
||||
$choose = $theme->name;
|
||||
|
||||
set_config('theme', $choose);
|
||||
if ($choose) {
|
||||
$chosentheme = $choose;
|
||||
$heading = get_string('themesaved');
|
||||
$config = 'theme';
|
||||
} else {
|
||||
$chosentheme = $chooselegacy;
|
||||
$heading = get_string('legacythemesaved');
|
||||
$config = 'themelegacy';
|
||||
}
|
||||
$theme = theme_config::load($chosentheme);
|
||||
set_config($config, $theme->name);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('themesaved'));
|
||||
|
||||
echo $OUTPUT->heading($heading);
|
||||
echo $OUTPUT->box_start();
|
||||
$text = get_string('choosereadme', 'theme_'.$CFG->theme);
|
||||
echo format_text($text, FORMAT_MOODLE);
|
||||
echo format_text(get_string('choosereadme', 'theme_'.$CFG->theme), FORMAT_MOODLE);
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
@ -89,29 +91,45 @@ foreach ($themes as $themename => $themedir) {
|
||||
// Build the table row, and also a list of items to go in the second cell.
|
||||
$row = array();
|
||||
$infoitems = array();
|
||||
$rowclasses = array();
|
||||
|
||||
// Set up bools whether this theme is chosen either main or legacy
|
||||
$ischosentheme = ($themename == $CFG->theme);
|
||||
$ischosenlegacytheme = (!empty($CFG->themelegacy) && $themename == $CFG->themelegacy);
|
||||
|
||||
if ($ischosentheme) {
|
||||
// Is the chosen main theme
|
||||
$rowclasses[] = 'selectedtheme';
|
||||
}
|
||||
if ($ischosenlegacytheme) {
|
||||
// Is the chosen legacy theme
|
||||
$rowclasses[] = 'selectedlegacytheme';
|
||||
}
|
||||
|
||||
// link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
|
||||
$screenshotpath = "$CFG->wwwroot/theme/image.php?theme=$themename&image=screenshot&component=theme";
|
||||
|
||||
$screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot','component'=>'theme'));
|
||||
// Contents of the first screenshot/preview cell.
|
||||
$row[] = "<img src=\"$screenshotpath\" alt=\"$themename\" />";
|
||||
$row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$themename));
|
||||
|
||||
// Contents of the second cell.
|
||||
$infocell = $OUTPUT->heading($themename, 3);
|
||||
if ($themename != $CFG->theme) {
|
||||
$infocell .= $OUTPUT->single_button(new moodle_url('index.php', array('choose' => $themename, 'sesskey' => sesskey())), get_string('choose'), 'get');
|
||||
|
||||
}
|
||||
// Button to choose this as the main theme
|
||||
$maintheme = new single_button(new moodle_url('/theme/index.php', array('choose' => $themename, 'sesskey' => sesskey())), get_string('useformaintheme'), 'get');
|
||||
$maintheme->disabled = $ischosentheme;
|
||||
$infocell .= $OUTPUT->render($maintheme);
|
||||
|
||||
// Button to choose this as the legacy theme
|
||||
$legacytheme = new single_button(new moodle_url('/theme/index.php', array('chooselegacy' => $themename, 'sesskey' => sesskey())), get_string('useforlegacytheme'), 'get');
|
||||
$legacytheme->disabled = $ischosenlegacytheme;
|
||||
$infocell .= $OUTPUT->render($legacytheme);
|
||||
|
||||
$row[] = $infocell;
|
||||
|
||||
|
||||
$table->data[$themename] = $row;
|
||||
if ($themename == $CFG->theme) {
|
||||
$table->rowclasses[$themename] = 'selectedtheme';
|
||||
}
|
||||
$table->rowclasses[$themename] = join(' ', $rowclasses);
|
||||
}
|
||||
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
echo $OUTPUT->footer();
|
Loading…
x
Reference in New Issue
Block a user