From ef24069ebf87dcd4a7b1b2239fafd09bb28d00b5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 23 Jan 2008 17:15:47 -0500 Subject: [PATCH] Removing the is_browser() function * Functions.php: (BSFunctions::is_browser): Removed (BSFunctions::download_file): Send both application/octet-stream and application/octetstream so we don't need to browser sniff anymore * UnitTest/FunctionsTest.php: Removed the empty unit test for is_browser() --- Functions.php | 162 +------------------------------------ UnitTest/FunctionsTest.php | 5 -- 2 files changed, 2 insertions(+), 165 deletions(-) diff --git a/Functions.php b/Functions.php index 8fb154c..fe89f43 100644 --- a/Functions.php +++ b/Functions.php @@ -197,16 +197,8 @@ class BSFunctions */ public static function download_file($file, $name, $exit = true) { - if (self::is_browser('ie') || self::is_browser('opera') || self::is_browser('safari')) - { - $mime = 'application/octetstream'; - } - else - { - $mime = 'application/octet-stream'; - } - - header("Content-Type: $mime"); + header("Content-Type: application/octetstream"); + header("Content-Type: application/octet-stream"); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $name . '"'); header('Content-length: ' . strlen($file)); @@ -241,156 +233,6 @@ class BSFunctions } } - // ################################################################### - /** - * Check a browser's user agent against a pre-determined list - * - * @param string Browser name - * @param string The browser's version - * - * @param mixed False if there is no match, the version if there is - */ - public static function is_browser($check, $version = '') - { - $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); - $browser = array(); - $matches = array(); - - // ------------------------------------------------------------------- - // -- Opera - // ------------------------------------------------------------------- - # Opera/6.05 (Windows 98; U) [en] - # Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en] - # Mozilla/5.0 (Windows 98; U) Opera 6.0 [en] - # Mozilla/4.0 (compatible; MSIE, 6.0; Windows 98) Opera 7.0 [en] - if (preg_match('#opera ([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[1])) - { - $browser['opera'] = $matches[1]; - } - } - - // ------------------------------------------------------------------- - // -- Mac browser - // ------------------------------------------------------------------- - if (strpos($useragent, 'mac') !== false) - { - $browser['mac'] = true; - } - - // ------------------------------------------------------------------- - // -- Internet explorer - // ------------------------------------------------------------------- - # Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914) - # Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) - if (preg_match('#msie ([0-9\.]+)#', $useragent, $matches) !== false && !isset($browser['opera'])) - { - if (isset($matches[1])) - { - $browser['ie'] = $matches[1]; - } - } - - // ------------------------------------------------------------------- - // -- Safari - // ------------------------------------------------------------------- - # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9 - if (preg_match('#safari/([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[1])) - { - $browser['safari'] = $matches[1]; - } - } - - // ------------------------------------------------------------------- - // -- Konqueror - // ------------------------------------------------------------------- - # Mozilla/5.0 (compatible; Konqueror/3) - # Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20020628) - if (preg_match('#konqueror/([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[1])) - { - $browser['konqueror'] = $matches[1]; - } - } - - // ------------------------------------------------------------------- - // -- Mozilla - // ------------------------------------------------------------------- - # Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101 - # Mozilla/5.001 (Macintosh; N; PPC; ja) Gecko/25250101 MegaCorpBrowser/1.0 (MegaCorp, Inc.) - if (preg_match('#gecko/([0-9]+)#', $useragent, $matches) !== false && !isset($browser['safari'])) - { - if (isset($matches[1])) - { - $browser['mozilla'] = $matches[1]; - } - - // ------------------------------------------------------------------- - // -- Firefox - // ------------------------------------------------------------------- - # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040628 Firefox/0.9.1 - # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6 - if (preg_match('#(firebird|firefox)( browser)?/([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[3])) - { - $browser['firefox'] = $matches[3]; - } - } - - // ------------------------------------------------------------------- - // -- Netscape - // ------------------------------------------------------------------- - # Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4.1) Gecko/20020318 Netscape6/6.2.2 - if (preg_match('#netscape([0-9].*?)?/([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[2])) - { - $browser['netscape'] = $matches[2]; - } - } - - // ------------------------------------------------------------------- - // -- Camino - // ------------------------------------------------------------------- - # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040623 Camino/0.8 - if (preg_match('#camino/([0-9\.]+)#', $useragent, $matches) !== false) - { - if (isset($matches[1])) - { - $browser['camino'] = $matches[1]; - } - } - } - - if (isset($browser["$check"])) - { - if ($version) - { - if ($browser["$check"] >= $version) - { - return $browser["$check"]; - } - else - { - return false; - } - } - else - { - return $browser["$check"]; - } - } - else - { - return false; - } - } - // ################################################################### /** * Generates a random string of random length (unless otherwise diff --git a/UnitTest/FunctionsTest.php b/UnitTest/FunctionsTest.php index 0356a53..8e676bc 100644 --- a/UnitTest/FunctionsTest.php +++ b/UnitTest/FunctionsTest.php @@ -53,11 +53,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase $this->assertFalse(BSFunctions::is_valid_email('test@.com')); } - public function testIsBrowser() - { - - } - public function testRandom() { $values = array(); -- 2.43.5