Source for file browser.php
Documentation is available at browser.php
* @package Joomla.Platform
* @subpackage Environment
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Browser class, provides capability information about the current web client.
* Browser identification is performed by examining the HTTP_USER_AGENT
* environment variable provided by the web server.
* This class has many influences from the lib/Browser.php code in
* version 3 of Horde by Chuck Hagenbuch and Jon Parise.
* @package Joomla.Platform
* @subpackage Environment
* @var integer Major version number
* @var integer Minor version number
* @var string Browser name.
* @var string Full user agent string.
* @var string Lower-case user agent string
* @var string HTTP_ACCEPT string.
* @var array Parsed HTTP_ACCEPT string
* @var string Platform the browser is running on
* @var array Known robots.
/* The most common ones. */
/* The rest alphabetically. */
'www.almaden.ibm.com/cs/crawler',
* @var boolean Is this a mobile browser?
* List of viewable image MIME subtypes.
* This list of viewable images works for IE and Netscape/Mozilla.
protected $images =
array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp');
* @var array JBrowser instances container.
protected static $instances =
array();
* Create a browser instance (constructor).
* @param string $userAgent The browser string to parse.
* @param string $accept The HTTP_ACCEPT settings to use.
public function __construct($userAgent =
null, $accept =
null)
$this->match($userAgent, $accept);
* Returns the global Browser object, only creating it
* if it doesn't already exist.
* @param string $userAgent The browser string to parse.
* @param string $accept The HTTP_ACCEPT settings to use.
* @return JBrowser The Browser object.
public static function getInstance($userAgent =
null, $accept =
null)
$signature =
serialize(array($userAgent, $accept));
if (empty(self::$instances[$signature]))
self::$instances[$signature] =
new JBrowser($userAgent, $accept);
return self::$instances[$signature];
* Parses the user agent string and inititializes the object with
* all the known features and quirks for the given browser.
* @param string $userAgent The browser string to parse.
* @param string $accept The HTTP_ACCEPT settings to use.
public function match($userAgent =
null, $accept =
null)
if (isset
($_SERVER['HTTP_USER_AGENT']))
$this->agent =
trim($_SERVER['HTTP_USER_AGENT']);
$this->agent =
$userAgent;
// Set our accept string.
if (isset
($_SERVER['HTTP_ACCEPT']))
if (!empty($this->agent))
/* Due to changes in Opera UA, we need to check Version/xx.yy,
* but only if version is > 9.80. See: http://dev.opera.com/articles/view/opera-ua-string-changes/ */
if (strpos($version[1], '.') !==
false)
/* Some Handhelds have their screen resolution in the
* user agent string, which we can use to look for
// Konqueror and Apple's Safari both use the KHTML
* Match the platform of the browser.
* This is a pretty simplistic implementation, but it's intended
* to let us tell what line breaks to send, so it's good enough
* Return the currently matched platform.
* @return string The user's platform.
* Set browser version, not by engine version
* Fallback to use when no other method identify the engine version
// Can't identify browser version
JLog::add("Can't identify browser version. Agent: " .
$this->agent, JLog::NOTICE);
* Sets the current browser.
* @param string $browser The browser to set as current.
* Retrieve the current browser.
* @return string The current browser.
* Retrieve the current browser's major version.
* @return integer The current browser's major version
* Retrieve the current browser's minor version.
* @return integer The current browser's minor version.
* Retrieve the current browser's version.
* @return string The current browser's version.
* Return the full browser agent string.
* @return string The browser agent string
* Returns the server protocol in use on the current server.
* @return string The HTTP server protocol version.
if (isset
($_SERVER['SERVER_PROTOCOL']))
if (($pos =
strrpos($_SERVER['SERVER_PROTOCOL'], '/')))
return substr($_SERVER['SERVER_PROTOCOL'], $pos +
1);
* Determines if a browser can display a given MIME type.
* Note that image/jpeg and image/pjpeg *appear* to be the same
* entity, but Mozilla doesn't seem to want to accept the latter.
* For our purposes, we will treat them the same.
* @param string $mimetype The MIME type to check.
* @return boolean True if the browser can display the MIME type.
list
($type, $subtype) =
explode('/', $mimetype);
// Deal with Mozilla pjpeg/jpeg issue
if ($this->isBrowser('mozilla') &&
($mimetype ==
'image/pjpeg') &&
(strpos($this->accept, 'image/jpeg') !==
false))
if (!$this->hasFeature('images') ||
($type !=
'image'))
* Determine if the given browser is the same as the current.
* @param string $browser The browser to check.
* @return boolean Is the given browser the same as the current?
return ($this->browser ===
$browser);
* Determines if the browser is a robot or not.
* @return boolean True if browser is a known robot.
foreach ($this->robots as $robot)
* Determines if the browser is mobile version or not.
* @return boolean True if browser is a known mobile version.
* Determine if we are using a secure (SSL) connection.
* @return boolean True if using SSL, false if not.
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use the isSSLConnection method on the application object.
JLog::add('JBrowser::isSSLConnection() is deprecated. Use the isSSLConnection method on the application object instead.',
JLog::WARNING, 'deprecated');
return ((isset
($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] ==
'on')) ||
getenv('SSL_PROTOCOL_VERSION'));
Documentation generated on Tue, 19 Nov 2013 14:54:46 +0100 by phpDocumentor 1.4.3