Location: PHPKode > projects > Entier Studio > entierstudio/framework/userbrowser.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.framework
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: userbrowser.php 81 2008-01-17 23:08:21Z yannromefort $
 */
##Source: Webmonkey Code Library
##(http://www.hotwired.com/webmonkey/javascript/code_library/)
##Author: Rich Blaylock
##Author Email: hide@address.com
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefUserBrowser")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefUserBrowser", "1");
    //-------------------------------------------------------------------------
    //	Class
    class UserBrowser {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * Browser code
         *
         * @var	string
         */
        var $m_Browser = "UN";
        /**
         * Version array
         *
         * @var	array
         */
        var $m_Version = array();
        /**
         * Platform name
         *
         * @var	string
         */
        var $m_Platform = "";
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * UserBrowser constructor.
         *
         * @access	public
         */
        function UserBrowser() {
            //
            $userAgent = getenv("HTTP_USER_AGENT");
            $preparens = "";
            $parens = "";
            //
            $i = strpos($userAgent, "(");
            if ($i >= 0) {
                $preparens = trim(substr($userAgent, 0, $i));
                $parens = substr($userAgent, $i+1, strlen($userAgent));
                $j = strpos($parens, ")");
                if ($j >= 0) {
                    $parens = substr($parens, 0, $j);
                }
            } else {
                $preparens = $userAgent;
            }
            //
            $browVer = $preparens;
            $token = trim(strtok($parens, ";"));
            //
            while ($token) {
                if ($token == "compatible") {
                } elseif (preg_match("/MSIE/i", "$token")) {
                    $browVer = $token;
                } elseif (preg_match("/Opera/i", "$token")) {
                    $browVer = $token;
                } elseif (preg_match("/X11/i", "$token") || preg_match("/SunOS/i", "$token") || preg_match("/Linux/i", "$token")) {
                    $this->m_Platform = "Unix";
                } elseif (preg_match("/Win/i", "$token")) {
                    $this->m_Platform = $token;
                } elseif (preg_match("/Mac/i", "$token") || preg_match("/PPC/i", "$token")) {
                    $this->m_Platform = $token;
                }
                $token = strtok(";");
            }
            //
            $msieIndex = strpos($browVer, "MSIE");
            if ($msieIndex >= 0) {
                $browVer = substr($browVer, $msieIndex, strlen($browVer));
            }
            $leftover = "";
            if (substr($browVer, 0, strlen("Mozilla")) == "Mozilla") {
                $this->m_Browser = "MZ";
                $leftover = substr($browVer, strlen("Mozilla") +1, strlen($browVer));
            } elseif (substr($browVer, 0, strlen("Lynx")) == "Lynx") {
                $this->m_Browser = "LX";
                $leftover = substr($browVer, strlen("Lynx") +1, strlen($browVer));
            } elseif (substr($browVer, 0, strlen("MSIE")) == "MSIE") {
                $this->m_Browser = "IE";
                $leftover = substr($browVer, strlen("MSIE") +1, strlen($browVer));
            } elseif (substr($browVer, 0, strlen("Microsoft Internet Explorer")) == "Microsoft Internet Explorer") {
                $this->m_Browser = "IE";
                $leftover = substr($browVer, strlen("Microsoft Internet Explorer") +1, strlen($browVer));
            } elseif (substr($browVer, 0, strlen("Opera")) == "Opera") {
                $this->m_Browser = "OP";
                $leftover = substr($browVer, strlen("Opera") +1, strlen($browVer));
            }
            //
            $leftover = trim($leftover);
            $i = strpos($leftover, " ");
            if ($i > 0) {
                $this->m_Version[0] = substr($leftover, 0, $i);
            } else {
                $this->m_Version[0] = $leftover;
            }
            $j = strpos($this->m_Version[0], ".");
            if ($j >= 0) {
                $this->m_Version[1] = substr($this->m_Version[0], 0, $j);
                $this->m_Version[2] = substr($this->m_Version[0], $j+1, strlen($this->m_Version[0]));
            } else {
                $this->m_Version[1] = $this->m_Version[0];
            }
            //
            
        }
        //---------------------------------------------------------------------
        //	Properties
        //	Property:	Browser
        
        /**
         *
         * @return	Browser name
         */
        function Browser() {
            //
            return ($this->m_Browser);
        }
        //	Property:	Version
        
        /**
         * full name
         * @return	m_Version[0]
         */
        function Version() {
            //
            return ($this->m_Version[0]);
        }
        /**
         * Major part
         * @return	m_Version[1]
         */
        function MajorVersion() {
            //
            return ($this->m_Version[1]);
        }
        /**
         * Minor part
         * @return	m_Version[2]
         */
        function MinorVersion() {
            //
            return ($this->m_Version[2]);
        }
        //	Property:	Platform
        
        /**
         *
         * @return	Platform name
         */
        function Platform() {
            //
            return ($this->m_Platform);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio