Completed
Push — master ( 082cfe...e31477 )
by Mark
04:01 queued 01:43
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   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -4,514 +4,514 @@
 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
-        'Apache-HttpClient\/',
97
-        'Arachmo',
98
-        'archive-com',
99
-        'B-l-i-t-z-B-O-T',
100
-        'Backlink-Ceck\.de',
101
-        'BazQux',
102
-        'bibnum\.bnf',
103
-        'biglotron',
104
-        'BingPreview',
105
-        'binlar',
106
-        'Bloglovin',
107
-        'Blogtrottr',
108
-        'boitho\.com-dc',
109
-        'Browsershots',
110
-        'BUbiNG',
111
-        'Butterfly\\/',
112
-        'BuzzSumo',
113
-        'CapsuleChecker',
114
-        'CC Metadata Scaper',
115
-        'Cerberian Drtrs',
116
-        'changedetection',
117
-        'Charlotte',
118
-        'clips\.ua\.ac\.be',
119
-        'CloudFlare-AlwaysOnline',
120
-        'coccoc',
121
-        'CommaFeed',
122
-        'Commons-HttpClient',
123
-        'convera',
124
-        'cosmos',
125
-        'Covario-IDS',
126
-        'Curious George',
127
-        'curl',
128
-        'CyberPatrol',
129
-        'DataparkSearch',
130
-        'dataprovider',
131
-        'Daum(oa)?[ \\/][0-9]',
132
-        'Digg',
133
-        'DomainAppender',
134
-        'Dragonfly File Reader',
135
-        'drupact',
136
-        'EARTHCOM',
137
-        'ec2linkfinder',
138
-        'ECCP',
139
-        'ElectricMonk',
140
-        'EMail Exractor',
141
-        'EmailWolf',
142
-        'Embed PHP Library',
143
-        'Embedly',
144
-        'europarchive\.org',
145
-        'EventMachine HttpClient',
146
-        'ExactSearch',
147
-        'ExaleadCloudview',
148
-        'eZ Publish Link Validator',
149
-        'ezooms',
150
-        'facebookexternalhit',
151
-        'facebookplatform',
152
-        'Feed Wrangler',
153
-        'Feedbin',
154
-        'FeedBurner',
155
-        'Feedfetcher-Google',
156
-        'Feedly',
157
-        'Feedspot',
158
-        'FeedValidator',
159
-        'Fever',
160
-        'findlink',
161
-        'findthatfile',
162
-        'Flamingo_SearchEngine',
163
-        'fluffy',
164
-        'g00g1e\.net',
165
-        'Genieo',
166
-        'getprismatic\.com',
167
-        'GigablastOpenSource',
168
-        'Go-http-client',
169
-        'Google favicon',
170
-        'Google Keyword Suggestion',
171
-        'Google Page Speed Insights',
172
-        'Google-HTTP-Java-Client',
173
-        'google_partner_monitoring',
174
-        'GoogleProducer',
175
-        'grub-client',
176
-        'heritrix',
177
-        'Holmes',
178
-        'htdig',
179
-        'HTTPMon',
180
-        'httpunit',
181
-        'http_request2',
182
-        'httrack',
183
-        'HubPages.*crawlingpolicy',
184
-        'HubSpot Marketing Grader',
185
-        'ichiro',
186
-        'IDG Twitter Links Resolver',
187
-        'igdeSpyder',
188
-        'InAGist',
189
-        'infegy',
190
-        'InfoWizards Reciprocal Link System PRO',
191
-        'inpwrd\.com',
192
-        'integromedb',
193
-        'IODC',
194
-        'IOI',
195
-        'ips-agent',
196
-        'iZSearch',
197
-        '^Java\/',
198
-        'Jigsaw',
199
-        'Jobrapido',
200
-        'kouio',
201
-        'L\.webis',
202
-        'Larbin',
203
-        'libwww',
204
-        'Link Valet',
205
-        'linkCheck',
206
-        'linkdex',
207
-        'LinkExaminer',
208
-        'LinkWalker',
209
-        'Lipperhey',
210
-        'LongURL API',
211
-        'ltx71',
212
-        'lwp-trivial',
213
-        'lycos',
214
-        'mabontland',
215
-        'MagpieRSS',
216
-        'Mediapartners-Google',
217
-        'Mediapartners-Google',
218
-        'MegaIndex\.ru',
219
-        'MetaURI',
220
-        'Mnogosearch',
221
-        'mogimogi',
222
-        'Morning Paper',
223
-        'Mrcgiguy',
224
-        'MVAClient',
225
-        'Netcraft Web Server Survey',
226
-        'NetcraftSurveyAgent',
227
-        'NetLyzer FastProbe',
228
-        'netresearch',
229
-        'Netvibes',
230
-        'NewsBlur .*(Fetcher|Finder)',
231
-        'NewsGator',
232
-        'newsme',
233
-        'NG-Search',
234
-        'nineconnections\.com',
235
-        'nominet\.org\.uk',
236
-        'Notifixious',
237
-        'nuhk',
238
-        'nutch',
239
-        'Nymesis',
240
-        'oegp',
241
-        'Omea Reader',
242
-        'online link validator',
243
-        'Online Website Link Checker',
244
-        'Orbiter',
245
-        'ow\.ly',
246
-        'page2rss',
247
-        'PagePeeker',
248
-        'panscient',
249
-        'Peew',
250
-        'phpcrawl',
251
-        'phpservermon',
252
-        'Pingdom\.com',
253
-        'Pinterest',
254
-        'Pizilla',
255
-        'Ploetz \+ Zeller',
256
-        'Plukkie',
257
-        'PocketParser',
258
-        'Pompos',
259
-        'postano',
260
-        'PostPost',
261
-        'postrank',
262
-        'proximic',
263
-        'Pulsepoint XT3 web scraper',
264
-        'Python-httplib2',
265
-        'python-requests',
266
-        'Python-urllib',
267
-        'Qseero',
268
-        'Qwantify',
269
-        'Radian6',
270
-        'RebelMouse',
271
-        'REL Link Checker',
272
-        'RetrevoPageAnalyzer',
273
-        'Riddler',
274
-        'Robosourcer',
275
-        'ROI Hunter',
276
-        'Ruby',
277
-        'SalesIntelligent',
278
-        'SBIder',
279
-        'scooter',
280
-        'ScoutJet',
281
-        'ScoutURLMonitor',
282
-        'Scrapy',
283
-        'Scrubby',
284
-        'SearchSight',
285
-        'semanticdiscovery',
286
-        'SEOstats',
287
-        'Server Density Service Monitoring.*',
288
-        'servernfo\.com',
289
-        'Seznam screenshot-generator',
290
-        'ShopWiki',
291
-        'SilverReader',
292
-        'SimplePie',
293
-        'Site24x7',
294
-        'SiteBar',
295
-        'siteexplorer\.info',
296
-        'Siteimprove\.com',
297
-        'SkypeUriPreview',
298
-        'slider\.com',
299
-        'slurp',
300
-        'Snappy',
301
-        'SNK Siteshooter B0t',
302
-        'sogou',
303
-        'SortSite',
304
-        'speedy',
305
-        'Spinn3r',
306
-        'Springshare Link Checker',
307
-        'Sqworm',
308
-        'StackRambler',
309
-        'Stratagems Kumo',
310
-        'summify',
311
-        'teoma',
312
-        'theoldreader\.com',
313
-        'TinEye',
314
-        'Tiny Tiny RSS',
315
-        'Traackr.com',
316
-        'truwoGPS',
317
-        'tweetedtimes\.com',
318
-        'Twikle',
319
-        'Typhoeus',
320
-        'ubermetrics-technologies',
321
-        'UdmSearch',
322
-        'UnwindFetchor',
323
-        'updated',
324
-        'URLChecker',
325
-        'urlresolver',
326
-        'Vagabondo',
327
-        'Validator\.nu\\/LV',
328
-        'via ggpht\.com GoogleImageProxy',
329
-        'Vivante Link Checker',
330
-        'Vortex',
331
-        'voyager\\/',
332
-        'VYU2',
333
-        'W3C-checklink',
334
-        'W3C-mobileOK',
335
-        'W3C_CSS_Validator_JFouffa',
336
-        'W3C_I18n-Checker',
337
-        'W3C_Unicorn',
338
-        'W3C_Validator',
339
-        'web-capture\.net',
340
-        'webcollage',
341
-        'WebIndex',
342
-        'webmon ',
343
-        'websitepulse[+ ]checker',
344
-        'Websquash\.com',
345
-        'WebThumbnail',
346
-        'WeSEE:Search',
347
-        'wf84',
348
-        'wget',
349
-        'WomlpeFactory',
350
-        'wotbox',
351
-        'www\.monitor\.us',
352
-        'XaxisSemanticsClassifier',
353
-        'Xenu Link Sleuth',
354
-        'XML Sitemaps Generator',
355
-        'Y!J-ASR',
356
-        'yacy',
357
-        'Yahoo Ad monitoring',
358
-        'Yahoo Link Preview',
359
-        'YahooSeeker',
360
-        'yandex',
361
-        'yanga',
362
-        'yeti',
363
-        'yoogliFetchAgent',
364
-        'YottaaMonitor',
365
-        'Zao',
366
-        'ZyBorg',
367
-        '[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
368
-    );
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
+		'Apache-HttpClient\/',
97
+		'Arachmo',
98
+		'archive-com',
99
+		'B-l-i-t-z-B-O-T',
100
+		'Backlink-Ceck\.de',
101
+		'BazQux',
102
+		'bibnum\.bnf',
103
+		'biglotron',
104
+		'BingPreview',
105
+		'binlar',
106
+		'Bloglovin',
107
+		'Blogtrottr',
108
+		'boitho\.com-dc',
109
+		'Browsershots',
110
+		'BUbiNG',
111
+		'Butterfly\\/',
112
+		'BuzzSumo',
113
+		'CapsuleChecker',
114
+		'CC Metadata Scaper',
115
+		'Cerberian Drtrs',
116
+		'changedetection',
117
+		'Charlotte',
118
+		'clips\.ua\.ac\.be',
119
+		'CloudFlare-AlwaysOnline',
120
+		'coccoc',
121
+		'CommaFeed',
122
+		'Commons-HttpClient',
123
+		'convera',
124
+		'cosmos',
125
+		'Covario-IDS',
126
+		'Curious George',
127
+		'curl',
128
+		'CyberPatrol',
129
+		'DataparkSearch',
130
+		'dataprovider',
131
+		'Daum(oa)?[ \\/][0-9]',
132
+		'Digg',
133
+		'DomainAppender',
134
+		'Dragonfly File Reader',
135
+		'drupact',
136
+		'EARTHCOM',
137
+		'ec2linkfinder',
138
+		'ECCP',
139
+		'ElectricMonk',
140
+		'EMail Exractor',
141
+		'EmailWolf',
142
+		'Embed PHP Library',
143
+		'Embedly',
144
+		'europarchive\.org',
145
+		'EventMachine HttpClient',
146
+		'ExactSearch',
147
+		'ExaleadCloudview',
148
+		'eZ Publish Link Validator',
149
+		'ezooms',
150
+		'facebookexternalhit',
151
+		'facebookplatform',
152
+		'Feed Wrangler',
153
+		'Feedbin',
154
+		'FeedBurner',
155
+		'Feedfetcher-Google',
156
+		'Feedly',
157
+		'Feedspot',
158
+		'FeedValidator',
159
+		'Fever',
160
+		'findlink',
161
+		'findthatfile',
162
+		'Flamingo_SearchEngine',
163
+		'fluffy',
164
+		'g00g1e\.net',
165
+		'Genieo',
166
+		'getprismatic\.com',
167
+		'GigablastOpenSource',
168
+		'Go-http-client',
169
+		'Google favicon',
170
+		'Google Keyword Suggestion',
171
+		'Google Page Speed Insights',
172
+		'Google-HTTP-Java-Client',
173
+		'google_partner_monitoring',
174
+		'GoogleProducer',
175
+		'grub-client',
176
+		'heritrix',
177
+		'Holmes',
178
+		'htdig',
179
+		'HTTPMon',
180
+		'httpunit',
181
+		'http_request2',
182
+		'httrack',
183
+		'HubPages.*crawlingpolicy',
184
+		'HubSpot Marketing Grader',
185
+		'ichiro',
186
+		'IDG Twitter Links Resolver',
187
+		'igdeSpyder',
188
+		'InAGist',
189
+		'infegy',
190
+		'InfoWizards Reciprocal Link System PRO',
191
+		'inpwrd\.com',
192
+		'integromedb',
193
+		'IODC',
194
+		'IOI',
195
+		'ips-agent',
196
+		'iZSearch',
197
+		'^Java\/',
198
+		'Jigsaw',
199
+		'Jobrapido',
200
+		'kouio',
201
+		'L\.webis',
202
+		'Larbin',
203
+		'libwww',
204
+		'Link Valet',
205
+		'linkCheck',
206
+		'linkdex',
207
+		'LinkExaminer',
208
+		'LinkWalker',
209
+		'Lipperhey',
210
+		'LongURL API',
211
+		'ltx71',
212
+		'lwp-trivial',
213
+		'lycos',
214
+		'mabontland',
215
+		'MagpieRSS',
216
+		'Mediapartners-Google',
217
+		'Mediapartners-Google',
218
+		'MegaIndex\.ru',
219
+		'MetaURI',
220
+		'Mnogosearch',
221
+		'mogimogi',
222
+		'Morning Paper',
223
+		'Mrcgiguy',
224
+		'MVAClient',
225
+		'Netcraft Web Server Survey',
226
+		'NetcraftSurveyAgent',
227
+		'NetLyzer FastProbe',
228
+		'netresearch',
229
+		'Netvibes',
230
+		'NewsBlur .*(Fetcher|Finder)',
231
+		'NewsGator',
232
+		'newsme',
233
+		'NG-Search',
234
+		'nineconnections\.com',
235
+		'nominet\.org\.uk',
236
+		'Notifixious',
237
+		'nuhk',
238
+		'nutch',
239
+		'Nymesis',
240
+		'oegp',
241
+		'Omea Reader',
242
+		'online link validator',
243
+		'Online Website Link Checker',
244
+		'Orbiter',
245
+		'ow\.ly',
246
+		'page2rss',
247
+		'PagePeeker',
248
+		'panscient',
249
+		'Peew',
250
+		'phpcrawl',
251
+		'phpservermon',
252
+		'Pingdom\.com',
253
+		'Pinterest',
254
+		'Pizilla',
255
+		'Ploetz \+ Zeller',
256
+		'Plukkie',
257
+		'PocketParser',
258
+		'Pompos',
259
+		'postano',
260
+		'PostPost',
261
+		'postrank',
262
+		'proximic',
263
+		'Pulsepoint XT3 web scraper',
264
+		'Python-httplib2',
265
+		'python-requests',
266
+		'Python-urllib',
267
+		'Qseero',
268
+		'Qwantify',
269
+		'Radian6',
270
+		'RebelMouse',
271
+		'REL Link Checker',
272
+		'RetrevoPageAnalyzer',
273
+		'Riddler',
274
+		'Robosourcer',
275
+		'ROI Hunter',
276
+		'Ruby',
277
+		'SalesIntelligent',
278
+		'SBIder',
279
+		'scooter',
280
+		'ScoutJet',
281
+		'ScoutURLMonitor',
282
+		'Scrapy',
283
+		'Scrubby',
284
+		'SearchSight',
285
+		'semanticdiscovery',
286
+		'SEOstats',
287
+		'Server Density Service Monitoring.*',
288
+		'servernfo\.com',
289
+		'Seznam screenshot-generator',
290
+		'ShopWiki',
291
+		'SilverReader',
292
+		'SimplePie',
293
+		'Site24x7',
294
+		'SiteBar',
295
+		'siteexplorer\.info',
296
+		'Siteimprove\.com',
297
+		'SkypeUriPreview',
298
+		'slider\.com',
299
+		'slurp',
300
+		'Snappy',
301
+		'SNK Siteshooter B0t',
302
+		'sogou',
303
+		'SortSite',
304
+		'speedy',
305
+		'Spinn3r',
306
+		'Springshare Link Checker',
307
+		'Sqworm',
308
+		'StackRambler',
309
+		'Stratagems Kumo',
310
+		'summify',
311
+		'teoma',
312
+		'theoldreader\.com',
313
+		'TinEye',
314
+		'Tiny Tiny RSS',
315
+		'Traackr.com',
316
+		'truwoGPS',
317
+		'tweetedtimes\.com',
318
+		'Twikle',
319
+		'Typhoeus',
320
+		'ubermetrics-technologies',
321
+		'UdmSearch',
322
+		'UnwindFetchor',
323
+		'updated',
324
+		'URLChecker',
325
+		'urlresolver',
326
+		'Vagabondo',
327
+		'Validator\.nu\\/LV',
328
+		'via ggpht\.com GoogleImageProxy',
329
+		'Vivante Link Checker',
330
+		'Vortex',
331
+		'voyager\\/',
332
+		'VYU2',
333
+		'W3C-checklink',
334
+		'W3C-mobileOK',
335
+		'W3C_CSS_Validator_JFouffa',
336
+		'W3C_I18n-Checker',
337
+		'W3C_Unicorn',
338
+		'W3C_Validator',
339
+		'web-capture\.net',
340
+		'webcollage',
341
+		'WebIndex',
342
+		'webmon ',
343
+		'websitepulse[+ ]checker',
344
+		'Websquash\.com',
345
+		'WebThumbnail',
346
+		'WeSEE:Search',
347
+		'wf84',
348
+		'wget',
349
+		'WomlpeFactory',
350
+		'wotbox',
351
+		'www\.monitor\.us',
352
+		'XaxisSemanticsClassifier',
353
+		'Xenu Link Sleuth',
354
+		'XML Sitemaps Generator',
355
+		'Y!J-ASR',
356
+		'yacy',
357
+		'Yahoo Ad monitoring',
358
+		'Yahoo Link Preview',
359
+		'YahooSeeker',
360
+		'yandex',
361
+		'yanga',
362
+		'yeti',
363
+		'yoogliFetchAgent',
364
+		'YottaaMonitor',
365
+		'Zao',
366
+		'ZyBorg',
367
+		'[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
368
+	);
369 369
 
370
-    /**
371
-     * All possible HTTP headers that represent the
372
-     * User-Agent string.
373
-     *
374
-     * @var array
375
-     */
376
-    protected static $uaHttpHeaders = array(
377
-        // The default User-Agent string.
378
-        'HTTP_USER_AGENT',
379
-        // Header can occur on devices using Opera Mini.
380
-        'HTTP_X_OPERAMINI_PHONE_UA',
381
-        // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
382
-        'HTTP_X_DEVICE_USER_AGENT',
383
-        'HTTP_X_ORIGINAL_USER_AGENT',
384
-        'HTTP_X_SKYFIRE_PHONE',
385
-        'HTTP_X_BOLT_PHONE_UA',
386
-        'HTTP_DEVICE_STOCK_UA',
387
-        'HTTP_X_UCBROWSER_DEVICE_UA',
388
-    );
370
+	/**
371
+	 * All possible HTTP headers that represent the
372
+	 * User-Agent string.
373
+	 *
374
+	 * @var array
375
+	 */
376
+	protected static $uaHttpHeaders = array(
377
+		// The default User-Agent string.
378
+		'HTTP_USER_AGENT',
379
+		// Header can occur on devices using Opera Mini.
380
+		'HTTP_X_OPERAMINI_PHONE_UA',
381
+		// Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
382
+		'HTTP_X_DEVICE_USER_AGENT',
383
+		'HTTP_X_ORIGINAL_USER_AGENT',
384
+		'HTTP_X_SKYFIRE_PHONE',
385
+		'HTTP_X_BOLT_PHONE_UA',
386
+		'HTTP_DEVICE_STOCK_UA',
387
+		'HTTP_X_UCBROWSER_DEVICE_UA',
388
+	);
389 389
 
390
-    /**
391
-     * Class constructor.
392
-     */
393
-    public function __construct(array $headers = null, $userAgent = null)
394
-    {
395
-        $this->setHttpHeaders($headers);
396
-        $this->setUserAgent($userAgent);
397
-    }
390
+	/**
391
+	 * Class constructor.
392
+	 */
393
+	public function __construct(array $headers = null, $userAgent = null)
394
+	{
395
+		$this->setHttpHeaders($headers);
396
+		$this->setUserAgent($userAgent);
397
+	}
398 398
 
399
-    /**
400
-     * Set HTTP headers.
401
-     *
402
-     * @param array $httpHeaders
403
-     */
404
-    public function setHttpHeaders($httpHeaders = null)
405
-    {
406
-        // use global _SERVER if $httpHeaders aren't defined
407
-        if (!is_array($httpHeaders) || !count($httpHeaders)) {
408
-            $httpHeaders = $_SERVER;
409
-        }
410
-        // clear existing headers
411
-        $this->httpHeaders = array();
412
-        // Only save HTTP headers. In PHP land, that means only _SERVER vars that
413
-        // start with HTTP_.
414
-        foreach ($httpHeaders as $key => $value) {
415
-            if (substr($key, 0, 5) === 'HTTP_') {
416
-                $this->httpHeaders[$key] = $value;
417
-            }
418
-        }
419
-    }
399
+	/**
400
+	 * Set HTTP headers.
401
+	 *
402
+	 * @param array $httpHeaders
403
+	 */
404
+	public function setHttpHeaders($httpHeaders = null)
405
+	{
406
+		// use global _SERVER if $httpHeaders aren't defined
407
+		if (!is_array($httpHeaders) || !count($httpHeaders)) {
408
+			$httpHeaders = $_SERVER;
409
+		}
410
+		// clear existing headers
411
+		$this->httpHeaders = array();
412
+		// Only save HTTP headers. In PHP land, that means only _SERVER vars that
413
+		// start with HTTP_.
414
+		foreach ($httpHeaders as $key => $value) {
415
+			if (substr($key, 0, 5) === 'HTTP_') {
416
+				$this->httpHeaders[$key] = $value;
417
+			}
418
+		}
419
+	}
420 420
 
421
-    /**
422
-     * Return user agent headers.
423
-     *
424
-     * @return array
425
-     */
426
-    public function getUaHttpHeaders()
427
-    {
428
-        return self::$uaHttpHeaders;
429
-    }
421
+	/**
422
+	 * Return user agent headers.
423
+	 *
424
+	 * @return array
425
+	 */
426
+	public function getUaHttpHeaders()
427
+	{
428
+		return self::$uaHttpHeaders;
429
+	}
430 430
 
431
-    /**
432
-     * Set the user agent.
433
-     *
434
-     * @param string $userAgent
435
-     */
436
-    public function setUserAgent($userAgent = null)
437
-    {
438
-        if (false === empty($userAgent)) {
439
-            return $this->userAgent = $userAgent;
440
-        } else {
441
-            $this->userAgent = null;
442
-            foreach ($this->getUaHttpHeaders() as $altHeader) {
443
-                if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
444
-                    $this->userAgent .= $this->httpHeaders[$altHeader].' ';
445
-                }
446
-            }
431
+	/**
432
+	 * Set the user agent.
433
+	 *
434
+	 * @param string $userAgent
435
+	 */
436
+	public function setUserAgent($userAgent = null)
437
+	{
438
+		if (false === empty($userAgent)) {
439
+			return $this->userAgent = $userAgent;
440
+		} else {
441
+			$this->userAgent = null;
442
+			foreach ($this->getUaHttpHeaders() as $altHeader) {
443
+				if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
444
+					$this->userAgent .= $this->httpHeaders[$altHeader].' ';
445
+				}
446
+			}
447 447
 
448
-            return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
449
-        }
450
-    }
448
+			return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
449
+		}
450
+	}
451 451
 
452
-    /**
453
-     * Return the array of crawler regexs.
454
-     *
455
-     * @return array
456
-     */
457
-    public function getCrawlers()
458
-    {
459
-        return self::$crawlers;
460
-    }
452
+	/**
453
+	 * Return the array of crawler regexs.
454
+	 *
455
+	 * @return array
456
+	 */
457
+	public function getCrawlers()
458
+	{
459
+		return self::$crawlers;
460
+	}
461 461
 
462
-    /**
463
-     * Build the user agent regex.
464
-     *
465
-     * @return string
466
-     */
467
-    public function getRegex()
468
-    {
469
-        return '('.implode('|', self::$crawlers).')';
470
-    }
462
+	/**
463
+	 * Build the user agent regex.
464
+	 *
465
+	 * @return string
466
+	 */
467
+	public function getRegex()
468
+	{
469
+		return '('.implode('|', self::$crawlers).')';
470
+	}
471 471
 
472
-    /**
473
-     * Build the replacement regex.
474
-     *
475
-     * @return string
476
-     */
477
-    public function getIgnored()
478
-    {
479
-        return '('.implode('|', self::$ignore).')';
480
-    }
472
+	/**
473
+	 * Build the replacement regex.
474
+	 *
475
+	 * @return string
476
+	 */
477
+	public function getIgnored()
478
+	{
479
+		return '('.implode('|', self::$ignore).')';
480
+	}
481 481
 
482
-    /**
483
-     * Check user agent string against the regex.
484
-     *
485
-     * @param string $userAgent
486
-     *
487
-     * @return bool
488
-     */
489
-    public function isCrawler($userAgent = null)
490
-    {
491
-        $agent = is_null($userAgent) ? $this->userAgent : $userAgent;
482
+	/**
483
+	 * Check user agent string against the regex.
484
+	 *
485
+	 * @param string $userAgent
486
+	 *
487
+	 * @return bool
488
+	 */
489
+	public function isCrawler($userAgent = null)
490
+	{
491
+		$agent = is_null($userAgent) ? $this->userAgent : $userAgent;
492 492
 
493
-        $agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
493
+		$agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
494 494
 
495
-        if (trim($agent) === false) {
496
-            return false;
497
-        } else {
498
-            $result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
499
-        }
495
+		if (trim($agent) === false) {
496
+			return false;
497
+		} else {
498
+			$result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
499
+		}
500 500
 
501
-        if ($matches) {
502
-            $this->matches = $matches;
503
-        }
501
+		if ($matches) {
502
+			$this->matches = $matches;
503
+		}
504 504
 
505
-        return (bool) $result;
506
-    }
505
+		return (bool) $result;
506
+	}
507 507
 
508
-    /**
509
-     * Return the matches.
510
-     *
511
-     * @return string
512
-     */
513
-    public function getMatches()
514
-    {
515
-        return $this->matches[0];
516
-    }
508
+	/**
509
+	 * Return the matches.
510
+	 *
511
+	 * @return string
512
+	 */
513
+	public function getMatches()
514
+	{
515
+		return $this->matches[0];
516
+	}
517 517
 }
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.