MDL-27862 Themes: Strings updated on theme selection pages
[moodle.git] / theme / index.php
CommitLineData
b7009474 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This page prvides the Administration -> ... -> Theme selector UI.
20 */
21
22require_once(dirname(__FILE__) . '/../config.php');
23require_once($CFG->libdir . '/adminlib.php');
24
aff24313 25$choose = optional_param('choose', '', PARAM_PLUGIN);
78946b9b 26$reset = optional_param('reset', 0, PARAM_BOOL);
37959dd4 27$device = optional_param('device', '', PARAM_TEXT);
b7009474 28
29admin_externalpage_setup('themeselector');
30
e5824bb9
SH
31if (!empty($device)) {
32 // Make sure the device requested is valid
33 $devices = get_device_type_list();
34 if (!in_array($device, $devices)) {
35 // The provided device isn't a valid device throw an error
36 print_error('invaliddevicetype');
37 }
38}
39
b7009474 40unset($SESSION->theme);
41
78946b9b
PS
42if ($reset and confirm_sesskey()) {
43 theme_reset_all_caches();
44
37959dd4 45} else if ($choose && $device && confirm_sesskey()) {
aff24313 46
e5824bb9
SH
47 // Load the theme to make sure it is valid.
48 $theme = theme_config::load($choose);
49 // Get the config argument for the chosen device.
37959dd4 50 $themename = get_device_cfg_var_name($device);
37959dd4 51 set_config($themename, $theme->name);
8ba55c01 52
752fdfbd
SH
53 // Create a new page for the display of the themes readme.
54 // This ensures that the readme page is shown using the new theme.
55 $confirmpage = new moodle_page();
56 $confirmpage->set_context($PAGE->context);
57 $confirmpage->set_url($PAGE->url);
58 $confirmpage->set_pagelayout($PAGE->pagelayout);
59 $confirmpage->set_pagetype($PAGE->pagetype);
60 $confirmpage->set_title($PAGE->title);
61 $confirmpage->set_heading($PAGE->heading);
62
63 // Get the core renderer for the new theme.
64 $output = $confirmpage->get_renderer('core');
65
66 echo $output->header();
e5824bb9 67 echo $output->heading(get_string('themesaved'));
752fdfbd 68 echo $output->box_start();
37959dd4 69 echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE);
752fdfbd 70 echo $output->box_end();
0e01784c 71 echo $output->continue_button($CFG->wwwroot . '/theme/index.php');
752fdfbd 72 echo $output->footer();
b7009474 73 exit;
74}
75
37959dd4
AF
76// Otherwise, show either a list of devices, or is enabledevicedetection set to no or a
77// device is specified show a list of themes.
78
fd09397e 79$table = new html_table();
e5824bb9 80$table->data = array();
604cb179 81$heading = '';
7bff5441 82if (!empty($CFG->enabledevicedetection) && empty($device)) {
604cb179 83 $heading = get_string('selectdevice', 'admin');
e5824bb9
SH
84 // Display a list of devices that a user can select a theme for.
85
86 $strthemenotselected = get_string('themenoselected', 'admin');
87 $strthemeselect = get_string('themeselect', 'admin');
88
89 // Display the device selection screen
90 $table->id = 'admindeviceselector';
604cb179 91 $table->head = array(get_string('devicetype', 'admin'), get_string('currenttheme', 'admin'), get_string('info'));
37959dd4
AF
92
93 $devices = get_device_type_list();
37959dd4 94 foreach ($devices as $device) {
37959dd4 95
43c741b9 96 $headingthemename = ''; // To output the picked theme name when needed
37959dd4 97 $themename = get_selected_theme_for_device_type($device);
37959dd4
AF
98 if (!$themename && $device == 'default') {
99 $themename = theme_config::DEFAULT_THEME;
100 }
101
e5824bb9 102 $screenshotcell = $strthemenotselected;
37959dd4 103 if ($themename) {
e5824bb9
SH
104 // Check the theme exists
105 $themename = clean_param($themename, PARAM_THEME);
106 if (empty($themename)) {
107 // Likely the theme has been deleted
108 unset_config(get_device_cfg_var_name($device));
109 } else {
110 $strthemename = get_string('pluginname', 'theme_'.$themename);
111 // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
112 $screenshoturl = new moodle_url('/theme/image.php', array('theme' => $themename, 'image' => 'screenshot', 'component' => 'theme'));
113 // Contents of the screenshot/preview cell.
114 $screenshotcell = html_writer::empty_tag('img', array('src' => $screenshoturl, 'alt' => $strthemename));
43c741b9
EL
115 // Show the name of the picked theme
116 $headingthemename = $OUTPUT->heading($strthemename, 3);
e5824bb9 117 }
37959dd4
AF
118 }
119
e5824bb9
SH
120 $deviceurl = new moodle_url('/theme/index.php', array('device' => $device, 'sesskey' => sesskey()));
121 $select = new single_button($deviceurl, $strthemeselect, 'get');
37959dd4 122
e5824bb9
SH
123 $table->data[] = array(
124 $device,
125 $screenshotcell,
43c741b9 126 $headingthemename . $OUTPUT->render($select)
e5824bb9 127 );
78946b9b 128 }
e5824bb9
SH
129} else {
130 // Either a device has been selected of $CFG->enabledevicedetection is off so display a list
131 // of themes to select.
604cb179 132 $heading = get_string('selecttheme', 'admin', $device);
e5824bb9
SH
133 if (empty($device)) {
134 // if $CFG->enabledevicedetection is off this will return 'default'
135 $device = get_device_type();
ee8df661 136 }
b7009474 137
e5824bb9
SH
138 $table->id = 'adminthemeselector';
139 $table->head = array(get_string('theme'), get_string('info'));
37959dd4 140
e5824bb9 141 $themes = get_plugin_list('theme');
78946b9b 142
e5824bb9 143 foreach ($themes as $themename => $themedir) {
37959dd4 144
e5824bb9
SH
145 // Load the theme config.
146 try {
147 $theme = theme_config::load($themename);
148 } catch (Exception $e) {
149 // Bad theme, just skip it for now.
150 continue;
151 }
152 if ($themename !== $theme->name) {
153 //obsoleted or broken theme, just skip for now
154 continue;
155 }
e625feaf 156 if (empty($CFG->themedesignermode) && $theme->hidefromselector) {
e5824bb9
SH
157 // The theme doesn't want to be shown in the theme selector and as theme
158 // designer mode is switched off we will respect that decision.
159 continue;
160 }
161 $strthemename = get_string('pluginname', 'theme_'.$themename);
74df4357 162
e5824bb9
SH
163 // Build the table row, and also a list of items to go in the second cell.
164 $row = array();
165 $infoitems = array();
166 $rowclasses = array();
b7009474 167
e5824bb9
SH
168 // Set up bools whether this theme is chosen either main or legacy
169 $ischosentheme = ($themename == get_selected_theme_for_device_type($device));
b7009474 170
e5824bb9
SH
171 if ($ischosentheme) {
172 // Is the chosen main theme
173 $rowclasses[] = 'selectedtheme';
174 }
0d399dc5 175
e5824bb9
SH
176 // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
177 $screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot', 'component'=>'theme'));
178 // Contents of the first screenshot/preview cell.
179 $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
180 // Contents of the second cell.
181 $infocell = $OUTPUT->heading($strthemename, 3);
ebb19aba 182
e5824bb9
SH
183 // Button to choose this as the main theme
184 $maintheme = new single_button(new moodle_url('/theme/index.php', array('device' => $device, 'choose' => $themename, 'sesskey' => sesskey())), get_string('usetheme'), 'get');
185 $maintheme->disabled = $ischosentheme;
186 $infocell .= $OUTPUT->render($maintheme);
b7009474 187
e5824bb9 188 $row[] = $infocell;
edda2b9a 189
e5824bb9
SH
190 $table->data[$themename] = $row;
191 $table->rowclasses[$themename] = join(' ', $rowclasses);
192 }
b7009474 193}
604cb179
RT
194echo $OUTPUT->header('themeselector');
195echo $OUTPUT->heading($heading);
196
197echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey' => sesskey(), 'reset' => 1)), get_string('themeresetcaches', 'admin'));
b7009474 198
16be8974 199echo html_writer::table($table);
b7009474 200
e625feaf 201echo $OUTPUT->footer();