Source code for file /joomla/environment/browser.php
Documentation is available at browser.php
* @version $Id: browser.php 6472 2007-02-03 10:47:26Z pasamio $
* @package Joomla.Framework
* @subpackage Environment
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* 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
* @package Joomla.Framework
* @subpackage Environment
* Full user agent string.
* Lower-case user agent string.
* Platform the browser is running on.
/* The most common ones. */
/* The rest alphabetically. */
'www.almaden.ibm.com/cs/crawler',
* Is this a mobile browser?
'avoid_popup_windows' =>
false,
'break_disposition_header' =>
false,
'break_disposition_filename' =>
false,
'broken_multipart_form' =>
false,
'cache_same_url' =>
false,
'cache_ssl_downloads' =>
false,
'double_linebreak_textarea' =>
false,
'empty_file_input_value' =>
false,
'must_cache_forms' =>
false,
'no_filename_spaces' =>
false,
'no_hidden_overflow_tables' =>
false,
'png_transparency' =>
false,
'scrollbar_in_way' =>
false,
'windowed_controls' =>
false,
* List of viewable image MIME subtypes.
* This list of viewable images works for IE and Netscape/Mozilla.
var $_images =
array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp');
* Create a browser instance (Constructor).
* @param string $userAgent The browser string to parse.
* @param string $accept The HTTP_ACCEPT settings to use.
function __construct($userAgent =
null, $accept =
null)
$this->match($userAgent, $accept);
* Returns a reference to the global Browser object, only creating it
* if it doesn't already exist.
* This method must be invoked as:
* <pre> $browser = &JBrowser::getInstance([$userAgent[, $accept]]);</pre>
* @param string $userAgent The browser string to parse.
* @param string $accept The HTTP_ACCEPT settings to use.
* @return JBrowser The Browser object.
function &getInstance($userAgent =
null, $accept =
null)
if (!isset
($instances)) {
$signature =
serialize(array($userAgent, $accept));
if (empty($instances[$signature])) {
$instances[$signature] =
new JBrowser($userAgent, $accept);
return $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.
function match($userAgent =
null, $accept =
null)
if (isset
($_SERVER['HTTP_USER_AGENT'])) {
$this->_agent =
trim($_SERVER['HTTP_USER_AGENT']);
// Set our accept string.
if (isset
($_SERVER['HTTP_ACCEPT'])) {
// Check for UTF support.
if (isset
($_SERVER['HTTP_ACCEPT_CHARSET'])) {
$this->setQuirk('double_linebreak_textarea');
$this->setQuirk('break_disposition_filename');
if (strpos($version[1], '.') !==
false) {
/* IE (< 7) on Windows does not support alpha transparency in
/* Some Handhelds have their screen resolution in the
* user agent string, which we can use to look for
$this->setQuirk('broken_multipart_form');
$this->setQuirk('break_disposition_header');
$this->setQuirk('broken_multipart_form');
// Konqueror and Apple's Safari both use the KHTML
$this->setQuirk('empty_file_input_value');
$this->setQuirk('no_hidden_overflow_tables');
if (isset
($version[2])) {
$this->setQuirk('break_disposition_filename');
if ($revision[1] >=
1.3) {
/* The device accepts Openwave GUI extensions for
* WML 1.3. Non-UP.Link gateways sometimes have
* problems, so exclude them. */
* 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.
* 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);
* Set unique behavior for the current browser.
* @param string $quirk The behavior to set.
* @param string $value Special behavior parameter.
function setQuirk($quirk, $value =
true) {
* Check unique behavior for the current browser.
* @param string $quirk The behavior to check.
* @return boolean Does the browser have the behavior set?
return !empty($this->_quirks[$quirk]);
* Retrieve unique behavior for the current browser.
* @param string $quirk The behavior to retrieve.
* @return string The value for the requested behavior.
return isset
($this->_quirks[$quirk])
* Set capabilities for the current browser.
* @param string $feature The capability to set.
* @param string $value Special capability parameter.
* Check the current browser capabilities.
* @param string $feature The capability to check.
* @return boolean Does the browser have the capability set?
* Retrieve the current browser capability.
* @param string $feature The capability to retrieve.
* @return string The value of the requested capability.
* Determines if a browser can display a given MIME type.
* @param string $mimetype The MIME type to check.
* @return boolean True if the browser can display the MIME type.
list
($type, $subtype) =
explode('/', $mimetype);
/* 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
($mimetype ==
'image/pjpeg') &&
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?
* Determines if the browser is a robot or not.
* @return boolean True if browser is a known robot.
foreach ($this->_robots as $robot) {
* Determine if we are using a secure (SSL) connection.
* @return boolean True if using SSL, false if not.
return ((isset
($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] ==
'on')) ||
getenv('SSL_PROTOCOL_VERSION'));