/** * Initialises the CSS classes that will be added to body tag of the page. * * The function is responsible for adding all of the critical CSS classes * that describe the current page, and its state. * This includes classes that describe the following for example: * - Current language * - Language direction * - YUI CSS initialisation * - Pagelayout * These are commonly used in CSS to target specific types of pages. */ protected function initialise_standard_body_classes() { global $CFG, $USER; $pagetype = $this->pagetype; if ($pagetype == 'site-index') { $this->_legacyclass = 'course'; } else { if (substr($pagetype, 0, 6) == 'admin-') { $this->_legacyclass = 'admin'; } } $this->add_body_class($this->_legacyclass); $pathbits = explode('-', trim($pagetype)); for ($i = 1; $i < count($pathbits); $i++) { $this->add_body_class('path-' . join('-', array_slice($pathbits, 0, $i))); } $this->add_body_classes(core_useragent::get_browser_version_classes()); $this->add_body_class('dir-' . get_string('thisdirection', 'langconfig')); $this->add_body_class('lang-' . current_language()); $this->add_body_class('yui-skin-sam'); // Make YUI happy, if it is used. $this->add_body_class('yui3-skin-sam'); // Make YUI3 happy, if it is used. $this->add_body_class($this->url_to_class_name($CFG->wwwroot)); // Extra class describing current page layout. $this->add_body_class('pagelayout-' . $this->_pagelayout); if (!during_initial_install()) { $this->add_body_class('course-' . $this->_course->id); $this->add_body_class('context-' . $this->_context->id); } if (!empty($this->_cm)) { $this->add_body_class('cmid-' . $this->_cm->id); } if (!empty($CFG->allowcategorythemes)) { $this->ensure_category_loaded(); foreach ($this->_categories as $catid => $notused) { $this->add_body_class('category-' . $catid); } } else { $catid = 0; if (is_array($this->_categories)) { $catids = array_keys($this->_categories); $catid = reset($catids); } else { if (!empty($this->_course->category)) { $catid = $this->_course->category; } } if ($catid) { $this->add_body_class('category-' . $catid); } } if (!isloggedin()) { $this->add_body_class('notloggedin'); } if (!empty($USER->editing)) { $this->add_body_class('editing'); if (optional_param('bui_moveid', false, PARAM_INT)) { $this->add_body_class('blocks-moving'); } } if (!empty($CFG->blocksdrag)) { $this->add_body_class('drag'); } if ($this->_devicetypeinuse != 'default') { $this->add_body_class($this->_devicetypeinuse . 'theme'); } // Add class for behat site to apply behat related fixes. if (defined('BEHAT_SITE_RUNNING')) { $this->add_body_class('behat-site'); } }
/** * Test browser version classes functionality. */ public function test_get_browser_version_classes() { core_useragent::instance(true, $this->user_agents['Safari']['412']['Mac OS X']); $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']); $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Safari iOS']['528']['iPhone']); $this->assertEquals(array('safari', 'ios'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['WebKit Android']['530']['Nexus']); $this->assertEquals(array('safari', 'android'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']); $this->assertEquals(array('safari'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Opera']['9.0']['Windows XP']); $this->assertEquals(array('opera'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['6.0']['Windows XP SP2']); $this->assertEquals(array('ie', 'ie6'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['7.0']['Windows XP SP2']); $this->assertEquals(array('ie', 'ie7'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['8.0']['Windows Vista']); $this->assertEquals(array('ie', 'ie8'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['9.0']['Windows 7']); $this->assertEquals(array('ie', 'ie9'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['9.0i']['Windows 7']); $this->assertEquals(array('ie', 'ie9'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['10.0']['Windows 8']); $this->assertEquals(array('ie', 'ie10'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['MSIE']['10.0i']['Windows 8']); $this->assertEquals(array('ie', 'ie10'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Firefox']['2.0']['Windows XP']); $this->assertEquals(array('gecko', 'gecko18'), core_useragent::get_browser_version_classes()); core_useragent::instance(true, $this->user_agents['Firefox']['3.0.6']['SUSE']); $this->assertEquals(array('gecko', 'gecko19'), core_useragent::get_browser_version_classes()); }
/** * Returns one or several CSS class names that match the user's browser. These can be put * in the body tag of the page to apply browser-specific rules without relying on CSS hacks * * @deprecated since 2.6 * @return array An array of browser version classes */ function get_browser_version_classes() { debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); return core_useragent::get_browser_version_classes(); }
/** * @dataProvider user_agents_providers */ public function test_get_browser_version_classes($useragent, $tests) { // Setup the core_useragent instance. core_useragent::instance(true, $useragent); $actual = core_useragent::get_browser_version_classes(); foreach ($tests['versionclasses'] as $expectedclass) { $this->assertContains($expectedclass, $actual); } $this->assertCount(count($tests['versionclasses']), $actual); }