From 6f7fc58710cdc07abef80e36e6da0784553c7155 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 10 Jun 2015 17:22:47 +0800 Subject: [PATCH] MDL-35148 themes: Updated checks deciding when mobile themes are used Now, if a site-theme is set for tablet/phone AND the user is using a tablet/phone that site-theme will be used, always. In any other case the normal theme resolution will be used: course, category, ... --- lib/pagelib.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/pagelib.php b/lib/pagelib.php index d1a5d780601..64f4621b0f1 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1560,16 +1560,22 @@ class moodle_page { } } + $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) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) { return $this->_course->theme; } break; case 'category': - if (!empty($CFG->allowcategorythemes) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) { $categories = $this->categories; foreach ($categories as $category) { if (!empty($category->theme)) { @@ -1586,7 +1592,7 @@ class moodle_page { break; case 'user': - if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && $this->devicetypeinuse == 'default') { + if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) { if ($mnetpeertheme) { return $mnetpeertheme; } else { @@ -1600,12 +1606,11 @@ class moodle_page { return $mnetpeertheme; } // First try for the device the user is using. - $devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse); if (!empty($devicetheme)) { return $devicetheme; } // Next try for the default device (as a fallback). - $devicetheme = core_useragent::get_device_type_theme('default'); + $devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT); if (!empty($devicetheme)) { return $devicetheme; }