Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/theme/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00022 require_once(dirname(__FILE__) . '/../config.php');
00023 require_once($CFG->libdir . '/adminlib.php');
00024 
00025 $choose = optional_param('choose', '', PARAM_PLUGIN);
00026 $reset  = optional_param('reset', 0, PARAM_BOOL);
00027 $device = optional_param('device', '', PARAM_TEXT);
00028 
00029 admin_externalpage_setup('themeselector');
00030 
00031 if (!empty($device)) {
00032     // Make sure the device requested is valid
00033     $devices = get_device_type_list();
00034     if (!in_array($device, $devices)) {
00035         // The provided device isn't a valid device throw an error
00036         print_error('invaliddevicetype');
00037     }
00038 }
00039 
00040 unset($SESSION->theme);
00041 
00042 if ($reset and confirm_sesskey()) {
00043     theme_reset_all_caches();
00044 
00045 } else if ($choose && $device && confirm_sesskey()) {
00046 
00047     // Load the theme to make sure it is valid.
00048     $theme = theme_config::load($choose);
00049     // Get the config argument for the chosen device.
00050     $themename = get_device_cfg_var_name($device);
00051     set_config($themename, $theme->name);
00052 
00053     // Create a new page for the display of the themes readme.
00054     // This ensures that the readme page is shown using the new theme.
00055     $confirmpage = new moodle_page();
00056     $confirmpage->set_context($PAGE->context);
00057     $confirmpage->set_url($PAGE->url);
00058     $confirmpage->set_pagelayout($PAGE->pagelayout);
00059     $confirmpage->set_pagetype($PAGE->pagetype);
00060     $confirmpage->set_title($PAGE->title);
00061     $confirmpage->set_heading($PAGE->heading);
00062 
00063     // Get the core renderer for the new theme.
00064     $output = $confirmpage->get_renderer('core');
00065 
00066     echo $output->header();
00067     echo $output->heading(get_string('themesaved'));
00068     echo $output->box_start();
00069     echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE);
00070     echo $output->box_end();
00071     echo $output->continue_button($CFG->wwwroot . '/theme/index.php');
00072     echo $output->footer();
00073     exit;
00074 }
00075 
00076 // Otherwise, show either a list of devices, or is enabledevicedetection set to no or a
00077 // device is specified show a list of themes.
00078 
00079 echo $OUTPUT->header('themeselector');
00080 echo $OUTPUT->heading(get_string('themes'));
00081 
00082 echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey' => sesskey(), 'reset' => 1)), get_string('themeresetcaches', 'admin'));
00083 
00084 $table = new html_table();
00085 $table->data = array();
00086 if (!empty($CFG->enabledevicedetection) && empty($device)) {
00087     // Display a list of devices that a user can select a theme for.
00088 
00089     $strthemenotselected = get_string('themenoselected', 'admin');
00090     $strthemeselect = get_string('themeselect', 'admin');
00091 
00092     // Display the device selection screen
00093     $table->id = 'admindeviceselector';
00094     $table->head = array(get_string('devicetype', 'admin'), get_string('theme'), get_string('info'));
00095 
00096     $devices = get_device_type_list();
00097     foreach ($devices as $device) {
00098 
00099         $headingthemename = ''; // To output the picked theme name when needed
00100         $themename = get_selected_theme_for_device_type($device);
00101         if (!$themename && $device == 'default') {
00102             $themename = theme_config::DEFAULT_THEME;
00103         }
00104 
00105         $screenshotcell = $strthemenotselected;
00106         if ($themename) {
00107             // Check the theme exists
00108             $themename = clean_param($themename, PARAM_THEME);
00109             if (empty($themename)) {
00110                 // Likely the theme has been deleted
00111                 unset_config(get_device_cfg_var_name($device));
00112             } else {
00113                 $strthemename = get_string('pluginname', 'theme_'.$themename);
00114                 // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
00115                 $screenshoturl = new moodle_url('/theme/image.php', array('theme' => $themename, 'image' => 'screenshot', 'component' => 'theme'));
00116                 // Contents of the screenshot/preview cell.
00117                 $screenshotcell = html_writer::empty_tag('img', array('src' => $screenshoturl, 'alt' => $strthemename));
00118                 // Show the name of the picked theme
00119                 $headingthemename = $OUTPUT->heading($strthemename, 3);
00120             }
00121         }
00122 
00123         $deviceurl = new moodle_url('/theme/index.php', array('device' => $device, 'sesskey' => sesskey()));
00124         $select = new single_button($deviceurl, $strthemeselect, 'get');
00125 
00126         $table->data[] = array(
00127             $device,
00128             $screenshotcell,
00129             $headingthemename . $OUTPUT->render($select)
00130         );
00131     }
00132 } else {
00133     // Either a device has been selected of $CFG->enabledevicedetection is off so display a list
00134     // of themes to select.
00135 
00136     if (empty($device)) {
00137         // if $CFG->enabledevicedetection is off this will return 'default'
00138         $device = get_device_type();
00139     }
00140 
00141     $table->id = 'adminthemeselector';
00142     $table->head = array(get_string('theme'), get_string('info'));
00143 
00144     $themes = get_plugin_list('theme');
00145 
00146     foreach ($themes as $themename => $themedir) {
00147 
00148         // Load the theme config.
00149         try {
00150             $theme = theme_config::load($themename);
00151         } catch (Exception $e) {
00152             // Bad theme, just skip it for now.
00153             continue;
00154         }
00155         if ($themename !== $theme->name) {
00156             //obsoleted or broken theme, just skip for now
00157             continue;
00158         }
00159         if (empty($CFG->themedesignermode) && $theme->hidefromselector) {
00160             // The theme doesn't want to be shown in the theme selector and as theme
00161             // designer mode is switched off we will respect that decision.
00162             continue;
00163         }
00164         $strthemename = get_string('pluginname', 'theme_'.$themename);
00165 
00166         // Build the table row, and also a list of items to go in the second cell.
00167         $row = array();
00168         $infoitems = array();
00169         $rowclasses = array();
00170 
00171         // Set up bools whether this theme is chosen either main or legacy
00172         $ischosentheme = ($themename == get_selected_theme_for_device_type($device));
00173 
00174         if ($ischosentheme) {
00175             // Is the chosen main theme
00176             $rowclasses[] = 'selectedtheme';
00177         }
00178 
00179         // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
00180         $screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot', 'component'=>'theme'));
00181         // Contents of the first screenshot/preview cell.
00182         $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
00183         // Contents of the second cell.
00184         $infocell = $OUTPUT->heading($strthemename, 3);
00185 
00186         // Button to choose this as the main theme
00187         $maintheme = new single_button(new moodle_url('/theme/index.php', array('device' => $device, 'choose' => $themename, 'sesskey' => sesskey())), get_string('usetheme'), 'get');
00188         $maintheme->disabled = $ischosentheme;
00189         $infocell .= $OUTPUT->render($maintheme);
00190 
00191         $row[] = $infocell;
00192 
00193         $table->data[$themename] = $row;
00194         $table->rowclasses[$themename] = join(' ', $rowclasses);
00195     }
00196 }
00197 
00198 echo html_writer::table($table);
00199 
00200 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations