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