Completed
Push — master ( db6c5d...08ee94 )
by Mark
6s
created
src/CrawlerDetect.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     public function setHttpHeaders($httpHeaders = null)
462 462
     {
463 463
         // use global _SERVER if $httpHeaders aren't defined
464
-        if (!is_array($httpHeaders) || !count($httpHeaders)) {
464
+        if ( ! is_array($httpHeaders) || ! count($httpHeaders)) {
465 465
             $httpHeaders = $_SERVER;
466 466
         }
467 467
         // clear existing headers
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
                 }
493 493
             }
494 494
 
495
-            return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
495
+            return $this->userAgent = ( ! empty($this->userAgent) ? trim($this->userAgent) : null);
496 496
         }
497 497
     }
498 498
 
Please login to merge, or discard this patch.
Indentation   +489 added lines, -489 removed lines patch added patch discarded remove patch
@@ -4,512 +4,512 @@
 block discarded – undo
4 4
 
5 5
 class CrawlerDetect
6 6
 {
7
-    /**
8
-     * The user agent.
9
-     *
10
-     * @var null
11
-     */
12
-    protected $userAgent = null;
7
+	/**
8
+	 * The user agent.
9
+	 *
10
+	 * @var null
11
+	 */
12
+	protected $userAgent = null;
13 13
 
14
-    /**
15
-     * Headers that contain a user agent.
16
-     *
17
-     * @var array
18
-     */
19
-    protected $httpHeaders = array();
14
+	/**
15
+	 * Headers that contain a user agent.
16
+	 *
17
+	 * @var array
18
+	 */
19
+	protected $httpHeaders = array();
20 20
 
21
-    /**
22
-     * Store regex matches.
23
-     *
24
-     * @var array
25
-     */
26
-    protected $matches = array();
21
+	/**
22
+	 * Store regex matches.
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected $matches = array();
27 27
 
28
-    /**
29
-     * List of strings to remove from the user agent before running the crawler regex
30
-     * Over a large list of user agents, this gives us about a 55% speed increase!
31
-     *
32
-     * @var array
33
-     */
34
-    protected static $ignore = array(
35
-        'Safari.[\d\.]*',
36
-        'Firefox.[\d\.]*',
37
-        'Chrome.[\d\.]*',
38
-        'Chromium.[\d\.]*',
39
-        'MSIE.[\d\.]',
40
-        'Opera\/[\d\.]*',
41
-        'Mozilla.[\d\.]*',
42
-        'AppleWebKit.[\d\.]*',
43
-        'Trident.[\d\.]*',
44
-        'Windows NT.[\d\.]*',
45
-        'Android.[\d\.]*',
46
-        'Macintosh.',
47
-        'Ubuntu',
48
-        'Linux',
49
-        '[ ]Intel',
50
-        'Mac OS X [\d_]*',
51
-        '(like )?Gecko(.[\d\.]*)?',
52
-        'KHTML',
53
-        'CriOS.[\d\.]*',
54
-        'CPU iPhone OS ([0-9_])* like Mac OS X',
55
-        'CPU OS ([0-9_])* like Mac OS X',
56
-        'iPod',
57
-        'compatible',
58
-        'x86_..',
59
-        'i686',
60
-        'x64',
61
-        'X11',
62
-        'rv:[\d\.]*',
63
-        'Version.[\d\.]*',
64
-        'WOW64',
65
-        'Win64',
66
-        'Dalvik.[\d\.]*',
67
-        ' \.NET CLR [\d\.]*',
68
-        'Presto.[\d\.]*',
69
-        'Media Center PC',
70
-        'BlackBerry',
71
-        'Build',
72
-        'Opera Mini\/\d{1,2}\.\d{1,2}\.[\d\.]*\/\d{1,2}\.',
73
-        'Opera',
74
-        ' \.NET[\d\.]*',
75
-        '\(|\)|;|,', // Remove the following characters ( ) : ,
76
-    );
28
+	/**
29
+	 * List of strings to remove from the user agent before running the crawler regex
30
+	 * Over a large list of user agents, this gives us about a 55% speed increase!
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected static $ignore = array(
35
+		'Safari.[\d\.]*',
36
+		'Firefox.[\d\.]*',
37
+		'Chrome.[\d\.]*',
38
+		'Chromium.[\d\.]*',
39
+		'MSIE.[\d\.]',
40
+		'Opera\/[\d\.]*',
41
+		'Mozilla.[\d\.]*',
42
+		'AppleWebKit.[\d\.]*',
43
+		'Trident.[\d\.]*',
44
+		'Windows NT.[\d\.]*',
45
+		'Android.[\d\.]*',
46
+		'Macintosh.',
47
+		'Ubuntu',
48
+		'Linux',
49
+		'[ ]Intel',
50
+		'Mac OS X [\d_]*',
51
+		'(like )?Gecko(.[\d\.]*)?',
52
+		'KHTML',
53
+		'CriOS.[\d\.]*',
54
+		'CPU iPhone OS ([0-9_])* like Mac OS X',
55
+		'CPU OS ([0-9_])* like Mac OS X',
56
+		'iPod',
57
+		'compatible',
58
+		'x86_..',
59
+		'i686',
60
+		'x64',
61
+		'X11',
62
+		'rv:[\d\.]*',
63
+		'Version.[\d\.]*',
64
+		'WOW64',
65
+		'Win64',
66
+		'Dalvik.[\d\.]*',
67
+		' \.NET CLR [\d\.]*',
68
+		'Presto.[\d\.]*',
69
+		'Media Center PC',
70
+		'BlackBerry',
71
+		'Build',
72
+		'Opera Mini\/\d{1,2}\.\d{1,2}\.[\d\.]*\/\d{1,2}\.',
73
+		'Opera',
74
+		' \.NET[\d\.]*',
75
+		'\(|\)|;|,', // Remove the following characters ( ) : ,
76
+	);
77 77
 
78
-    /**
79
-     * Array of regular expressions to match against the user agent.
80
-     *
81
-     * @var array
82
-     */
83
-    protected static $crawlers = array(
84
-        '.*Java.*outbrain',
85
-        '008\\/',
86
-        '^NING\\/',
87
-        'A6-Indexer',
88
-        'Aboundex',
89
-        'Accoona-AI-Agent',
90
-        'acoon',
91
-        'AddThis',
92
-        'ADmantX',
93
-        'AHC',
94
-        'Airmail',
95
-        'Anemone',
96
-        'Arachmo',
97
-        'archive-com',
98
-        'B-l-i-t-z-B-O-T',
99
-        'Backlink-Ceck\.de',
100
-        'BazQux',
101
-        'bibnum\.bnf',
102
-        'biglotron',
103
-        'BingPreview',
104
-        'binlar',
105
-        'Bloglovin',
106
-        'Blogtrottr',
107
-        'boitho\.com-dc',
108
-        'Browsershots',
109
-        'BUbiNG',
110
-        'Butterfly\\/',
111
-        'BuzzSumo',
112
-        'CapsuleChecker',
113
-        'CC Metadata Scaper',
114
-        'Cerberian Drtrs',
115
-        'changedetection',
116
-        'Charlotte',
117
-        'clips\.ua\.ac\.be',
118
-        'CloudFlare-AlwaysOnline',
119
-        'coccoc',
120
-        'CommaFeed',
121
-        'Commons-HttpClient',
122
-        'convera',
123
-        'cosmos',
124
-        'Covario-IDS',
125
-        'Curious George',
126
-        'curl',
127
-        'CyberPatrol',
128
-        'DataparkSearch',
129
-        'dataprovider',
130
-        'Daum(oa)?[ \\/][0-9]',
131
-        'Digg',
132
-        'DomainAppender',
133
-        'Dragonfly File Reader',
134
-        'drupact',
135
-        'EARTHCOM',
136
-        'ec2linkfinder',
137
-        'ECCP',
138
-        'ElectricMonk',
139
-        'EMail Exractor',
140
-        'EmailWolf',
141
-        'Embed PHP Library',
142
-        'Embedly',
143
-        'europarchive\.org',
144
-        'EventMachine HttpClient',
145
-        'ExactSearch',
146
-        'ExaleadCloudview',
147
-        'eZ Publish Link Validator',
148
-        'ezooms',
149
-        'facebookexternalhit',
150
-        'facebookplatform',
151
-        'Feed Wrangler',
152
-        'Feedbin',
153
-        'FeedBurner',
154
-        'Feedfetcher-Google',
155
-        'Feedly',
156
-        'Feedspot',
157
-        'FeedValidator',
158
-        'Fever',
159
-        'findlink',
160
-        'findthatfile',
161
-        'Flamingo_SearchEngine',
162
-        'fluffy',
163
-        'g00g1e\.net',
164
-        'Genieo',
165
-        'getprismatic\.com',
166
-        'GigablastOpenSource',
167
-        'Go-http-client',
168
-        'Google favicon',
169
-        'Google Keyword Suggestion',
170
-        'Google Page Speed Insights',
171
-        'Google-HTTP-Java-Client',
172
-        'google_partner_monitoring',
173
-        'GoogleProducer',
174
-        'grub-client',
175
-        'heritrix',
176
-        'Holmes',
177
-        'htdig',
178
-        'HTTPMon',
179
-        'httpunit',
180
-        'http_request2',
181
-        'httrack',
182
-        'HubPages.*crawlingpolicy',
183
-        'HubSpot Marketing Grader',
184
-        'ichiro',
185
-        'IDG Twitter Links Resolver',
186
-        'igdeSpyder',
187
-        'InAGist',
188
-        'infegy',
189
-        'InfoWizards Reciprocal Link System PRO',
190
-        'inpwrd\.com',
191
-        'integromedb',
192
-        'IODC',
193
-        'IOI',
194
-        'ips-agent',
195
-        'iZSearch',
196
-        'Jigsaw',
197
-        'Jobrapido',
198
-        'kouio',
199
-        'L\.webis',
200
-        'Larbin',
201
-        'libwww',
202
-        'Link Valet',
203
-        'linkCheck',
204
-        'linkdex',
205
-        'LinkExaminer',
206
-        'LinkWalker',
207
-        'Lipperhey',
208
-        'LongURL API',
209
-        'ltx71',
210
-        'lwp-trivial',
211
-        'lycos',
212
-        'mabontland',
213
-        'MagpieRSS',
214
-        'Mediapartners-Google',
215
-        'Mediapartners-Google',
216
-        'MegaIndex\.ru',
217
-        'MetaURI',
218
-        'Mnogosearch',
219
-        'mogimogi',
220
-        'Morning Paper',
221
-        'Mrcgiguy',
222
-        'MVAClient',
223
-        'Netcraft Web Server Survey',
224
-        'NetcraftSurveyAgent',
225
-        'NetLyzer FastProbe',
226
-        'netresearch',
227
-        'Netvibes',
228
-        'NewsBlur .*(Fetcher|Finder)',
229
-        'NewsGator',
230
-        'newsme',
231
-        'NG-Search',
232
-        'nineconnections\.com',
233
-        'nominet\.org\.uk',
234
-        'Notifixious',
235
-        'nuhk',
236
-        'nutch',
237
-        'Nymesis',
238
-        'oegp',
239
-        'Omea Reader',
240
-        'online link validator',
241
-        'Online Website Link Checker',
242
-        'Orbiter',
243
-        'ow\.ly',
244
-        'page2rss',
245
-        'PagePeeker',
246
-        'panscient',
247
-        'Peew',
248
-        'phpcrawl',
249
-        'phpservermon',
250
-        'Pingdom\.com',
251
-        'Pinterest',
252
-        'Pizilla',
253
-        'Ploetz \+ Zeller',
254
-        'Plukkie',
255
-        'PocketParser',
256
-        'Pompos',
257
-        'postano',
258
-        'PostPost',
259
-        'postrank',
260
-        'proximic',
261
-        'Pulsepoint XT3 web scraper',
262
-        'Python-httplib2',
263
-        'python-requests',
264
-        'Python-urllib',
265
-        'Qseero',
266
-        'Qwantify',
267
-        'Radian6',
268
-        'RebelMouse',
269
-        'REL Link Checker',
270
-        'RetrevoPageAnalyzer',
271
-        'Riddler',
272
-        'Robosourcer',
273
-        'ROI Hunter',
274
-        'Ruby',
275
-        'SalesIntelligent',
276
-        'SBIder',
277
-        'scooter',
278
-        'ScoutJet',
279
-        'ScoutURLMonitor',
280
-        'Scrapy',
281
-        'Scrubby',
282
-        'SearchSight',
283
-        'semanticdiscovery',
284
-        'SEOstats',
285
-        'Server Density Service Monitoring.*',
286
-        'servernfo\.com',
287
-        'Seznam screenshot-generator',
288
-        'ShopWiki',
289
-        'SilverReader',
290
-        'SimplePie',
291
-        'Site24x7',
292
-        'SiteBar',
293
-        'siteexplorer\.info',
294
-        'Siteimprove\.com',
295
-        'SkypeUriPreview',
296
-        'slider\.com',
297
-        'slurp',
298
-        'Snappy',
299
-        'SNK Siteshooter B0t',
300
-        'sogou',
301
-        'SortSite',
302
-        'speedy',
303
-        'Spinn3r',
304
-        'Springshare Link Checker',
305
-        'Sqworm',
306
-        'StackRambler',
307
-        'Stratagems Kumo',
308
-        'summify',
309
-        'teoma',
310
-        'theoldreader\.com',
311
-        'TinEye',
312
-        'Tiny Tiny RSS',
313
-        'Traackr.com',
314
-        'truwoGPS',
315
-        'tweetedtimes\.com',
316
-        'Twikle',
317
-        'Typhoeus',
318
-        'ubermetrics-technologies',
319
-        'UdmSearch',
320
-        'UnwindFetchor',
321
-        'updated',
322
-        'URLChecker',
323
-        'urlresolver',
324
-        'Vagabondo',
325
-        'Validator\.nu\\/LV',
326
-        'via ggpht\.com GoogleImageProxy',
327
-        'Vivante Link Checker',
328
-        'Vortex',
329
-        'voyager\\/',
330
-        'VYU2',
331
-        'W3C-checklink',
332
-        'W3C-mobileOK',
333
-        'W3C_CSS_Validator_JFouffa',
334
-        'W3C_I18n-Checker',
335
-        'W3C_Unicorn',
336
-        'W3C_Validator',
337
-        'web-capture\.net',
338
-        'webcollage',
339
-        'WebIndex',
340
-        'webmon ',
341
-        'websitepulse[+ ]checker',
342
-        'Websquash\.com',
343
-        'WebThumbnail',
344
-        'WeSEE:Search',
345
-        'wf84',
346
-        'wget',
347
-        'WomlpeFactory',
348
-        'wotbox',
349
-        'www\.monitor\.us',
350
-        'XaxisSemanticsClassifier',
351
-        'Xenu Link Sleuth',
352
-        'XML Sitemaps Generator',
353
-        'Y!J-ASR',
354
-        'yacy',
355
-        'Yahoo Ad monitoring',
356
-        'Yahoo Link Preview',
357
-        'YahooSeeker',
358
-        'yandex',
359
-        'yanga',
360
-        'yeti',
361
-        'yoogliFetchAgent',
362
-        'YottaaMonitor',
363
-        'Zao',
364
-        'ZyBorg',
365
-        '[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
366
-    );
78
+	/**
79
+	 * Array of regular expressions to match against the user agent.
80
+	 *
81
+	 * @var array
82
+	 */
83
+	protected static $crawlers = array(
84
+		'.*Java.*outbrain',
85
+		'008\\/',
86
+		'^NING\\/',
87
+		'A6-Indexer',
88
+		'Aboundex',
89
+		'Accoona-AI-Agent',
90
+		'acoon',
91
+		'AddThis',
92
+		'ADmantX',
93
+		'AHC',
94
+		'Airmail',
95
+		'Anemone',
96
+		'Arachmo',
97
+		'archive-com',
98
+		'B-l-i-t-z-B-O-T',
99
+		'Backlink-Ceck\.de',
100
+		'BazQux',
101
+		'bibnum\.bnf',
102
+		'biglotron',
103
+		'BingPreview',
104
+		'binlar',
105
+		'Bloglovin',
106
+		'Blogtrottr',
107
+		'boitho\.com-dc',
108
+		'Browsershots',
109
+		'BUbiNG',
110
+		'Butterfly\\/',
111
+		'BuzzSumo',
112
+		'CapsuleChecker',
113
+		'CC Metadata Scaper',
114
+		'Cerberian Drtrs',
115
+		'changedetection',
116
+		'Charlotte',
117
+		'clips\.ua\.ac\.be',
118
+		'CloudFlare-AlwaysOnline',
119
+		'coccoc',
120
+		'CommaFeed',
121
+		'Commons-HttpClient',
122
+		'convera',
123
+		'cosmos',
124
+		'Covario-IDS',
125
+		'Curious George',
126
+		'curl',
127
+		'CyberPatrol',
128
+		'DataparkSearch',
129
+		'dataprovider',
130
+		'Daum(oa)?[ \\/][0-9]',
131
+		'Digg',
132
+		'DomainAppender',
133
+		'Dragonfly File Reader',
134
+		'drupact',
135
+		'EARTHCOM',
136
+		'ec2linkfinder',
137
+		'ECCP',
138
+		'ElectricMonk',
139
+		'EMail Exractor',
140
+		'EmailWolf',
141
+		'Embed PHP Library',
142
+		'Embedly',
143
+		'europarchive\.org',
144
+		'EventMachine HttpClient',
145
+		'ExactSearch',
146
+		'ExaleadCloudview',
147
+		'eZ Publish Link Validator',
148
+		'ezooms',
149
+		'facebookexternalhit',
150
+		'facebookplatform',
151
+		'Feed Wrangler',
152
+		'Feedbin',
153
+		'FeedBurner',
154
+		'Feedfetcher-Google',
155
+		'Feedly',
156
+		'Feedspot',
157
+		'FeedValidator',
158
+		'Fever',
159
+		'findlink',
160
+		'findthatfile',
161
+		'Flamingo_SearchEngine',
162
+		'fluffy',
163
+		'g00g1e\.net',
164
+		'Genieo',
165
+		'getprismatic\.com',
166
+		'GigablastOpenSource',
167
+		'Go-http-client',
168
+		'Google favicon',
169
+		'Google Keyword Suggestion',
170
+		'Google Page Speed Insights',
171
+		'Google-HTTP-Java-Client',
172
+		'google_partner_monitoring',
173
+		'GoogleProducer',
174
+		'grub-client',
175
+		'heritrix',
176
+		'Holmes',
177
+		'htdig',
178
+		'HTTPMon',
179
+		'httpunit',
180
+		'http_request2',
181
+		'httrack',
182
+		'HubPages.*crawlingpolicy',
183
+		'HubSpot Marketing Grader',
184
+		'ichiro',
185
+		'IDG Twitter Links Resolver',
186
+		'igdeSpyder',
187
+		'InAGist',
188
+		'infegy',
189
+		'InfoWizards Reciprocal Link System PRO',
190
+		'inpwrd\.com',
191
+		'integromedb',
192
+		'IODC',
193
+		'IOI',
194
+		'ips-agent',
195
+		'iZSearch',
196
+		'Jigsaw',
197
+		'Jobrapido',
198
+		'kouio',
199
+		'L\.webis',
200
+		'Larbin',
201
+		'libwww',
202
+		'Link Valet',
203
+		'linkCheck',
204
+		'linkdex',
205
+		'LinkExaminer',
206
+		'LinkWalker',
207
+		'Lipperhey',
208
+		'LongURL API',
209
+		'ltx71',
210
+		'lwp-trivial',
211
+		'lycos',
212
+		'mabontland',
213
+		'MagpieRSS',
214
+		'Mediapartners-Google',
215
+		'Mediapartners-Google',
216
+		'MegaIndex\.ru',
217
+		'MetaURI',
218
+		'Mnogosearch',
219
+		'mogimogi',
220
+		'Morning Paper',
221
+		'Mrcgiguy',
222
+		'MVAClient',
223
+		'Netcraft Web Server Survey',
224
+		'NetcraftSurveyAgent',
225
+		'NetLyzer FastProbe',
226
+		'netresearch',
227
+		'Netvibes',
228
+		'NewsBlur .*(Fetcher|Finder)',
229
+		'NewsGator',
230
+		'newsme',
231
+		'NG-Search',
232
+		'nineconnections\.com',
233
+		'nominet\.org\.uk',
234
+		'Notifixious',
235
+		'nuhk',
236
+		'nutch',
237
+		'Nymesis',
238
+		'oegp',
239
+		'Omea Reader',
240
+		'online link validator',
241
+		'Online Website Link Checker',
242
+		'Orbiter',
243
+		'ow\.ly',
244
+		'page2rss',
245
+		'PagePeeker',
246
+		'panscient',
247
+		'Peew',
248
+		'phpcrawl',
249
+		'phpservermon',
250
+		'Pingdom\.com',
251
+		'Pinterest',
252
+		'Pizilla',
253
+		'Ploetz \+ Zeller',
254
+		'Plukkie',
255
+		'PocketParser',
256
+		'Pompos',
257
+		'postano',
258
+		'PostPost',
259
+		'postrank',
260
+		'proximic',
261
+		'Pulsepoint XT3 web scraper',
262
+		'Python-httplib2',
263
+		'python-requests',
264
+		'Python-urllib',
265
+		'Qseero',
266
+		'Qwantify',
267
+		'Radian6',
268
+		'RebelMouse',
269
+		'REL Link Checker',
270
+		'RetrevoPageAnalyzer',
271
+		'Riddler',
272
+		'Robosourcer',
273
+		'ROI Hunter',
274
+		'Ruby',
275
+		'SalesIntelligent',
276
+		'SBIder',
277
+		'scooter',
278
+		'ScoutJet',
279
+		'ScoutURLMonitor',
280
+		'Scrapy',
281
+		'Scrubby',
282
+		'SearchSight',
283
+		'semanticdiscovery',
284
+		'SEOstats',
285
+		'Server Density Service Monitoring.*',
286
+		'servernfo\.com',
287
+		'Seznam screenshot-generator',
288
+		'ShopWiki',
289
+		'SilverReader',
290
+		'SimplePie',
291
+		'Site24x7',
292
+		'SiteBar',
293
+		'siteexplorer\.info',
294
+		'Siteimprove\.com',
295
+		'SkypeUriPreview',
296
+		'slider\.com',
297
+		'slurp',
298
+		'Snappy',
299
+		'SNK Siteshooter B0t',
300
+		'sogou',
301
+		'SortSite',
302
+		'speedy',
303
+		'Spinn3r',
304
+		'Springshare Link Checker',
305
+		'Sqworm',
306
+		'StackRambler',
307
+		'Stratagems Kumo',
308
+		'summify',
309
+		'teoma',
310
+		'theoldreader\.com',
311
+		'TinEye',
312
+		'Tiny Tiny RSS',
313
+		'Traackr.com',
314
+		'truwoGPS',
315
+		'tweetedtimes\.com',
316
+		'Twikle',
317
+		'Typhoeus',
318
+		'ubermetrics-technologies',
319
+		'UdmSearch',
320
+		'UnwindFetchor',
321
+		'updated',
322
+		'URLChecker',
323
+		'urlresolver',
324
+		'Vagabondo',
325
+		'Validator\.nu\\/LV',
326
+		'via ggpht\.com GoogleImageProxy',
327
+		'Vivante Link Checker',
328
+		'Vortex',
329
+		'voyager\\/',
330
+		'VYU2',
331
+		'W3C-checklink',
332
+		'W3C-mobileOK',
333
+		'W3C_CSS_Validator_JFouffa',
334
+		'W3C_I18n-Checker',
335
+		'W3C_Unicorn',
336
+		'W3C_Validator',
337
+		'web-capture\.net',
338
+		'webcollage',
339
+		'WebIndex',
340
+		'webmon ',
341
+		'websitepulse[+ ]checker',
342
+		'Websquash\.com',
343
+		'WebThumbnail',
344
+		'WeSEE:Search',
345
+		'wf84',
346
+		'wget',
347
+		'WomlpeFactory',
348
+		'wotbox',
349
+		'www\.monitor\.us',
350
+		'XaxisSemanticsClassifier',
351
+		'Xenu Link Sleuth',
352
+		'XML Sitemaps Generator',
353
+		'Y!J-ASR',
354
+		'yacy',
355
+		'Yahoo Ad monitoring',
356
+		'Yahoo Link Preview',
357
+		'YahooSeeker',
358
+		'yandex',
359
+		'yanga',
360
+		'yeti',
361
+		'yoogliFetchAgent',
362
+		'YottaaMonitor',
363
+		'Zao',
364
+		'ZyBorg',
365
+		'[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
366
+	);
367 367
 
368
-    /**
369
-     * All possible HTTP headers that represent the
370
-     * User-Agent string.
371
-     *
372
-     * @var array
373
-     */
374
-    protected static $uaHttpHeaders = array(
375
-        // The default User-Agent string.
376
-        'HTTP_USER_AGENT',
377
-        // Header can occur on devices using Opera Mini.
378
-        'HTTP_X_OPERAMINI_PHONE_UA',
379
-        // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
380
-        'HTTP_X_DEVICE_USER_AGENT',
381
-        'HTTP_X_ORIGINAL_USER_AGENT',
382
-        'HTTP_X_SKYFIRE_PHONE',
383
-        'HTTP_X_BOLT_PHONE_UA',
384
-        'HTTP_DEVICE_STOCK_UA',
385
-        'HTTP_X_UCBROWSER_DEVICE_UA',
386
-    );
368
+	/**
369
+	 * All possible HTTP headers that represent the
370
+	 * User-Agent string.
371
+	 *
372
+	 * @var array
373
+	 */
374
+	protected static $uaHttpHeaders = array(
375
+		// The default User-Agent string.
376
+		'HTTP_USER_AGENT',
377
+		// Header can occur on devices using Opera Mini.
378
+		'HTTP_X_OPERAMINI_PHONE_UA',
379
+		// Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
380
+		'HTTP_X_DEVICE_USER_AGENT',
381
+		'HTTP_X_ORIGINAL_USER_AGENT',
382
+		'HTTP_X_SKYFIRE_PHONE',
383
+		'HTTP_X_BOLT_PHONE_UA',
384
+		'HTTP_DEVICE_STOCK_UA',
385
+		'HTTP_X_UCBROWSER_DEVICE_UA',
386
+	);
387 387
 
388
-    /**
389
-     * Class constructor.
390
-     */
391
-    public function __construct(array $headers = null, $userAgent = null)
392
-    {
393
-        $this->setHttpHeaders($headers);
394
-        $this->setUserAgent($userAgent);
395
-    }
388
+	/**
389
+	 * Class constructor.
390
+	 */
391
+	public function __construct(array $headers = null, $userAgent = null)
392
+	{
393
+		$this->setHttpHeaders($headers);
394
+		$this->setUserAgent($userAgent);
395
+	}
396 396
 
397
-    /**
398
-     * Set HTTP headers.
399
-     *
400
-     * @param array $httpHeaders
401
-     */
402
-    public function setHttpHeaders($httpHeaders = null)
403
-    {
404
-        // use global _SERVER if $httpHeaders aren't defined
405
-        if (!is_array($httpHeaders) || !count($httpHeaders)) {
406
-            $httpHeaders = $_SERVER;
407
-        }
408
-        // clear existing headers
409
-        $this->httpHeaders = array();
410
-        // Only save HTTP headers. In PHP land, that means only _SERVER vars that
411
-        // start with HTTP_.
412
-        foreach ($httpHeaders as $key => $value) {
413
-            if (substr($key, 0, 5) === 'HTTP_') {
414
-                $this->httpHeaders[$key] = $value;
415
-            }
416
-        }
417
-    }
397
+	/**
398
+	 * Set HTTP headers.
399
+	 *
400
+	 * @param array $httpHeaders
401
+	 */
402
+	public function setHttpHeaders($httpHeaders = null)
403
+	{
404
+		// use global _SERVER if $httpHeaders aren't defined
405
+		if (!is_array($httpHeaders) || !count($httpHeaders)) {
406
+			$httpHeaders = $_SERVER;
407
+		}
408
+		// clear existing headers
409
+		$this->httpHeaders = array();
410
+		// Only save HTTP headers. In PHP land, that means only _SERVER vars that
411
+		// start with HTTP_.
412
+		foreach ($httpHeaders as $key => $value) {
413
+			if (substr($key, 0, 5) === 'HTTP_') {
414
+				$this->httpHeaders[$key] = $value;
415
+			}
416
+		}
417
+	}
418 418
 
419
-    /**
420
-     * Return user agent headers.
421
-     *
422
-     * @return array
423
-     */
424
-    public function getUaHttpHeaders()
425
-    {
426
-        return self::$uaHttpHeaders;
427
-    }
419
+	/**
420
+	 * Return user agent headers.
421
+	 *
422
+	 * @return array
423
+	 */
424
+	public function getUaHttpHeaders()
425
+	{
426
+		return self::$uaHttpHeaders;
427
+	}
428 428
 
429
-    /**
430
-     * Set the user agent.
431
-     *
432
-     * @param string $userAgent
433
-     */
434
-    public function setUserAgent($userAgent = null)
435
-    {
436
-        if (false === empty($userAgent)) {
437
-            return $this->userAgent = $userAgent;
438
-        } else {
439
-            $this->userAgent = null;
440
-            foreach ($this->getUaHttpHeaders() as $altHeader) {
441
-                if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
442
-                    $this->userAgent .= $this->httpHeaders[$altHeader].' ';
443
-                }
444
-            }
429
+	/**
430
+	 * Set the user agent.
431
+	 *
432
+	 * @param string $userAgent
433
+	 */
434
+	public function setUserAgent($userAgent = null)
435
+	{
436
+		if (false === empty($userAgent)) {
437
+			return $this->userAgent = $userAgent;
438
+		} else {
439
+			$this->userAgent = null;
440
+			foreach ($this->getUaHttpHeaders() as $altHeader) {
441
+				if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
442
+					$this->userAgent .= $this->httpHeaders[$altHeader].' ';
443
+				}
444
+			}
445 445
 
446
-            return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
447
-        }
448
-    }
446
+			return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
447
+		}
448
+	}
449 449
 
450
-    /**
451
-     * Return the array of crawler regexs.
452
-     *
453
-     * @return array
454
-     */
455
-    public function getCrawlers()
456
-    {
457
-        return self::$crawlers;
458
-    }
450
+	/**
451
+	 * Return the array of crawler regexs.
452
+	 *
453
+	 * @return array
454
+	 */
455
+	public function getCrawlers()
456
+	{
457
+		return self::$crawlers;
458
+	}
459 459
 
460
-    /**
461
-     * Build the user agent regex.
462
-     *
463
-     * @return string
464
-     */
465
-    public function getRegex()
466
-    {
467
-        return '('.implode('|', self::$crawlers).')';
468
-    }
460
+	/**
461
+	 * Build the user agent regex.
462
+	 *
463
+	 * @return string
464
+	 */
465
+	public function getRegex()
466
+	{
467
+		return '('.implode('|', self::$crawlers).')';
468
+	}
469 469
 
470
-    /**
471
-     * Build the replacement regex.
472
-     *
473
-     * @return string
474
-     */
475
-    public function getIgnored()
476
-    {
477
-        return '('.implode('|', self::$ignore).')';
478
-    }
470
+	/**
471
+	 * Build the replacement regex.
472
+	 *
473
+	 * @return string
474
+	 */
475
+	public function getIgnored()
476
+	{
477
+		return '('.implode('|', self::$ignore).')';
478
+	}
479 479
 
480
-    /**
481
-     * Check user agent string against the regex.
482
-     *
483
-     * @param string $userAgent
484
-     *
485
-     * @return bool
486
-     */
487
-    public function isCrawler($userAgent = null)
488
-    {
489
-        $agent = is_null($userAgent) ? $this->userAgent : $userAgent;
480
+	/**
481
+	 * Check user agent string against the regex.
482
+	 *
483
+	 * @param string $userAgent
484
+	 *
485
+	 * @return bool
486
+	 */
487
+	public function isCrawler($userAgent = null)
488
+	{
489
+		$agent = is_null($userAgent) ? $this->userAgent : $userAgent;
490 490
 
491
-        $agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
491
+		$agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
492 492
 
493
-        if (trim($agent) === false) {
494
-            return false;
495
-        } else {
496
-            $result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
497
-        }
493
+		if (trim($agent) === false) {
494
+			return false;
495
+		} else {
496
+			$result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
497
+		}
498 498
 
499
-        if ($matches) {
500
-            $this->matches = $matches;
501
-        }
499
+		if ($matches) {
500
+			$this->matches = $matches;
501
+		}
502 502
 
503
-        return (bool) $result;
504
-    }
503
+		return (bool) $result;
504
+	}
505 505
 
506
-    /**
507
-     * Return the matches.
508
-     *
509
-     * @return string
510
-     */
511
-    public function getMatches()
512
-    {
513
-        return $this->matches[0];
514
-    }
506
+	/**
507
+	 * Return the matches.
508
+	 *
509
+	 * @return string
510
+	 */
511
+	public function getMatches()
512
+	{
513
+		return $this->matches[0];
514
+	}
515 515
 }
Please login to merge, or discard this patch.
tests/UATests.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -2,55 +2,55 @@
 block discarded – undo
2 2
 
3 3
 class UserAgentTest extends PHPUnit_Framework_TestCase
4 4
 {
5
-    protected $CrawlerDetect;
6
-
7
-    public function setUp()
8
-    {
9
-        $this->CrawlerDetect = new Jaybizzle\CrawlerDetect\CrawlerDetect();
10
-    }
11
-
12
-    public function testBots()
13
-    {
14
-        $lines = file(__DIR__.'/crawlers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
15
-
16
-        foreach ($lines as $line) {
17
-            $test = $this->CrawlerDetect->isCrawler($line);
18
-            $this->assertEquals($test, true, $line);
19
-        }
20
-    }
21
-
22
-    public function testDevices()
23
-    {
24
-        $lines = file(__DIR__.'/devices.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
25
-
26
-        foreach ($lines as $line) {
27
-            $test = $this->CrawlerDetect->isCrawler($line);
28
-            $this->assertEquals($test, false, $line);
29
-        }
30
-    }
31
-
32
-    public function testReturnsCorrectMatchedBotName()
33
-    {
34
-        $test = $this->CrawlerDetect->isCrawler('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)');
35
-
36
-        $matches = $this->CrawlerDetect->getMatches();
37
-
38
-        $this->assertEquals($this->CrawlerDetect->getMatches(), 'Yahoo Ad monitoring', $matches);
39
-    }
40
-
41
-    public function testForRegexCollision()
42
-    {
43
-        $crawlers = $this->CrawlerDetect->getCrawlers();
44
-
45
-        foreach ($crawlers as $regex) {
46
-            foreach ($crawlers as $compare) {
47
-                // Dont check this regex against itself
48
-                if ($regex != $compare) {
49
-                    preg_match('/'.$regex.'/i', stripslashes($compare), $matches);
50
-
51
-                    $this->assertEmpty($matches, $regex.' collided with '.$compare);
52
-                }
53
-            }
54
-        }
55
-    }
5
+	protected $CrawlerDetect;
6
+
7
+	public function setUp()
8
+	{
9
+		$this->CrawlerDetect = new Jaybizzle\CrawlerDetect\CrawlerDetect();
10
+	}
11
+
12
+	public function testBots()
13
+	{
14
+		$lines = file(__DIR__.'/crawlers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
15
+
16
+		foreach ($lines as $line) {
17
+			$test = $this->CrawlerDetect->isCrawler($line);
18
+			$this->assertEquals($test, true, $line);
19
+		}
20
+	}
21
+
22
+	public function testDevices()
23
+	{
24
+		$lines = file(__DIR__.'/devices.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
25
+
26
+		foreach ($lines as $line) {
27
+			$test = $this->CrawlerDetect->isCrawler($line);
28
+			$this->assertEquals($test, false, $line);
29
+		}
30
+	}
31
+
32
+	public function testReturnsCorrectMatchedBotName()
33
+	{
34
+		$test = $this->CrawlerDetect->isCrawler('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)');
35
+
36
+		$matches = $this->CrawlerDetect->getMatches();
37
+
38
+		$this->assertEquals($this->CrawlerDetect->getMatches(), 'Yahoo Ad monitoring', $matches);
39
+	}
40
+
41
+	public function testForRegexCollision()
42
+	{
43
+		$crawlers = $this->CrawlerDetect->getCrawlers();
44
+
45
+		foreach ($crawlers as $regex) {
46
+			foreach ($crawlers as $compare) {
47
+				// Dont check this regex against itself
48
+				if ($regex != $compare) {
49
+					preg_match('/'.$regex.'/i', stripslashes($compare), $matches);
50
+
51
+					$this->assertEmpty($matches, $regex.' collided with '.$compare);
52
+				}
53
+			}
54
+		}
55
+	}
56 56
 }
Please login to merge, or discard this patch.