Skip to content

Commit bc3e602

Browse files
authored
Merge pull request #78 from cbschuld/palemoon
added palemoon
2 parents f48bdc9 + fd6374a commit bc3e602

File tree

7 files changed

+677
-93
lines changed

7 files changed

+677
-93
lines changed

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,25 @@ changes when it socially makes sense.
7878
## 0.0.3 - 2009-02-19
7979
### Fixed
8080
* updated typical usage to show a correct example! (thanks David!)
81-
81+
* Updated the version detection for Amaya
82+
* Updated the version detection for Firefox
83+
* Updated the version detection for Lynx
84+
* Updated the version detection for WebTV
85+
* Updated the version detection for NetPositive
86+
* Updated the version detection for IE
87+
* Updated the version detection for OmniWeb
88+
* Updated the version detection for iCab
89+
* Updated the version detection for Safari
90+
* Updated Safari to remove mobile devices (iPhone)
91+
### Added
92+
* Added version detectionf for edge via [pixelbacon](https://github.com/pixelbacon)
93+
* Added detection for Chrome
94+
* Added detection for iPhone
95+
* Added detection for robots
96+
* Added detection for mobile devices
97+
* Added detection for BlackBerry
98+
* Added detection for iPhone
99+
* Added detection for iPad
100+
* Added detection for Android
101+
### Removed
102+
* Removed Netscape checks

README.md

Lines changed: 71 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,89 @@
1-
Browser.php
2-
=============
1+
# cbschuld/browser.php
32

43
[![Build Status](https://travis-ci.org/cbschuld/Browser.php.png?branch=master)](https://travis-ci.org/cbschuld/Browser.php)
54

65
Helps detect the user's browser and platform at the PHP level via the user agent
76

87

9-
Installation
10-
============
8+
## Installation
119

12-
To install, simply `require` the `Browser.php` file under `lib`.
10+
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
1311

14-
You can also install it via `Composer` by using the [Packagist archive](https://packagist.org/packages/cbschuld/browser.php).
12+
composer require cbschuld/browser.php
1513

14+
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
1615

17-
Background
18-
============
16+
composer require --dev cbschuld/browser.php
1917

20-
Detecting the user's browser type and version is helpful in web applications that harness some of the newer bleeding edge concepts. With the browser type and version you can notify users about challenges they may experience and suggest they upgrade before using such application. Not a great idea on a large scale public site; but on a private application this type of check can be helpful.
21-
22-
In an active project of mine we have a pretty graphically intensive and visually appealing user interface which leverages a lot of transparent PNG files. Because we all know how great IE6 supports PNG files it was necessary for us to tell our users the lack of power their browser has in a kind way.
2318

24-
Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user.s browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess.
25-
26-
I based this solution off of Gary White.s original solution but added a few things:
27-
28-
I added the ability to view the return values as class constants to increase the readability
29-
30-
* Added version detectionf for edge via [pixelbacon](https://github.com/pixelbacon)
31-
* Updated the version detection for Amaya
32-
* Updated the version detection for Firefox
33-
* Updated the version detection for Lynx
34-
* Updated the version detection for WebTV
35-
* Updated the version detection for NetPositive
36-
* Updated the version detection for IE
37-
* Updated the version detection for OmniWeb
38-
* Updated the version detection for iCab
39-
* Updated the version detection for Safari
40-
* Added detection for Chrome
41-
* Added detection for iPhone
42-
* Added detection for robots
43-
* Added detection for mobile devices
44-
* Added detection for BlackBerry
45-
* Added detection for iPhone
46-
* Added detection for iPad
47-
* Added detection for Android
48-
* Removed Netscape checks
49-
* Updated Safari to remove mobile devices (iPhone)
50-
51-
**This solution identifies the following Operating Systems:**
52-
53-
* Windows (Browser::PLATFORM_WINDOWS)
54-
* Windows CE (Browser::PLATFORM_WINDOWS_CE)
55-
* Apple (Browser::PLATFORM_APPLE)
56-
* Linux (Browser::PLATFORM_LINUX)
57-
* Android (Browser::PLATFORM_ANDROID)
58-
* OS/2 (Browser::PLATFORM_OS2)
59-
* BeOS (Browser::PLATFORM_BEOS)
60-
* iPhone (Browser::PLATFORM_IPHONE)
61-
* iPod (Browser::PLATFORM_IPOD)
62-
* BlackBerry (Browser::PLATFORM_BLACKBERRY)
63-
* FreeBSD (Browser::PLATFORM_FREEBSD)
64-
* OpenBSD (Browser::PLATFORM_OPENBSD)
65-
* NetBSD (Browser::PLATFORM_NETBSD)
66-
* SunOS (Browser::PLATFORM_SUNOS)
67-
* OpenSolaris (Browser::PLATFORM_OPENSOLARIS)
68-
* iPad (Browser::PLATFORM_IPAD)
69-
70-
**This solution identifies the following Browsers and does a best-guess on the version:**
71-
72-
* Opera (Browser::BROWSER_OPERA)
73-
* WebTV (Browser::BROWSER_WEBTV)
74-
* NetPositive (Browser::BROWSER_NETPOSITIVE)
75-
* Edge (Browser::BROWSER_EDGE)
76-
* Internet Explorer (Browser::BROWSER_IE)
77-
* Pocket Internet Explorer (Browser::BROWSER_POCKET_IE)
78-
* Galeon (Browser::BROWSER_GALEON)
79-
* Konqueror (Browser::BROWSER_KONQUEROR)
80-
* iCab (Browser::BROWSER_ICAB)
81-
* OmniWeb (Browser::BROWSER_OMNIWEB)
82-
* Phoenix (Browser::BROWSER_PHOENIX)
83-
* Firebird (Browser::BROWSER_FIREBIRD)
84-
* Firefox (Browser::BROWSER_FIREFOX)
85-
* Mozilla (Browser::BROWSER_MOZILLA)
86-
* Amaya (Browser::BROWSER_AMAYA)
87-
* Lynx (Browser::BROWSER_LYNX)
88-
* Safari (Browser::BROWSER_SAFARI)
89-
* iPhone (Browser::BROWSER_IPHONE)
90-
* iPod (Browser::BROWSER_IPOD)
91-
* Google.s Android(Browser::BROWSER_ANDROID)
92-
* Google.s Chrome(Browser::BROWSER_CHROME)
93-
* GoogleBot(Browser::BROWSER_GOOGLEBOT)
94-
* Yahoo!.s Slurp(Browser::BROWSER_SLURP)
95-
* W3C.s Validator(Browser::BROWSER_W3CVALIDATOR)
96-
* BlackBerry(Browser::BROWSER_BLACKBERRY)
97-
98-
**Typical Usage:**
19+
## Typical Usage:
9920

10021
```php
10122
$browser = new Browser();
102-
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
103-
echo 'You have FireFox version 2 or greater';
23+
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >=10 ) {
24+
echo 'You have FireFox version 10 or greater';
10425
}
10526
```
10627

28+
## Browser Detection
29+
30+
This solution identifies the following Browsers and does a best-guess on the version:
31+
32+
* Opera (`Browser::BROWSER_OPERA`)
33+
* WebTV (`Browser::BROWSER_WEBTV`)
34+
* NetPositive (`Browser::BROWSER_NETPOSITIVE`)
35+
* Edge (`Browser::BROWSER_EDGE`)
36+
* Internet Explorer (`Browser::BROWSER_IE`)
37+
* Pocket Internet Explorer (`Browser::BROWSER_POCKET_IE`)
38+
* Galeon (`Browser::BROWSER_GALEON`)
39+
* Konqueror (`Browser::BROWSER_KONQUEROR`)
40+
* iCab (`Browser::BROWSER_ICAB`)
41+
* OmniWeb (`Browser::BROWSER_OMNIWEB`)
42+
* Phoenix (`Browser::BROWSER_PHOENIX`)
43+
* Firebird (`Browser::BROWSER_FIREBIRD`)
44+
* Firefox (`Browser::BROWSER_FIREFOX`)
45+
* Mozilla (`Browser::BROWSER_MOZILLA`)
46+
* Palemoon (`Browser::BROWSER_PALEMOON`)
47+
* Amaya (`Browser::BROWSER_AMAYA`)
48+
* Lynx (`Browser::BROWSER_LYNX`)
49+
* Safari (`Browser::BROWSER_SAFARI`)
50+
* iPhone (`Browser::BROWSER_IPHONE`)
51+
* iPod (`Browser::BROWSER_IPOD`)
52+
* Google.s Android(`Browser::BROWSER_ANDROID`)
53+
* Google.s Chrome(`Browser::BROWSER_CHROME`)
54+
* GoogleBot(`Browser::BROWSER_GOOGLEBOT`)
55+
* Yahoo!.s Slurp(`Browser::BROWSER_SLURP`)
56+
* W3C.s Validator(`Browser::BROWSER_W3CVALIDATOR`)
57+
* BlackBerry(`Browser::BROWSER_BLACKBERRY`)
58+
59+
## Operating System Detection
60+
61+
This solution identifies the following Operating Systems:
62+
63+
* Windows (`Browser::PLATFORM_WINDOWS`)
64+
* Windows CE (`Browser::PLATFORM_WINDOWS_CE`)
65+
* Apple (`Browser::PLATFORM_APPLE`)
66+
* Linux (`Browser::PLATFORM_LINUX`)
67+
* Android (`Browser::PLATFORM_ANDROID`)
68+
* OS/2 (`Browser::PLATFORM_OS2`)
69+
* BeOS (`Browser::PLATFORM_BEOS`)
70+
* iPhone (`Browser::PLATFORM_IPHONE`)
71+
* iPod (`Browser::PLATFORM_IPOD`)
72+
* BlackBerry (`Browser::PLATFORM_BLACKBERRY`)
73+
* FreeBSD (`Browser::PLATFORM_FREEBSD`)
74+
* OpenBSD (`Browser::PLATFORM_OPENBSD`)
75+
* NetBSD (`Browser::PLATFORM_NETBSD`)
76+
* SunOS (`Browser::PLATFORM_SUNOS`)
77+
* OpenSolaris (`Browser::PLATFORM_OPENSOLARIS`)
78+
* iPad (`Browser::PLATFORM_IPAD`)
79+
80+
## History and Legacy
81+
82+
Detecting the user's browser type and version is helpful in web applications that harness some of the newer bleeding edge concepts. With the browser type and version you can notify users about challenges they may experience and suggest they upgrade before using such application. Not a great idea on a large scale public site; but on a private application this type of check can be helpful.
83+
84+
In an active project of mine we have a pretty graphically intensive and visually appealing user interface which leverages a lot of transparent PNG files. Because we all know how great IE6 supports PNG files it was necessary for us to tell our users the lack of power their browser has in a kind way.
85+
86+
Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user.s browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess.
87+
88+
I based this solution off of Gary White's original work but have since replaced all of his original code. Either way, thank you to Gary. Sadly, I never was able to get in touch with him regarding this soludion.
89+

lib/Browser.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Browser
6262
const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
6363
const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
6464
const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
65+
const BROWSER_PALEMOON = 'Palemoon'; // https://www.palemoon.org/
6566
const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
6667
const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
6768
const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
@@ -426,6 +427,7 @@ protected function checkBrowsers()
426427
$this->checkBrowserNetscapeNavigator9Plus() ||
427428
$this->checkBrowserVivaldi() ||
428429
$this->checkBrowserYandex() ||
430+
$this->checkBrowserPalemoon() ||
429431
$this->checkBrowserFirefox() ||
430432
$this->checkBrowserChrome() ||
431433
$this->checkBrowserOmniWeb() ||
@@ -1265,6 +1267,30 @@ protected function checkBrowserNokia()
12651267
return false;
12661268
}
12671269

1270+
/**
1271+
* Determine if the browser is Palemoon or not
1272+
* @return boolean True if the browser is Palemoon otherwise false
1273+
*/
1274+
protected function checkBrowserPalemoon()
1275+
{
1276+
if (stripos($this->_agent, 'safari') === false) {
1277+
if (preg_match("/Palemoon[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) {
1278+
$this->setVersion($matches[1]);
1279+
$this->setBrowser(self::BROWSER_PALEMOON);
1280+
return true;
1281+
} else if (preg_match("/Palemoon([0-9a-zA-Z\.]+)/i", $this->_agent, $matches)) {
1282+
$this->setVersion($matches[1]);
1283+
$this->setBrowser(self::BROWSER_PALEMOON);
1284+
return true;
1285+
} else if (preg_match("/Palemoon/i", $this->_agent, $matches)) {
1286+
$this->setVersion('');
1287+
$this->setBrowser(self::BROWSER_PALEMOON);
1288+
return true;
1289+
}
1290+
}
1291+
return false;
1292+
}
1293+
12681294
/**
12691295
* Determine if the browser is Firefox or not (last updated 1.7)
12701296
* @return boolean True if the browser is Firefox otherwise false

tests/ChromeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
final class ChromeTest extends TestCase
99
{
1010
/**
11-
* @dataProvider userAgentFirefoxProvider
11+
* @dataProvider userAgentChromeProvider
1212
* @param $userAgent string Browser's User Agent
1313
* @param $type string Type of the Browser
1414
* @param $browser string Name of the Browser
@@ -18,15 +18,15 @@ final class ChromeTest extends TestCase
1818
* @param $osVersionName string Version of the Operating System (name)
1919
* @param $osVersionNumber string Version of the Operating System (number)
2020
*/
21-
public function testFirefoxUserAgent($userAgent,$type,$browser,$version,$osType,$osName,$osVersionName,$osVersionNumber)
21+
public function testChromeUserAgent($userAgent,$type,$browser,$version,$osType,$osName,$osVersionName,$osVersionNumber)
2222
{
2323
$b = new Browser($userAgent);
2424

2525
$this->assertSame($browser, $b->getBrowser());
2626
$this->assertSame($version, $b->getVersion());
2727
}
2828

29-
public function userAgentFirefoxProvider()
29+
public function userAgentChromeProvider()
3030
{
3131
return new TabDelimitedFileIterator(dirname(__FILE__).'/lists/chrome.txt');
3232
}

tests/FirefoxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";
77

8-
final class MozillaTest extends TestCase
8+
final class FirefoxTest extends TestCase
99
{
1010
/**
1111
* @dataProvider userAgentFirefoxProvider

tests/PalemoonTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";
7+
8+
final class PalemoonTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider userAgentPalemoonProvider
12+
* @param $userAgent string Browser's User Agent
13+
* @param $type string Type of the Browser
14+
* @param $browser string Name of the Browser
15+
* @param $version string Version of the Browser
16+
* @param $osType string Type of operating system associated with the Browser
17+
* @param $osName string Name of the operating system associated with the Browser, typically has the version number
18+
* @param $osVersionName string Version of the Operating System (name)
19+
* @param $osVersionNumber string Version of the Operating System (number)
20+
*/
21+
public function testPalemoonUserAgent($userAgent,$type,$browser,$version,$osType,$osName,$osVersionName,$osVersionNumber)
22+
{
23+
$b = new Browser($userAgent);
24+
25+
$this->assertSame($browser, $b->getBrowser());
26+
$this->assertSame($version, $b->getVersion());
27+
}
28+
29+
public function userAgentPalemoonProvider()
30+
{
31+
return new TabDelimitedFileIterator(dirname(__FILE__).'/lists/palemoon.txt');
32+
}
33+
}

0 commit comments

Comments
 (0)