<?php
//
// +--------------------------------------------------------------------------+
// | |
// | XS PHP Library Generic Classes Library |
// | |
// | Copyright (c) 2001-2002 XSPHPLib Group. |
// | |
// +--------------------------------------------------------------------------+
// | |
// | Distributed under the terms of the GNU Lesser General Public License as |
// | published by the Free Software Foundation version 2.1 |
// | See the GNU Lesser General Public License for more details. You should |
// | have received a copy of the GNU Lesser General Public License along with |
// | this package; if not, write to the Free Software Foundation, Inc., |
// | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +--------------------------------------------------------------------------+
// | |
// | Authors: Robert Bala <hide@address.com> |
// | |
// +--------------------------------------------------------------------------+
//
// $Id: browser.inc.php,v 1.2 2002/11/28 09:50:30 rbala Exp $
/**
* Web Browser class.
*
* Tells what the user's browser is capable of.
*
* @author Robert Bala <hide@address.com>
* @access public
* @package core
* @version $Id: browser.inc.php,v 1.2 2002/11/28 09:50:30 rbala Exp $
*/
class Browser extends Object {
/**
* Indicates whether the html tables are supported.
* @access private
* @var boolean
*/
var $_tables;
/**
* Indicates whether the html frames are supported.
* @access private
* @var boolean
*/
var $_frames;
/**
* Indicates whether the html layers are supported.
* @access private
* @var boolean
*/
var $_layers;
/**
* Browser version.
* @access private
* @var string
*/
var $_version;
/**
* Browser name.
* @access private
* @var string
*/
var $_browser;
/**
* Browser OS platform.
* @access private
* @var string
*/
var $_platform;
/**
* Browser accepted language.
* @access private
* @var string
*/
var $_language;
/**
* Indicates whether the JavaScript is supported.
* @access private
* @var boolean
*/
var $_javascript;
/**
* Indicates whether the file uploads are supported.
* @access private
* @var boolean
*/
var $_fileupload;
/**
* Browser class constructor.
*
* Creates the new instance of File class.
*
* @access public
* @return void
*/
function Browser() {
Object::Object();
$this->_tables = false;
$this->_frames = false;
$this->_layers = false;
$this->_version = '';
$this->_browser = '';
$this->_platform = '';
$this->_language = '';
$this->_javascript = false;
$this->_fileupload = false;
}
/**
* Finds whether the HTML tables are supported.
*
* Returns true if the HTML tables are supported, false otherwise.
*
* @access public
* @return boolean
*/
function getTables() {
return $this->_tables;
}
/**
* Finds whether the HTML frames are supported.
*
* Returns true if the HTML frames are supported, false otherwise.
*
* @access public
* @return boolean
*/
function getFrames() {
return $this->_frames;
}
/**
* Finds whether the HTML layers are supported.
*
* Returns true if the HTML layers are supported, false otherwise.
*
* @access public
* @return boolean
*/
function getLayers() {
return $this->_layers;
}
/**
* Gets browser version.
*
* Returns the browser version, empty string otherwise.
*
* @access public
* @return string
*/
function getVersion() {
return $this->_version;
}
/**
* Gets browser name.
*
* Returns the browser name, empty string otherwise.
*
* @access public
* @return string
*/
function getBrowser() {
return $this->_browser;
}
/**
* Gets browser OS platform.
*
* Returns the browser OS platform, empty string otherwise.
*
* @access public
* @return string
*/
function getPlatform() {
return $this->_platform;
}
/**
* Gets browser accepted language.
*
* Returns the browser accepted language, empty string otherwise.
*
* @access public
* @return string
*/
function getLanguage() {
return $this->_language;
}
/**
* Finds whether the file uploads are supported.
*
* Returns true if the file uploads are, false otherwise.
*
* @access public
* @return boolean
*/
function getFileUpload() {
return $this->_fileupload;
}
/**
* Finds whether the JavaScript is supported.
*
* Returns true if the JavaScript is supported, false otherwise.
*
* @access public
* @return boolean
*/
function getJavaScript() {
return $this->_javascript;
}
/**
* Attempts to determine the capabilities of the user's browser.
*
* Returns true on success or error object with an error message on any
* kind of failure. By default, the value of $HTTP_USER_AGENT is used to
* determine the capabilities of the user's browser; however, you can alter
* this by passing the optional user_agent parameter.
*
* @access public
* @param string $agent the browser name.
* @return mixed
*/
function parse($agent='') {
global $HTTP_SERVER_VARS;
if (empty($agent) && isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
$agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
} else {
return new Error('parse(): Could not determine user agent.');
}
$this->_tables = false;
$this->_frames = false;
$this->_layers = false;
$this->_version = strtok(' ');
$this->_browser = strtok($agent, '/');
$this->_platform = 'unknown';
$this->_language = 'en_US';
$this->_javascript = false;
$this->_fileupload = false;
if (ereg("MSIE", $agent)) {
$this->_browser = 'MSIE';
$this->_version = strtok('MSIE');
$this->_version = strtok(' ');
$this->_version = strtok(';');
}
if (ereg("Opera", $agent)) {
$this->_browser = "Opera";
$this->_version = strtok("Opera");
$this->_version = strtok("/");
$this->_version = strtok(";");
}
if (ereg("Windows", $agent) || ereg("WinNT", $agent) || ereg("Win98", $agent) || ereg("Win95", $agent)) {
$this->_platform = "Windows";
}
if(ereg("Mac", $agent)) {
$this->_platform = "Macintosh";
}
if(ereg("X11", $agent)) {
$this->_platform = "Unix";
}
if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'])) {
$this->_language = $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'];
}
if ($this->_platform == "Windows") {
if ($this->_browser == "Mozilla") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_javascript = true;
$this->_fileupload = true;
}
if ($this->_version >= 4.0) {
$this->_layers = true;
}
} elseif ($this->_browser == "MSIE") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_javascript = true;
$this->_fileupload = true;
}
if ($this->_version >= 4.0) {
$this->_layers = true;
}
} elseif ($this->_browser == "Opera") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_layers = true;
$this->_javascript = true;
$this->_fileupload = true;
}
}
} elseif ($this->_platform == "Macintosh") {
if ($this->_browser == "Mozilla") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_javascript = true;
$this->_fileupload = true;
}
if ($this->_version >= 4.0) {
$this->_layers = true;
}
} elseif ($this->_browser == "MSIE") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_javascript = true;
$this->_fileupload = true;
}
if ($this->_version >= 4.0) {
$this->_layers = true;
}
}
} elseif ($this->_platform == "Unix") {
if ($this->_browser == "Mozilla") {
if ($this->_version >= 3.0) {
$this->_tables = true;
$this->_frames = true;
$this->_javascript = true;
$this->_fileupload = true;
}
if ($this->_version >= 4.0) {
$this->_layers = true;
}
}
}
return true;
}
}
?>