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