/** * Work out the theme this page should use. * * This depends on numerous $CFG settings, and the properties of this page. * * @return string the name of the theme that should be used on this page. */ protected function resolve_theme() { global $CFG, $USER, $SESSION; if (empty($CFG->themeorder)) { $themeorder = array('course', 'category', 'session', 'user', 'site'); } else { $themeorder = $CFG->themeorder; // Just in case, make sure we always use the site theme if nothing else matched. $themeorder[] = 'site'; } $mnetpeertheme = ''; if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) { require_once $CFG->dirroot . '/mnet/peer.php'; $mnetpeer = new mnet_peer(); $mnetpeer->set_id($USER->mnethostid); if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') { $mnetpeertheme = $mnetpeer->theme; } } $devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse); // The user is using another device than default, and we have a theme for that, we should use it. $hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme); foreach ($themeorder as $themetype) { switch ($themetype) { case 'course': if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) { return $this->_course->theme; } break; case 'category': if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) { $categories = $this->categories; foreach ($categories as $category) { if (!empty($category->theme)) { return $category->theme; } } } break; case 'session': if (!empty($SESSION->theme)) { return $SESSION->theme; } break; case 'user': if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) { if ($mnetpeertheme) { return $mnetpeertheme; } else { return $USER->theme; } } break; case 'site': if ($mnetpeertheme) { return $mnetpeertheme; } // First try for the device the user is using. if (!empty($devicetheme)) { return $devicetheme; } // Next try for the default device (as a fallback). $devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT); if (!empty($devicetheme)) { return $devicetheme; } // The default device theme isn't set up - use the overall default theme. return theme_config::DEFAULT_THEME; } } // We should most certainly have resolved a theme by now. Something has gone wrong. debugging('Error resolving the theme to use for this page.', DEBUG_DEVELOPER); return theme_config::DEFAULT_THEME; }
if ($themename !== $theme->name) { // Obsoleted or broken theme, just skip for now. continue; } if (empty($CFG->themedesignermode) && $theme->hidefromselector) { // The theme doesn't want to be shown in the theme selector and as theme // designer mode is switched off we will respect that decision. continue; } $strthemename = get_string('pluginname', 'theme_' . $themename); // Build the table row, and also a list of items to go in the second cell. $row = array(); $infoitems = array(); $rowclasses = array(); // Set up bools whether this theme is chosen either main or legacy. $ischosentheme = $themename == core_useragent::get_device_type_theme($device); if ($ischosentheme) { // Is the chosen main theme. $rowclasses[] = 'selectedtheme'; } // 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)); // Contents of the second cell. $infocell = $OUTPUT->heading($strthemename, 3); if ($themelocked) { $infocell .= html_writer::div(get_string('configoverride', 'admin'), 'alert alert-info'); } // Button to choose this as the main theme or unset this theme for devices other then default.
/** * Returns the theme selected for a particular device or false if none selected. * * @deprecated since 2.6 * @param string $devicetype * @return string|false The name of the theme to use for the device or the false if not set */ function get_selected_theme_for_device_type($devicetype = null) { debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); return core_useragent::get_device_type_theme($devicetype); }