Parses the user agent string and inititializes the object with all the known features and quirks for the given browser.
{
if (is_null($userAgent))
{
if (isset($_SERVER['HTTP_USER_AGENT']))
{
$this->agent = trim($_SERVER['HTTP_USER_AGENT']);
}
}
else
{
$this->agent = $userAgent;
}
$this->lowerAgent = strtolower($this->agent);
{
if (isset($_SERVER['HTTP_ACCEPT']))
{
$this->accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
}
}
else
{
$this->accept = strtolower(
$accept);
}
if (!empty($this->agent))
{
if (strpos($this->lowerAgent, 'mobileexplorer') !== false
|| strpos($this->lowerAgent, 'openwave') !== false
|| strpos($this->lowerAgent, 'opera mini') !== false
|| strpos($this->lowerAgent, 'opera mobi') !== false
|| strpos($this->lowerAgent, 'operamini') !== false)
{
$this->mobile = true;
}
elseif (preg_match('|Opera[/ ]([0-9.]+)|', $this->agent, $version))
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
if ($this->majorVersion == 9 && $this->minorVersion >= 80)
{
}
}
elseif (preg_match('|Chrome[/ ]([0-9.]+)|', $this->agent, $version))
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
}
elseif (preg_match('|CrMo[/ ]([0-9.]+)|', $this->agent, $version))
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
}
elseif (preg_match('|CriOS[/ ]([0-9.]+)|', $this->agent, $version))
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
$this->mobile = true;
}
elseif (strpos($this->lowerAgent, 'elaine/') !== false
|| strpos($this->lowerAgent, 'palmsource') !== false
|| strpos($this->lowerAgent, 'digital paths') !== false)
{
$this->mobile = true;
}
elseif ((preg_match('|MSIE ([0-9.]+)|', $this->agent, $version)) || (preg_match('|Internet Explorer/([0-9.]+)|', $this->agent, $version)))
{
if (strpos($version[1], '.') !== false)
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
}
else
{
$this->majorVersion = $version[1];
$this->minorVersion = 0;
}
if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $this->agent))
{
$this->mobile = true;
}
}
elseif (preg_match('|amaya/([0-9.]+)|', $this->agent, $version))
{
$this->majorVersion = $version[1];
if (isset($version[2]))
{
$this->minorVersion = $version[2];
}
}
elseif (preg_match('|ANTFresco/([0-9]+)|', $this->agent, $version))
{
}
elseif (strpos($this->lowerAgent, 'avantgo') !== false)
{
$this->mobile = true;
}
elseif (preg_match('|Konqueror/([0-9]+)|', $this->agent, $version) || preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->agent, $version))
{
$this->majorVersion = $version[1];
if (isset($version[2]))
{
$this->minorVersion = $version[2];
}
if (strpos($this->agent, 'Safari') !== false && $this->majorVersion >= 60)
{
}
}
elseif (preg_match('|Mozilla/([0-9.]+)|', $this->agent, $version))
{
list ($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
}
elseif (preg_match('|Lynx/([0-9]+)|', $this->agent, $version))
{
}
elseif (preg_match('|Links \(([0-9]+)|', $this->agent, $version))
{
}
elseif (preg_match('|HotJava/([0-9]+)|', $this->agent, $version))
{
}
elseif (strpos($this->agent, 'UP/') !== false || strpos($this->agent, 'UP.B') !== false || strpos($this->agent, 'UP.L') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'Xiino/') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'Palmscape/') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'Nokia') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'Ericsson') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->lowerAgent, 'wap') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->lowerAgent, 'docomo') !== false || strpos($this->lowerAgent, 'portalmmm') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'BlackBerry') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->agent, 'MOT-') !== false)
{
$this->mobile = true;
}
elseif (strpos($this->lowerAgent, 'j-') !== false)
{
$this->mobile = true;
}
}
}