Selecting theme based on browser and its version

Selecting theme based on browser and its version

by Catherine Birch -
Number of replies: 1

This subject derives from a problem I had when I wanted to use the Aardvark 1.5 theme, which doesn't work with Internet Explorer 6 for perfectly sensible reasons that are documented here: http://moodle.org/mod/forum/discuss.php?d=155052.

I was at a site  where they used moodle on an intranet and everybody had Internet Explorer, ranging in versions from 6, 7, 8.  They were in the process of upgrading every one of their several thousand users to IE7 or higher, but in an ill-defined timeframe.

It was decided to proceed  with Aardvark 1.5, but to detect the browser version and drop back to an older theme for IE6.

It being a while since I had written browser detector code, I downloaded browser.php, a recent version, from the web http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/ into moodle\lib. This was overkill for my case, since I only wanted to detect IE6.

Then in moodle\lib\setup.php, I included the new code:

require_once('browser.php');

Then after the following code:

if (!isset($CFG->theme)) {
$CFG->theme = 'standardwhite';
}


I added:


else {
$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_IE && $browser->getVersion() <= 6 ) {
$CFG->theme = 'knowledge-library';
}
}

This drops the theme back to the knowledge-library theme if the browser is IE version 6 or less (unless no theme is set). It is quite crude, as it takes away your ability to configure the theme for IE6 users. But it demonstrates the general approach and could be made more intelligent.  [At that site I left them with instructions to rename another theme folder to knowledge-library if they want to change the theme for IE6 users.  But they were expected to upgrade in a timeframe where that was unlikely.]

Average of ratings: -