diff options
author | Thomas BrĂ¼derli | 2006-12-14 17:22:01 +0000 |
---|---|---|
committer | Thomas BrĂ¼derli | 2006-12-14 17:22:01 +0000 |
commit | fd0ccecb0ce59140422b4dc4d8d9cee2d43dca0b (patch) | |
tree | ed7b4b0f36edf012e42e5c02a0f8cea332b9edc5 | |
parent | 8b5892069871ccfbe7dd8b4df211b0c7061a5365 (diff) | |
download | itools-fd0ccecb0ce59140422b4dc4d8d9cee2d43dca0b.tar.gz itools-fd0ccecb0ce59140422b4dc4d8d9cee2d43dca0b.tar.bz2 itools-fd0ccecb0ce59140422b4dc4d8d9cee2d43dca0b.zip |
Updated it_browser class with new properties
-rw-r--r-- | browser.class | 86 |
1 files changed, 69 insertions, 17 deletions
diff --git a/browser.class b/browser.class index 2018247..e67b658 100644 --- a/browser.class +++ b/browser.class @@ -1,6 +1,6 @@ <?php /* -** $Id$ +** $Id$ ** ** ITools - the Internet Tools Library ** @@ -18,7 +18,7 @@ /** * Browser capabilities class - * var $Type string: Browser type, "Netscape", "MSIE", "Konqueror" etc. + * var $Type string: Browser type, "Netscape", "MSIE", "Konqueror", "Opera", "Safari", "Gecko" 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 @@ -37,8 +37,12 @@ class it_browser 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 $CSS=1; /* int: Style sheet level (0..3) */ + var $CSSFilter=0; /* bool: Is MSIE and supports CSS filter: property */ var $TextOnly=0; /* bool: Browser supports only text, no graphics */ + var $VML=0; /* bool: Browser support VectorMarkupLanguage */ + var $Canvas=0; /* bool: Supports Canvas */ + var $XMLHTTP=0; /* bool: Browser supports XMLHTTP requests */ /* Browser specific stuff (DEPRECATED, use generic attributes above) */ var $MSIE; /* float: Microsoft Internet Explorer Version or 0 */ @@ -60,9 +64,9 @@ function it_browser() } /* Find optional "(compatible; MSIE 3.0; Win95)" */ - if (ereg("\((.*)\)", $this->UserAgent, $regs)) + if (preg_match("/\((.+)\)/U", $this->UserAgent, $regs)) { - $optattr = split("; ", $regs[1]); + $optattr = preg_split("/;\s+/", $regs[1]); if ($optattr[0] == "compatible") { if (ereg("([^/]*)[/ ]([^/]*)", $optattr[1], $regs)) @@ -70,54 +74,102 @@ function it_browser() $this->Type = $regs[1]; $this->Version = (double)$regs[2]; } - else $this->Type = $optattr[1]; + else + $this->Type = $optattr[1]; + $this->Platform = $optattr[count($optattr)-1]; } else $this->Platform = $optattr[0]; - } - if ($this->Type == "Mozilla") - $this->Type = "Netscape"; + for ($i=1; $i < count($optattr); $i++) + { + if (preg_match("/^([a-z]{2})(\-[a-z]{2})?$/i", $optattr[$i], $regs)) + $this->Language = $regs[1]; + if (preg_match("/^rv:([0-9\.]+)/", $optattr[$i], $regs)) + $this->Version = floatval($regs[1]); + if (strstr($optattr[$i], "Linux") || $optattr[$i] == "X11") + $this->Platform = "Linux"; + } + } /* Find optional "[de]" */ - if (ereg("\[(.*)\]", $this->UserAgent, $regs)) + if (!$this->Language && ereg("\[(.*)\]", $this->UserAgent, $regs)) $this->Language = $regs[1]; + /* Check for Safari/KHTML */ + if (preg_match("/(Safari|AppleWebKit)\/([0-9\.]+)/", $this->UserAgent, $regs)) + { + $this->Type = "Safari"; + $this->Version = floatval($regs[2]); + } + + /* Check for Gecko based browser */ + if ($this->Type == "Mozilla" && preg_match("/[^a-z]Gecko[^a-z]/", $this->UserAgent)) + $this->Type = "Gecko"; + else if ($this->Type == "Mozilla" && $this->Version < 5) + $this->Type = "Netscape"; + + /* 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; + $this->JavaScript = true; + $this->VML = ($this->Version >= 5.5); + $this->XMLHTTP = ($this->Version >= 5); + $this->CSS = $this->Version >= 4.0 ? 2 : 1; + $this->CSSFilter = ($this->Version >= 5.0); } else if ($this->Type == "Opera") { $this->Opera = $this->Version; if ($this->Version >= 3.5) + { $this->HTMLVersion = 4.0; + $this->CSS = 2; + } else + { $this->HTMLVersion = 3.2; - $this->JavaScript = 1; + $this->CSS = 1; + } + $this->JavaScript = true; + $this->XMLHTTP = ($this->Version >= 8); } else if ($this->Type == "Konqueror") { $this->HTMLVersion = 4.0; $this->CSS = 2; - $this->JavaScript = 1; + $this->JavaScript = true; + $this->XMLHTTP = ($this->Version >= 3); } else if ($this->Type == "Netscape") { $this->NS = $this->Version; $this->HTMLVersion = 4.0; - $this->JavaScript = 1; + $this->JavaScript = true; if ($this->Version >= 5.0) $this->CSS = 2; } + else if ($this->Type == "Gecko") + { + $this->HTMLVersion = 4.0; + $this->CSS = 2; + $this->JavaScript = true; + $this->XMLHTTP = true; + $this->Canvas = ($this->Version >= 1.8); + } + else if ($this->Type == "Safari") + { + $this->HTMLVersion = 4.0; + $this->JavaScript = true; + $this->CSS = 2; + $this->XMLHTTP = true; + $this->Canvas = ($this->Version >= 418); + } else if ($this->Type == "Lynx") $this->TextOnly = 1; } |