diff options
author | Christian Schneider | 2006-10-26 13:35:12 +0000 |
---|---|---|
committer | Christian Schneider | 2006-10-26 13:35:12 +0000 |
commit | a5a19fd672bc0b8113d620669b557f17dccd343a (patch) | |
tree | 876ba4fec8362ac2e9374f61b9b7f67fcd2b8e59 /browser.class | |
download | itools-a5a19fd672bc0b8113d620669b557f17dccd343a.tar.gz itools-a5a19fd672bc0b8113d620669b557f17dccd343a.tar.bz2 itools-a5a19fd672bc0b8113d620669b557f17dccd343a.zip |
Moved itools to live branch
Diffstat (limited to 'browser.class')
-rw-r--r-- | browser.class | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/browser.class b/browser.class new file mode 100644 index 0000000..2018247 --- /dev/null +++ b/browser.class @@ -0,0 +1,126 @@ +<?php +/* +** $Id$ +** +** ITools - the Internet Tools Library +** +** Copyright (C) 1995-2003 by the ITools Authors. +** This program is free software; you can redistribute it and/or +** modify it under the terms of either the GNU General Public License +** or the GNU Lesser General Public License, as published by the Free +** Software Foundation. See http://www.gnu.org/licenses/ for details. +** +** Class it_Browser: Browser capability class +** For a good list see http://www.msb.edu/dept/msbtc/waehner/browser/ +** +** Inspired by browser.pinc,v 1.1.1.1 1999/03/23 14:51:39 bobak Exp +*/ + +/** + * Browser capabilities class + * var $Type string: Browser type, "Netscape", "MSIE", "Konqueror" etc. + * var $Version float: Browser-Version x.y for all brands + * var $Platform string: "Win95", "Macintosh", "Linux" ... may be wrong + * var $Language string: Browser's language, "de", "en", ... or unset + * var $HTMLVersion float: Suported HTML version x.y + * var $JavaScript bool: Browser supports Javascript + * var $CSS bool: Browser supports Style sheets + * var $TextOnly bool: Browser supports only text, no graphics + */ +class it_browser +{ + /* Generic attributes */ + var $UserAgent; /* string: Unparsed HTTP_USER_AGENT */ + var $Type = ''; /* string: Browser type, "Netscape", "MSIE", etc. */ + var $Version; /* float: Browser-Version x.y for all brands */ + var $Platform; /* string: "Win95", "Macintosh", "Linux" ... may be wrong */ + var $Language; /* string: Browser's language, "de", "en", ... or unset */ + var $HTMLVersion=0; /* float: Suported HTML version x.y */ + var $JavaScript=0; /* bool: Browser supports Javascript */ + var $CSS=1; /* int: Style sheet level (0..3) */ + var $TextOnly=0; /* bool: Browser supports only text, no graphics */ + + /* Browser specific stuff (DEPRECATED, use generic attributes above) */ + var $MSIE; /* float: Microsoft Internet Explorer Version or 0 */ + var $NS; /* float: Netscape Navigator Version or 0 */ + +/** + * Constructor: Initializes public fields with browser capabilities + */ +function it_browser() +{ + $this->UserAgent = $_SERVER['HTTP_USER_AGENT']; + /* $this->UserAgent = "Mozilla/4.0 [de] (compatible; MSIE 5.0; Bill Gates 1.0; Windows 95)"; */ + + /* Find "Mozilla/4.0" */ + if (ereg("([^/]*)/([^ ]*)", $this->UserAgent, $regs)) + { + $this->Type = $regs[1]; + $this->Version = (double)$regs[2]; + } + + /* Find optional "(compatible; MSIE 3.0; Win95)" */ + if (ereg("\((.*)\)", $this->UserAgent, $regs)) + { + $optattr = split("; ", $regs[1]); + if ($optattr[0] == "compatible") + { + if (ereg("([^/]*)[/ ]([^/]*)", $optattr[1], $regs)) + { + $this->Type = $regs[1]; + $this->Version = (double)$regs[2]; + } + else $this->Type = $optattr[1]; + $this->Platform = $optattr[count($optattr)-1]; + } + else + $this->Platform = $optattr[0]; + } + + if ($this->Type == "Mozilla") + $this->Type = "Netscape"; + + /* Find optional "[de]" */ + if (ereg("\[(.*)\]", $this->UserAgent, $regs)) + $this->Language = $regs[1]; + + /* And now for the browser capabilities ... */ + if ($this->Type == "MSIE") + { + $this->MSIE = $this->Version; + $this->HTMLVersion = 4.0; + $this->JavaScript = 1; + + if ($this->Version >= 4.0) + $this->CSS = 2; + } + else if ($this->Type == "Opera") + { + $this->Opera = $this->Version; + if ($this->Version >= 3.5) + $this->HTMLVersion = 4.0; + else + $this->HTMLVersion = 3.2; + $this->JavaScript = 1; + } + else if ($this->Type == "Konqueror") + { + $this->HTMLVersion = 4.0; + $this->CSS = 2; + $this->JavaScript = 1; + } + else if ($this->Type == "Netscape") + { + $this->NS = $this->Version; + $this->HTMLVersion = 4.0; + $this->JavaScript = 1; + + if ($this->Version >= 5.0) + $this->CSS = 2; + } + else if ($this->Type == "Lynx") + $this->TextOnly = 1; +} + +} /* End Class it_Browser */ +?> |