MDL-26030 update filter regex and create unittest for filter mediaplugin
[moodle.git] / theme / index.php
blob9bd70a8a1992d04973bd0bbc8cd4af8f90762835
1 <?php
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.
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/>.
18 /**
19 * This page prvides the Administration -> ... -> Theme selector UI.
22 require_once(dirname(__FILE__) . '/../config.php');
23 require_once($CFG->libdir . '/adminlib.php');
25 $choose = optional_param('choose', '', PARAM_SAFEDIR);
26 $chooselegacy = optional_param('chooselegacy', '', PARAM_SAFEDIR);
27 $reset = optional_param('reset', 0, PARAM_BOOL);
29 admin_externalpage_setup('themeselector');
31 unset($SESSION->theme);
33 if ($reset and confirm_sesskey()) {
34 theme_reset_all_caches();
36 } else if (($choose || $chooselegacy) && confirm_sesskey()) {
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';
47 $theme = theme_config::load($chosentheme);
48 set_config($config, $theme->name);
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);
60 // Get the core renderer for the new theme.
61 $output = $confirmpage->get_renderer('core');
63 echo $output->header();
64 echo $output->heading($heading);
65 echo $output->box_start();
66 echo format_text(get_string('choosereadme', 'theme_'.$CFG->theme), FORMAT_MOODLE);
67 echo $output->box_end();
68 echo $output->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
69 echo $output->footer();
70 exit;
73 // Otherwise, show a list of themes.
74 echo $OUTPUT->header('themeselector');
75 echo $OUTPUT->heading(get_string('themes'));
77 echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey'=>sesskey(),'reset'=>1)), get_string('themeresetcaches', 'admin'));
79 $table = new html_table();
80 $table->id = 'adminthemeselector';
81 $table->head = array(get_string('theme'), get_string('info'));
83 $themes = get_plugin_list('theme');
85 foreach ($themes as $themename => $themedir) {
87 // Load the theme config.
88 try {
89 $theme = theme_config::load($themename);
90 } catch (Exception $e) {
91 // Bad theme, just skip it for now.
92 continue;
94 if ($themename !== $theme->name) {
95 //obsoleted or broken theme, just skip for now
96 continue;
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;
103 $strthemename = get_string('pluginname', 'theme_'.$themename);
105 // Build the table row, and also a list of items to go in the second cell.
106 $row = array();
107 $infoitems = array();
108 $rowclasses = array();
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);
114 if ($ischosentheme) {
115 // Is the chosen main theme
116 $rowclasses[] = 'selectedtheme';
118 if ($ischosenlegacytheme) {
119 // Is the chosen legacy theme
120 $rowclasses[] = 'selectedlegacytheme';
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'));
125 // Contents of the first screenshot/preview cell.
126 $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
128 // Contents of the second cell.
129 $infocell = $OUTPUT->heading($strthemename, 3);
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);
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);
141 $row[] = $infocell;
143 $table->data[$themename] = $row;
144 $table->rowclasses[$themename] = join(' ', $rowclasses);
147 echo html_writer::table($table);
149 echo $OUTPUT->footer();