MDL-25589 removing extra align value
[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
78946b9b 25$choose = optional_param('choose', '', PARAM_SAFEDIR);
ee8df661 26$chooselegacy = optional_param('chooselegacy', '', PARAM_SAFEDIR);
78946b9b 27$reset = optional_param('reset', 0, PARAM_BOOL);
b7009474 28
29admin_externalpage_setup('themeselector');
30
31unset($SESSION->theme);
32
78946b9b
PS
33if ($reset and confirm_sesskey()) {
34 theme_reset_all_caches();
35
ee8df661 36} else if (($choose || $chooselegacy) && confirm_sesskey()) {
b7009474 37
ee8df661
SH
38 if ($choose) {
39 $chosentheme = $choose;
40 $heading = get_string('themesaved');
41 $config = 'theme';
42 } else {
43 $chosentheme = $chooselegacy;
44 $heading = get_string('legacythemesaved');
45 $config = 'themelegacy';
46 }
47 $theme = theme_config::load($chosentheme);
48 set_config($config, $theme->name);
8ba55c01 49
752fdfbd
SH
50 // Create a new page for the display of the themes readme.
51 // This ensures that the readme page is shown using the new theme.
52 $confirmpage = new moodle_page();
53 $confirmpage->set_context($PAGE->context);
54 $confirmpage->set_url($PAGE->url);
55 $confirmpage->set_pagelayout($PAGE->pagelayout);
56 $confirmpage->set_pagetype($PAGE->pagetype);
57 $confirmpage->set_title($PAGE->title);
58 $confirmpage->set_heading($PAGE->heading);
59
60 // Get the core renderer for the new theme.
61 $output = $confirmpage->get_renderer('core');
62
63 echo $output->header();
64 echo $output->heading($heading);
65 echo $output->box_start();
ee8df661 66 echo format_text(get_string('choosereadme', 'theme_'.$CFG->theme), FORMAT_MOODLE);
752fdfbd
SH
67 echo $output->box_end();
68 echo $output->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
69 echo $output->footer();
b7009474 70 exit;
71}
72
73// Otherwise, show a list of themes.
61ef8f9f 74echo $OUTPUT->header('themeselector');
cdc62220 75echo $OUTPUT->heading(get_string('themes'));
b7009474 76
5c2ed7e2 77echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey'=>sesskey(),'reset'=>1)), get_string('themeresetcaches', 'admin'));
78946b9b 78
fd09397e 79$table = new html_table();
b7009474 80$table->id = 'adminthemeselector';
81$table->head = array(get_string('theme'), get_string('info'));
82
83$themes = get_plugin_list('theme');
78946b9b 84
b7009474 85foreach ($themes as $themename => $themedir) {
86
87 // Load the theme config.
88 try {
89 $theme = theme_config::load($themename);
78946b9b 90 } catch (Exception $e) {
b7009474 91 // Bad theme, just skip it for now.
92 continue;
60a9a6ea 93 }
78946b9b
PS
94 if ($themename !== $theme->name) {
95 //obsoleted or broken theme, just skip for now
96 continue;
97 }
4d56ee95
SH
98 if (!$CFG->themedesignermode && $theme->hidefromselector) {
99 // The theme doesn't want to be shown in the theme selector and as theme
100 // designer mode is switched off we will respect that decision.
101 continue;
102 }
edda2b9a 103 $strthemename = get_string('pluginname', 'theme_'.$themename);
74df4357 104
b7009474 105 // Build the table row, and also a list of items to go in the second cell.
106 $row = array();
107 $infoitems = array();
ee8df661 108 $rowclasses = array();
b7009474 109
ee8df661
SH
110 // Set up bools whether this theme is chosen either main or legacy
111 $ischosentheme = ($themename == $CFG->theme);
112 $ischosenlegacytheme = (!empty($CFG->themelegacy) && $themename == $CFG->themelegacy);
b7009474 113
ee8df661
SH
114 if ($ischosentheme) {
115 // Is the chosen main theme
116 $rowclasses[] = 'selectedtheme';
117 }
118 if ($ischosenlegacytheme) {
119 // Is the chosen legacy theme
120 $rowclasses[] = 'selectedlegacytheme';
121 }
0d399dc5 122
ee8df661
SH
123 // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
124 $screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot','component'=>'theme'));
b7009474 125 // Contents of the first screenshot/preview cell.
edda2b9a 126 $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
b7009474 127
128 // Contents of the second cell.
edda2b9a 129 $infocell = $OUTPUT->heading($strthemename, 3);
ebb19aba 130
ee8df661
SH
131 // Button to choose this as the main theme
132 $maintheme = new single_button(new moodle_url('/theme/index.php', array('choose' => $themename, 'sesskey' => sesskey())), get_string('useformaintheme'), 'get');
133 $maintheme->disabled = $ischosentheme;
134 $infocell .= $OUTPUT->render($maintheme);
b7009474 135
ee8df661
SH
136 // Button to choose this as the legacy theme
137 $legacytheme = new single_button(new moodle_url('/theme/index.php', array('chooselegacy' => $themename, 'sesskey' => sesskey())), get_string('useforlegacytheme'), 'get');
138 $legacytheme->disabled = $ischosenlegacytheme;
139 $infocell .= $OUTPUT->render($legacytheme);
edda2b9a 140
ee8df661 141 $row[] = $infocell;
edda2b9a 142
b7009474 143 $table->data[$themename] = $row;
ee8df661 144 $table->rowclasses[$themename] = join(' ', $rowclasses);
b7009474 145}
146
16be8974 147echo html_writer::table($table);
b7009474 148
ee8df661 149echo $OUTPUT->footer();