3 | 3 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK @ALL_TESTS);
|
4 | 4 |
require Exporter;
|
5 | 5 |
|
6 | |
@ISA = qw(Exporter);
|
7 | |
@EXPORT = qw();
|
|
6 |
@ISA = qw(Exporter);
|
|
7 |
@EXPORT = qw();
|
8 | 8 |
@EXPORT_OK = qw();
|
9 | |
$VERSION = '1.02';
|
|
9 |
$VERSION = '1.03';
|
10 | 10 |
|
11 | 11 |
# Operating Systems
|
12 | |
push @ALL_TESTS,(qw(win16 win3x win31 win95 win98 winnt windows win32 win2k winxp win2k3 winvista winme dotnet mac macosx mac68k macppc os2 unix sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10 aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant dec sinix freebsd bsd vms x11 amiga));
|
|
12 |
push @ALL_TESTS,
|
|
13 |
(
|
|
14 |
qw(win16 win3x win31 win95 win98 winnt windows win32 win2k winxp win2k3 winvista winme dotnet mac macosx mac68k macppc os2 unix sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10 aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant dec sinix freebsd bsd vms x11 amiga)
|
|
15 |
);
|
13 | 16 |
|
14 | 17 |
# Devices
|
15 | |
push @ALL_TESTS,(qw(palm audrey iopener wap blackberry));
|
|
18 |
push @ALL_TESTS, (qw(palm audrey iopener wap blackberry));
|
16 | 19 |
|
17 | 20 |
# Browsers
|
18 | |
push @ALL_TESTS,(qw(mosaic netscape nav2 nav3 nav4 nav4up nav45 nav45up nav6 nav6up navgold firefox chrome safari ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 ie7 ie8 opera opera3 opera4 opera5 opera6 opera7 lynx links aol aol3 aol4 aol5 aol6 neoplanet neoplanet2 avantgo emacs mozilla gecko));
|
|
21 |
push @ALL_TESTS,
|
|
22 |
(
|
|
23 |
qw(mosaic netscape nav2 nav3 nav4 nav4up nav45 nav45up nav6 nav6up navgold firefox chrome safari ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 ie7 ie8 opera opera3 opera4 opera5 opera6 opera7 lynx links aol aol3 aol4 aol5 aol6 neoplanet neoplanet2 avantgo emacs mozilla gecko)
|
|
24 |
);
|
19 | 25 |
|
20 | 26 |
# Robots
|
21 | |
push @ALL_TESTS,(qw(puf curl wget getright robot yahoo altavista lycos infoseek lwp webcrawler linkexchange slurp webtv staroffice lotusnotes konqueror icab google java));
|
|
27 |
push @ALL_TESTS,
|
|
28 |
(
|
|
29 |
qw(puf curl wget getright robot yahoo altavista lycos infoseek lwp webcrawler linkexchange slurp webtv staroffice lotusnotes konqueror icab google java)
|
|
30 |
);
|
|
31 |
|
|
32 |
# Properties
|
|
33 |
push @ALL_TESTS, 'mobile';
|
22 | 34 |
|
23 | 35 |
#######################################################################################################
|
24 | 36 |
# BROWSER OBJECT
|
|
26 | 38 |
my $default = undef;
|
27 | 39 |
|
28 | 40 |
sub new {
|
29 | |
my ($class, $user_agent) = @_;
|
30 | |
|
31 | |
my $self = {};
|
32 | |
bless $self, $class;
|
33 | |
|
34 | |
unless (defined $user_agent) {
|
35 | |
$user_agent = $ENV{'HTTP_USER_AGENT'};
|
36 | |
}
|
37 | |
|
38 | |
$self->user_agent($user_agent);
|
39 | |
return $self;
|
|
41 |
my ( $class, $user_agent ) = @_;
|
|
42 |
|
|
43 |
my $self = {};
|
|
44 |
bless $self, $class;
|
|
45 |
|
|
46 |
unless ( defined $user_agent ) {
|
|
47 |
$user_agent = $ENV{'HTTP_USER_AGENT'};
|
|
48 |
}
|
|
49 |
|
|
50 |
$self->user_agent($user_agent);
|
|
51 |
return $self;
|
40 | 52 |
}
|
41 | 53 |
|
42 | 54 |
foreach my $test (@ALL_TESTS) {
|
43 | 55 |
no strict 'refs';
|
44 | 56 |
my $key = uc $test;
|
45 | |
*{$test} = sub { my ($self) = _self_or_default(@_);
|
46 | |
return $self->{tests}->{$key} };
|
|
57 |
*{$test} = sub {
|
|
58 |
my ($self) = _self_or_default(@_);
|
|
59 |
return $self->{tests}->{$key};
|
|
60 |
};
|
47 | 61 |
}
|
48 | 62 |
|
49 | 63 |
sub _self_or_default {
|
50 | |
my ($self) = $_[0];
|
51 | |
return @_ if (defined $self &&
|
52 | |
ref $self &&
|
53 | |
(ref $self eq 'HTTP::BrowserDetect') || UNIVERSAL::isa($self,'HTTP::BrowserDetect'));
|
54 | |
$default ||= HTTP::BrowserDetect->new();
|
55 | |
unshift (@_, $default);
|
56 | |
return @_;
|
57 | |
}
|
58 | |
|
|
64 |
my ($self) = $_[0];
|
|
65 |
return @_
|
|
66 |
if ( defined $self
|
|
67 |
&& ref $self
|
|
68 |
&& ( ref $self eq 'HTTP::BrowserDetect' )
|
|
69 |
|| UNIVERSAL::isa( $self, 'HTTP::BrowserDetect' ) );
|
|
70 |
$default ||= HTTP::BrowserDetect->new();
|
|
71 |
unshift( @_, $default );
|
|
72 |
return @_;
|
|
73 |
}
|
59 | 74 |
|
60 | 75 |
sub user_agent {
|
61 | |
my ($self, $user_agent) = _self_or_default(@_);
|
62 | |
if (defined $user_agent) {
|
63 | |
$self->{user_agent} = $user_agent;
|
64 | |
$self->_test();
|
65 | |
}
|
66 | |
return $self->{user_agent};
|
|
76 |
my ( $self, $user_agent ) = _self_or_default(@_);
|
|
77 |
if ( defined $user_agent ) {
|
|
78 |
$self->{user_agent} = $user_agent;
|
|
79 |
$self->_test();
|
|
80 |
}
|
|
81 |
return $self->{user_agent};
|
67 | 82 |
}
|
68 | 83 |
|
69 | 84 |
# Private method -- test the UA string
|
70 | 85 |
sub _test {
|
71 | |
my ($self) = @_;
|
72 | |
|
73 | |
my $ua = lc $self->{user_agent};
|
74 | |
|
75 | |
# Browser version
|
76 | |
my ($major, $minor, $beta) = ($ua =~ / \/ # Version starts with a slash
|
|
86 |
my ($self) = @_;
|
|
87 |
|
|
88 |
my $ua = lc $self->{user_agent};
|
|
89 |
|
|
90 |
# Browser version
|
|
91 |
my ( $major, $minor, $beta ) = (
|
|
92 |
$ua =~ / \/ # Version starts with a slash
|
77 | 93 |
[A-Za-z]* # Eat any letters before the major version
|
78 | 94 |
( [^.]* ) # Major version number is everything before the first dot
|
79 | 95 |
\. # The first dot
|
80 | 96 |
( [\d]* ) # Minor version number is every digit after the first dot
|
81 | 97 |
[\d.]* # Throw away remaining numbers and dots
|
82 | 98 |
( [^\s]* ) # Beta version string is up to next space
|
83 | |
/x);
|
84 | |
|
85 | |
# Firefox version
|
86 | |
|
87 | |
if ($ua =~ /(firefox|firebird|iceweasel|phoenix)/i) {
|
88 | |
(undef,$major, $minor) = ($ua =~ /
|
|
99 |
/x
|
|
100 |
);
|
|
101 |
|
|
102 |
# Firefox version
|
|
103 |
|
|
104 |
if ( $ua =~ /(firefox|firebird|iceweasel|phoenix)/i ) {
|
|
105 |
( undef, $major, $minor ) = (
|
|
106 |
$ua =~ /
|
89 | 107 |
(firefox|firebird|iceweasel|phoenix)
|
90 | 108 |
\/
|
91 | 109 |
( [^.]* ) # Major version number is everything before first dot
|
92 | 110 |
\. # The first dot
|
93 | 111 |
( [\d]* ) # Minor version nnumber is digits after first dot
|
94 | |
/x);
|
95 | |
}
|
96 | |
|
97 | |
|
98 | |
|
99 | |
# IE version
|
100 | |
if (index($ua,"compatible") !=-1) {
|
101 | |
($major, $minor, $beta) = ($ua =~ /
|
|
112 |
/x
|
|
113 |
);
|
|
114 |
}
|
|
115 |
|
|
116 |
# IE version
|
|
117 |
if ( index( $ua, "compatible" ) != -1 ) {
|
|
118 |
( $major, $minor, $beta ) = (
|
|
119 |
$ua =~ /
|
102 | 120 |
compatible;
|
103 | 121 |
\s*
|
104 | 122 |
\w* # Browser name
|
|
110 | 128 |
[\d.]* # Throw away remaining dots and digits
|
111 | 129 |
( [^;]* ) # Beta version is up to the ;
|
112 | 130 |
;
|
113 | |
/x);
|
114 | |
|
115 | |
}
|
116 | |
|
117 | |
|
118 | |
$major = 0 if !$major;
|
119 | |
$minor = 0+('.' . ($minor || 0));
|
120 | |
|
121 | |
$self->{tests} = {};
|
122 | |
my $tests = $self->{tests};
|
123 | |
|
124 | |
# Mozilla browsers
|
125 | |
|
126 | |
$tests->{GECKO} = (index($ua,"gecko") != -1) && (index($ua, "khtml, like gecko") == -1 );
|
127 | |
$tests->{FIREFOX} = (index($ua,"firefox") != -1) ||
|
128 | |
(index($ua,"firebird") != -1) ||
|
129 | |
(index($ua,"iceweasel") != -1) ||
|
130 | |
(index($ua,"phoenix") != -1);
|
131 | |
|
132 | |
$tests->{CHROME} = (index($ua,"chrome") != -1);
|
133 | |
$tests->{SAFARI} = ( (index($ua,"safari") != -1) || (index($ua,"applewebkit") != -1) )
|
134 | |
&& (index($ua,"chrome") == -1);
|
135 | |
|
136 | |
# Chome Version
|
137 | |
if ($tests->{CHROME}) {
|
138 | |
($major, $minor) = ($ua =~ /
|
|
131 |
/x
|
|
132 |
);
|
|
133 |
|
|
134 |
}
|
|
135 |
|
|
136 |
$major = 0 if !$major;
|
|
137 |
$minor = 0 + ( '.' . ( $minor || 0 ) );
|
|
138 |
|
|
139 |
$self->{tests} = {};
|
|
140 |
my $tests = $self->{tests};
|
|
141 |
|
|
142 |
# Mozilla browsers
|
|
143 |
|
|
144 |
$tests->{GECKO} = ( index( $ua, "gecko" ) != -1 )
|
|
145 |
&& ( index( $ua, "khtml, like gecko" ) == -1 );
|
|
146 |
$tests->{FIREFOX}
|
|
147 |
= ( index( $ua, "firefox" ) != -1 )
|
|
148 |
|| ( index( $ua, "firebird" ) != -1 )
|
|
149 |
|| ( index( $ua, "iceweasel" ) != -1 )
|
|
150 |
|| ( index( $ua, "phoenix" ) != -1 );
|
|
151 |
|
|
152 |
$tests->{CHROME} = ( index( $ua, "chrome" ) != -1 );
|
|
153 |
$tests->{SAFARI}
|
|
154 |
= ( ( index( $ua, "safari" ) != -1 )
|
|
155 |
|| ( index( $ua, "applewebkit" ) != -1 ) )
|
|
156 |
&& ( index( $ua, "chrome" ) == -1 );
|
|
157 |
|
|
158 |
# Chome Version
|
|
159 |
if ( $tests->{CHROME} ) {
|
|
160 |
( $major, $minor ) = (
|
|
161 |
$ua =~ /
|
139 | 162 |
chrome
|
140 | 163 |
\/
|
141 | 164 |
( [^.]* ) # Major version number is everything before first dot
|
142 | 165 |
\. # The first dot
|
143 | 166 |
( [^.]* ) # Minor version number is digits after first dot
|
144 | |
/x);
|
145 | |
#print "major=$major minor=$minor beta=$beta\n";
|
146 | |
}
|
147 | |
# Safari Version
|
148 | |
elsif ($tests->{SAFARI}) {
|
149 | |
if ( index($ua,"version/") != -1 ) {
|
150 | |
($major,$minor) = ( $ua =~ m{
|
|
167 |
/x
|
|
168 |
);
|
|
169 |
|
|
170 |
#print "major=$major minor=$minor beta=$beta\n";
|
|
171 |
}
|
|
172 |
|
|
173 |
# Safari Version
|
|
174 |
elsif ( $tests->{SAFARI} ) {
|
|
175 |
if ( index( $ua, "version/" ) != -1 ) {
|
|
176 |
( $major, $minor ) = (
|
|
177 |
$ua =~ m{
|
151 | 178 |
version/
|
152 | 179 |
( [^.]* ) # Major version number is everything before first dot
|
153 | 180 |
\. # The first dot
|
154 | 181 |
( [^.]* ) # Minor version number is digits after first dot
|
155 | |
}x );
|
156 | |
}
|
157 | |
else {
|
158 | |
my ($safari_build, $safari_minor);
|
159 | |
($safari_build,$safari_minor) = ($ua =~ /
|
|
182 |
}x
|
|
183 |
);
|
|
184 |
}
|
|
185 |
else {
|
|
186 |
my ( $safari_build, $safari_minor );
|
|
187 |
( $safari_build, $safari_minor ) = (
|
|
188 |
$ua =~ /
|
160 | 189 |
safari
|
161 | 190 |
\/
|
162 | 191 |
( [^.]* ) # Major version number is everything before first dot
|
163 | 192 |
(?: # The first dot
|
164 | 193 |
( \d* ))? # Minor version number is digits after first dot
|
165 | |
/x);
|
166 | |
# in some obscure cases, extra characters are captured by the regex
|
167 | |
# like: Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413 UP.Link/6.3.1.15.0
|
168 | |
$safari_build =~ s{ [^\d] }{}gxms;
|
169 | |
|
170 | |
$major = int($safari_build / 100);
|
171 | |
$minor = int($safari_build % 100) / 100;
|
172 | |
$beta = $safari_minor;
|
173 | |
#print "major=$major minor=$minor beta=$beta\n";
|
174 | |
}
|
175 | |
|
176 | |
}
|
177 | |
|
178 | |
# Gecko-powered Netscape (i.e. Mozilla) versions
|
179 | |
$tests->{NETSCAPE} = (!$tests->{FIREFOX} && !$tests->{SAFARI} && index($ua,"mozilla") != -1 &&
|
180 | |
index($ua,"spoofer") == -1 && index($ua,"compatible") == -1 &&
|
181 | |
index($ua,"opera") == -1 && index($ua,"webtv") == -1 &&
|
182 | |
index($ua,"hotjava") == -1);
|
183 | |
|
184 | |
|
185 | |
if ($tests->{GECKO} && $tests->{NETSCAPE} && index($ua,"netscape")!=-1) {
|
186 | |
($major, $minor, $beta) = ($ua =~ /
|
|
194 |
/x
|
|
195 |
);
|
|
196 |
|
|
197 |
# in some obscure cases, extra characters are captured by the regex
|
|
198 |
# like: Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413 UP.Link/6.3.1.15.0
|
|
199 |
$safari_build =~ s{ [^\d] }{}gxms;
|
|
200 |
|
|
201 |
$major = int( $safari_build / 100 );
|
|
202 |
$minor = int( $safari_build % 100 ) / 100;
|
|
203 |
$beta = $safari_minor;
|
|
204 |
|
|
205 |
#print "major=$major minor=$minor beta=$beta\n";
|
|
206 |
}
|
|
207 |
|
|
208 |
}
|
|
209 |
|
|
210 |
# Gecko-powered Netscape (i.e. Mozilla) versions
|
|
211 |
$tests->{NETSCAPE}
|
|
212 |
= ( !$tests->{FIREFOX}
|
|
213 |
&& !$tests->{SAFARI}
|
|
214 |
&& index( $ua, "mozilla" ) != -1
|
|
215 |
&& index( $ua, "spoofer" ) == -1
|
|
216 |
&& index( $ua, "compatible" ) == -1
|
|
217 |
&& index( $ua, "opera" ) == -1
|
|
218 |
&& index( $ua, "webtv" ) == -1
|
|
219 |
&& index( $ua, "hotjava" ) == -1 );
|
|
220 |
|
|
221 |
if ( $tests->{GECKO}
|
|
222 |
&& $tests->{NETSCAPE}
|
|
223 |
&& index( $ua, "netscape" ) != -1 )
|
|
224 |
{
|
|
225 |
( $major, $minor, $beta ) = (
|
|
226 |
$ua =~ /
|
187 | 227 |
netscape\/
|
188 | 228 |
( [^.]* ) # Major version number is everything before first dot
|
189 | 229 |
\. # The first dot
|
190 | 230 |
( [\d]* ) # Minor version nnumber is digits after first dot
|
191 | 231 |
( [^\s]* )
|
192 | |
/x);
|
193 | |
$minor = 0+".$minor";
|
194 | |
#print "major=$major minor=$minor beta=$beta\n";
|
195 | |
}
|
196 | |
|
197 | |
|
198 | |
# Netscape browsers
|
199 | |
$tests->{NAV2} = ($tests->{NETSCAPE} && $major == 2);
|
200 | |
$tests->{NAV3} = ($tests->{NETSCAPE} && $major == 3);
|
201 | |
$tests->{NAV4} = ($tests->{NETSCAPE} && $major == 4);
|
202 | |
$tests->{NAV4UP} = ($tests->{NETSCAPE} && $major >= 4);
|
203 | |
$tests->{NAV45} = ($tests->{NETSCAPE} && $major == 4 && $minor == .5);
|
204 | |
$tests->{NAV45UP} = ($tests->{NAV4} && $minor >= .5) || ($tests->{NETSCAPE} && $major >= 5);
|
205 | |
$tests->{NAVGOLD} = (defined($beta) && index($beta,"gold") != -1);
|
206 | |
$tests->{NAV6} = ($tests->{NETSCAPE} && $major == 5); # go figure
|
207 | |
$tests->{NAV6UP} = ($tests->{NETSCAPE} && $major >= 5);
|
208 | |
|
209 | |
$tests->{MOZILLA} = ($tests->{NETSCAPE} && $tests->{GECKO});
|
210 | |
|
211 | |
# Internet Explorer browsers
|
212 | |
|
213 | |
$tests->{IE} = (index($ua,"msie") != -1 || index($ua,'microsoft internet explorer') != -1);
|
214 | |
$tests->{IE3} = ($tests->{IE} && $major == 3);
|
215 | |
$tests->{IE4} = ($tests->{IE} && $major == 4);
|
216 | |
$tests->{IE4UP} = ($tests->{IE} && $major >= 4);
|
217 | |
$tests->{IE5} = ($tests->{IE} && $major == 5);
|
218 | |
$tests->{IE5UP} = ($tests->{IE} && $major >= 5);
|
219 | |
$tests->{IE55} = ($tests->{IE} && $major == 5 && $minor >= .5);
|
220 | |
$tests->{IE55UP} = ($tests->{IE5} && $minor >= .5) || ($tests->{IE} && $major >= 6);
|
221 | |
$tests->{IE6} = ($tests->{IE} && $major == 6);
|
222 | |
$tests->{IE7} = ($tests->{IE} && $major == 7);
|
223 | |
$tests->{IE8} = ($tests->{IE} && $major == 8);
|
224 | |
|
225 | |
# Neoplanet browsers
|
226 | |
|
227 | |
$tests->{NEOPLANET} = (index($ua,"neoplanet") != -1);
|
228 | |
$tests->{NEOPLANET2} = ($tests->{NEOPLANET} && index($ua,"2.") != -1);
|
229 | |
|
230 | |
# AOL Browsers
|
231 | |
|
232 | |
$tests->{AOL} = (index($ua,"aol") != -1);
|
233 | |
$tests->{AOL3} = (index($ua,"aol 3.0") != -1) || ($tests->{AOL} && $tests->{IE3});
|
234 | |
$tests->{AOL4} = (index($ua,"aol 4.0") != -1) || ($tests->{AOL} && $tests->{IE4});
|
235 | |
$tests->{AOL5} = (index($ua,"aol 5.0") != -1);
|
236 | |
$tests->{AOL6} = (index($ua,"aol 6.0") != -1);
|
237 | |
$tests->{AOLTV} = (index($ua,"navio") != -1) || (index($ua,"navio_aoltv") != -1);
|
238 | |
|
239 | |
# Opera browsers
|
240 | |
|
241 | |
$tests->{OPERA} = (index($ua,"opera") != -1);
|
242 | |
$tests->{OPERA3} = (index($ua,"opera 3") != -1) || (index($ua,"opera/3") != -1);
|
243 | |
$tests->{OPERA4} = (index($ua,"opera 4") != -1) || (index($ua,"opera/4") != -1);
|
244 | |
$tests->{OPERA5} = (index($ua,"opera 5") != -1) || (index($ua,"opera/5") != -1);
|
245 | |
$tests->{OPERA6} = (index($ua,"opera 6") != -1) || (index($ua,"opera/6") != -1);
|
246 | |
$tests->{OPERA7} = (index($ua,"opera 7") != -1) || (index($ua,"opera/7") != -1);
|
247 | |
|
248 | |
# Other browsers
|
249 | |
|
250 | |
$tests->{CURL} = (index($ua,"libcurl") != -1);
|
251 | |
$tests->{STAROFFICE} = (index($ua,"staroffice") != -1);
|
252 | |
$tests->{ICAB} = (index($ua,"icab") != -1);
|
253 | |
$tests->{LOTUSNOTES} = (index($ua,"lotus-notes") != -1);
|
254 | |
$tests->{KONQUEROR} = (index($ua,"konqueror") != -1);
|
255 | |
$tests->{LYNX} = (index($ua,"lynx") != -1);
|
256 | |
$tests->{LINKS} = (index($ua,"links") != -1);
|
257 | |
$tests->{WEBTV} = (index($ua,"webtv") != -1);
|
258 | |
$tests->{MOSAIC} = (index($ua,"mosaic") != -1);
|
259 | |
$tests->{PUF} = (index($ua,"puf") != -1);
|
260 | |
$tests->{WGET} = (index($ua,"wget") != -1);
|
261 | |
$tests->{GETRIGHT} = (index($ua,"getright") != -1);
|
262 | |
$tests->{LWP} = (index($ua,"libwww-perl") != -1 ||
|
263 | |
index($ua,"lwp-") != -1);
|
264 | |
$tests->{YAHOO} = (index($ua,"yahoo") != -1);
|
265 | |
$tests->{GOOGLE} = (index($ua,"google") != -1);
|
266 | |
$tests->{JAVA} = (index($ua,"java") != -1 ||
|
267 | |
index($ua,"jdk") != -1);
|
268 | |
$tests->{ALTAVISTA} = (index($ua,"altavista") != -1);
|
269 | |
$tests->{SCOOTER} = (index($ua,"scooter") != -1);
|
270 | |
$tests->{LYCOS} = (index($ua,"lycos") != -1);
|
271 | |
$tests->{INFOSEEK} = (index($ua,"infoseek") != -1);
|
272 | |
$tests->{WEBCRAWLER} = (index($ua,"webcrawler") != -1);
|
273 | |
$tests->{LINKEXCHANGE} = (index($ua,"lecodechecker") != -1);
|
274 | |
$tests->{SLURP} = (index($ua,"slurp") != -1);
|
275 | |
$tests->{ROBOT} = (($tests->{WGET} ||
|
276 | |
$tests->{PUF} ||
|
277 | |
$tests->{GETRIGHT} ||
|
278 | |
$tests->{LWP} ||
|
279 | |
$tests->{YAHOO} ||
|
280 | |
$tests->{ALTAVISTA} ||
|
281 | |
$tests->{LYCOS} ||
|
282 | |
$tests->{INFOSEEK} ||
|
283 | |
$tests->{WEBCRAWLER} ||
|
284 | |
$tests->{LINKEXCHANGE} ||
|
285 | |
$tests->{SLURP} ||
|
286 | |
$tests->{GOOGLE}) ||
|
287 | |
index($ua,"bot") != -1 ||
|
288 | |
index($ua,"spider") != -1 ||
|
289 | |
index($ua,"crawl") != -1 ||
|
290 | |
index($ua,"agent") != -1 ||
|
291 | |
index($ua,"seek") != -1 ||
|
292 | |
index($ua,"search") != -1 ||
|
293 | |
index($ua,"reap") != -1 ||
|
294 | |
index($ua,"worm") != -1 ||
|
295 | |
index($ua,"find") != -1 ||
|
296 | |
index($ua,"index") != -1 ||
|
297 | |
index($ua,"copy") != -1 ||
|
298 | |
index($ua,"fetch") != -1 ||
|
299 | |
index($ua,"ia_archive") != -1 ||
|
300 | |
index($ua,"zyborg") != -1);
|
301 | |
|
302 | |
# Devices
|
303 | |
|
304 | |
$tests->{BLACKBERRY} = (index($ua,"blackberry") != -1);
|
305 | |
$tests->{AUDREY} = (index($ua,"audrey") != -1);
|
306 | |
$tests->{IOPENER} = (index($ua,"i-opener") != -1);
|
307 | |
$tests->{AVANTGO} = (index($ua,"avantgo") != -1);
|
308 | |
$tests->{PALM} = ($tests->{AVANTGO} ||
|
309 | |
index($ua,"palmos") != -1 );
|
310 | |
$tests->{WAP} = (index($ua,"up.browser") != -1 ||
|
311 | |
index($ua,"nokia") != -1 ||
|
312 | |
index($ua,"alcatel") != -1 ||
|
313 | |
index($ua,"ericsson") != -1 ||
|
314 | |
index($ua,"sie-") == 0 ||
|
315 | |
index($ua,"wmlib") != -1 ||
|
316 | |
index($ua," wap") != -1 ||
|
317 | |
index($ua,"wap ") != -1 ||
|
318 | |
index($ua,"wap/") != -1 ||
|
319 | |
index($ua,"-wap") != -1 ||
|
320 | |
index($ua,"wap-") != -1 ||
|
321 | |
index($ua,"wap") == 0 ||
|
322 | |
index($ua,"wapper") != -1 ||
|
323 | |
index($ua,"zetor") != -1);
|
324 | |
|
325 | |
|
326 | |
# Operating System
|
327 | |
|
328 | |
$tests->{WIN16} = (index($ua,"win16") != -1 || index($ua,"16bit") != -1 || index($ua,"windows 3") != -1 ||
|
329 | |
index($ua,"windows 16-bit") != -1);
|
330 | |
$tests->{WIN3X} = (index($ua,"win16") != -1 || index($ua,"windows 3") != -1 || index($ua,"windows 16-bit") != -1);
|
331 | |
$tests->{WIN31} = (index($ua,"win16") != -1 || index($ua,"windows 3.1") != -1 || index($ua,"windows 16-bit") != -1);
|
332 | |
$tests->{WIN95} = (index($ua,"win95") != -1 || index($ua,"windows 95") != -1);
|
333 | |
$tests->{WIN98} = (index($ua,"win98") != -1 || index($ua,"windows 98") != -1);
|
334 | |
$tests->{WINNT} = (index($ua,"winnt") != -1 ||
|
335 | |
index($ua,"windows nt") != -1 ||
|
336 | |
index($ua,"nt4") != -1 ||
|
337 | |
index($ua,"nt3") != -1);
|
338 | |
$tests->{WIN2K} = (index($ua,"nt 5.0") != -1 || index($ua,"nt5") != -1);
|
339 | |
$tests->{WINXP} = (index($ua,"nt 5.1") != -1 );
|
340 | |
$tests->{WIN2K3} = (index($ua,"nt 5.2") != -1 );
|
341 | |
$tests->{WINVISTA} = (index($ua,"nt 6.0") != -1 );
|
342 | |
$tests->{DOTNET} = (index($ua,".net clr") != -1);
|
343 | |
|
344 | |
$tests->{WINME} = (index($ua,"win 9x 4.90") != -1); # whatever
|
345 | |
$tests->{WIN32} = (($tests->{WIN95} || $tests->{WIN98} || $tests->{WINME} || $tests->{WINNT} ||
|
346 | |
$tests->{WIN2K}) || $tests->{WINXP} || $tests->{WIN2K3} || $tests->{WINVISTA} || index($ua,"win32") != -1);
|
347 | |
$tests->{WINDOWS} = (($tests->{WIN16} || $tests->{WIN31} || $tests->{WIN95} || $tests->{WIN98} ||
|
348 | |
$tests->{WINNT} || $tests->{WIN32} || $tests->{WIN2K} || $tests->{WINXP} || $tests->{WIN2K3} || $tests->{WINVISTA} || $tests->{WINME}) || index($ua,"win") != -1);
|
349 | |
|
350 | |
# Mac operating systems
|
351 | |
|
352 | |
$tests->{MAC} = (index($ua,"macintosh") != -1 || index($ua,"mac_") != -1);
|
353 | |
$tests->{MACOSX} = (index($ua,"macintosh") != -1 && index($ua,"mac os x") != -1);
|
354 | |
$tests->{MAC68K} = (($tests->{MAC}) && (index($ua,"68k") != -1 || index($ua,"68000") != -1));
|
355 | |
$tests->{MACPPC} = (($tests->{MAC}) && (index($ua,"ppc") != -1 || index($ua,"powerpc") != -1));
|
356 | |
|
357 | |
# Others
|
358 | |
|
359 | |
$tests->{AMIGA} = (index($ua,'amiga') != -1);
|
360 | |
|
361 | |
$tests->{EMACS} = (index($ua,'emacs') != -1);
|
362 | |
$tests->{OS2} = (index($ua,'os/2') != -1);
|
363 | |
|
364 | |
$tests->{SUN} = (index($ua,"sun") != -1);
|
365 | |
$tests->{SUN4} = (index($ua,"sunos 4") != -1);
|
366 | |
$tests->{SUN5} = (index($ua,"sunos 5") != -1);
|
367 | |
$tests->{SUNI86} = (($tests->{SUN}) && index($ua,"i86") != -1);
|
368 | |
|
369 | |
$tests->{IRIX} = (index($ua,"irix") != -1);
|
370 | |
$tests->{IRIX5} = (index($ua,"irix5") != -1);
|
371 | |
$tests->{IRIX6} = (index($ua,"irix6") != -1);
|
372 | |
|
373 | |
$tests->{HPUX} = (index($ua,"hp-ux") != -1);
|
374 | |
$tests->{HPUX9} = (($tests->{HPUX}) && index($ua,"09.") != -1);
|
375 | |
$tests->{HPUX10} = (($tests->{HPUX}) && index($ua,"10.") != -1);
|
376 | |
|
377 | |
$tests->{AIX} = (index($ua,"aix") != -1);
|
378 | |
$tests->{AIX1} = (index($ua,"aix 1") != -1);
|
379 | |
$tests->{AIX2} = (index($ua,"aix 2") != -1);
|
380 | |
$tests->{AIX3} = (index($ua,"aix 3") != -1);
|
381 | |
$tests->{AIX4} = (index($ua,"aix 4") != -1);
|
382 | |
|
383 | |
$tests->{LINUX} = (index($ua,"inux") != -1);
|
384 | |
$tests->{SCO} = (index($ua,"sco") != -1 || index($ua,"unix_sv") != -1);
|
385 | |
$tests->{UNIXWARE} = (index($ua,"unix_system_v") != -1);
|
386 | |
$tests->{MPRAS} = (index($ua,"ncr") != -1);
|
387 | |
$tests->{RELIANT} = (index($ua,"reliantunix") != -1);
|
388 | |
|
389 | |
$tests->{DEC} = (index($ua,"dec") != -1 || index($ua,"osf1") != -1 || index($ua,"declpha") != -1 ||
|
390 | |
index($ua,"alphaserver") != -1 || index($ua,"ultrix") != -1 ||
|
391 | |
index($ua,"alphastation") != -1);
|
392 | |
|
393 | |
$tests->{SINIX} = (index($ua,"sinix") != -1);
|
394 | |
$tests->{FREEBSD} = (index($ua,"freebsd") != -1);
|
395 | |
$tests->{BSD} = (index($ua,"bsd") != -1);
|
396 | |
$tests->{X11} = (index($ua,"x11") != -1);
|
397 | |
$tests->{UNIX} = ($tests->{X11} || $tests->{SUN} || $tests->{IRIX} || $tests->{HPUX} ||
|
398 | |
$tests->{SCO} || $tests->{UNIXWARE} || $tests->{MPRAS} ||
|
399 | |
$tests->{RELIANT} || $tests->{DEC} || $tests->{LINUX} ||
|
400 | |
$tests->{BSD});
|
401 | |
|
402 | |
$tests->{VMS} = (index($ua,"vax") != -1 || index($ua,"openvms") != -1);
|
403 | |
|
404 | |
# A final try at browser version, if we haven't gotten it so far
|
405 | |
if (!defined($major) || $major eq '') {
|
406 | |
if ($ua =~ /[A-Za-z]+\/(\d+)\;/) {
|
407 | |
$major = $1;
|
408 | |
$minor = 0;
|
409 | |
}
|
410 | |
}
|
411 | |
|
412 | |
|
413 | |
# Gecko version
|
414 | |
$self->{gecko_version} = undef;
|
415 | |
if ($tests->{GECKO}) {
|
416 | |
if( $ua =~ /\([^)]*rv:([\w.\d]*)/ ) {
|
417 | |
$self->{gecko_version} = $1;
|
418 | |
}
|
419 | |
}
|
420 | |
|
421 | |
$self->{major} = $major;
|
422 | |
$self->{minor} = $minor;
|
423 | |
$self->{beta} = $beta;
|
|
232 |
/x
|
|
233 |
);
|
|
234 |
$minor = 0 + ".$minor";
|
|
235 |
|
|
236 |
#print "major=$major minor=$minor beta=$beta\n";
|
|
237 |
}
|
|
238 |
|
|
239 |
# Netscape browsers
|
|
240 |
$tests->{NAV2} = ( $tests->{NETSCAPE} && $major == 2 );
|
|
241 |
$tests->{NAV3} = ( $tests->{NETSCAPE} && $major == 3 );
|
|
242 |
$tests->{NAV4} = ( $tests->{NETSCAPE} && $major == 4 );
|
|
243 |
$tests->{NAV4UP} = ( $tests->{NETSCAPE} && $major >= 4 );
|
|
244 |
$tests->{NAV45} = ( $tests->{NETSCAPE} && $major == 4 && $minor == .5 );
|
|
245 |
$tests->{NAV45UP} = ( $tests->{NAV4} && $minor >= .5 )
|
|
246 |
|| ( $tests->{NETSCAPE} && $major >= 5 );
|
|
247 |
$tests->{NAVGOLD} = ( defined($beta) && index( $beta, "gold" ) != -1 );
|
|
248 |
$tests->{NAV6} = ( $tests->{NETSCAPE} && $major == 5 ); # go figure
|
|
249 |
$tests->{NAV6UP} = ( $tests->{NETSCAPE} && $major >= 5 );
|
|
250 |
|
|
251 |
$tests->{MOZILLA} = ( $tests->{NETSCAPE} && $tests->{GECKO} );
|
|
252 |
|
|
253 |
# Internet Explorer browsers
|
|
254 |
|
|
255 |
$tests->{IE} = ( index( $ua, "msie" ) != -1
|
|
256 |
|| index( $ua, 'microsoft internet explorer' ) != -1 );
|
|
257 |
$tests->{IE3} = ( $tests->{IE} && $major == 3 );
|
|
258 |
$tests->{IE4} = ( $tests->{IE} && $major == 4 );
|
|
259 |
$tests->{IE4UP} = ( $tests->{IE} && $major >= 4 );
|
|
260 |
$tests->{IE5} = ( $tests->{IE} && $major == 5 );
|
|
261 |
$tests->{IE5UP} = ( $tests->{IE} && $major >= 5 );
|
|
262 |
$tests->{IE55} = ( $tests->{IE} && $major == 5 && $minor >= .5 );
|
|
263 |
$tests->{IE55UP} = ( $tests->{IE5} && $minor >= .5 )
|
|
264 |
|| ( $tests->{IE} && $major >= 6 );
|
|
265 |
$tests->{IE6} = ( $tests->{IE} && $major == 6 );
|
|
266 |
$tests->{IE7} = ( $tests->{IE} && $major == 7 );
|
|
267 |
$tests->{IE8} = ( $tests->{IE} && $major == 8 );
|
|
268 |
|
|
269 |
# Neoplanet browsers
|
|
270 |
|
|
271 |
$tests->{NEOPLANET} = ( index( $ua, "neoplanet" ) != -1 );
|
|
272 |
$tests->{NEOPLANET2}
|
|
273 |
= ( $tests->{NEOPLANET} && index( $ua, "2." ) != -1 );
|
|
274 |
|
|
275 |
# AOL Browsers
|
|
276 |
|
|
277 |
$tests->{AOL} = ( index( $ua, "aol" ) != -1 );
|
|
278 |
$tests->{AOL3} = ( index( $ua, "aol 3.0" ) != -1 )
|
|
279 |
|| ( $tests->{AOL} && $tests->{IE3} );
|
|
280 |
$tests->{AOL4} = ( index( $ua, "aol 4.0" ) != -1 )
|
|
281 |
|| ( $tests->{AOL} && $tests->{IE4} );
|
|
282 |
$tests->{AOL5} = ( index( $ua, "aol 5.0" ) != -1 );
|
|
283 |
$tests->{AOL6} = ( index( $ua, "aol 6.0" ) != -1 );
|
|
284 |
$tests->{AOLTV} = ( index( $ua, "navio" ) != -1 )
|
|
285 |
|| ( index( $ua, "navio_aoltv" ) != -1 );
|
|
286 |
|
|
287 |
# Opera browsers
|
|
288 |
|
|
289 |
$tests->{OPERA} = ( index( $ua, "opera" ) != -1 );
|
|
290 |
$tests->{OPERA3} = ( index( $ua, "opera 3" ) != -1 )
|
|
291 |
|| ( index( $ua, "opera/3" ) != -1 );
|
|
292 |
$tests->{OPERA4} = ( index( $ua, "opera 4" ) != -1 )
|
|
293 |
|| ( index( $ua, "opera/4" ) != -1 );
|
|
294 |
$tests->{OPERA5} = ( index( $ua, "opera 5" ) != -1 )
|
|
295 |
|| ( index( $ua, "opera/5" ) != -1 );
|
|
296 |
$tests->{OPERA6} = ( index( $ua, "opera 6" ) != -1 )
|
|
297 |
|| ( index( $ua, "opera/6" ) != -1 );
|
|
298 |
$tests->{OPERA7} = ( index( $ua, "opera 7" ) != -1 )
|
|
299 |
|| ( index( $ua, "opera/7" ) != -1 );
|
|
300 |
|
|
301 |
# Other browsers
|
|
302 |
|
|
303 |
$tests->{CURL} = ( index( $ua, "libcurl" ) != -1 );
|
|
304 |
$tests->{STAROFFICE} = ( index( $ua, "staroffice" ) != -1 );
|
|
305 |
$tests->{ICAB} = ( index( $ua, "icab" ) != -1 );
|
|
306 |
$tests->{LOTUSNOTES} = ( index( $ua, "lotus-notes" ) != -1 );
|
|
307 |
$tests->{KONQUEROR} = ( index( $ua, "konqueror" ) != -1 );
|
|
308 |
$tests->{LYNX} = ( index( $ua, "lynx" ) != -1 );
|
|
309 |
$tests->{LINKS} = ( index( $ua, "links" ) != -1 );
|
|
310 |
$tests->{WEBTV} = ( index( $ua, "webtv" ) != -1 );
|
|
311 |
$tests->{MOSAIC} = ( index( $ua, "mosaic" ) != -1 );
|
|
312 |
$tests->{PUF} = ( index( $ua, "puf" ) != -1 );
|
|
313 |
$tests->{WGET} = ( index( $ua, "wget" ) != -1 );
|
|
314 |
$tests->{GETRIGHT} = ( index( $ua, "getright" ) != -1 );
|
|
315 |
$tests->{LWP}
|
|
316 |
= ( index( $ua, "libwww-perl" ) != -1 || index( $ua, "lwp-" ) != -1 );
|
|
317 |
$tests->{YAHOO} = ( index( $ua, "yahoo" ) != -1 );
|
|
318 |
$tests->{GOOGLE} = ( index( $ua, "google" ) != -1 );
|
|
319 |
$tests->{JAVA}
|
|
320 |
= ( index( $ua, "java" ) != -1 || index( $ua, "jdk" ) != -1 );
|
|
321 |
$tests->{ALTAVISTA} = ( index( $ua, "altavista" ) != -1 );
|
|
322 |
$tests->{SCOOTER} = ( index( $ua, "scooter" ) != -1 );
|
|
323 |
$tests->{LYCOS} = ( index( $ua, "lycos" ) != -1 );
|
|
324 |
$tests->{INFOSEEK} = ( index( $ua, "infoseek" ) != -1 );
|
|
325 |
$tests->{WEBCRAWLER} = ( index( $ua, "webcrawler" ) != -1 );
|
|
326 |
$tests->{LINKEXCHANGE} = ( index( $ua, "lecodechecker" ) != -1 );
|
|
327 |
$tests->{SLURP} = ( index( $ua, "slurp" ) != -1 );
|
|
328 |
$tests->{ROBOT} = (
|
|
329 |
( $tests->{WGET}
|
|
330 |
|| $tests->{PUF}
|
|
331 |
|| $tests->{GETRIGHT}
|
|
332 |
|| $tests->{LWP}
|
|
333 |
|| $tests->{YAHOO}
|
|
334 |
|| $tests->{ALTAVISTA}
|
|
335 |
|| $tests->{LYCOS}
|
|
336 |
|| $tests->{INFOSEEK}
|
|
337 |
|| $tests->{WEBCRAWLER}
|
|
338 |
|| $tests->{LINKEXCHANGE}
|
|
339 |
|| $tests->{SLURP}
|
|
340 |
|| $tests->{GOOGLE}
|
|
341 |
)
|
|
342 |
|| index( $ua, "bot" ) != -1
|
|
343 |
|| index( $ua, "spider" ) != -1
|
|
344 |
|| index( $ua, "crawl" ) != -1
|
|
345 |
|| index( $ua, "agent" ) != -1
|
|
346 |
|| index( $ua, "seek" ) != -1
|
|
347 |
|| index( $ua, "search" ) != -1
|
|
348 |
|| index( $ua, "reap" ) != -1
|
|
349 |
|| index( $ua, "worm" ) != -1
|
|
350 |
|| index( $ua, "find" ) != -1
|
|
351 |
|| index( $ua, "index" ) != -1
|
|
352 |
|| index( $ua, "copy" ) != -1
|
|
353 |
|| index( $ua, "fetch" ) != -1
|
|
354 |
|| index( $ua, "ia_archive" ) != -1
|
|
355 |
|| index( $ua, "zyborg" ) != -1
|
|
356 |
);
|
|
357 |
|
|
358 |
# Devices
|
|
359 |
|
|
360 |
$tests->{BLACKBERRY} = ( index( $ua, "blackberry" ) != -1 );
|
|
361 |
$tests->{AUDREY} = ( index( $ua, "audrey" ) != -1 );
|
|
362 |
$tests->{IOPENER} = ( index( $ua, "i-opener" ) != -1 );
|
|
363 |
$tests->{AVANTGO} = ( index( $ua, "avantgo" ) != -1 );
|
|
364 |
$tests->{PALM}
|
|
365 |
= ( $tests->{AVANTGO} || index( $ua, "palmos" ) != -1 );
|
|
366 |
$tests->{WAP}
|
|
367 |
= ( index( $ua, "up.browser" ) != -1
|
|
368 |
|| index( $ua, "nokia" ) != -1
|
|
369 |
|| index( $ua, "alcatel" ) != -1
|
|
370 |
|| index( $ua, "ericsson" ) != -1
|
|
371 |
|| index( $ua, "sie-" ) == 0
|
|
372 |
|| index( $ua, "wmlib" ) != -1
|
|
373 |
|| index( $ua, " wap" ) != -1
|
|
374 |
|| index( $ua, "wap " ) != -1
|
|
375 |
|| index( $ua, "wap/" ) != -1
|
|
376 |
|| index( $ua, "-wap" ) != -1
|
|
377 |
|| index( $ua, "wap-" ) != -1
|
|
378 |
|| index( $ua, "wap" ) == 0
|
|
379 |
|| index( $ua, "wapper" ) != -1
|
|
380 |
|| index( $ua, "zetor" ) != -1 );
|
|
381 |
|
|
382 |
$tests->{MOBILE} = (
|
|
383 |
index( $ua, "up.browser" ) != -1
|
|
384 |
|| index( $ua, "nokia" ) != -1
|
|
385 |
|| index( $ua, "alcatel" ) != -1
|
|
386 |
|| index( $ua, "ericsson" ) != -1
|
|
387 |
|| index( $ua, "sie-" ) == 0
|
|
388 |
|| index( $ua, "wmlib" ) != -1
|
|
389 |
|| index( $ua, " wap" ) != -1
|
|
390 |
|| index( $ua, "wap " ) != -1
|
|
391 |
|| index( $ua, "wap/" ) != -1
|
|
392 |
|| index( $ua, "-wap" ) != -1
|
|
393 |
|| index( $ua, "wap-" ) != -1
|
|
394 |
|| index( $ua, "wap" ) == 0
|
|
395 |
|| index( $ua, "wapper" ) != -1
|
|
396 |
|| index( $ua, "blackberry" ) != -1
|
|
397 |
|| index( $ua, "iemobile" ) != -1
|
|
398 |
|| index( $ua, "palm" ) != -1
|
|
399 |
|| index( $ua, "smartphone" ) != -1
|
|
400 |
|| index( $ua, "windows ce" ) != -1
|
|
401 |
|| index( $ua, "palmsource" ) != -1
|
|
402 |
|| index( $ua, "iphone" ) != -1
|
|
403 |
|| index( $ua, "opera mini" ) != -1
|
|
404 |
|| index( $ua, "android" ) != -1
|
|
405 |
|| index( $ua, "htc_" ) != -1
|
|
406 |
|| index( $ua, "symbian" ) != -1
|
|
407 |
|| index( $ua, "webos" ) != -1
|
|
408 |
||
|
|
409 |
|
|
410 |
# index($ua," ppc") != -1 ||
|
|
411 |
index( $ua, "samsung" ) != -1
|
|
412 |
|| index( $ua, "samsung" ) != -1
|
|
413 |
|| index( $ua, "zetor" ) != -1
|
|
414 |
);
|
|
415 |
|
|
416 |
# Operating System
|
|
417 |
|
|
418 |
$tests->{WIN16}
|
|
419 |
= ( index( $ua, "win16" ) != -1
|
|
420 |
|| index( $ua, "16bit" ) != -1
|
|
421 |
|| index( $ua, "windows 3" ) != -1
|
|
422 |
|| index( $ua, "windows 16-bit" ) != -1 );
|
|
423 |
$tests->{WIN3X}
|
|
424 |
= ( index( $ua, "win16" ) != -1
|
|
425 |
|| index( $ua, "windows 3" ) != -1
|
|
426 |
|| index( $ua, "windows 16-bit" ) != -1 );
|
|
427 |
$tests->{WIN31}
|
|
428 |
= ( index( $ua, "win16" ) != -1
|
|
429 |
|| index( $ua, "windows 3.1" ) != -1
|
|
430 |
|| index( $ua, "windows 16-bit" ) != -1 );
|
|
431 |
$tests->{WIN95}
|
|
432 |
= ( index( $ua, "win95" ) != -1 || index( $ua, "windows 95" ) != -1 );
|
|
433 |
$tests->{WIN98}
|
|
434 |
= ( index( $ua, "win98" ) != -1 || index( $ua, "windows 98" ) != -1 );
|
|
435 |
$tests->{WINNT}
|
|
436 |
= ( index( $ua, "winnt" ) != -1
|
|
437 |
|| index( $ua, "windows nt" ) != -1
|
|
438 |
|| index( $ua, "nt4" ) != -1
|
|
439 |
|| index( $ua, "nt3" ) != -1 );
|
|
440 |
$tests->{WIN2K}
|
|
441 |
= ( index( $ua, "nt 5.0" ) != -1 || index( $ua, "nt5" ) != -1 );
|
|
442 |
$tests->{WINXP} = ( index( $ua, "nt 5.1" ) != -1 );
|
|
443 |
$tests->{WIN2K3} = ( index( $ua, "nt 5.2" ) != -1 );
|
|
444 |
$tests->{WINVISTA} = ( index( $ua, "nt 6.0" ) != -1 );
|
|
445 |
$tests->{DOTNET} = ( index( $ua, ".net clr" ) != -1 );
|
|
446 |
|
|
447 |
$tests->{WINME} = ( index( $ua, "win 9x 4.90" ) != -1 ); # whatever
|
|
448 |
$tests->{WIN32} = (
|
|
449 |
( $tests->{WIN95}
|
|
450 |
|| $tests->{WIN98}
|
|
451 |
|| $tests->{WINME}
|
|
452 |
|| $tests->{WINNT}
|
|
453 |
|| $tests->{WIN2K}
|
|
454 |
)
|
|
455 |
|| $tests->{WINXP}
|
|
456 |
|| $tests->{WIN2K3}
|
|
457 |
|| $tests->{WINVISTA}
|
|
458 |
|| index( $ua, "win32" ) != -1
|
|
459 |
);
|
|
460 |
$tests->{WINDOWS} = (
|
|
461 |
( $tests->{WIN16}
|
|
462 |
|| $tests->{WIN31}
|
|
463 |
|| $tests->{WIN95}
|
|
464 |
|| $tests->{WIN98}
|
|
465 |
|| $tests->{WINNT}
|
|
466 |
|| $tests->{WIN32}
|
|
467 |
|| $tests->{WIN2K}
|
|
468 |
|| $tests->{WINXP}
|
|
469 |
|| $tests->{WIN2K3}
|
|
470 |
|| $tests->{WINVISTA}
|
|
471 |
|| $tests->{WINME}
|
|
472 |
)
|
|
473 |
|| index( $ua, "win" ) != -1
|
|
474 |
);
|
|
475 |
|
|
476 |
# Mac operating systems
|
|
477 |
|
|
478 |
$tests->{MAC}
|
|
479 |
= ( index( $ua, "macintosh" ) != -1 || index( $ua, "mac_" ) != -1 );
|
|
480 |
$tests->{MACOSX} = ( index( $ua, "macintosh" ) != -1
|
|
481 |
&& index( $ua, "mac os x" ) != -1 );
|
|
482 |
$tests->{MAC68K} = ( ( $tests->{MAC} )
|
|
483 |
&& ( index( $ua, "68k" ) != -1 || index( $ua, "68000" ) != -1 ) );
|
|
484 |
$tests->{MACPPC}
|
|
485 |
= ( ( $tests->{MAC} )
|
|
486 |
&& ( index( $ua, "ppc" ) != -1 || index( $ua, "powerpc" ) != -1 )
|
|
487 |
);
|
|
488 |
|
|
489 |
# Others
|
|
490 |
|
|
491 |
$tests->{AMIGA} = ( index( $ua, 'amiga' ) != -1 );
|
|
492 |
|
|
493 |
$tests->{EMACS} = ( index( $ua, 'emacs' ) != -1 );
|
|
494 |
$tests->{OS2} = ( index( $ua, 'os/2' ) != -1 );
|
|
495 |
|
|
496 |
$tests->{SUN} = ( index( $ua, "sun" ) != -1 );
|
|
497 |
$tests->{SUN4} = ( index( $ua, "sunos 4" ) != -1 );
|
|
498 |
$tests->{SUN5} = ( index( $ua, "sunos 5" ) != -1 );
|
|
499 |
$tests->{SUNI86} = ( ( $tests->{SUN} ) && index( $ua, "i86" ) != -1 );
|
|
500 |
|
|
501 |
$tests->{IRIX} = ( index( $ua, "irix" ) != -1 );
|
|
502 |
$tests->{IRIX5} = ( index( $ua, "irix5" ) != -1 );
|
|
503 |
$tests->{IRIX6} = ( index( $ua, "irix6" ) != -1 );
|
|
504 |
|
|
505 |
$tests->{HPUX} = ( index( $ua, "hp-ux" ) != -1 );
|
|
506 |
$tests->{HPUX9} = ( ( $tests->{HPUX} ) && index( $ua, "09." ) != -1 );
|
|
507 |
$tests->{HPUX10} = ( ( $tests->{HPUX} ) && index( $ua, "10." ) != -1 );
|
|
508 |
|
|
509 |
$tests->{AIX} = ( index( $ua, "aix" ) != -1 );
|
|
510 |
$tests->{AIX1} = ( index( $ua, "aix 1" ) != -1 );
|
|
511 |
$tests->{AIX2} = ( index( $ua, "aix 2" ) != -1 );
|
|
512 |
$tests->{AIX3} = ( index( $ua, "aix 3" ) != -1 );
|
|
513 |
$tests->{AIX4} = ( index( $ua, "aix 4" ) != -1 );
|
|
514 |
|
|
515 |
$tests->{LINUX} = ( index( $ua, "inux" ) != -1 );
|
|
516 |
$tests->{SCO}
|
|
517 |
= ( index( $ua, "sco" ) != -1 || index( $ua, "unix_sv" ) != -1 );
|
|
518 |
$tests->{UNIXWARE} = ( index( $ua, "unix_system_v" ) != -1 );
|
|
519 |
$tests->{MPRAS} = ( index( $ua, "ncr" ) != -1 );
|
|
520 |
$tests->{RELIANT} = ( index( $ua, "reliantunix" ) != -1 );
|
|
521 |
|
|
522 |
$tests->{DEC}
|
|
523 |
= ( index( $ua, "dec" ) != -1
|
|
524 |
|| index( $ua, "osf1" ) != -1
|
|
525 |
|| index( $ua, "declpha" ) != -1
|
|
526 |
|| index( $ua, "alphaserver" ) != -1
|
|
527 |
|| index( $ua, "ultrix" ) != -1
|
|
528 |
|| index( $ua, "alphastation" ) != -1 );
|
|
529 |
|
|
530 |
$tests->{SINIX} = ( index( $ua, "sinix" ) != -1 );
|
|
531 |
$tests->{FREEBSD} = ( index( $ua, "freebsd" ) != -1 );
|
|
532 |
$tests->{BSD} = ( index( $ua, "bsd" ) != -1 );
|
|
533 |
$tests->{X11} = ( index( $ua, "x11" ) != -1 );
|
|
534 |
$tests->{UNIX}
|
|
535 |
= ( $tests->{X11}
|
|
536 |
|| $tests->{SUN}
|
|
537 |
|| $tests->{IRIX}
|
|
538 |
|| $tests->{HPUX}
|
|
539 |
|| $tests->{SCO}
|
|
540 |
|| $tests->{UNIXWARE}
|
|
541 |
|| $tests->{MPRAS}
|
|
542 |
|| $tests->{RELIANT}
|
|
543 |
|| $tests->{DEC}
|
|
544 |
|| $tests->{LINUX}
|
|
545 |
|| $tests->{BSD} );
|
|
546 |
|
|
547 |
$tests->{VMS}
|
|
548 |
= ( index( $ua, "vax" ) != -1 || index( $ua, "openvms" ) != -1 );
|
|
549 |
|
|
550 |
# A final try at browser version, if we haven't gotten it so far
|
|
551 |
if ( !defined($major) || $major eq '' ) {
|
|
552 |
if ( $ua =~ /[A-Za-z]+\/(\d+)\;/ ) {
|
|
553 |
$major = $1;
|
|
554 |
$minor = 0;
|
|
555 |
}
|
|
556 |
}
|
|
557 |
|
|
558 |
# Gecko version
|
|
559 |
$self->{gecko_version} = undef;
|
|
560 |
if ( $tests->{GECKO} ) {
|
|
561 |
if ( $ua =~ /\([^)]*rv:([\w.\d]*)/ ) {
|
|
562 |
$self->{gecko_version} = $1;
|
|
563 |
}
|
|
564 |
}
|
|
565 |
|
|
566 |
$self->{major} = $major;
|
|
567 |
$self->{minor} = $minor;
|
|
568 |
$self->{beta} = $beta;
|
424 | 569 |
}
|
425 | 570 |
|
426 | 571 |
sub browser_string {
|
427 | |
my ($self) = _self_or_default(@_);
|
|
572 |
my ($self) = _self_or_default(@_);
|
428 | 573 |
my $browser_string = undef;
|
|
574 |
my $user_agent = $self->user_agent;
|
|
575 |
if ( defined $user_agent ) {
|
|
576 |
$browser_string = 'Netscape' if $self->netscape;
|
|
577 |
$browser_string = 'Firefox' if $self->firefox;
|
|
578 |
$browser_string = 'Safari' if $self->safari;
|
|
579 |
$browser_string = 'Chrome' if $self->chrome;
|
|
580 |
$browser_string = 'MSIE' if $self->ie;
|
|
581 |
$browser_string = 'WebTV' if $self->webtv;
|
|
582 |
$browser_string = 'AOL Browser' if $self->aol;
|
|
583 |
$browser_string = 'Opera' if $self->opera;
|
|
584 |
$browser_string = 'Mosaic' if $self->mosaic;
|
|
585 |
$browser_string = 'Lynx' if $self->lynx;
|
|
586 |
}
|
|
587 |
return $browser_string;
|
|
588 |
}
|
|
589 |
|
|
590 |
sub os_string {
|
|
591 |
my ($self) = _self_or_default(@_);
|
|
592 |
my $os_string = undef;
|
429 | 593 |
my $user_agent = $self->user_agent;
|
430 | |
if (defined $user_agent) {
|
431 | |
$browser_string = 'Netscape' if $self->netscape;
|
432 | |
$browser_string = 'Firefox' if $self->firefox;
|
433 | |
$browser_string = 'Safari' if $self->safari;
|
434 | |
$browser_string = 'Chrome' if $self->chrome;
|
435 | |
$browser_string = 'MSIE' if $self->ie;
|
436 | |
$browser_string = 'WebTV' if $self->webtv;
|
437 | |
$browser_string = 'AOL Browser' if $self->aol;
|
438 | |
$browser_string = 'Opera' if $self->opera;
|
439 | |
$browser_string = 'Mosaic' if $self->mosaic;
|
440 | |
$browser_string = 'Lynx' if $self->lynx;
|
441 | |
}
|
442 | |
return $browser_string;
|
443 | |
}
|
444 | |
|
445 | |
sub os_string {
|
446 | |
my ($self) = _self_or_default(@_);
|
447 | |
my $os_string = undef;
|
448 | |
my $user_agent = $self->user_agent;
|
449 | |
if (defined $user_agent) {
|
450 | |
$os_string = 'Win95' if $self->win95;
|
451 | |
$os_string = 'Win98' if $self->win98;
|
452 | |
$os_string = 'WinNT' if $self->winnt;
|
453 | |
$os_string = 'Win2k' if $self->win2k;
|
454 | |
$os_string = 'WinXP' if $self->winxp;
|
455 | |
$os_string = 'Win2k3' if $self->win2k3;
|
|
594 |
if ( defined $user_agent ) {
|
|
595 |
$os_string = 'Win95' if $self->win95;
|
|
596 |
$os_string = 'Win98' if $self->win98;
|
|
597 |
$os_string = 'WinNT' if $self->winnt;
|
|
598 |
$os_string = 'Win2k' if $self->win2k;
|
|
599 |
$os_string = 'WinXP' if $self->winxp;
|
|
600 |
$os_string = 'Win2k3' if $self->win2k3;
|
456 | 601 |
$os_string = 'WinVista' if $self->winvista;
|
457 | |
$os_string = 'Mac' if $self->mac;
|
|
602 |
$os_string = 'Mac' if $self->mac;
|
458 | 603 |
$os_string = 'Mac OS X' if $self->macosx;
|
459 | |
$os_string = 'Win3x' if $self->win3x;
|
460 | |
$os_string = 'OS2' if $self->os2;
|
461 | |
$os_string = 'Unix' if $self->unix && !$self->linux;
|
462 | |
$os_string = 'Linux' if $self->linux;
|
|
604 |
$os_string = 'Win3x' if $self->win3x;
|
|
605 |
$os_string = 'OS2' if $self->os2;
|
|
606 |
$os_string = 'Unix' if $self->unix && !$self->linux;
|
|
607 |
$os_string = 'Linux' if $self->linux;
|
463 | 608 |
}
|
464 | 609 |
return $os_string;
|
465 | 610 |
}
|
466 | 611 |
|
467 | 612 |
sub gecko_version {
|
468 | |
my ($self, $check) = _self_or_default(@_);
|
469 | |
my $version;
|
470 | |
$version = $self->{gecko_version};
|
471 | |
if (defined $check) {
|
472 | |
return $check == $version;
|
473 | |
} else {
|
474 | |
return $version;
|
475 | |
}
|
476 | |
}
|
477 | |
|
|
613 |
my ( $self, $check ) = _self_or_default(@_);
|
|
614 |
my $version;
|
|
615 |
$version = $self->{gecko_version};
|
|
616 |
if ( defined $check ) {
|
|
617 |
return $check == $version;
|
|
618 |
}
|
|
619 |
else {
|
|
620 |
return $version;
|
|
621 |
}
|
|
622 |
}
|
478 | 623 |
|
479 | 624 |
sub version {
|
480 | |
my ($self, $check) = _self_or_default(@_);
|
481 | |
my $version;
|
482 | |
$version = $self->{major} + $self->{minor};
|
483 | |
if (defined $check) {
|
484 | |
return $check == $version;
|
485 | |
} else {
|
486 | |
return $version;
|
487 | |
}
|
|
625 |
my ( $self, $check ) = _self_or_default(@_);
|
|
626 |
my $version;
|
|
627 |
$version = $self->{major} + $self->{minor};
|
|
628 |
if ( defined $check ) {
|
|
629 |
return $check == $version;
|
|
630 |
}
|
|
631 |
else {
|
|
632 |
return $version;
|
|
633 |
}
|
488 | 634 |
}
|
489 | 635 |
|
490 | 636 |
sub major {
|
491 | |
my ($self, $check) = _self_or_default(@_);
|
492 | |
my ($version) = $self->{major};
|
493 | |
if (defined $check) {
|
494 | |
return $check == $version;
|
495 | |
} else {
|
496 | |
return $version;
|
497 | |
}
|
|
637 |
my ( $self, $check ) = _self_or_default(@_);
|
|
638 |
my ($version) = $self->{major};
|
|
639 |
if ( defined $check ) {
|
|
640 |
return $check == $version;
|
|
641 |
}
|
|
642 |
else {
|
|
643 |
return $version;
|
|
644 |
}
|
498 | 645 |
}
|
499 | 646 |
|
500 | 647 |
sub minor {
|
501 | |
my ($self, $check) = _self_or_default(@_);
|
502 | |
my ($version) = $self->{minor};
|
503 | |
if (defined $check) {
|
504 | |
return ($check == $self->{minor});
|
505 | |
} else {
|
506 | |
return $version;
|
507 | |
}
|
|
648 |
my ( $self, $check ) = _self_or_default(@_);
|
|
649 |
my ($version) = $self->{minor};
|
|
650 |
if ( defined $check ) {
|
|
651 |
return ( $check == $self->{minor} );
|
|
652 |
}
|
|
653 |
else {
|
|
654 |
return $version;
|
|
655 |
}
|
508 | 656 |
}
|
509 | 657 |
|
510 | 658 |
sub beta {
|
511 | |
my ($self, $check) = _self_or_default(@_);
|
512 | |
my ($version) = $self->{beta};
|
513 | |
if ($check) {
|
514 | |
return $check eq $version;
|
515 | |
} else {
|
516 | |
return $version;
|
517 | |
}
|
|
659 |
my ( $self, $check ) = _self_or_default(@_);
|
|
660 |
my ($version) = $self->{beta};
|
|
661 |
if ($check) {
|
|
662 |
return $check eq $version;
|
|
663 |
}
|
|
664 |
else {
|
|
665 |
return $version;
|
|
666 |
}
|
518 | 667 |
}
|
519 | 668 |
|
520 | 669 |
1;
|
521 | 670 |
|
522 | |
|
523 | 671 |
__END__
|
524 | 672 |
|
525 | 673 |
=head1 NAME
|
|
528 | 676 |
|
529 | 677 |
=head1 VERSION
|
530 | 678 |
|
531 | |
Version 1.02
|
|
679 |
Version 1.03
|
532 | 680 |
|
533 | 681 |
=head1 SYNOPSIS
|
534 | 682 |
|
|
570 | 718 |
available at
|
571 | 719 |
B<http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html>.
|
572 | 720 |
|
573 | |
=head2 CREATING A NEW BROWSER DETECT OBJECT AND SETTING THE USER AGENT STRING
|
574 | |
|
575 | |
=over 4
|
576 | |
|
577 | |
=item HTTP::BrowserDetect->new( $user_agent_string )
|
|
721 |
=head1 CONSTRUCTOR AND STARTUP
|
|
722 |
|
|
723 |
=head2 new()
|
|
724 |
|
|
725 |
HTTP::BrowserDetect->new( $user_agent_string )
|
578 | 726 |
|
579 | 727 |
The constructor may be called with a user agent string specified.
|
580 | 728 |
Otherwise, it will use the value specified by $ENV{'HTTP_USER_AGENT'},
|
|
585 | 733 |
working with a default HTTP::BrowserDetect object that is created
|
586 | 734 |
behind the scenes.
|
587 | 735 |
|
588 | |
=item user_agent($user_agent_string)
|
|
736 |
=head2 user_agent($user_agent_string)
|
589 | 737 |
|
590 | 738 |
Returns the value of the user agent string. When called with a
|
591 | 739 |
parameter, it resets the user agent and reperforms all tests on the
|
|
593 | 741 |
a log file, perhaps) without creating a new HTTP::BrowserDetect object
|
594 | 742 |
each time.
|
595 | 743 |
|
596 | |
=back
|
597 | |
|
598 | |
=head2 DETECTING BROWSER VERSION
|
599 | |
|
600 | |
=over 4
|
601 | |
|
602 | |
=item major($major)
|
|
744 |
=head1 Detecting Browser Version
|
|
745 |
|
|
746 |
=head2 major($major)
|
603 | 747 |
|
604 | 748 |
Returns the integer portion of the browser version.
|
605 | 749 |
If passed a parameter, returns true if it equals
|
606 | 750 |
the browser major version.
|
607 | 751 |
|
608 | |
=item minor($minor)
|
|
752 |
=head2 minor($minor)
|
609 | 753 |
|
610 | 754 |
Returns the decimal portion of the browser version as a B<floating-point number> less than 1.
|
611 | 755 |
For example, if the version is 4.05, this method returns .05; if the version is 4.5, this method returns .5.
|
|
618 | 762 |
as 'Wget/1.4.5'. The minor version does not include the second decimal point,
|
619 | 763 |
or any further digits or decimals.
|
620 | 764 |
|
621 | |
=item version($version)
|
|
765 |
=head2 version($version)
|
622 | 766 |
|
623 | 767 |
Returns the version as a floating-point number. If passed a
|
624 | 768 |
parameter, returns true if it is equal to the version
|
625 | 769 |
specified by the user agent string.
|
626 | 770 |
|
627 | |
=item beta($beta)
|
|
771 |
=head2 beta($beta)
|
628 | 772 |
|
629 | 773 |
Returns any the beta version, consisting of any non-numeric characters
|
630 | 774 |
after the version number. For instance, if the user agent string is
|
|
632 | 776 |
passed a parameter, returns true if equal to the beta version. If the beta
|
633 | 777 |
starts with a dot, it is thrown away.
|
634 | 778 |
|
635 | |
=back
|
636 | |
|
637 | |
=head2 DETECTING OS PLATFORM AND VERSION
|
|
779 |
=head1 Detecting OS Platform and Version
|
638 | 780 |
|
639 | 781 |
The following methods are available, each returning a true or false
|
640 | 782 |
value. Some methods also test for the operating system version.
|
|
666 | 808 |
It may not be possibile to detect Win98 in Netscape 4.x and earlier.
|
667 | 809 |
On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all Win32, so you can't distinguish between Win95 and WinNT.
|
668 | 810 |
|
669 | |
=over
|
670 | |
|
671 | |
=item os_string()
|
|
811 |
=head2 os_string()
|
672 | 812 |
|
673 | 813 |
Returns one of the following strings, or undef. This method exists solely for compatibility with the
|
674 | 814 |
B<HTTP::Headers::UserAgent> module.
|
675 | 815 |
|
676 | 816 |
Win95, Win98, WinNT, Win2K, WinXP, Win2K3, WinVista, Mac, Mac OS X, Win3x, OS2, Unix, Linux
|
677 | 817 |
|
678 | |
=back
|
679 | |
|
680 | |
=head2 DETECTING BROWSER VENDOR
|
|
818 |
=head1 Detecting Browser Vendor
|
681 | 819 |
|
682 | 820 |
The following methods are available, each returning a true or false value. Some methods also
|
683 | 821 |
test for the browser version, saving you from checking the version separately.
|
|
706 | 844 |
Netscape 6, even though its called six, in the userAgent string has version number 5. The nav6 and nav6up methods correctly handle this quirk.
|
707 | 845 |
The firefox text correctly detects the older-named versions of the browser (Phoenix, Firebird)
|
708 | 846 |
|
709 | |
=over
|
710 | |
|
711 | |
|
712 | |
=item browser_string()
|
|
847 |
|
|
848 |
=head2 browser_string()
|
713 | 849 |
|
714 | 850 |
Returns one of the following strings, or undef.
|
715 | 851 |
|
716 | 852 |
Netscape, MSIE, WebTV, AOL Browser, Opera, Mosaic, Lynx
|
717 | 853 |
|
718 | |
=item gecko_version()
|
|
854 |
=head2 gecko_version()
|
719 | 855 |
|
720 | 856 |
If a Gecko rendering engine is used (as in Mozilla or Firebird), returns the version of the renderer (e.g. 1.3a, 1.7, 1.8)
|
721 | 857 |
This might be more useful than the particular browser name or version when correcting for quirks in different versions of this rendering engine.
|
722 | 858 |
If no Gecko browser is being used, or the version number can't be detected, returns undef.
|
723 | 859 |
|
724 | |
=back
|
725 | |
|
726 | |
|
727 | |
=head2 DETECTING OTHER DEVICES
|
|
860 |
=head1 Detecting Other Devices
|
728 | 861 |
|
729 | 862 |
The following methods are available, each returning a true or false value.
|
730 | 863 |
|
|
735 | 868 |
avantgo
|
736 | 869 |
blackberry
|
737 | 870 |
|
738 | |
=head2 DETECTING ROBOTS
|
739 | |
|
740 | |
=item robot()
|
|
871 |
=head2 mobile()
|
|
872 |
|
|
873 |
Returns true if the browser appears to belong to a handheld device.
|
|
874 |
|
|
875 |
=head2 robot()
|
741 | 876 |
|
742 | 877 |
Returns true if the user agent appears to be a robot, spider,
|
743 | 878 |
crawler, or other automated Web client.
|
|
759 | 894 |
google
|
760 | 895 |
puf
|
761 | 896 |
|
|
897 |
|
762 | 898 |
=head1 AUTHOR
|
763 | 899 |
|
764 | 900 |
Lee Semel, lee@semel.net (Original Author)
|
|
790 | 926 |
Andrew McGregor
|
791 | 927 |
|
792 | 928 |
Robin Smidsrod
|
|
929 |
|
|
930 |
Richard Noble
|
793 | 931 |
|
794 | 932 |
=head1 SEE ALSO
|
795 | 933 |
|