Actions

API16

JBrowser/match

From Joomla! Documentation

< API16:JBrowser
Revision as of 16:46, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Parses the user agent string and inititializes the object with all the known features and quirks for the given browser.

[Edit Descripton]

Description:JBrowser/match

Syntax

match($userAgent=null, $accept=null)
Parameter Name Default Value Description
$userAgent null $userAgent The browser string to parse.
$accept null $accept The HTTP_ACCEPT settings to use.

Defined in

libraries/joomla/environment/browser.php

Importing

jimport( 'joomla.environment.browser' );

Source Body

public function match($userAgent = null, $accept = null)
{
        // Set our agent string.
        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);
 
        // Set our accept string.
        if (is_null($accept)) {
                if (isset($_SERVER['HTTP_ACCEPT'])) {
                        $this->_accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
                }
        } else {
                $this->_accept = strtolower($accept);
        }
 
 
        // Check if browser excepts content type xhtml+xml.
        if (strpos($this->_accept, 'application/xhtml+xml')) {
                $this->setFeature('xhtml+xml');
        }
 
        // Check for a mathplayer plugin is installed, so we can use MathML on several browsers.
        if (strpos($this->_lowerAgent, 'mathplayer') !== false) {
                $this->setFeature('mathml');
        }
 
        // Check for UTF support.
        if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
                $this->setFeature('utf', strpos(strtolower($_SERVER['HTTP_ACCEPT_CHARSET']), 'utf') !== false);
        }
 
        if (!empty($this->_agent)) {
                $this->_setPlatform();
 
                if (strpos($this->_lowerAgent, 'mobileexplorer') !== false ||
                        strpos($this->_lowerAgent, 'openwave') !== false ||
                        strpos($this->_lowerAgent, 'opera mini') !== false ||
                        strpos($this->_lowerAgent, 'operamini') !== false) {
                        $this->setFeature('frames', false);
                        $this->setFeature('javascript', false);
                        $this->setQuirk('avoid_popup_windows');
                        $this->_mobile = true;
                } elseif (preg_match('|Opera[/ ]([0-9.]+)|', $this->_agent, $version)) {
                                        $this->setBrowser('opera');
                                        list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
                                        $this->setFeature('javascript', true);
                                        $this->setQuirk('no_filename_spaces');
 
                        if ($this->_majorVersion >= 7) {
                                $this->setFeature('dom');
                                $this->setFeature('iframes');
                                $this->setFeature('accesskey');
                                $this->setFeature('optgroup');
                                $this->setQuirk('double_linebreak_textarea');
                        }
                } elseif (strpos($this->_lowerAgent, 'elaine/') !== false ||
                                        strpos($this->_lowerAgent, 'palmsource') !== false ||
                                        strpos($this->_lowerAgent, 'digital paths') !== false) {
                        $this->setBrowser('palm');
                        $this->setFeature('images', false);
                        $this->setFeature('frames', false);
                        $this->setFeature('javascript', false);
                        $this->setQuirk('avoid_popup_windows');
                        $this->_mobile = true;
                } elseif ((preg_match('|MSIE ([0-9.]+)|', $this->_agent, $version)) ||
                                        (preg_match('|Internet Explorer/([0-9.]+)|', $this->_agent, $version))) {
 
                        $this->setBrowser('msie');
                        $this->setQuirk('cache_ssl_downloads');
                        $this->setQuirk('cache_same_url');
                        $this->setQuirk('break_disposition_filename');
 
                        if (strpos($version[1], '.') !== false) {
                                list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
                        } else {
                                $this->_majorVersion = $version[1];
                                $this->_minorVersion = 0;
                        }
 
                        /* IE (< 7) on Windows does not support alpha transparency in
                         * PNG images. */
                        if (($this->_majorVersion < 7) &&
                                preg_match('/windows/i', $this->_agent)) {
                                $this->setQuirk('png_transparency');
                        }
 
                        /* Some Handhelds have their screen resolution in the
                         * user agent string, which we can use to look for
                         * mobile agents. */
                        if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $this->_agent)) {
                                $this->_mobile = true;
                        }
 
                        switch ($this->_majorVersion) {
                        case 7:
                                $this->setFeature('javascript', 1.4);
                                $this->setFeature('dom');
                                $this->setFeature('iframes');
                                $this->setFeature('utf');
                                $this->setFeature('rte');
                                $this->setFeature('homepage');
                                $this->setFeature('accesskey');
                                $this->setFeature('optgroup');
                                $this->setFeature('xmlhttpreq');
                                $this->setQuirk('scrollbar_in_way');
                                break;
 
                        case 6:
                                $this->setFeature('javascript', 1.4);
                                $this->setFeature('dom');
                                $this->setFeature('iframes');
                                $this->setFeature('utf');
                                $this->setFeature('rte');
                                $this->setFeature('homepage');
                                $this->setFeature('accesskey');
                                $this->setFeature('optgroup');
                                $this->setFeature('xmlhttpreq');
                                $this->setQuirk('scrollbar_in_way');
                                $this->setQuirk('broken_multipart_form');
                                $this->setQuirk('windowed_controls');
                                break;
 
                        case 5:
                                if ($this->getPlatform() == 'mac') {
                                        $this->setFeature('javascript', 1.2);
                                        $this->setFeature('optgroup');
                                } else {
                                        // MSIE 5 for Windows.
                                        $this->setFeature('javascript', 1.4);
                                        $this->setFeature('dom');
                                        $this->setFeature('xmlhttpreq');
                                        if ($this->_minorVersion >= 5) {
                                                $this->setFeature('rte');
                                                $this->setQuirk('windowed_controls');
                                        }
                                }
                                $this->setFeature('iframes');
                                $this->setFeature('utf');
                                $this->setFeature('homepage');
                                $this->setFeature('accesskey');
                                if ($this->_minorVersion == 5) {
                                        $this->setQuirk('break_disposition_header');
                                        $this->setQuirk('broken_multipart_form');
                                }
                                break;
 
                        case 4:
                                $this->setFeature('javascript', 1.2);
                                $this->setFeature('accesskey');
                                if ($this->_minorVersion > 0) {
                                        $this->setFeature('utf');
                                }
                                break;
 
                        case 3:
                                $this->setFeature('javascript', 1.5);
                                $this->setQuirk('avoid_popup_windows');
                                break;
                        }
                } elseif (preg_match('|amaya/([0-9.]+)|', $this->_agent, $version)) {
                        $this->setBrowser('amaya');
                        $this->_majorVersion = $version[1];
                        if (isset($version[2])) {
                                $this->_minorVersion = $version[2];
                        }
                        if ($this->_majorVersion > 1) {
                                $this->setFeature('mathml');
                                $this->setFeature('svg');
                        }
                        $this->setFeature('xhtml+xml');
                } elseif (preg_match('|W3C_Validator/([0-9.]+)|', $this->_agent, $version)) {
                        $this->setFeature('mathml');
                        $this->setFeature('svg');
                        $this->setFeature('xhtml+xml');
                } elseif (preg_match('|ANTFresco/([0-9]+)|', $this->_agent, $version)) {
                        $this->setBrowser('fresco');
                        $this->setFeature('javascript', 1.5);
                        $this->setQuirk('avoid_popup_windows');
                } elseif (strpos($this->_lowerAgent, 'avantgo') !== false) {
                        $this->setBrowser('avantgo');
                        $this->_mobile = true;
                } elseif (preg_match('|Konqueror/([0-9]+)|', $this->_agent, $version) ||
                                        preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->_agent, $version)) {
                        // Konqueror and Apple's Safari both use the KHTML
                        // rendering engine.
                        $this->setBrowser('konqueror');
                        $this->setQuirk('empty_file_input_value');
                        $this->setQuirk('no_hidden_overflow_tables');
                        $this->_majorVersion = $version[1];
                        if (isset($version[2])) {
                                $this->_minorVersion = $version[2];
                        }
 
                        if (strpos($this->_agent, 'Safari') !== false &&
                                $this->_majorVersion >= 60) {
                                // Safari.
                                $this->setFeature('utf');
                                $this->setFeature('javascript', 1.4);
                                $this->setFeature('dom');
                                $this->setFeature('iframes');
                                if ($this->_majorVersion > 125 ||
                                        ($this->_majorVersion == 125 &&
                                        $this->_minorVersion >= 1)) {
                                        $this->setFeature('accesskey');
                                        $this->setFeature('xmlhttpreq');
                                }
                                if ($this->_majorVersion > 522) {
                                        $this->setFeature('svg');
                                        $this->setFeature('xhtml+xml');
                                }
                        } else {
                                // Konqueror.
                                $this->setFeature('javascript', 1.5);
                                switch ($this->_majorVersion) {
                                case 3:
                                        $this->setFeature('dom');
                                        $this->setFeature('iframes');
                        $this->setFeature('xhtml+xml');
                                        break;
                                }
                        }
                } elseif (preg_match('|Mozilla/([0-9.]+)|', $this->_agent, $version)) {
                        $this->setBrowser('mozilla');
                        $this->setQuirk('must_cache_forms');
 
                        list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
                        switch ($this->_majorVersion) {
                        case 5:
                                if ($this->getPlatform() == 'win') {
                                        $this->setQuirk('break_disposition_filename');
                                }
                                $this->setFeature('javascript', 1.4);
                                $this->setFeature('dom');
                                $this->setFeature('accesskey');
                                $this->setFeature('optgroup');
                                $this->setFeature('xmlhttpreq');
                                $this->setFeature('cite');
                                if (preg_match('|rv:(.*)\)|', $this->_agent, $revision)) {
                                        if ($revision[1] >= 1) {
                                                $this->setFeature('iframes');
                                        }
                                        if ($revision[1] >= 1.3) {
                                                $this->setFeature('rte');
                                        }
                                        if ($revision[1] >= 1.5) {
                                                $this->setFeature('svg');
                                                $this->setFeature('mathml');
                        $this->setFeature('xhtml+xml');
                                        }
                                }
                                break;
 
                        case 4:
                                $this->setFeature('javascript', 1.3);
                                $this->setQuirk('buggy_compression');
                                break;
 
                        case 3:
                        default:
                                $this->setFeature('javascript', 1);
                                $this->setQuirk('buggy_compression');
                                break;
                        }
                } elseif (preg_match('|Lynx/([0-9]+)|', $this->_agent, $version)) {
                        $this->setBrowser('lynx');
                        $this->setFeature('images', false);
                        $this->setFeature('frames', false);
                        $this->setFeature('javascript', false);
                        $this->setQuirk('avoid_popup_windows');
                } elseif (preg_match('|Links \(([0-9]+)|', $this->_agent, $version)) {
                        $this->setBrowser('links');
                        $this->setFeature('images', false);
                        $this->setFeature('frames', false);
                        $this->setFeature('javascript', false);
                        $this->setQuirk('avoid_popup_windows');
                } elseif (preg_match('|HotJava/([0-9]+)|', $this->_agent, $version)) {
                        $this->setBrowser('hotjava');
                        $this->setFeature('javascript', false);
                } elseif (strpos($this->_agent, 'UP/') !== false ||
                                        strpos($this->_agent, 'UP.B') !== false ||
                                        strpos($this->_agent, 'UP.L') !== false) {
                        $this->setBrowser('up');
                        $this->setFeature('html', false);
                        $this->setFeature('javascript', false);
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
 
                        if (strpos($this->_agent, 'GUI') !== false &&
                                strpos($this->_agent, 'UP.Link') !== false) {
                                /* The device accepts Openwave GUI extensions for
                                 * WML 1.3. Non-UP.Link gateways sometimes have
                                 * problems, so exclude them. */
                                $this->setQuirk('ow_gui_1.3');
                        }
                        $this->_mobile = true;
                } elseif (strpos($this->_agent, 'Xiino/') !== false) {
                        $this->setBrowser('xiino');
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_agent, 'Palmscape/') !== false) {
                        $this->setBrowser('palmscape');
                        $this->setFeature('javascript', false);
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_agent, 'Nokia') !== false) {
                        $this->setBrowser('nokia');
                        $this->setFeature('html', false);
                        $this->setFeature('wml');
                        $this->setFeature('xhtml');
                        $this->_mobile = true;
                } elseif (strpos($this->_agent, 'Ericsson') !== false) {
                        $this->setBrowser('ericsson');
                        $this->setFeature('html', false);
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_lowerAgent, 'wap') !== false) {
                        $this->setBrowser('wap');
                        $this->setFeature('html', false);
                        $this->setFeature('javascript', false);
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_lowerAgent, 'docomo') !== false ||
                                        strpos($this->_lowerAgent, 'portalmmm') !== false) {
                        $this->setBrowser('imode');
                        $this->setFeature('images', false);
                        $this->_mobile = true;
        } elseif (strpos($this->_agent, 'BlackBerry') !== false) {
                        $this->setBrowser('blackberry');
                        $this->setFeature('html', false);
                        $this->setFeature('javascript', false);
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_agent, 'MOT-') !== false) {
                        $this->setBrowser('motorola');
                        $this->setFeature('html', false);
                        $this->setFeature('javascript', false);
                        $this->setFeature('hdml');
                        $this->setFeature('wml');
                        $this->_mobile = true;
                } elseif (strpos($this->_lowerAgent, 'j-') !== false) {
                        $this->setBrowser('mml');
                        $this->_mobile = true;
                }
        }
}

[Edit See Also] SeeAlso:JBrowser/match

Examples

<CodeExamplesForm />