Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/environment/browser.php

Documentation is available at browser.php

  1. <?php
  2. /**
  3. @version        $Id: browser.php 6472 2007-02-03 10:47:26Z pasamio $
  4. @package        Joomla.Framework
  5. @subpackage    Environment
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Browser class, provides capability information about the current web client.
  20.  *
  21.  * Browser identification is performed by examining the HTTP_USER_AGENT
  22.  * environment variable provided by the web server.
  23.  *
  24.  * This class has many influences from the lib/Browser.php code in
  25.  * version 3 of Horde.
  26.  *
  27.  * @author  Chuck Hagenbuch <[email protected]>
  28.  * @author  Jon Parise <[email protected]>
  29.  * @author    Johan Janssens <[email protected]>
  30.  *
  31.  * @package        Joomla.Framework
  32.  * @subpackage    Environment
  33.  * @since        1.5
  34.  */
  35.  
  36. class JBrowser extends JObject
  37. {
  38.     /**
  39.      * Major version number.
  40.      *
  41.      * @var integer 
  42.      */
  43.     var $_majorVersion = 0;
  44.  
  45.     /**
  46.      * Minor version number.
  47.      *
  48.      * @var integer 
  49.      */
  50.     var $_minorVersion = 0;
  51.  
  52.     /**
  53.      * Browser name.
  54.      *
  55.      * @var string 
  56.      */
  57.     var $_browser = '';
  58.  
  59.     /**
  60.      * Full user agent string.
  61.      *
  62.      * @var string 
  63.      */
  64.     var $_agent = '';
  65.  
  66.     /**
  67.      * Lower-case user agent string.
  68.      *
  69.      * @var string 
  70.      */
  71.     var $_lowerAgent = '';
  72.  
  73.     /**
  74.      * HTTP_ACCEPT string
  75.      *
  76.      * @var string 
  77.      */
  78.     var $_accept = '';
  79.  
  80.      /**
  81.      * Platform the browser is running on.
  82.      *
  83.      * @var string 
  84.      */
  85.     var $_platform = '';
  86.  
  87.     /**
  88.      * Known robots.
  89.      *
  90.      * @var array 
  91.      */
  92.     var $_robots = array(
  93.         /* The most common ones. */
  94.         
  95.         'Googlebot',
  96.         'msnbot',
  97.         'Slurp',
  98.         'Yahoo',
  99.         /* The rest alphabetically. */
  100.         
  101.         'Arachnoidea',
  102.         'ArchitextSpider',
  103.         'Ask Jeeves',
  104.         'B-l-i-t-z-Bot',
  105.         'Baiduspider',
  106.         'BecomeBot',
  107.         'cfetch',
  108.         'ConveraCrawler',
  109.         'ExtractorPro',
  110.         'FAST-WebCrawler',
  111.         'FDSE robot',
  112.         'fido',
  113.         'geckobot',
  114.         'Gigabot',
  115.         'Girafabot',
  116.         'grub-client',
  117.         'Gulliver',
  118.         'HTTrack',
  119.         'ia_archiver',
  120.         'InfoSeek',
  121.         'kinjabot',
  122.         'KIT-Fireball',
  123.         'larbin',
  124.         'LEIA',
  125.         'lmspider',
  126.         'Lycos_Spider',
  127.         'Mediapartners-Google',
  128.         'MuscatFerret',
  129.         'NaverBot',
  130.         'OmniExplorer_Bot',
  131.         'polybot',
  132.         'Pompos',
  133.         'Scooter',
  134.         'Teoma',
  135.         'TheSuBot',
  136.         'TurnitinBot',
  137.         'Ultraseek',
  138.         'ViolaBot',
  139.         'webbandit',
  140.         'www.almaden.ibm.com/cs/crawler',
  141.         'ZyBorg',
  142.     );
  143.  
  144.     /**
  145.      * Is this a mobile browser?
  146.      *
  147.      * @var boolean 
  148.      */
  149.     var $_mobile = false;
  150.  
  151.     /**
  152.      * Features.
  153.      *
  154.      * @var array 
  155.      */
  156.     var $_features = array(
  157.         'html'            => true,
  158.         'hdml'            => false,
  159.         'wml'            => false,
  160.         'images'         => true,
  161.         'iframes'        => false,
  162.         'frames'         => true,
  163.         'tables'         => true,
  164.         'java'            => true,
  165.         'javascript'    => true,
  166.         'dom'            => false,
  167.         'utf'            => false,
  168.         'rte'            => false,
  169.         'homepage'        => false,
  170.         'accesskey'        => false,
  171.         'optgroup'        => false,
  172.         'xmlhttpreq'    => false,
  173.         'cite'            => false,
  174.     );
  175.  
  176.     /**
  177.      * Quirks
  178.      *
  179.      * @var array 
  180.      */
  181.     var $_quirks = array(
  182.         'avoid_popup_windows'            => false,
  183.         'break_disposition_header'        => false,
  184.         'break_disposition_filename'    => false,
  185.         'broken_multipart_form'            => false,
  186.         'cache_same_url'                => false,
  187.         'cache_ssl_downloads'            => false,
  188.         'double_linebreak_textarea'        => false,
  189.         'empty_file_input_value'        => false,
  190.         'must_cache_forms'                => false,
  191.         'no_filename_spaces'            => false,
  192.         'no_hidden_overflow_tables'        => false,
  193.         'ow_gui_1.3'                    => false,
  194.         'png_transparency'                => false,
  195.         'scrollbar_in_way'                => false,
  196.         'scroll_tds'                    => false,
  197.         'windowed_controls'                => false,
  198.     );
  199.  
  200.     /**
  201.      * List of viewable image MIME subtypes.
  202.      * This list of viewable images works for IE and Netscape/Mozilla.
  203.      *
  204.      * @var array 
  205.      */
  206.     var $_images = array('jpeg''gif''png''pjpeg''x-png''bmp');
  207.  
  208.  
  209.     /**
  210.      * Create a browser instance (Constructor).
  211.      *
  212.      * @param string $userAgent  The browser string to parse.
  213.      * @param string $accept     The HTTP_ACCEPT settings to use.
  214.      */
  215.     function __construct($userAgent null$accept null)
  216.     {
  217.         $this->match($userAgent$accept);
  218.     }
  219.  
  220.     /**
  221.      * Returns a reference to the global Browser object, only creating it
  222.      * if it doesn't already exist.
  223.      *
  224.      * This method must be invoked as:
  225.      *         <pre>  $browser = &JBrowser::getInstance([$userAgent[, $accept]]);</pre>
  226.      *
  227.      * @access public
  228.      * @param string $userAgent  The browser string to parse.
  229.      * @param string $accept     The HTTP_ACCEPT settings to use.
  230.      * @return JBrowser  The Browser object.
  231.      */
  232.     function &getInstance($userAgent null$accept null)
  233.     {
  234.         static $instances;
  235.  
  236.         if (!isset($instances)) {
  237.             $instances array();
  238.         }
  239.  
  240.         $signature serialize(array($userAgent$accept));
  241.  
  242.         if (empty($instances[$signature])) {
  243.             $instances[$signaturenew JBrowser($userAgent$accept);
  244.         }
  245.  
  246.         return $instances[$signature];
  247.     }
  248.  
  249.    /**
  250.      * Parses the user agent string and inititializes the object with
  251.      * all the known features and quirks for the given browser.
  252.      *
  253.      * @param string $userAgent  The browser string to parse.
  254.      * @param string $accept     The HTTP_ACCEPT settings to use.
  255.      */
  256.     function match($userAgent null$accept null)
  257.     {
  258.         // Set our agent string.
  259.         if (is_null($userAgent)) {
  260.             if (isset($_SERVER['HTTP_USER_AGENT'])) {
  261.                 $this->_agent = trim($_SERVER['HTTP_USER_AGENT']);
  262.             }
  263.         else {
  264.             $this->_agent = $userAgent;
  265.         }
  266.         $this->_lowerAgent = strtolower($this->_agent);
  267.  
  268.         // Set our accept string.
  269.         if (is_null($accept)) {
  270.             if (isset($_SERVER['HTTP_ACCEPT'])) {
  271.                 $this->_accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
  272.             }
  273.         else {
  274.             $this->_accept = strtolower($accept);
  275.         }
  276.  
  277.         // Check for UTF support.
  278.         if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
  279.             $this->setFeature('utf'strpos(strtolower($_SERVER['HTTP_ACCEPT_CHARSET'])'utf'!== false);
  280.         }
  281.  
  282.         if (!empty($this->_agent)) {
  283.             $this->_setPlatform();
  284.  
  285.             if (strpos($this->_lowerAgent'mobileexplorer'!== false ||
  286.                 strpos($this->_lowerAgent'openwave'!== false ||
  287.                 strpos($this->_lowerAgent'opera mini'!== false ||
  288.                 strpos($this->_lowerAgent'operamini'!== false{
  289.                 $this->setFeature('frames'false);
  290.                 $this->setFeature('javascript'false);
  291.                 $this->setQuirk('avoid_popup_windows');
  292.                 $this->_mobile = true;
  293.             elseif (preg_match('|Opera[/ ]([0-9.]+)|'$this->_agent$version)) {
  294.                         $this->setBrowser('opera');
  295.                         list($this->_majorVersion$this->_minorVersionexplode('.'$version[1]);
  296.                         $this->setFeature('javascript'true);
  297.                         $this->setQuirk('no_filename_spaces');
  298.  
  299.                 if ($this->_majorVersion >= 7{
  300.                     $this->setFeature('dom');
  301.                     $this->setFeature('iframes');
  302.                     $this->setFeature('accesskey');
  303.                     $this->setFeature('optgroup');
  304.                     $this->setQuirk('double_linebreak_textarea');
  305.                 }
  306.             elseif (strpos($this->_lowerAgent'elaine/'!== false ||
  307.                         strpos($this->_lowerAgent'palmsource'!== false ||
  308.                         strpos($this->_lowerAgent'digital paths'!== false{
  309.                 $this->setBrowser('palm');
  310.                 $this->setFeature('images'false);
  311.                 $this->setFeature('frames'false);
  312.                 $this->setFeature('javascript'false);
  313.                 $this->setQuirk('avoid_popup_windows');
  314.                 $this->_mobile = true;
  315.             elseif ((preg_match('|MSIE ([0-9.]+)|'$this->_agent$version)) ||
  316.                         (preg_match('|Internet Explorer/([0-9.]+)|'$this->_agent$version))) {
  317.  
  318.                 $this->setBrowser('msie');
  319.                 $this->setQuirk('cache_ssl_downloads');
  320.                 $this->setQuirk('cache_same_url');
  321.                 $this->setQuirk('break_disposition_filename');
  322.  
  323.                 if (strpos($version[1]'.'!== false{
  324.                     list($this->_majorVersion$this->_minorVersionexplode('.'$version[1]);
  325.                 else {
  326.                     $this->_majorVersion = $version[1];
  327.                     $this->_minorVersion = 0;
  328.                 }
  329.  
  330.                 /* IE (< 7) on Windows does not support alpha transparency in
  331.                  * PNG images. */
  332.                 if (($this->_majorVersion < 7&&
  333.                     preg_match('/windows/i'$this->_agent)) {
  334.                     $this->setQuirk('png_transparency');
  335.                 }
  336.  
  337.                 /* Some Handhelds have their screen resolution in the
  338.                  * user agent string, which we can use to look for
  339.                  * mobile agents. */
  340.                 if (preg_match('/; (120x160|240x280|240x320|320x320)\)/'$this->_agent)) {
  341.                     $this->_mobile = true;
  342.                 }
  343.  
  344.                 switch ($this->_majorVersion{
  345.                 case 7:
  346.                     $this->setFeature('javascript'1.4);
  347.                     $this->setFeature('dom');
  348.                     $this->setFeature('iframes');
  349.                     $this->setFeature('utf');
  350.                     $this->setFeature('rte');
  351.                     $this->setFeature('homepage');
  352.                     $this->setFeature('accesskey');
  353.                     $this->setFeature('optgroup');
  354.                     $this->setFeature('xmlhttpreq');
  355.                     $this->setQuirk('scrollbar_in_way');
  356.                     break;
  357.  
  358.                 case 6:
  359.                     $this->setFeature('javascript'1.4);
  360.                     $this->setFeature('dom');
  361.                     $this->setFeature('iframes');
  362.                     $this->setFeature('utf');
  363.                     $this->setFeature('rte');
  364.                     $this->setFeature('homepage');
  365.                     $this->setFeature('accesskey');
  366.                     $this->setFeature('optgroup');
  367.                     $this->setFeature('xmlhttpreq');
  368.                     $this->setQuirk('scrollbar_in_way');
  369.                     $this->setQuirk('broken_multipart_form');
  370.                     $this->setQuirk('windowed_controls');
  371.                     break;
  372.  
  373.                 case 5:
  374.                     if ($this->getPlatform(== 'mac'{
  375.                         $this->setFeature('javascript'1.2);
  376.                         $this->setFeature('optgroup');
  377.                     else {
  378.                         // MSIE 5 for Windows.
  379.                         $this->setFeature('javascript'1.4);
  380.                         $this->setFeature('dom');
  381.                         $this->setFeature('xmlhttpreq');
  382.                         if ($this->_minorVersion >= 5{
  383.                             $this->setFeature('rte');
  384.                             $this->setQuirk('windowed_controls');
  385.                         }
  386.                     }
  387.                     $this->setFeature('iframes');
  388.                     $this->setFeature('utf');
  389.                     $this->setFeature('homepage');
  390.                     $this->setFeature('accesskey');
  391.                     if ($this->_minorVersion == 5{
  392.                         $this->setQuirk('break_disposition_header');
  393.                         $this->setQuirk('broken_multipart_form');
  394.                     }
  395.                     break;
  396.  
  397.                 case 4:
  398.                     $this->setFeature('javascript'1.2);
  399.                     $this->setFeature('accesskey');
  400.                     if ($this->_minorVersion > 0{
  401.                         $this->setFeature('utf');
  402.                     }
  403.                     break;
  404.  
  405.                 case 3:
  406.                     $this->setFeature('javascript'1.5);
  407.                     $this->setQuirk('avoid_popup_windows');
  408.                     break;
  409.                 }
  410.             elseif (preg_match('|ANTFresco/([0-9]+)|'$this->_agent$version)) {
  411.                 $this->setBrowser('fresco');
  412.                 $this->setFeature('javascript'1.5);
  413.                 $this->setQuirk('avoid_popup_windows');
  414.             elseif (strpos($this->_lowerAgent'avantgo'!== false{
  415.                 $this->setBrowser('avantgo');
  416.                 $this->_mobile = true;
  417.             elseif (preg_match('|Konqueror/([0-9]+)|'$this->_agent$version||
  418.                         preg_match('|Safari/([0-9]+)\.?([0-9]+)?|'$this->_agent$version)) {
  419.                 // Konqueror and Apple's Safari both use the KHTML
  420.                 // rendering engine.
  421.                 $this->setBrowser('konqueror');
  422.                 $this->setQuirk('empty_file_input_value');
  423.                 $this->setQuirk('no_hidden_overflow_tables');
  424.                 $this->_majorVersion = $version[1];
  425.                 if (isset($version[2])) {
  426.                     $this->_minorVersion = $version[2];
  427.                 }
  428.  
  429.                 if (strpos($this->_agent'Safari'!== false &&
  430.                     $this->_majorVersion >= 60{
  431.                     // Safari.
  432.                     $this->setFeature('utf');
  433.                     $this->setFeature('javascript'1.4);
  434.                     $this->setFeature('dom');
  435.                     $this->setFeature('iframes');
  436.                     if ($this->_majorVersion > 125 ||
  437.                         ($this->_majorVersion == 125 &&
  438.                          $this->_minorVersion >= 1)) {
  439.                         $this->setFeature('accesskey');
  440.                         $this->setFeature('xmlhttpreq');
  441.                     }
  442.                 else {
  443.                     // Konqueror.
  444.                     $this->setFeature('javascript'1.5);
  445.                     switch ($this->_majorVersion{
  446.                     case 3:
  447.                         $this->setFeature('dom');
  448.                         $this->setFeature('iframes');
  449.                         break;
  450.                     }
  451.                 }
  452.             elseif (preg_match('|Mozilla/([0-9.]+)|'$this->_agent$version)) {
  453.                 $this->setBrowser('mozilla');
  454.                 $this->setQuirk('must_cache_forms');
  455.  
  456.                 list($this->_majorVersion$this->_minorVersionexplode('.'$version[1]);
  457.                 switch ($this->_majorVersion{
  458.                 case 5:
  459.                     if ($this->getPlatform(== 'win'{
  460.                         $this->setQuirk('break_disposition_filename');
  461.                     }
  462.                     $this->setFeature('javascript'1.4);
  463.                     $this->setFeature('dom');
  464.                     $this->setFeature('accesskey');
  465.                     $this->setFeature('optgroup');
  466.                     $this->setFeature('xmlhttpreq');
  467.                     $this->setFeature('cite');
  468.                     if (preg_match('|rv:(.*)\)|'$this->_agent$revision)) {
  469.                         if ($revision[1>= 1{
  470.                             $this->setFeature('iframes');
  471.                         }
  472.                         if ($revision[1>= 1.3{
  473.                             $this->setFeature('rte');
  474.                         }
  475.                     }
  476.                     break;
  477.  
  478.                 case 4:
  479.                     $this->setFeature('javascript'1.3);
  480.                     $this->setQuirk('buggy_compression');
  481.                     break;
  482.  
  483.                 case 3:
  484.                 default:
  485.                     $this->setFeature('javascript'1);
  486.                     $this->setQuirk('buggy_compression');
  487.                     break;
  488.                 }
  489.             elseif (preg_match('|Lynx/([0-9]+)|'$this->_agent$version)) {
  490.                 $this->setBrowser('lynx');
  491.                 $this->setFeature('images'false);
  492.                 $this->setFeature('frames'false);
  493.                 $this->setFeature('javascript'false);
  494.                 $this->setQuirk('avoid_popup_windows');
  495.             elseif (preg_match('|Links \(([0-9]+)|'$this->_agent$version)) {
  496.                 $this->setBrowser('links');
  497.                 $this->setFeature('images'false);
  498.                 $this->setFeature('frames'false);
  499.                 $this->setFeature('javascript'false);
  500.                 $this->setQuirk('avoid_popup_windows');
  501.             elseif (preg_match('|HotJava/([0-9]+)|'$this->_agent$version)) {
  502.                 $this->setBrowser('hotjava');
  503.                 $this->setFeature('javascript'false);
  504.             elseif (strpos($this->_agent'UP/'!== false ||
  505.                         strpos($this->_agent'UP.B'!== false ||
  506.                         strpos($this->_agent'UP.L'!== false{
  507.                 $this->setBrowser('up');
  508.                 $this->setFeature('html'false);
  509.                 $this->setFeature('javascript'false);
  510.                 $this->setFeature('hdml');
  511.                 $this->setFeature('wml');
  512.  
  513.                 if (strpos($this->_agent'GUI'!== false &&
  514.                     strpos($this->_agent'UP.Link'!== false{
  515.                     /* The device accepts Openwave GUI extensions for
  516.                      * WML 1.3. Non-UP.Link gateways sometimes have
  517.                      * problems, so exclude them. */
  518.                     $this->setQuirk('ow_gui_1.3');
  519.                 }
  520.                 $this->_mobile = true;
  521.             elseif (strpos($this->_agent'Xiino/'!== false{
  522.                 $this->setBrowser('xiino');
  523.                 $this->setFeature('hdml');
  524.                 $this->setFeature('wml');
  525.                 $this->_mobile = true;
  526.             elseif (strpos($this->_agent'Palmscape/'!== false{
  527.                 $this->setBrowser('palmscape');
  528.                 $this->setFeature('javascript'false);
  529.                 $this->setFeature('hdml');
  530.                 $this->setFeature('wml');
  531.                 $this->_mobile = true;
  532.             elseif (strpos($this->_agent'Nokia'!== false{
  533.                 $this->setBrowser('nokia');
  534.                 $this->setFeature('html'false);
  535.                 $this->setFeature('wml');
  536.                 $this->setFeature('xhtml');
  537.                 $this->_mobile = true;
  538.             elseif (strpos($this->_agent'Ericsson'!== false{
  539.                 $this->setBrowser('ericsson');
  540.                 $this->setFeature('html'false);
  541.                 $this->setFeature('wml');
  542.                 $this->_mobile = true;
  543.             elseif (strpos($this->_lowerAgent'wap'!== false{
  544.                 $this->setBrowser('wap');
  545.                 $this->setFeature('html'false);
  546.                 $this->setFeature('javascript'false);
  547.                 $this->setFeature('hdml');
  548.                 $this->setFeature('wml');
  549.                 $this->_mobile = true;
  550.             elseif (strpos($this->_lowerAgent'docomo'!== false ||
  551.                         strpos($this->_lowerAgent'portalmmm'!== false{
  552.                 $this->setBrowser('imode');
  553.                 $this->setFeature('images'false);
  554.                 $this->_mobile = true;
  555.         elseif (strpos($this->_agent'BlackBerry'!== false{
  556.                 $this->setBrowser('blackberry');
  557.                 $this->setFeature('html'false);
  558.                 $this->setFeature('javascript'false);
  559.                 $this->setFeature('hdml');
  560.                 $this->setFeature('wml');
  561.                 $this->_mobile = true;
  562.             elseif (strpos($this->_agent'MOT-'!== false{
  563.                 $this->setBrowser('motorola');
  564.                 $this->setFeature('html'false);
  565.                 $this->setFeature('javascript'false);
  566.                 $this->setFeature('hdml');
  567.                 $this->setFeature('wml');
  568.                 $this->_mobile = true;
  569.             elseif (strpos($this->_lowerAgent'j-'!== false{
  570.                 $this->setBrowser('mml');
  571.                 $this->_mobile = true;
  572.             }
  573.         }
  574.     }
  575.  
  576.      /**
  577.      * Match the platform of the browser.
  578.      *
  579.      * This is a pretty simplistic implementation, but it's intended
  580.      * to let us tell what line breaks to send, so it's good enough
  581.      * for its purpose.
  582.      */
  583.     function _setPlatform()
  584.     {
  585.         if (strpos($this->_lowerAgent'wind'!== false{
  586.             $this->_platform = 'win';
  587.         elseif (strpos($this->_lowerAgent'mac'!== false{
  588.             $this->_platform = 'mac';
  589.         else {
  590.             $this->_platform = 'unix';
  591.         }
  592.     }
  593.  
  594.     /**
  595.      * Return the currently matched platform.
  596.      *
  597.      * @return string  The user's platform.
  598.      */
  599.     function getPlatform()     {
  600.         return $this->_platform;
  601.     }
  602.  
  603.     /**
  604.      * Sets the current browser.
  605.      *
  606.      * @param string $browser  The browser to set as current.
  607.      */
  608.     function setBrowser($browser{
  609.         $this->_browser = $browser;
  610.     }
  611.  
  612.     /**
  613.      * Retrieve the current browser.
  614.      *
  615.      * @return string  The current browser.
  616.      */
  617.     function getBrowser()     {
  618.         return $this->_browser;
  619.     }
  620.  
  621.     /**
  622.      * Retrieve the current browser's major version.
  623.      *
  624.      * @return integer  The current browser's major version.
  625.      */
  626.     function getMajor()     {
  627.         return $this->_majorVersion;
  628.     }
  629.  
  630.     /**
  631.      * Retrieve the current browser's minor version.
  632.      * @return integer  The current browser's minor version.
  633.      */
  634.     function getMinor()     {
  635.         return $this->_minorVersion;
  636.     }
  637.  
  638.     /**
  639.      * Retrieve the current browser's version.
  640.      * @return string  The current browser's version.
  641.      */
  642.     function getVersion()     {
  643.         return $this->_majorVersion . '.' $this->_minorVersion;
  644.     }
  645.  
  646.     /**
  647.      * Return the full browser agent string.
  648.      *
  649.      * @return string  The browser agent string.
  650.      */
  651.     function getAgentString()     {
  652.         return $this->_agent;
  653.     }
  654.  
  655.     /**
  656.      * Returns the server protocol in use on the current server.
  657.      *
  658.      * @return string  The HTTP server protocol version.
  659.      */
  660.     function getHTTPProtocol()
  661.     {
  662.         if (isset($_SERVER['SERVER_PROTOCOL'])) {
  663.             if (($pos strrpos($_SERVER['SERVER_PROTOCOL']'/'))) {
  664.                 return substr($_SERVER['SERVER_PROTOCOL']$pos 1);
  665.             }
  666.         }
  667.         return null;
  668.     }
  669.  
  670.     /**
  671.      * Set unique behavior for the current browser.
  672.      *
  673.      * @param string $quirk  The behavior to set.
  674.      * @param string $value  Special behavior parameter.
  675.      */
  676.     function setQuirk($quirk$value true{
  677.         $this->_quirks[$quirk$value;
  678.     }
  679.  
  680.     /**
  681.      * Check unique behavior for the current browser.
  682.      *
  683.      * @param string $quirk  The behavior to check.
  684.      * @return boolean  Does the browser have the behavior set?
  685.      */
  686.     function hasQuirk($quirk{
  687.         return !empty($this->_quirks[$quirk]);
  688.     }
  689.  
  690.      /**
  691.      * Retrieve unique behavior for the current browser.
  692.      *
  693.      * @param string $quirk  The behavior to retrieve.
  694.      * @return string  The value for the requested behavior.
  695.      */
  696.     function getQuirk($quirk)
  697.     {
  698.         return isset($this->_quirks[$quirk])
  699.                 ? $this->_quirks[$quirk]
  700.                 : null;
  701.     }
  702.  
  703.     /**
  704.      * Set capabilities for the current browser.
  705.      *
  706.      * @param string $feature  The capability to set.
  707.      * @param string $value    Special capability parameter.
  708.      */
  709.     function setFeature($feature$value true{
  710.         $this->_features[$feature$value;
  711.     }
  712.  
  713.  
  714.     /**
  715.      * Check the current browser capabilities.
  716.      * @param string $feature  The capability to check.
  717.      * @return boolean  Does the browser have the capability set?
  718.      */
  719.     function hasFeature($feature)     {
  720.         return !empty($this->_features[$feature]);
  721.     }
  722.  
  723.     /**
  724.      * Retrieve the current browser capability.
  725.      *
  726.      * @param string $feature  The capability to retrieve.
  727.      * @return string  The value of the requested capability.
  728.      */
  729.     function getFeature($feature)     {
  730.          return isset($this->_features[$feature])
  731.                 ? $this->_features[$feature]
  732.                 : null;
  733.     }
  734.  
  735.     /**
  736.      * Determines if a browser can display a given MIME type.
  737.      *
  738.      * @param string $mimetype  The MIME type to check.
  739.      * @return boolean  True if the browser can display the MIME type.
  740.      */
  741.     function isViewable($mimetype)
  742.     {
  743.         $mimetype strtolower($mimetype);
  744.         list($type$subtypeexplode('/'$mimetype);
  745.  
  746.         if (!empty($this->_accept)) {
  747.             $wildcard_match false;
  748.  
  749.             if (strpos($this->_accept$mimetype!== false{
  750.                 return true;
  751.             }
  752.  
  753.             if (strpos($this->_accept'*/*'!== false{
  754.                 $wildcard_match true;
  755.                 if ($type != 'image'{
  756.                     return true;
  757.                 }
  758.              }
  759.  
  760.             /* image/jpeg and image/pjpeg *appear* to be the same
  761.             * entity, but Mozilla doesn't seem to want to accept the
  762.             * latter.  For our purposes, we will treat them the
  763.             * same.
  764.             */
  765.                 if ($this->isBrowser('mozilla'&&
  766.                 ($mimetype == 'image/pjpeg'&&
  767.                 (strpos($this->_accept'image/jpeg'!== false)) {
  768.                     return true;
  769.                 }
  770.  
  771.             if (!$wildcard_match{
  772.                 return false;
  773.             }
  774.         }
  775.  
  776.         if (!$this->hasFeature('images'|| ($type != 'image')) {
  777.             return false;
  778.         }
  779.  
  780.         return (in_array($subtype$this->_images));
  781.     }
  782.  
  783.     /**
  784.      * Determine if the given browser is the same as the current.
  785.      *
  786.      * @param string $browser  The browser to check.
  787.      * @return boolean  Is the given browser the same as the current?
  788.      */
  789.     function isBrowser($browser)
  790.     {
  791.         return ($this->_browser === $browser);
  792.     }
  793.  
  794.     /**
  795.      * Determines if the browser is a robot or not.
  796.      *
  797.      * @return boolean  True if browser is a known robot.
  798.      */
  799.     function isRobot()
  800.     {
  801.          foreach ($this->_robots as $robot{
  802.              if (strpos($this->_agent$robot!== false{
  803.                  return true;
  804.             }
  805.         }
  806.         return false;
  807.     }
  808.  
  809.     /**
  810.      * Determine if we are using a secure (SSL) connection.
  811.      *
  812.      * @return boolean  True if using SSL, false if not.
  813.      */
  814.     function isSSLConnection()
  815.     {
  816.         return ((isset($_SERVER['HTTPS']&&
  817.             ($_SERVER['HTTPS'== 'on')) ||
  818.             getenv('SSL_PROTOCOL_VERSION'));
  819.     }
  820. }
  821. ?>

Documentation generated on Mon, 05 Mar 2007 20:53:26 +0000 by phpDocumentor 1.3.1