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