mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-25394 Improved support for mobile and device themes
This commit is contained in:
parent
16b5541dd2
commit
37959dd471
11 changed files with 534 additions and 70 deletions
|
@ -23,8 +23,8 @@ 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);
|
||||
$device = optional_param('device', '', PARAM_TEXT);
|
||||
|
||||
admin_externalpage_setup('themeselector');
|
||||
|
||||
|
@ -33,19 +33,15 @@ unset($SESSION->theme);
|
|||
if ($reset and confirm_sesskey()) {
|
||||
theme_reset_all_caches();
|
||||
|
||||
} else if (($choose || $chooselegacy) && confirm_sesskey()) {
|
||||
} else if ($choose && $device && confirm_sesskey()) {
|
||||
|
||||
if ($choose) {
|
||||
$chosentheme = $choose;
|
||||
$heading = get_string('themesaved');
|
||||
$config = 'theme';
|
||||
} else {
|
||||
$chosentheme = $chooselegacy;
|
||||
$heading = get_string('legacythemesaved');
|
||||
$config = 'themelegacy';
|
||||
}
|
||||
$chosentheme = $choose;
|
||||
$heading = get_string('themesaved');
|
||||
|
||||
$theme = theme_config::load($chosentheme);
|
||||
set_config($config, $theme->name);
|
||||
$themename = get_device_cfg_var_name($device);
|
||||
|
||||
set_config($themename, $theme->name);
|
||||
|
||||
// Create a new page for the display of the themes readme.
|
||||
// This ensures that the readme page is shown using the new theme.
|
||||
|
@ -63,18 +59,65 @@ if ($reset and confirm_sesskey()) {
|
|||
echo $output->header();
|
||||
echo $output->heading($heading);
|
||||
echo $output->box_start();
|
||||
echo format_text(get_string('choosereadme', 'theme_'.$CFG->theme), FORMAT_MOODLE);
|
||||
echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE);
|
||||
echo $output->box_end();
|
||||
echo $output->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
||||
echo $output->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Otherwise, show a list of themes.
|
||||
// Otherwise, show either a list of devices, or is enabledevicedetection set to no or a
|
||||
// device is specified show a list of themes.
|
||||
|
||||
echo $OUTPUT->header('themeselector');
|
||||
echo $OUTPUT->heading(get_string('themes'));
|
||||
|
||||
echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey'=>sesskey(),'reset'=>1)), get_string('themeresetcaches', 'admin'));
|
||||
echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey'=>sesskey(), 'reset'=>1)), get_string('themeresetcaches', 'admin'));
|
||||
|
||||
if ($CFG->enabledevicedetection && empty($device)) {
|
||||
$table = new html_table();
|
||||
$table->id = 'devicethemeselector';
|
||||
$table->head = array(get_string('devicetype', 'admin'), get_string('theme'), get_string('info'));
|
||||
|
||||
$devices = get_device_type_list();
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$row = array();
|
||||
$row[] = $device;
|
||||
|
||||
$themename = get_selected_theme_for_device_type($device);
|
||||
|
||||
if (!$themename && $device == 'default') {
|
||||
$themename = theme_config::DEFAULT_THEME;
|
||||
}
|
||||
|
||||
if ($themename) {
|
||||
$strthemename = get_string('pluginname', 'theme_'.$themename);
|
||||
// link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
|
||||
$screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot', 'component'=>'theme'));
|
||||
// Contents of the first screenshot/preview cell.
|
||||
$row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
|
||||
} else {
|
||||
$row[] = get_string('themenoselected', 'admin');
|
||||
}
|
||||
|
||||
$select = new single_button(new moodle_url('/theme/index.php', array('device' => $device, 'sesskey' => sesskey())), get_string('themeselect', 'admin'), 'get');
|
||||
|
||||
$row[] = $OUTPUT->render($select);
|
||||
|
||||
$table->data[$device] = $row;
|
||||
}
|
||||
|
||||
echo html_writer::table($table);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
//if $CFG->enabledevicedetection is set to no, then this will return the default device type.
|
||||
if (empty($device)) {
|
||||
$device = get_device_type();
|
||||
}
|
||||
|
||||
$table = new html_table();
|
||||
$table->id = 'adminthemeselector';
|
||||
|
@ -83,7 +126,6 @@ $table->head = array(get_string('theme'), get_string('info'));
|
|||
$themes = get_plugin_list('theme');
|
||||
|
||||
foreach ($themes as $themename => $themedir) {
|
||||
|
||||
// Load the theme config.
|
||||
try {
|
||||
$theme = theme_config::load($themename);
|
||||
|
@ -91,6 +133,7 @@ foreach ($themes as $themename => $themedir) {
|
|||
// Bad theme, just skip it for now.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($themename !== $theme->name) {
|
||||
//obsoleted or broken theme, just skip for now
|
||||
continue;
|
||||
|
@ -108,36 +151,25 @@ foreach ($themes as $themename => $themedir) {
|
|||
$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);
|
||||
$ischosentheme = ($themename == get_selected_theme_for_device_type($device));
|
||||
|
||||
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 = new moodle_url('/theme/image.php', array('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[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
|
||||
|
||||
// Contents of the second cell.
|
||||
$infocell = $OUTPUT->heading($strthemename, 3);
|
||||
|
||||
// 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 = new single_button(new moodle_url('/theme/index.php', array('device' => $device, 'choose' => $themename, 'sesskey' => sesskey())), get_string('usetheme'), '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;
|
||||
|
|
27
theme/switch.php
Normal file
27
theme/switch.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This code processes switch requests-> ... -> Theme selector UI.
|
||||
*/
|
||||
|
||||
require('../config.php');
|
||||
|
||||
$url = required_param('url', PARAM_LOCALURL);
|
||||
|
||||
switch_device();
|
||||
|
||||
redirect($url);
|
Loading…
Add table
Add a link
Reference in a new issue