You are here

function mt_browscap_detect_mobile_device in Mobile Tools 6.2

Implementatation of hook_detect_mobile_device().

File

modules/mt_browscap/mt_browscap.module, line 11
Primarily Drupal hooks.

Code

function mt_browscap_detect_mobile_device() {

  // Assume that the site visitor is using a desktop browser until we can prove
  // otherwise
  $device_information = array(
    'type' => 'desktop',
    'group' => '',
  );

  // Get Browscap information about the current user agent
  $user_agent = browscap_get_browser();

  // Check the browscap information to see if the current user agent is flagged
  // as a mobile device
  if (isset($user_agent['ismobiledevice']) && $user_agent['ismobiledevice'] == TRUE) {
    $device_information['type'] = 'mobile';
  }

  // Get the currently defined device groups
  $groups = mt_browscap_device_groups_info();

  // Check if the current user agent name can be found within the list of
  // device groups
  if (isset($user_agent['browser']) && in_array($user_agent['browser'], $groups)) {
    $device_information['group'] = array_search($user_agent['browser'], $groups);
  }
  return $device_information;
}