You are here

function _pagerer_browser_info in Pagerer 7

Returns basic information on the client browser.

Parameters

string $agent: the HTTP user agent to be analysed; defaults to $_SERVER['HTTP_USER_AGENT']

Return value

array an array containing browser, full version, major version, minor version

2 calls to _pagerer_browser_info()
pagerer_example_page in ./pagerer_example.module
Build the pagerer example.
_pagerer_itemize_js_element in ./pagerer.module
Return HTML to an active js element for page navigation.

File

./pagerer.module, line 2190
Pagerer

Code

function _pagerer_browser_info($agent = NULL) {
  $agent = $agent ? $agent : $_SERVER['HTTP_USER_AGENT'];
  $ub = $version = "";

  // Find browser.
  if (preg_match('/MSIE/i', $agent) && !preg_match('/Opera/i', $agent)) {
    $ub = "MSIE";
  }
  elseif (preg_match('/Firefox/i', $agent)) {
    $ub = "Firefox";
  }
  elseif (preg_match('/Chrome/i', $agent)) {
    $ub = "Chrome";
  }
  elseif (preg_match('/Safari/i', $agent)) {
    $ub = "Safari";
  }
  elseif (preg_match('/Opera/i', $agent)) {
    $ub = "Opera";
  }
  elseif (preg_match('/Netscape/i', $agent)) {
    $ub = "Netscape";
  }

  // Get the version number.
  $known = array(
    'Version',
    $ub,
    'other',
  );
  $pattern = '#(?<browser>' . implode('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  if (!preg_match_all($pattern, $agent, $matches)) {

    // We have no matching number just continue.
  }

  // See how many matches we have.
  $i = count($matches['browser']);
  if ($i != 1) {

    // We will have two since we are not using 'other' argument yet
    // see if version is before or after the name.
    if (strripos($agent, "Version") < strripos($agent, $ub)) {
      $version = $matches['version'][0];
    }
    else {
      $version = isset($matches['version'][1]) ? $matches['version'][1] : NULL;
    }
  }
  else {
    $version = $matches['version'][0];
  }

  // Check if we have a number.
  if (is_null($version) || $version == "") {
    $version = "?";
  }
  $ex_version = explode('.', $version);
  $ret = array(
    'browser' => $ub,
    'version' => $version,
    'version_major' => isset($ex_version[0]) ? $ex_version[0] : NULL,
    'version_minor' => isset($ex_version[1]) ? $ex_version[1] : NULL,
  );
  return $ret;
}