Changeset 1642

Show
Ignore:
Timestamp:
12/09/06 23:38:03 (3 years ago)
Author:
mbonetti
Message:

Applied Damien Raude-Morvan's changes for proper Konqueror and newer Safari browser capabilities detection.

http://www.drazzib.com/docs:php:browser_detection

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/gregarius/extlib/browser.php

    r1049 r1642  
    11<?php 
    22/***************************************************************** 
    3  * File name: browser.php Author: Gary White 
    4  * Last modified: November 10, 2003 
     3 * File name: browser.php 
     4 * Author: Gary White & Damien Raude-Morvan 
     5 * Last modified: December 10, 2006 
    56 * 
    67 ************************************************************** 
    78 * Copyright (C) 2003  Gary White 
     9 * Copyright (C) 2006  Damien Raude-Morvan <drazzib@drazzib.com> 
    810 * 
    911 This program is free software; you can redistribute it and/or 
     
    1719 GNU General Public License for more details at: 
    1820 http://www.gnu.org/copyleft/gpl.html 
    19  * 
     21 */ 
     22 
     23/** 
    2024 ************************************************************** 
    2125 * 
     
    5963 WebTV 
    6064 *****************************************************************/ 
    61  
    6265class browser { 
    6366 
     
    7073    var $isOpera = false; 
    7174    var $isSafari = false; 
     75    var $isKonqueror = false; 
    7276    var $isIE = false; 
    7377 
     
    174178            $bd['version'] = $val[1]; 
    175179 
     180            $this->isKonqueror = true; 
     181 
    176182            // test for iCab 
    177183        } 
     
    249255            // test for Safari 
    250256        } 
    251         elseif (eregi("safari", $agent)) { 
     257        elseif (eregi("AppleWebKit", $agent)) { 
    252258            $bd['browser'] = "Safari"; 
    253             $bd['version'] = ""; 
     259            $val = explode("/", $agent); 
     260            $bd['version'] = $val[3]; 
    254261            $this -> isSafari = true; 
    255262 
     
    306313    } 
    307314 
     315    /** Support of multipart/x-mixed-replace complete and stable : 
     316      * o in Safari 2.0.2 (http://webkit.org/blog/?p=32) 
     317      *     (http://developer.apple.com/internet/safari/uamatrix.html) 
     318      * o in Konqueror at least 3.4.3 
     319      *     (http://websvn.kde.org/trunk/KDE/kdelibs/khtml/kmultipart/kmultipart.cpp/) 
     320      */ 
    308321    function supportsServerPush() { 
    309         return ($this->isMoz || $this->isOpera); 
    310     } 
    311  
     322        return  ($this->isMoz 
     323             ||  $this->isOpera 
     324             || ($this->isSafari && $this->compareBrowserVersion("416", $this->Version)) 
     325             || ($this->isKonqueror && $this->compareBrowserVersion("3.4.3", $this->Version)) 
     326                ); 
     327    } 
     328 
     329    /** Support of XMLHTTPRequest complete and stable : 
     330      * o in Konqueror at least 3.4 (since 2004 - 
     331      *     http://websvn.kde.org/trunk/KDE/kdelibs/khtml/ecma/xmlhttprequest.cpp/) 
     332      */ 
    312333    function supportsAJAX() { 
    313         return ($this->isMoz || $this->isOpera || $this->isSafari || ($this -> isIE && $this -> Version > 5)); 
     334        return  ($this->isMoz 
     335             ||  $this->isOpera 
     336             ||  $this->isSafari 
     337             || ($this->isIE && $this->compareBrowserVersion("5", $this->Version)) 
     338             || ($this->isKonqueror && $this->compareBrowserVersion("3.4", $this->Version)) 
     339                ); 
     340    } 
     341 
     342    /** 
     343     * Compare two version strings of browser. 
     344     * @param $requiredVersion minimal version number required for feature 
     345     * @param $browserVersion current detected browser version 
     346     * @return true if $browserVersion is greater than $requiredVersion 
     347     */ 
     348    function compareBrowserVersion($requiredVersion, $browserVersion) { 
     349        // Standardise versions 
     350        $requiredVersion = preg_replace('/([^0-9\.]+)/', '.$1.', $requiredVersion); 
     351        $requiredVersion = trim($requiredVersion); 
     352        $v1 = explode('.', $requiredVersion); 
     353 
     354        $browserVersion = preg_replace('/([^0-9\.]+)/', '.$1.', $browserVersion); 
     355        $browserVersion = trim($browserVersion); 
     356        $v2 = explode('.', $browserVersion); 
     357 
     358        $compare = 0; 
     359        for ($i = 0, $x = min(count($v1), count($v2)); $i < $x; $i++) { 
     360            if ($v1[$i] == $v2[$i]) { 
     361                continue; 
     362            } 
     363 
     364            $i1 = $v1[$i]; 
     365            $i2 = $v2[$i]; 
     366 
     367            if (is_numeric($i1) && is_numeric($i2)) { 
     368                $compare = ($i1 < $i2) ? -1 : 1; 
     369            } 
     370        } 
     371 
     372        return (bool) ($compare <= 0); 
    314373    } 
    315374}