You are here

function is_mobile in Back To Top 7

Same name and namespace in other branches
  1. 8 back_to_top.module \is_mobile()
  2. 2.x back_to_top.module \is_mobile()

Check if mobile or touch device with PHP so javascript and css isn't included in that case.

1 call to is_mobile()
back_to_top_page_build in ./back_to_top.module
Implements hook_page_build().

File

./back_to_top.module, line 162
Back To Top link using JQuery.

Code

function is_mobile() {

  // Check for mobile device using Browscap module if it is available.
  if (module_exists('browscap')) {
    $browser = browscap_get_browser();
    if (isset($browser['ismobiledevice']) && $browser['ismobiledevice'] == 1) {
      return TRUE;
    }
  }
  if (isset($_SERVER["HTTP_X_WAP_PROFILE"])) {
    return TRUE;
  }
  if (isset($_SERVER["HTTP_ACCEPT"]) && preg_match("/wap\\.|\\.wap/i", $_SERVER["HTTP_ACCEPT"])) {
    return TRUE;
  }
  if (isset($_SERVER["HTTP_USER_AGENT"])) {
    $user_agents = array(
      "midp",
      "j2me",
      "iphone",
      "avantg",
      "docomo",
      "novarra",
      "palmos",
      "palmsource",
      "240x320",
      "opwv",
      "chtml",
      "pda",
      "windows\\ ce",
      "mmp\\/",
      "blackberry",
      "mib\\/",
      "symbian",
      "wireless",
      "nokia",
      "hand",
      "mobi",
      "phone",
      "cdm",
      "up\\.b",
      "audio",
      "sie\\-",
      "sec\\-",
      "samsung",
      "htc",
      "mot\\-",
      "mitsu",
      "sagem",
      "sony",
      "alcatel",
      "lg",
      "erics",
      "vx",
      "^nec",
      "philips",
      "mmm",
      "xx",
      "panasonic",
      "sharp",
      "wap",
      "sch",
      "rover",
      "pocket",
      "benq",
      "java",
      "pt",
      "pg",
      "vox",
      "amoi",
      "bird",
      "compal",
      "kg",
      "voda",
      "sany",
      "kdd",
      "dbt",
      "sendo",
      "sgh",
      "gradi",
      "jb",
      "\\d\\d\\di",
      "moto",
      "ipad",
      "android",
      "ipod",
      "webos",
    );
    foreach ($user_agents as $user_string) {
      if (preg_match("/" . $user_string . "/i", strtolower($_SERVER["HTTP_USER_AGENT"]))) {
        return TRUE;
      }
    }
  }
  return FALSE;
}