You are here

function mobile_detect_check_type in Mobile Detect 7

Predicate function to test a device type.

This is intended to be used when the check could be based on user input. The $type argument is checked against the list of valid types. If the $type is not a valid choice, an error is logged and FALSE is returned. Otherwise the test is run and returned.

Parameters

string $type: The type to check.

Return value

boolean The result of the test; FALSE if the test name was invalid.

3 calls to mobile_detect_check_type()
mobile_detect_ctools_access_check in mobile_detect_ctools/plugins/access/mobile_detect_ctools.inc
The actual access callback.
_mobile_detect_full_debug in ./mobile_detect.module
Content generator for hook_block_view('mobile_detect_full_debug')
_mobile_detect_simple_debug in ./mobile_detect.module
Content generator for hook_block_view('mobile_detect_simple_debug')

File

./mobile_detect.module, line 90
Lightweight mobile detection based on the Mobile_Detect.php library.

Code

function mobile_detect_check_type($type) {
  $detect = mobile_detect_get_object();
  $rules = array(
    'Mobile',
    'Tablet',
    'Handheld',
  ) + $detect
    ->getRules();
  $name = preg_replace('/^is/', '', $type);
  if (!in_array($name, $rules)) {
    watchdog('mobile_detect', 'Illegal access rule: %type', array(
      '%type' => $type,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  if ($type == 'isHandheld') {
    return $detect
      ->isMobile() && !$detect
      ->isTablet();
  }
  else {
    return $detect
      ->{$type}();
  }
}