Exemplo n.º 1
0
        if (!$themelocked) {
            $select = $OUTPUT->render(new single_button($deviceurl, $strthemeselect, 'get'));
        }
        $lockwarning = '';
        if ($themelocked) {
            $lockwarning = html_writer::div(get_string('configoverride', 'admin'), 'alert alert-info');
        }
        $table->data[] = array($OUTPUT->heading(ucfirst($thedevice), 3), $screenshotcell, $headingthemename . $lockwarning . $select . $unsetthemebutton);
    }
} else {
    // Either a device has been selected of $CFG->enabledevicedetection is off so display a list
    // of themes to select.
    $heading = get_string('selecttheme', 'admin', $device);
    if (empty($device)) {
        // If $CFG->enabledevicedetection is off this will return 'default'.
        $device = core_useragent::get_device_type();
    }
    $themelocked = theme_is_device_locked($device);
    $table->id = 'adminthemeselector';
    $table->head = array(get_string('theme'), get_string('info'));
    $themes = array();
    if ($themelocked) {
        $heading = get_string('currenttheme', 'admin');
        $themename = theme_get_locked_theme_for_device($device);
        $themedirectory = core_component::get_plugin_directory('theme', $themename);
        $themes[$themename] = $themedirectory;
    } else {
        $themes = core_component::get_plugin_list('theme');
    }
    foreach ($themes as $themename => $themedir) {
        // Load the theme config.
Exemplo n.º 2
0
/**
 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
 * an optional admin specified regular expression.  If enabledevicedetection is set to no or not set
 * it returns default
 *
 * @deprecated since 2.6
 * @return string device type
 */
function get_device_type()
{
    debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
    return core_useragent::get_device_type();
}
Exemplo n.º 3
0
    /**
     * Renders theme links for switching between default and other themes.
     *
     * @return string
     */
    protected function theme_switch_links() {

        $actualdevice = core_useragent::get_device_type();
        $currentdevice = $this->page->devicetypeinuse;
        $switched = ($actualdevice != $currentdevice);

        if (!$switched && $currentdevice == 'default' && $actualdevice == 'default') {
            // The user is using the a default device and hasn't switched so don't shown the switch
            // device links.
            return '';
        }

        if ($switched) {
            $linktext = get_string('switchdevicerecommended');
            $devicetype = $actualdevice;
        } else {
            $linktext = get_string('switchdevicedefault');
            $devicetype = 'default';
        }
        $linkurl = new moodle_url('/theme/switchdevice.php', array('url' => $this->page->url, 'device' => $devicetype, 'sesskey' => sesskey()));

        $content  = html_writer::start_tag('div', array('id' => 'theme_switch_link'));
        $content .= html_writer::link($linkurl, $linktext, array('rel' => 'nofollow'));
        $content .= html_writer::end_tag('div');

        return $content;
    }
Exemplo n.º 4
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This is built using the bootstrapbase template to allow for new theme's using
 * Moodle's new Bootstrap theme engine
 *
 * @package     theme_essential
 * @copyright   2013 Julian Ridden
 * @copyright   2014 Gareth J Barnard, David Bezemer
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once \theme_essential\toolbox::get_include_file('additionaljs');
require_once \theme_essential\toolbox::get_include_file('header');
if (core_useragent::get_device_type() == "tablet") {
    $tablet = true;
} else {
    $tablet = false;
}
?>

<div id="page" class="container-fluid">
    <div id="page-navbar" class="clearfix row-fluid">
        <div
            class="breadcrumb-nav pull-<?php 
echo $left ? 'left' : 'right';
?>
"><?php 
echo $OUTPUT->navbar();
?>
Exemplo n.º 5
0
 static public function showslider() {
     global $CFG;
     $noslides = self::get_setting('numberofslides');
     if ($noslides && (intval($CFG->version) >= 2013111800)) {
         $devicetype = \core_useragent::get_device_type(); // In useragent.php.
         if (($devicetype == "mobile") && self::get_setting('hideonphone')) {
             $noslides = false;
         } else if (($devicetype == "tablet") && self::get_setting('hideontablet')) {
             $noslides = false;
         }
     }
     return $noslides;
 }
Exemplo n.º 6
0
function lti_get_launch_container($lti, $toolconfig)
{
    if (empty($lti->launchcontainer)) {
        $lti->launchcontainer = LTI_LAUNCH_CONTAINER_DEFAULT;
    }
    if ($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
        if (isset($toolconfig['launchcontainer'])) {
            $launchcontainer = $toolconfig['launchcontainer'];
        }
    } else {
        $launchcontainer = $lti->launchcontainer;
    }
    if (empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
        $launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
    }
    $devicetype = core_useragent::get_device_type();
    //Scrolling within the object element doesn't work on iOS or Android
    //Opening the popup window also had some issues in testing
    //For mobile devices, always take up the entire screen to ensure the best experience
    if ($devicetype === core_useragent::DEVICETYPE_MOBILE || $devicetype === core_useragent::DEVICETYPE_TABLET) {
        $launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW;
    }
    return $launchcontainer;
}
Exemplo n.º 7
0
function theme_essential_showslider()
{
    global $CFG;
    $noslides = theme_essential_get_setting('numberofslides');
    if ($noslides && intval($CFG->version) >= 2013111800) {
        $devicetype = core_useragent::get_device_type();
        // In moodlelib.php.
        if ($devicetype == "mobile" && theme_essential_get_setting('hideonphone')) {
            $noslides = false;
        } else {
            if ($devicetype == "tablet" && theme_essential_get_setting('hideontablet')) {
                $noslides = false;
            }
        }
    }
    return $noslides;
}
Exemplo n.º 8
0
 /**
  * Test device type detection.
  */
 public function test_get_device_type()
 {
     // IE8 (common pattern ~1.5% of IE7/8 users have embedded IE6 agent).
     $ie8 = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BT Openworld BB; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Hotbar 10.2.197.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)';
     core_useragent::instance(true, $ie8);
     $this->assertEquals('default', core_useragent::get_device_type());
     // Genuine IE6.
     $ie6 = 'Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.0.3705; Media Center PC 2.8)';
     core_useragent::instance(true, $ie6);
     $this->assertEquals('legacy', core_useragent::get_device_type());
     core_useragent::instance(true);
 }
Exemplo n.º 9
0
 /**
  * This has been taken directly from the moodle_page class but modified to work independently.
  * It's used by config.php so that hacks can be targetted at just the snap theme.
  * 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.
  */
 public static function resolve_theme()
 {
     global $CFG, $USER, $SESSION, $COURSE;
     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;
         }
     }
     $deviceinuse = \core_useragent::get_device_type();
     $devicetheme = \core_useragent::get_device_type_theme($deviceinuse);
     // The user is using another device than default, and we have a theme for that, we should use it.
     $hascustomdevicetheme = \core_useragent::DEVICETYPE_DEFAULT != $deviceinuse && !empty($devicetheme);
     foreach ($themeorder as $themetype) {
         switch ($themetype) {
             case 'course':
                 if (!empty($CFG->allowcoursethemes) && !empty($COURSE->theme) && !$hascustomdevicetheme) {
                     return $COURSE->theme;
                 }
                 break;
             case 'category':
                 if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) {
                     $categories = self::get_course_categories($COURSE);
                     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;
 }
Exemplo n.º 10
0
 /**
  * @dataProvider user_agents_providers
  */
 public function test_get_device_type($useragent, $tests)
 {
     // Setup the core_useragent instance.
     core_useragent::instance(true, $useragent);
     $expected = 'default';
     if (isset($tests['devicetype'])) {
         $expected = $tests['devicetype'];
     }
     $this->assertEquals($expected, core_useragent::get_device_type(), "Device Type was not correctly identified");
 }