Completed
Push — master ( 8a091a...f8048d )
by Mark
9s
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   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -4,460 +4,460 @@
 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
-        '008\\/',
85
-        'A6-Indexer',
86
-        'Aboundex',
87
-        'Accoona-AI-Agent',
88
-        'acoon',
89
-        'AddThis',
90
-        'ADmantX',
91
-        'AHC',
92
-        'Airmail',
93
-        'Anemone',
94
-        'Arachmo',
95
-        'archive-com',
96
-        'B-l-i-t-z-B-O-T',
97
-        'bibnum\.bnf',
98
-        'biglotron',
99
-        'binlar',
100
-        'BingPreview',
101
-        'boitho\.com-dc',
102
-        'BrokenLinkCheck\.com',
103
-        'BUbiNG',
104
-        'Butterfly\\/',
105
-        'BuzzSumo',
106
-        'CapsuleChecker',
107
-        'CC Metadata Scaper',
108
-        'Cerberian Drtrs',
109
-        'changedetection',
110
-        'Charlotte',
111
-        'clips\.ua\.ac\.be',
112
-        'CloudFlare-AlwaysOnline',
113
-        'coccoc',
114
-        'Commons-HttpClient',
115
-        'convera',
116
-        'cosmos',
117
-        'Covario-IDS',
118
-        'curl',
119
-        'CyberPatrol',
120
-        'Dragonfly File Reader',
121
-        'DataparkSearch',
122
-        'dataprovider',
123
-        'deadlinkchecker\.com',
124
-        'Digg',
125
-        'DomainAppender',
126
-        'drupact',
127
-        'EARTHCOM',
128
-        'ECCP',
129
-        'ec2linkfinder',
130
-        'ElectricMonk',
131
-        'Embedly',
132
-        'europarchive\.org',
133
-        'EventMachine HttpClient',
134
-        'ExactSearch',
135
-        'ezooms',
136
-        'eZ Publish Link Validator',
137
-        'facebookexternalhit',
138
-        'FeedBurner',
139
-        'Feedfetcher-Google',
140
-        'FeedValidator',
141
-        'FindLinks',
142
-        'findlink',
143
-        'findthatfile',
144
-        'Flamingo_SearchEngine',
145
-        'fluffy',
146
-        'getprismatic\.com',
147
-        'g00g1e\.net',
148
-        'GigablastOpenSource',
149
-        'grub-client',
150
-        'Genieo',
151
-        'Go-http-client',
152
-        'Google-HTTP-Java-Client',
153
-        'Google favicon',
154
-        'Google Keyword Suggestion',
155
-        'GoogleProducer',
156
-        'heritrix',
157
-        'Holmes',
158
-        'htdig',
159
-        'httpunit',
160
-        'httrack',
161
-        'HubSpot Marketing Grader',
162
-        'ichiro',
163
-        'infegy',
164
-        'igdeSpyder',
165
-        'InAGist',
166
-        'InfoWizards Reciprocal Link System PRO',
167
-        'integromedb',
168
-        'IODC',
169
-        'IOI',
170
-        'ips-agent',
171
-        'iZSearch',
172
-        'Jobrapido',
173
-        'L\.webis',
174
-        'Larbin',
175
-        'libwww',
176
-        'Link Valet',
177
-        'linkdex',
178
-        'LinkExaminer',
179
-        'LinkWalker',
180
-        'Lipperhey',
181
-        'LongURL API',
182
-        'ltx71',
183
-        'lwp-trivial',
184
-        'Mediapartners-Google',
185
-        'MegaIndex\.ru',
186
-        'mabontland',
187
-        'MagpieRSS',
188
-        'Mediapartners-Google',
189
-        'MetaURI',
190
-        'Mnogosearch',
191
-        'mogimogi',
192
-        'Morning Paper',
193
-        'Mrcgiguy',
194
-        'MVAClient',
195
-        'Netcraft Web Server Survey',
196
-        'netresearchserver',
197
-        'Netvibes',
198
-        'NewsGator',
199
-        'newsme',
200
-        'NG-Search',
201
-        '^NING\\/',
202
-        'nineconnections\.com',
203
-        'nominet\.org\.uk',
204
-        'Notifixious',
205
-        'nutch',
206
-        'NutchCVS',
207
-        'Nymesis',
208
-        'oegp',
209
-        'Omea Reader',
210
-        'online link validator',
211
-        'Online Website Link Checker',
212
-        'Orbiter',
213
-        'ow\.ly',
214
-        'Ploetz \+ Zeller',
215
-        'PagePeeker',
216
-        'page2rss',
217
-        'panscient',
218
-        'Peew',
219
-        'phpcrawl',
220
-        'Pinterest',
221
-        'Pizilla',
222
-        'Plukkie',
223
-        'PocketParser',
224
-        'Pompos',
225
-        'postano',
226
-        'PostPost',
227
-        'postrank',
228
-        'proximic',
229
-        'Pulsepoint XT3 web scraper',
230
-        'PycURL',
231
-        'Python-httplib2',
232
-        'python-requests',
233
-        'Python-urllib',
234
-        'Qseero',
235
-        'Qwantify',
236
-        'Radian6',
237
-        'RebelMouse',
238
-        'REL Link Checker',
239
-        'RetrevoPageAnalyzer',
240
-        'Riddler',
241
-        'Robosourcer',
242
-        'Ruby',
243
-        'SBIder',
244
-        'ScoutJet',
245
-        'ScoutURLMonitor',
246
-        'Scrapy',
247
-        'Scrubby',
248
-        'SearchSight',
249
-        'semanticdiscovery',
250
-        'SEOstats',
251
-        'servernfo\.com',
252
-        'Seznam screenshot-generator',
253
-        'ShopWiki',
254
-        'SimplePie',
255
-        'SiteBar',
256
-        'siteexplorer\.info',
257
-        'Siteimprove\.com',
258
-        'slider\.com',
259
-        'slurp',
260
-        'Snappy',
261
-        'sogou',
262
-        'SortSite',
263
-        'speedy',
264
-        'Springshare Link Checker',
265
-        'Sqworm',
266
-        'StackRambler',
267
-        'Stratagems Kumo',
268
-        'summify',
269
-        'teoma',
270
-        'theoldreader\.com',
271
-        'TinEye',
272
-        'Traackr.com',
273
-        'truwoGPS',
274
-        'Typhoeus',
275
-        'tweetedtimes\.com',
276
-        'Twikle',
277
-        'UdmSearch',
278
-        'UnwindFetchor',
279
-        'updated',
280
-        'URLChecker',
281
-        'urlresolver',
282
-        'Validator\.nu\\/LV',
283
-        'Vagabondo',
284
-        'Vivante Link Checker',
285
-        'Vortex',
286
-        'voyager\\/',
287
-        'VYU2',
288
-        'W3C-checklink',
289
-        'W3C_CSS_Validator_JFouffa',
290
-        'W3C_I18n-Checker',
291
-        'W3C-mobileOK',
292
-        'W3C_Unicorn',
293
-        'W3C_Validator',
294
-        'WebIndex',
295
-        'Websquash\.com',
296
-        'webcollage',
297
-        'webmon ',
298
-        'web-capture\.net',
299
-        'WeSEE:Search',
300
-        'wf84',
301
-        'wget',
302
-        'WomlpeFactory',
303
-        'wotbox',
304
-        'Xenu Link Sleuth',
305
-        'XML Sitemaps Generator',
306
-        'Y!J-ASR',
307
-        'yacy',
308
-        'Yahoo Ad monitoring',
309
-        'Yahoo Link Preview',
310
-        'Yahoo! Slurp China',
311
-        'Yahoo! Slurp',
312
-        'YahooSeeker',
313
-        'YahooSeeker-Testing',
314
-        'YandexImages',
315
-        'YandexMetrika',
316
-        'YandexDirectDyn',
317
-        'yandex',
318
-        'yanga',
319
-        'yeti',
320
-        'yoogliFetchAgent',
321
-        'Zao',
322
-        'ZyBorg',
323
-        '[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
324
-    );
78
+	/**
79
+	 * Array of regular expressions to match against the user agent.
80
+	 *
81
+	 * @var array
82
+	 */
83
+	protected static $crawlers = array(
84
+		'008\\/',
85
+		'A6-Indexer',
86
+		'Aboundex',
87
+		'Accoona-AI-Agent',
88
+		'acoon',
89
+		'AddThis',
90
+		'ADmantX',
91
+		'AHC',
92
+		'Airmail',
93
+		'Anemone',
94
+		'Arachmo',
95
+		'archive-com',
96
+		'B-l-i-t-z-B-O-T',
97
+		'bibnum\.bnf',
98
+		'biglotron',
99
+		'binlar',
100
+		'BingPreview',
101
+		'boitho\.com-dc',
102
+		'BrokenLinkCheck\.com',
103
+		'BUbiNG',
104
+		'Butterfly\\/',
105
+		'BuzzSumo',
106
+		'CapsuleChecker',
107
+		'CC Metadata Scaper',
108
+		'Cerberian Drtrs',
109
+		'changedetection',
110
+		'Charlotte',
111
+		'clips\.ua\.ac\.be',
112
+		'CloudFlare-AlwaysOnline',
113
+		'coccoc',
114
+		'Commons-HttpClient',
115
+		'convera',
116
+		'cosmos',
117
+		'Covario-IDS',
118
+		'curl',
119
+		'CyberPatrol',
120
+		'Dragonfly File Reader',
121
+		'DataparkSearch',
122
+		'dataprovider',
123
+		'deadlinkchecker\.com',
124
+		'Digg',
125
+		'DomainAppender',
126
+		'drupact',
127
+		'EARTHCOM',
128
+		'ECCP',
129
+		'ec2linkfinder',
130
+		'ElectricMonk',
131
+		'Embedly',
132
+		'europarchive\.org',
133
+		'EventMachine HttpClient',
134
+		'ExactSearch',
135
+		'ezooms',
136
+		'eZ Publish Link Validator',
137
+		'facebookexternalhit',
138
+		'FeedBurner',
139
+		'Feedfetcher-Google',
140
+		'FeedValidator',
141
+		'FindLinks',
142
+		'findlink',
143
+		'findthatfile',
144
+		'Flamingo_SearchEngine',
145
+		'fluffy',
146
+		'getprismatic\.com',
147
+		'g00g1e\.net',
148
+		'GigablastOpenSource',
149
+		'grub-client',
150
+		'Genieo',
151
+		'Go-http-client',
152
+		'Google-HTTP-Java-Client',
153
+		'Google favicon',
154
+		'Google Keyword Suggestion',
155
+		'GoogleProducer',
156
+		'heritrix',
157
+		'Holmes',
158
+		'htdig',
159
+		'httpunit',
160
+		'httrack',
161
+		'HubSpot Marketing Grader',
162
+		'ichiro',
163
+		'infegy',
164
+		'igdeSpyder',
165
+		'InAGist',
166
+		'InfoWizards Reciprocal Link System PRO',
167
+		'integromedb',
168
+		'IODC',
169
+		'IOI',
170
+		'ips-agent',
171
+		'iZSearch',
172
+		'Jobrapido',
173
+		'L\.webis',
174
+		'Larbin',
175
+		'libwww',
176
+		'Link Valet',
177
+		'linkdex',
178
+		'LinkExaminer',
179
+		'LinkWalker',
180
+		'Lipperhey',
181
+		'LongURL API',
182
+		'ltx71',
183
+		'lwp-trivial',
184
+		'Mediapartners-Google',
185
+		'MegaIndex\.ru',
186
+		'mabontland',
187
+		'MagpieRSS',
188
+		'Mediapartners-Google',
189
+		'MetaURI',
190
+		'Mnogosearch',
191
+		'mogimogi',
192
+		'Morning Paper',
193
+		'Mrcgiguy',
194
+		'MVAClient',
195
+		'Netcraft Web Server Survey',
196
+		'netresearchserver',
197
+		'Netvibes',
198
+		'NewsGator',
199
+		'newsme',
200
+		'NG-Search',
201
+		'^NING\\/',
202
+		'nineconnections\.com',
203
+		'nominet\.org\.uk',
204
+		'Notifixious',
205
+		'nutch',
206
+		'NutchCVS',
207
+		'Nymesis',
208
+		'oegp',
209
+		'Omea Reader',
210
+		'online link validator',
211
+		'Online Website Link Checker',
212
+		'Orbiter',
213
+		'ow\.ly',
214
+		'Ploetz \+ Zeller',
215
+		'PagePeeker',
216
+		'page2rss',
217
+		'panscient',
218
+		'Peew',
219
+		'phpcrawl',
220
+		'Pinterest',
221
+		'Pizilla',
222
+		'Plukkie',
223
+		'PocketParser',
224
+		'Pompos',
225
+		'postano',
226
+		'PostPost',
227
+		'postrank',
228
+		'proximic',
229
+		'Pulsepoint XT3 web scraper',
230
+		'PycURL',
231
+		'Python-httplib2',
232
+		'python-requests',
233
+		'Python-urllib',
234
+		'Qseero',
235
+		'Qwantify',
236
+		'Radian6',
237
+		'RebelMouse',
238
+		'REL Link Checker',
239
+		'RetrevoPageAnalyzer',
240
+		'Riddler',
241
+		'Robosourcer',
242
+		'Ruby',
243
+		'SBIder',
244
+		'ScoutJet',
245
+		'ScoutURLMonitor',
246
+		'Scrapy',
247
+		'Scrubby',
248
+		'SearchSight',
249
+		'semanticdiscovery',
250
+		'SEOstats',
251
+		'servernfo\.com',
252
+		'Seznam screenshot-generator',
253
+		'ShopWiki',
254
+		'SimplePie',
255
+		'SiteBar',
256
+		'siteexplorer\.info',
257
+		'Siteimprove\.com',
258
+		'slider\.com',
259
+		'slurp',
260
+		'Snappy',
261
+		'sogou',
262
+		'SortSite',
263
+		'speedy',
264
+		'Springshare Link Checker',
265
+		'Sqworm',
266
+		'StackRambler',
267
+		'Stratagems Kumo',
268
+		'summify',
269
+		'teoma',
270
+		'theoldreader\.com',
271
+		'TinEye',
272
+		'Traackr.com',
273
+		'truwoGPS',
274
+		'Typhoeus',
275
+		'tweetedtimes\.com',
276
+		'Twikle',
277
+		'UdmSearch',
278
+		'UnwindFetchor',
279
+		'updated',
280
+		'URLChecker',
281
+		'urlresolver',
282
+		'Validator\.nu\\/LV',
283
+		'Vagabondo',
284
+		'Vivante Link Checker',
285
+		'Vortex',
286
+		'voyager\\/',
287
+		'VYU2',
288
+		'W3C-checklink',
289
+		'W3C_CSS_Validator_JFouffa',
290
+		'W3C_I18n-Checker',
291
+		'W3C-mobileOK',
292
+		'W3C_Unicorn',
293
+		'W3C_Validator',
294
+		'WebIndex',
295
+		'Websquash\.com',
296
+		'webcollage',
297
+		'webmon ',
298
+		'web-capture\.net',
299
+		'WeSEE:Search',
300
+		'wf84',
301
+		'wget',
302
+		'WomlpeFactory',
303
+		'wotbox',
304
+		'Xenu Link Sleuth',
305
+		'XML Sitemaps Generator',
306
+		'Y!J-ASR',
307
+		'yacy',
308
+		'Yahoo Ad monitoring',
309
+		'Yahoo Link Preview',
310
+		'Yahoo! Slurp China',
311
+		'Yahoo! Slurp',
312
+		'YahooSeeker',
313
+		'YahooSeeker-Testing',
314
+		'YandexImages',
315
+		'YandexMetrika',
316
+		'YandexDirectDyn',
317
+		'yandex',
318
+		'yanga',
319
+		'yeti',
320
+		'yoogliFetchAgent',
321
+		'Zao',
322
+		'ZyBorg',
323
+		'[a-z0-9\\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider)',
324
+	);
325 325
 
326
-    /**
327
-     * All possible HTTP headers that represent the
328
-     * User-Agent string.
329
-     *
330
-     * @var array
331
-     */
332
-    protected static $uaHttpHeaders = array(
333
-        // The default User-Agent string.
334
-        'HTTP_USER_AGENT',
335
-        // Header can occur on devices using Opera Mini.
336
-        'HTTP_X_OPERAMINI_PHONE_UA',
337
-        // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
338
-        'HTTP_X_DEVICE_USER_AGENT',
339
-        'HTTP_X_ORIGINAL_USER_AGENT',
340
-        'HTTP_X_SKYFIRE_PHONE',
341
-        'HTTP_X_BOLT_PHONE_UA',
342
-        'HTTP_DEVICE_STOCK_UA',
343
-        'HTTP_X_UCBROWSER_DEVICE_UA',
344
-    );
326
+	/**
327
+	 * All possible HTTP headers that represent the
328
+	 * User-Agent string.
329
+	 *
330
+	 * @var array
331
+	 */
332
+	protected static $uaHttpHeaders = array(
333
+		// The default User-Agent string.
334
+		'HTTP_USER_AGENT',
335
+		// Header can occur on devices using Opera Mini.
336
+		'HTTP_X_OPERAMINI_PHONE_UA',
337
+		// Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/
338
+		'HTTP_X_DEVICE_USER_AGENT',
339
+		'HTTP_X_ORIGINAL_USER_AGENT',
340
+		'HTTP_X_SKYFIRE_PHONE',
341
+		'HTTP_X_BOLT_PHONE_UA',
342
+		'HTTP_DEVICE_STOCK_UA',
343
+		'HTTP_X_UCBROWSER_DEVICE_UA',
344
+	);
345 345
 
346
-    /**
347
-     * Class constructor.
348
-     */
349
-    public function __construct(array $headers = null, $userAgent = null)
350
-    {
351
-        $this->setHttpHeaders($headers);
352
-        $this->setUserAgent($userAgent);
353
-    }
346
+	/**
347
+	 * Class constructor.
348
+	 */
349
+	public function __construct(array $headers = null, $userAgent = null)
350
+	{
351
+		$this->setHttpHeaders($headers);
352
+		$this->setUserAgent($userAgent);
353
+	}
354 354
 
355
-    /**
356
-     * Set HTTP headers.
357
-     *
358
-     * @param array $httpHeaders
359
-     */
360
-    public function setHttpHeaders($httpHeaders = null)
361
-    {
362
-        // use global _SERVER if $httpHeaders aren't defined
363
-        if (!is_array($httpHeaders) || !count($httpHeaders)) {
364
-            $httpHeaders = $_SERVER;
365
-        }
366
-        // clear existing headers
367
-        $this->httpHeaders = array();
368
-        // Only save HTTP headers. In PHP land, that means only _SERVER vars that
369
-        // start with HTTP_.
370
-        foreach ($httpHeaders as $key => $value) {
371
-            if (substr($key, 0, 5) === 'HTTP_') {
372
-                $this->httpHeaders[$key] = $value;
373
-            }
374
-        }
375
-    }
355
+	/**
356
+	 * Set HTTP headers.
357
+	 *
358
+	 * @param array $httpHeaders
359
+	 */
360
+	public function setHttpHeaders($httpHeaders = null)
361
+	{
362
+		// use global _SERVER if $httpHeaders aren't defined
363
+		if (!is_array($httpHeaders) || !count($httpHeaders)) {
364
+			$httpHeaders = $_SERVER;
365
+		}
366
+		// clear existing headers
367
+		$this->httpHeaders = array();
368
+		// Only save HTTP headers. In PHP land, that means only _SERVER vars that
369
+		// start with HTTP_.
370
+		foreach ($httpHeaders as $key => $value) {
371
+			if (substr($key, 0, 5) === 'HTTP_') {
372
+				$this->httpHeaders[$key] = $value;
373
+			}
374
+		}
375
+	}
376 376
 
377
-    /**
378
-     * Return user agent headers.
379
-     *
380
-     * @return array
381
-     */
382
-    public function getUaHttpHeaders()
383
-    {
384
-        return self::$uaHttpHeaders;
385
-    }
377
+	/**
378
+	 * Return user agent headers.
379
+	 *
380
+	 * @return array
381
+	 */
382
+	public function getUaHttpHeaders()
383
+	{
384
+		return self::$uaHttpHeaders;
385
+	}
386 386
 
387
-    /**
388
-     * Set the user agent.
389
-     *
390
-     * @param string $userAgent
391
-     */
392
-    public function setUserAgent($userAgent = null)
393
-    {
394
-        if (false === empty($userAgent)) {
395
-            return $this->userAgent = $userAgent;
396
-        } else {
397
-            $this->userAgent = null;
398
-            foreach ($this->getUaHttpHeaders() as $altHeader) {
399
-                if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
400
-                    $this->userAgent .= $this->httpHeaders[$altHeader].' ';
401
-                }
402
-            }
387
+	/**
388
+	 * Set the user agent.
389
+	 *
390
+	 * @param string $userAgent
391
+	 */
392
+	public function setUserAgent($userAgent = null)
393
+	{
394
+		if (false === empty($userAgent)) {
395
+			return $this->userAgent = $userAgent;
396
+		} else {
397
+			$this->userAgent = null;
398
+			foreach ($this->getUaHttpHeaders() as $altHeader) {
399
+				if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow.
400
+					$this->userAgent .= $this->httpHeaders[$altHeader].' ';
401
+				}
402
+			}
403 403
 
404
-            return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
405
-        }
406
-    }
404
+			return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null);
405
+		}
406
+	}
407 407
 
408
-    /**
409
-     * Build the user agent regex.
410
-     *
411
-     * @return string
412
-     */
413
-    public function getRegex()
414
-    {
415
-        return '('.implode('|', self::$crawlers).')';
416
-    }
408
+	/**
409
+	 * Build the user agent regex.
410
+	 *
411
+	 * @return string
412
+	 */
413
+	public function getRegex()
414
+	{
415
+		return '('.implode('|', self::$crawlers).')';
416
+	}
417 417
 
418
-    /**
419
-     * Build the replacement regex.
420
-     *
421
-     * @return string
422
-     */
423
-    public function getIgnored()
424
-    {
425
-        return '('.implode('|', self::$ignore).')';
426
-    }
418
+	/**
419
+	 * Build the replacement regex.
420
+	 *
421
+	 * @return string
422
+	 */
423
+	public function getIgnored()
424
+	{
425
+		return '('.implode('|', self::$ignore).')';
426
+	}
427 427
 
428
-    /**
429
-     * Check user agent string against the regex.
430
-     *
431
-     * @param string $userAgent
432
-     *
433
-     * @return bool
434
-     */
435
-    public function isCrawler($userAgent = null)
436
-    {
437
-        $agent = is_null($userAgent) ? $this->userAgent : $userAgent;
428
+	/**
429
+	 * Check user agent string against the regex.
430
+	 *
431
+	 * @param string $userAgent
432
+	 *
433
+	 * @return bool
434
+	 */
435
+	public function isCrawler($userAgent = null)
436
+	{
437
+		$agent = is_null($userAgent) ? $this->userAgent : $userAgent;
438 438
 
439
-        $agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
439
+		$agent = preg_replace('/'.$this->getIgnored().'/i', '', $agent);
440 440
 
441
-        if (trim($agent) === false) {
442
-            return false;
443
-        } else {
444
-            $result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
445
-        }
441
+		if (trim($agent) === false) {
442
+			return false;
443
+		} else {
444
+			$result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
445
+		}
446 446
 
447
-        if ($matches) {
448
-            $this->matches = $matches;
449
-        }
447
+		if ($matches) {
448
+			$this->matches = $matches;
449
+		}
450 450
 
451
-        return (bool) $result;
452
-    }
451
+		return (bool) $result;
452
+	}
453 453
 
454
-    /**
455
-     * Return the matches.
456
-     *
457
-     * @return string
458
-     */
459
-    public function getMatches()
460
-    {
461
-        return $this->matches[0];
462
-    }
454
+	/**
455
+	 * Return the matches.
456
+	 *
457
+	 * @return string
458
+	 */
459
+	public function getMatches()
460
+	{
461
+		return $this->matches[0];
462
+	}
463 463
 }
Please login to merge, or discard this patch.
tests/UATests.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -2,39 +2,39 @@
 block discarded – undo
2 2
 
3 3
 class UserAgentTest extends PHPUnit_Framework_TestCase
4 4
 {
5
-    protected $CrawlerDetect;
5
+	protected $CrawlerDetect;
6 6
 
7
-    public function setUp()
8
-    {
9
-        $this->CrawlerDetect = new Jaybizzle\CrawlerDetect\CrawlerDetect();
10
-    }
7
+	public function setUp()
8
+	{
9
+		$this->CrawlerDetect = new Jaybizzle\CrawlerDetect\CrawlerDetect();
10
+	}
11 11
 
12
-    public function testBots()
13
-    {
14
-        $lines = file(__DIR__.'/crawlers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
12
+	public function testBots()
13
+	{
14
+		$lines = file(__DIR__.'/crawlers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
15 15
 
16
-        foreach ($lines as $line) {
17
-            $test = $this->CrawlerDetect->isCrawler($line);
18
-            $this->assertEquals($test, true, $line);
19
-        }
20
-    }
16
+		foreach ($lines as $line) {
17
+			$test = $this->CrawlerDetect->isCrawler($line);
18
+			$this->assertEquals($test, true, $line);
19
+		}
20
+	}
21 21
 
22
-    public function testDevices()
23
-    {
24
-        $lines = file(__DIR__.'/devices.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
22
+	public function testDevices()
23
+	{
24
+		$lines = file(__DIR__.'/devices.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
25 25
 
26
-        foreach ($lines as $line) {
27
-            $test = $this->CrawlerDetect->isCrawler($line);
28
-            $this->assertEquals($test, false, $line);
29
-        }
30
-    }
26
+		foreach ($lines as $line) {
27
+			$test = $this->CrawlerDetect->isCrawler($line);
28
+			$this->assertEquals($test, false, $line);
29
+		}
30
+	}
31 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)');
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 35
 
36
-        $matches = $this->CrawlerDetect->getMatches();
36
+		$matches = $this->CrawlerDetect->getMatches();
37 37
 
38
-        $this->assertEquals($this->CrawlerDetect->getMatches(), 'Yahoo Ad monitoring', $matches);
39
-    }
38
+		$this->assertEquals($this->CrawlerDetect->getMatches(), 'Yahoo Ad monitoring', $matches);
39
+	}
40 40
 }
Please login to merge, or discard this patch.