PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 7.5.0.1
Jetpack – WP Security, Backup, Speed, & Growth v7.5.0.1
15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / class.jetpack-user-agent.php
jetpack Last commit date
3rd-party 6 years ago _inc 6 years ago bin 6 years ago css 6 years ago extensions 6 years ago images 7 years ago json-endpoints 6 years ago languages 6 years ago logs 9 years ago modules 6 years ago sal 6 years ago src 6 years ago sync 6 years ago vendor 6 years ago views 7 years ago wp-cli-templates 7 years ago .svnignore 12 years ago CODE-OF-CONDUCT.md 9 years ago changelog.txt 6 years ago class.frame-nonce-preview.php 9 years ago class.jetpack-admin.php 7 years ago class.jetpack-affiliate.php 7 years ago class.jetpack-autoupdate.php 7 years ago class.jetpack-bbpress-json-api-compat.php 9 years ago class.jetpack-cli.php 6 years ago class.jetpack-client-server.php 6 years ago class.jetpack-client.php 6 years ago class.jetpack-connection-banner.php 6 years ago class.jetpack-constants.php 6 years ago class.jetpack-data.php 6 years ago class.jetpack-debugger.php 7 years ago class.jetpack-error.php 10 years ago class.jetpack-gutenberg.php 6 years ago class.jetpack-heartbeat.php 7 years ago class.jetpack-idc.php 6 years ago class.jetpack-ixr-client.php 6 years ago class.jetpack-jitm.php 6 years ago class.jetpack-modules-list-table.php 6 years ago class.jetpack-network-sites-list-table.php 9 years ago class.jetpack-network.php 6 years ago class.jetpack-options.php 6 years ago class.jetpack-plan.php 6 years ago class.jetpack-post-images.php 7 years ago class.jetpack-signature.php 6 years ago class.jetpack-tracks.php 6 years ago class.jetpack-twitter-cards.php 7 years ago class.jetpack-user-agent.php 7 years ago class.jetpack-xmlrpc-server.php 6 years ago class.jetpack.php 6 years ago class.json-api-endpoints.php 6 years ago class.json-api.php 7 years ago class.photon.php 6 years ago composer.json 6 years ago functions.compat.php 6 years ago functions.gallery.php 6 years ago functions.global.php 6 years ago functions.opengraph.php 7 years ago functions.photon.php 6 years ago jest.config.js 7 years ago jetpack.php 6 years ago json-api-config.php 10 years ago json-endpoints.php 7 years ago load-jetpack.php 6 years ago locales.php 7 years ago readme.txt 6 years ago require-lib.php 6 years ago uninstall.php 6 years ago wpml-config.xml 10 years ago
class.jetpack-user-agent.php
1512 lines
1 <?php
2
3 /**
4 * Determine if the current User Agent matches the passed $kind
5 *
6 * @param string $kind Category of mobile device to check for.
7 * Either: any, dumb, smart.
8 * @param bool $return_matched_agent Boolean indicating if the UA should be returned
9 *
10 * @return bool|string Boolean indicating if current UA matches $kind. If
11 * $return_matched_agent is true, returns the UA string
12 */
13 function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) {
14 static $kinds = array( 'smart' => false, 'dumb' => false, 'any' => false );
15 static $first_run = true;
16 static $matched_agent = '';
17
18 // If an invalid kind is passed in, reset it to default.
19 if ( ! isset( $kinds[ $kind ] ) ) {
20 $kind = 'any';
21 }
22
23 if ( function_exists( 'apply_filters' ) ) {
24 /**
25 * Filter the value of jetpack_is_mobile before it is calculated.
26 *
27 * Passing a truthy value to the filter will short-circuit determining the
28 * mobile type, returning the passed value instead.
29 *
30 * @since 4.2.0
31 *
32 * @param bool|string $matches Boolean if current UA matches $kind or not. If
33 * $return_matched_agent is true, should return the UA string
34 * @param string $kind Category of mobile device being checked
35 * @param bool $return_matched_agent Boolean indicating if the UA should be returned
36 */
37 $pre = apply_filters( 'pre_jetpack_is_mobile', null, $kind, $return_matched_agent );
38
39 if ( null !== $pre ) {
40 return $pre;
41 }
42 }
43
44 $ua_info = new Jetpack_User_Agent_Info();
45
46 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) || strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'ipad' ) ) {
47 return false;
48 }
49
50 // Remove Samsung Galaxy tablets (SCH-I800) from being mobile devices
51 if ( strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ) , 'sch-i800') ) {
52 return false;
53 }
54
55 if( $ua_info->is_android_tablet() && false === $ua_info->is_kindle_touch() ) {
56 return false;
57 }
58
59 if( $ua_info->is_blackberry_tablet() ) {
60 return false;
61 }
62
63 if ( $first_run ) {
64 $first_run = false;
65
66 //checks for iPhoneTier devices & RichCSS devices
67 if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) {
68 $kinds['smart'] = true;
69 $matched_agent = $ua_info->matched_agent;
70 }
71
72 if ( ! $kinds['smart'] ) {
73 // if smart, we are not dumb so no need to check
74 $dumb_agents = $ua_info->dumb_agents;
75 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
76
77 foreach ( $dumb_agents as $dumb_agent ) {
78 if ( false !== strpos( $agent, $dumb_agent ) ) {
79 $kinds['dumb'] = true;
80 $matched_agent = $dumb_agent;
81
82 break;
83 }
84 }
85
86 if ( ! $kinds['dumb'] ) {
87 if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
88 $kinds['dumb'] = true;
89 $matched_agent = 'http_x_wap_profile';
90 } elseif ( isset( $_SERVER['HTTP_ACCEPT']) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) {
91 $kinds['dumb'] = true;
92 $matched_agent = 'vnd.wap.xhtml+xml';
93 }
94 }
95 }
96
97 if ( $kinds['dumb'] || $kinds['smart'] ) {
98 $kinds['any'] = true;
99 }
100 }
101
102 $value = $kinds[ $kind ];
103
104 if ( $return_matched_agent ) {
105 $value = $matched_agent;
106 }
107
108 if ( function_exists( 'apply_filters' ) ) {
109 /**
110 * Filter the value of jetpack_is_mobile
111 *
112 * @since 4.2.0
113 *
114 * @param bool|string $matches Boolean if current UA matches $kind or not. If
115 * $return_matched_agent is true, should return the UA string
116 * @param string $kind Category of mobile device being checked
117 * @param bool $return_matched_agent Boolean indicating if the UA should be returned
118 */
119 $value = apply_filters( 'jetpack_is_mobile', $value, $kind, $return_matched_agent );
120 }
121
122 return $value;
123 }
124
125 class Jetpack_User_Agent_Info {
126
127 public $useragent;
128 public $matched_agent;
129 public $isTierIphone; //Stores whether is the iPhone tier of devices.
130 public $isTierRichCss; //Stores whether the device can probably support Rich CSS, but JavaScript (jQuery) support is not assumed.
131 public $isTierGenericMobile; //Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR)
132
133 private $_platform = null; //Stores the device platform name
134 const PLATFORM_WINDOWS = 'windows';
135 const PLATFORM_IPHONE = 'iphone';
136 const PLATFORM_IPOD = 'ipod';
137 const PLATFORM_IPAD = 'ipad';
138 const PLATFORM_BLACKBERRY = 'blackberry';
139 const PLATFORM_BLACKBERRY_10 = 'blackberry_10';
140 const PLATFORM_SYMBIAN = 'symbian_series60';
141 const PLATFORM_SYMBIAN_S40 = 'symbian_series40';
142 const PLATFORM_J2ME_MIDP = 'j2me_midp';
143 const PLATFORM_ANDROID = 'android';
144 const PLATFORM_ANDROID_TABLET = 'android_tablet';
145 const PLATFORM_FIREFOX_OS = 'firefoxOS';
146
147 public $dumb_agents = array(
148 'nokia', 'blackberry', 'philips', 'samsung', 'sanyo', 'sony', 'panasonic', 'webos',
149 'ericsson', 'alcatel', 'palm',
150 'windows ce', 'opera mini', 'series60', 'series40',
151 'au-mic,', 'audiovox', 'avantgo', 'blazer',
152 'danger', 'docomo', 'epoc',
153 'ericy', 'i-mode', 'ipaq', 'midp-',
154 'mot-', 'netfront', 'nitro',
155 'palmsource', 'pocketpc', 'portalmmm',
156 'rover', 'sie-',
157 'symbian', 'cldc-', 'j2me',
158 'smartphone', 'up.browser', 'up.link',
159 'up.link', 'vodafone/', 'wap1.', 'wap2.', 'mobile', 'googlebot-mobile',
160 );
161
162 //The constructor. Initializes default variables.
163 function __construct()
164 {
165 if ( !empty( $_SERVER['HTTP_USER_AGENT'] ) )
166 $this->useragent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
167 }
168
169 /**
170 * This method detects the mobile User Agent name.
171 *
172 * @return string The matched User Agent name, false otherwise.
173 */
174 function get_mobile_user_agent_name() {
175 if( $this->is_chrome_for_iOS( ) ) //keep this check before the safari rule
176 return 'chrome-for-ios';
177 elseif ( $this->is_iphone_or_ipod( 'iphone-safari' ) )
178 return 'iphone';
179 elseif ( $this->is_ipad( 'ipad-safari' ) )
180 return 'ipad';
181 elseif ( $this->is_android_tablet() ) //keep this check before the android rule
182 return 'android_tablet';
183 elseif ( $this->is_android() )
184 return 'android';
185 elseif ( $this->is_blackberry_10() )
186 return 'blackberry_10';
187 elseif ( $this->is_blackbeberry() )
188 return 'blackberry';
189 elseif ( $this->is_WindowsPhone7() )
190 return 'win7';
191 elseif ( $this->is_windows_phone_8() )
192 return 'winphone8';
193 elseif ( $this->is_opera_mini() )
194 return 'opera-mini';
195 elseif ( $this->is_opera_mini_dumb() )
196 return 'opera-mini-dumb';
197 elseif ( $this->is_opera_mobile() )
198 return 'opera-mobi';
199 elseif ( $this->is_blackberry_tablet() )
200 return 'blackberry_tablet';
201 elseif ( $this->is_kindle_fire() )
202 return 'kindle-fire';
203 elseif ( $this->is_PalmWebOS() )
204 return 'webos';
205 elseif ( $this->is_S60_OSSBrowser() )
206 return 'series60';
207 elseif ( $this->is_firefox_os() )
208 return 'firefoxOS';
209 elseif ( $this->is_firefox_mobile() )
210 return 'firefox_mobile';
211 elseif ( $this->is_MaemoTablet() )
212 return 'maemo';
213 elseif ( $this->is_MeeGo() )
214 return 'meego';
215 elseif( $this->is_TouchPad() )
216 return 'hp_tablet';
217 elseif ( $this->is_facebook_for_iphone() )
218 return 'facebook-for-iphone';
219 elseif ( $this->is_facebook_for_ipad() )
220 return 'facebook-for-ipad';
221 elseif ( $this->is_twitter_for_iphone() )
222 return 'twitter-for-iphone';
223 elseif ( $this->is_twitter_for_ipad() )
224 return 'twitter-for-ipad';
225 elseif ( $this->is_wordpress_for_ios() )
226 return 'ios-app';
227 elseif ( $this->is_iphone_or_ipod( 'iphone-not-safari' ) )
228 return 'iphone-unknown';
229 elseif ( $this->is_ipad( 'ipad-not-safari' ) )
230 return 'ipad-unknown';
231 elseif ( $this->is_Nintendo_3DS() )
232 return 'nintendo-3ds';
233 else {
234 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
235 $dumb_agents = $this->dumb_agents;
236 foreach ( $dumb_agents as $dumb_agent ) {
237 if ( false !== strpos( $agent, $dumb_agent ) ) {
238 return $dumb_agent;
239 }
240 }
241 }
242
243 return false;
244 }
245
246 /**
247 * This method detects the mobile device's platform. All return strings are from the class constants.
248 * Note that this function returns the platform name, not the UA name/type. You should use a different function
249 * if you need to test the UA capabilites.
250 *
251 * @return string Name of the platform, false otherwise.
252 */
253 public function get_platform() {
254 if ( isset( $this->_platform ) ) {
255 return $this->_platform;
256 }
257
258 if ( strpos( $this->useragent, 'windows phone' ) !== false ) {
259 $this->_platform = self::PLATFORM_WINDOWS;
260 }
261 elseif ( strpos( $this->useragent, 'windows ce' ) !== false ) {
262 $this->_platform = self::PLATFORM_WINDOWS;
263 }
264 elseif ( strpos( $this->useragent, 'ipad' ) !== false ) {
265 $this->_platform = self::PLATFORM_IPAD;
266 }
267 else if ( strpos( $this->useragent, 'ipod' ) !== false ) {
268 $this->_platform = self::PLATFORM_IPOD;
269 }
270 else if ( strpos( $this->useragent, 'iphone' ) !== false ) {
271 $this->_platform = self::PLATFORM_IPHONE;
272 }
273 elseif ( strpos( $this->useragent, 'android' ) !== false ) {
274 if ( $this->is_android_tablet() )
275 $this->_platform = self::PLATFORM_ANDROID_TABLET;
276 else
277 $this->_platform = self::PLATFORM_ANDROID;
278 }
279 elseif ( $this->is_kindle_fire() ) {
280 $this->_platform = self::PLATFORM_ANDROID_TABLET;
281 }
282 elseif ( $this->is_blackberry_10() ) {
283 $this->_platform = self::PLATFORM_BLACKBERRY_10;
284 }
285 elseif ( strpos( $this->useragent, 'blackberry' ) !== false ) {
286 $this->_platform = self::PLATFORM_BLACKBERRY;
287 }
288 elseif ( $this->is_blackberry_tablet() ) {
289 $this->_platform = self::PLATFORM_BLACKBERRY;
290 }
291 elseif ( $this->is_symbian_platform() ) {
292 $this->_platform = self::PLATFORM_SYMBIAN;
293 }
294 elseif ( $this->is_symbian_s40_platform() ) {
295 $this->_platform = self::PLATFORM_SYMBIAN_S40;
296 }
297 elseif ( $this->is_J2ME_platform() ) {
298 $this->_platform = self::PLATFORM_J2ME_MIDP;
299 }
300 elseif ( $this->is_firefox_os() ) {
301 $this->_platform = self::PLATFORM_FIREFOX_OS;
302 }
303 else
304 $this->_platform = false;
305
306 return $this->_platform;
307 }
308
309 /*
310 * This method detects for UA which can display iPhone-optimized web content.
311 * Includes iPhone, iPod Touch, Android, WebOS, Fennec (Firefox mobile), etc.
312 *
313 */
314 function isTierIphone() {
315 if ( isset( $this->isTierIphone ) ) {
316 return $this->isTierIphone;
317 }
318 if ( $this->is_iphoneOrIpod() ) {
319 $this->matched_agent = 'iphone';
320 $this->isTierIphone = true;
321 $this->isTierRichCss = false;
322 $this->isTierGenericMobile = false;
323 }
324 elseif ( $this->is_android() ) {
325 $this->matched_agent = 'android';
326 $this->isTierIphone = true;
327 $this->isTierRichCss = false;
328 $this->isTierGenericMobile = false;
329 }
330 elseif ( $this->is_windows_phone_8() ) {
331 $this->matched_agent = 'winphone8';
332 $this->isTierIphone = true;
333 $this->isTierRichCss = false;
334 $this->isTierGenericMobile = false;
335 }
336 elseif ( $this->is_WindowsPhone7() ) {
337 $this->matched_agent = 'win7';
338 $this->isTierIphone = true;
339 $this->isTierRichCss = false;
340 $this->isTierGenericMobile = false;
341 }
342 elseif ( $this->is_blackberry_10() ) {
343 $this->matched_agent = 'blackberry-10';
344 $this->isTierIphone = true;
345 $this->isTierRichCss = false;
346 $this->isTierGenericMobile = false;
347 }
348 elseif ( $this->is_blackbeberry() && $this->detect_blackberry_browser_version() == 'blackberry-webkit' ) {
349 $this->matched_agent = 'blackberry-webkit';
350 $this->isTierIphone = true;
351 $this->isTierRichCss = false;
352 $this->isTierGenericMobile = false;
353 }
354 elseif ( $this->is_blackberry_tablet() ) {
355 $this->matched_agent = 'blackberry_tablet';
356 $this->isTierIphone = true;
357 $this->isTierRichCss = false;
358 $this->isTierGenericMobile = false;
359 }
360 elseif ( $this->is_PalmWebOS() ) {
361 $this->matched_agent = 'webos';
362 $this->isTierIphone = true;
363 $this->isTierRichCss = false;
364 $this->isTierGenericMobile = false;
365 }
366 elseif ( $this->is_TouchPad() ) {
367 $this->matched_agent = 'hp_tablet';
368 $this->isTierIphone = true;
369 $this->isTierRichCss = false;
370 $this->isTierGenericMobile = false;
371 }
372 elseif ( $this->is_firefox_os() ) {
373 $this->matched_agent = 'firefoxOS';
374 $this->isTierIphone = true;
375 $this->isTierRichCss = false;
376 $this->isTierGenericMobile = false;
377 }
378 elseif ( $this->is_firefox_mobile() ) {
379 $this->matched_agent = 'fennec';
380 $this->isTierIphone = true;
381 $this->isTierRichCss = false;
382 $this->isTierGenericMobile = false;
383 }
384 elseif ( $this->is_opera_mobile() ) {
385 $this->matched_agent = 'opera-mobi';
386 $this->isTierIphone = true;
387 $this->isTierRichCss = false;
388 $this->isTierGenericMobile = false;
389 }
390 elseif ( $this->is_MaemoTablet() ) {
391 $this->matched_agent = 'maemo';
392 $this->isTierIphone = true;
393 $this->isTierRichCss = false;
394 $this->isTierGenericMobile = false;
395 }
396 elseif ( $this->is_MeeGo() ) {
397 $this->matched_agent = 'meego';
398 $this->isTierIphone = true;
399 $this->isTierRichCss = false;
400 $this->isTierGenericMobile = false;
401 }
402 elseif ( $this->is_kindle_touch() ) {
403 $this->matched_agent = 'kindle-touch';
404 $this->isTierIphone = true;
405 $this->isTierRichCss = false;
406 $this->isTierGenericMobile = false;
407 }
408 elseif ( $this->is_Nintendo_3DS() ) {
409 $this->matched_agent = 'nintendo-3ds';
410 $this->isTierIphone = true;
411 $this->isTierRichCss = false;
412 $this->isTierGenericMobile = false;
413 }
414 else {
415 $this->isTierIphone = false;
416 }
417 return $this->isTierIphone;
418 }
419
420 /*
421 * This method detects for UA which are likely to be capable
422 * but may not necessarily support JavaScript.
423 * Excludes all iPhone Tier UA.
424 *
425 */
426 function isTierRichCss(){
427 if ( isset( $this->isTierRichCss ) ) {
428 return $this->isTierRichCss;
429 }
430 if ($this->isTierIphone())
431 return false;
432
433 //The following devices are explicitly ok.
434 if ( $this->is_S60_OSSBrowser() ) {
435 $this->matched_agent = 'series60';
436 $this->isTierIphone = false;
437 $this->isTierRichCss = true;
438 $this->isTierGenericMobile = false;
439 }
440 elseif ( $this->is_opera_mini() ) {
441 $this->matched_agent = 'opera-mini';
442 $this->isTierIphone = false;
443 $this->isTierRichCss = true;
444 $this->isTierGenericMobile = false;
445 }
446 elseif ( $this->is_blackbeberry() ) {
447 $detectedDevice = $this->detect_blackberry_browser_version();
448 if ( $detectedDevice === 'blackberry-5' || $detectedDevice == 'blackberry-4.7' || $detectedDevice === 'blackberry-4.6' ) {
449 $this->matched_agent = $detectedDevice;
450 $this->isTierIphone = false;
451 $this->isTierRichCss = true;
452 $this->isTierGenericMobile = false;
453 }
454 }
455 else {
456 $this->isTierRichCss = false;
457 }
458
459 return $this->isTierRichCss;
460 }
461
462 // Detects if the user is using a tablet.
463 // props Corey Gilmore, BGR.com
464 static function is_tablet() {
465 return ( 0 // never true, but makes it easier to manage our list of tablet conditions
466 || self::is_ipad()
467 || self::is_android_tablet()
468 || self::is_blackberry_tablet()
469 || self::is_kindle_fire()
470 || self::is_MaemoTablet()
471 || self::is_TouchPad()
472 );
473 }
474
475 /*
476 * Detects if the current UA is the default iPhone or iPod Touch Browser.
477 *
478 * DEPRECATED: use is_iphone_or_ipod
479 *
480 */
481 static function is_iphoneOrIpod(){
482
483 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
484 return false;
485
486 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
487 if ( ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua,'ipod' ) !== false ) ) {
488 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
489 return false;
490 else
491 return true;
492 }
493 else
494 return false;
495 }
496
497
498 /*
499 * Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser.
500 *
501 * They type can check for any iPhone, an iPhone using Safari, or an iPhone using something other than Safari.
502 *
503 * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPhone browser),
504 * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'.
505 * Otherwise those browsers will be 'catched' by the iphone string.
506 *
507 */
508 static function is_iphone_or_ipod( $type = 'iphone-any' ) {
509
510 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
511 return false;
512
513 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
514 $is_iphone = ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua,'ipod' ) !== false );
515 $is_safari = ( false !== strpos( $ua, 'safari' ) );
516
517 if ( 'iphone-safari' == $type )
518 return $is_iphone && $is_safari;
519 elseif ( 'iphone-not-safari' == $type )
520 return $is_iphone && !$is_safari;
521 else
522 return $is_iphone;
523 }
524
525
526 /*
527 * Detects if the current UA is Chrome for iOS
528 *
529 * The User-Agent string in Chrome for iOS is the same as the Mobile Safari User-Agent, with CriOS/<ChromeRevision> instead of Version/<VersionNum>.
530 * - Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
531 */
532 static function is_chrome_for_iOS( ) {
533 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
534 return false;
535
536 if ( self::is_iphone_or_ipod( 'iphone-safari' ) === false ) return false;
537
538 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
539
540 if ( strpos( $ua, 'crios/' ) !== false )
541 return true;
542 else
543 return false;
544 }
545
546
547 /*
548 * Detects if the current UA is Twitter for iPhone
549 *
550 * Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; nb-no) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1 Twitter for iPhone
551 * Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 Twitter for iPhone
552 *
553 */
554 static function is_twitter_for_iphone( ) {
555 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
556 return false;
557
558 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
559
560 if ( strpos( $ua, 'ipad' ) !== false )
561 return false;
562
563 if ( strpos( $ua, 'twitter for iphone' ) !== false )
564 return true;
565 else
566 return false;
567 }
568
569 /*
570 * Detects if the current UA is Twitter for iPad
571 *
572 * Old version 4.X - Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1 Twitter for iPad
573 * Ver 5.0 or Higher - Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 Twitter for iPhone
574 *
575 */
576 static function is_twitter_for_ipad( ) {
577 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
578 return false;
579
580 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
581
582 if ( strpos( $ua, 'twitter for ipad' ) !== false )
583 return true;
584 elseif( strpos( $ua, 'ipad' ) !== false && strpos( $ua, 'twitter for iphone' ) !== false )
585 return true;
586 else
587 return false;
588 }
589
590
591 /*
592 * Detects if the current UA is Facebook for iPhone
593 * - Facebook 4020.0 (iPhone; iPhone OS 5.0.1; fr_FR)
594 * - Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.0.2;FBBV/4020.0;FBDV/iPhone3,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.0;FBSS/2; FBCR/O2;FBID/phone;FBLC/en_US;FBSF/2.0]
595 * - Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 [FBAN/FBIOS;FBAV/5.0;FBBV/47423;FBDV/iPhone3,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.1.1;FBSS/2; FBCR/3ITA;FBID/phone;FBLC/en_US]
596 */
597 static function is_facebook_for_iphone( ) {
598 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
599 return false;
600
601 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
602
603 if( false === strpos( $ua, 'iphone' ) )
604 return false;
605
606 if ( false !== strpos( $ua, 'facebook' ) && false === strpos( $ua, 'ipad' ) )
607 return true;
608 else if ( false !== strpos( $ua, 'fbforiphone' ) && false === strpos( $ua, 'tablet' ) )
609 return true;
610 else if ( false !== strpos( $ua, 'fban/fbios;' ) && false === strpos( $ua, 'tablet' ) ) //FB app v5.0 or higher
611 return true;
612 else
613 return false;
614 }
615
616 /*
617 * Detects if the current UA is Facebook for iPad
618 * - Facebook 4020.0 (iPad; iPhone OS 5.0.1; en_US)
619 * - Mozilla/5.0 (iPad; U; CPU iPhone OS 5_0 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.0.2;FBBV/4020.0;FBDV/iPad2,1;FBMD/iPad;FBSN/iPhone OS;FBSV/5.0;FBSS/1; FBCR/;FBID/tablet;FBLC/en_US;FBSF/1.0]
620 * - Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A403 [FBAN/FBIOS;FBAV/5.0;FBBV/47423;FBDV/iPad2,1;FBMD/iPad;FBSN/iPhone OS;FBSV/6.0;FBSS/1; FBCR/;FBID/tablet;FBLC/en_US]
621 */
622 static function is_facebook_for_ipad( ) {
623 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
624 return false;
625
626 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
627
628 if ( false === strpos( $ua, 'ipad' ) )
629 return false;
630
631 if ( false !== strpos( $ua, 'facebook' ) || false !== strpos( $ua, 'fbforiphone' ) || false !== strpos( $ua, 'fban/fbios;' ) )
632 return true;
633 else
634 return false;
635 }
636
637 /*
638 * Detects if the current UA is WordPress for iOS
639 */
640 static function is_wordpress_for_ios( ) {
641 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
642 return false;
643
644 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
645 if ( false !== strpos( $ua, 'wp-iphone' ) )
646 return true;
647 else
648 return false;
649 }
650
651 /*
652 * Detects if the current device is an iPad.
653 * They type can check for any iPad, an iPad using Safari, or an iPad using something other than Safari.
654 *
655 * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPad browser),
656 * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'.
657 * Otherwise those browsers will be 'catched' by the ipad string.
658 *
659 */
660 static function is_ipad( $type = 'ipad-any' ) {
661
662 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
663 return false;
664
665 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
666
667 $is_ipad = ( false !== strpos( $ua, 'ipad' ) );
668 $is_safari = ( false !== strpos( $ua, 'safari' ) );
669
670 if ( 'ipad-safari' == $type )
671 return $is_ipad && $is_safari;
672 elseif ( 'ipad-not-safari' == $type )
673 return $is_ipad && !$is_safari;
674 else
675 return $is_ipad;
676 }
677
678 /*
679 * Detects if the current browser is Firefox Mobile (Fennec)
680 *
681 * http://www.useragentstring.com/pages/Fennec/
682 * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.1.1) Gecko/20110415 Firefox/4.0.2pre Fennec/4.0.1
683 * Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1
684 */
685 static function is_firefox_mobile( ) {
686
687 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
688 return false;
689
690 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
691
692 if ( strpos( $ua, 'fennec' ) !== false )
693 return true;
694 else
695 return false;
696 }
697
698 /*
699 * Detects if the current browser is Firefox for desktop
700 *
701 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
702 * Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
703 * The platform section will include 'Mobile' for phones and 'Tablet' for tablets.
704 *
705 */
706 static function is_firefox_desktop() {
707
708 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
709 return false;
710 }
711
712 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
713
714 if ( false !== strpos( $ua, 'firefox' ) && false === strpos( $ua, 'mobile' ) && false === strpos( $ua, 'tablet' ) ) {
715 return true;
716 } else {
717 return false;
718 }
719 }
720
721 /*
722 * Detects if the current browser is FirefoxOS Native browser
723 *
724 * Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0
725 *
726 */
727 static function is_firefox_os( ) {
728
729 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
730 return false;
731
732 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
733
734 if ( strpos( $ua, 'mozilla' ) !== false && strpos( $ua, 'mobile' ) !== false && strpos( $ua, 'gecko' ) !== false && strpos( $ua, 'firefox' ) !== false)
735 return true;
736 else
737 return false;
738 }
739
740
741 /*
742 * Detects if the current browser is Opera Mobile
743 *
744 * What is the difference between Opera Mobile and Opera Mini?
745 * - Opera Mobile is a full Internet browser for mobile devices.
746 * - Opera Mini always uses a transcoder to convert the page for a small display.
747 * (it uses Opera advanced server compression technology to compress web content before it gets to a device.
748 * The rendering engine is on Opera's server.)
749 *
750 * Opera/9.80 (Windows NT 6.1; Opera Mobi/14316; U; en) Presto/2.7.81 Version/11.00"
751 * Opera/9.50 (Nintendo DSi; Opera/507; U; en-US)
752 */
753 static function is_opera_mobile( ) {
754
755 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
756 return false;
757
758 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
759
760 if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mobi' ) !== false )
761 return true;
762 elseif ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'nintendo dsi' ) !== false )
763 return true;
764 else
765 return false;
766 }
767
768
769 /*
770 * Detects if the current browser is Opera Mini
771 *
772 * Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr)
773 * Opera/9.80 (Android;Opera Mini/6.0.24212/24.746 U;en) Presto/2.5.25 Version/10.5454
774 * Opera/9.80 (iPhone; Opera Mini/5.0.019802/18.738; U; en) Presto/2.4.15
775 * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15
776 * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15
777 * Opera/9.80 (Series 60; Opera Mini/5.1.22783/23.334; U; en) Presto/2.5.25 Version/10.54
778 * Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/22.387; U; en) Presto/2.5.25 Version/10.54
779 *
780 */
781 static function is_opera_mini( ) {
782
783 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
784 return false;
785
786 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
787
788 if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mini' ) !== false )
789 return true;
790 else
791 return false;
792 }
793
794 /*
795 * Detects if the current browser is Opera Mini, but not on a smart device OS(Android, iOS, etc)
796 * Used to send users on dumb devices to m.wor
797 */
798 static function is_opera_mini_dumb( ) {
799
800 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
801 return false;
802 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
803
804 if ( self::is_opera_mini() ) {
805 if ( strpos( $ua, 'android' ) !== false || strpos( $ua, 'iphone' ) !== false || strpos( $ua, 'ipod' ) !== false
806 || strpos( $ua, 'ipad' ) !== false || strpos( $ua, 'blackberry' ) !== false)
807 return false;
808 else
809 return true;
810 } else {
811 return false;
812 }
813 }
814
815 /*
816 * Detects if the current browser is Opera Mobile or Mini.
817 * DEPRECATED: use is_opera_mobile or is_opera_mini
818 *
819 * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0
820 * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr)
821 */
822 static function is_OperaMobile() {
823 _deprecated_function( __FUNCTION__, 'always', 'is_opera_mini() or is_opera_mobile()' );
824
825 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
826 return false;
827
828 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
829
830 if ( strpos( $ua, 'opera' ) !== false ) {
831 if ( ( strpos( $ua, 'mini' ) !== false ) || ( strpos( $ua,'mobi' ) !== false ) )
832 return true;
833 else
834 return false;
835 } else {
836 return false;
837 }
838 }
839
840 /*
841 * Detects if the current browser is a Windows Phone 7 device.
842 * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910)
843 */
844 static function is_WindowsPhone7() {
845 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
846 return false;
847
848 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
849
850 if ( false === strpos( $ua, 'windows phone os 7' ) ) {
851 return false;
852 } else {
853 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
854 return false;
855 else
856 return true;
857 }
858 }
859
860 /*
861 * Detects if the current browser is a Windows Phone 8 device.
862 * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>])
863 */
864 static function is_windows_phone_8() {
865 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
866 return false;
867
868 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
869 if ( strpos( $ua, 'windows phone 8' ) === false ) {
870 return false;
871 } else {
872 return true;
873 }
874 }
875
876
877 /*
878 * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad.
879 *
880 * ex1: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1
881 * ex2: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1
882 *
883 */
884 static function is_PalmWebOS() {
885 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
886 return false;
887
888 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
889
890 if ( false === strpos( $ua, 'webos' ) ) {
891 return false;
892 } else {
893 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
894 return false;
895 else
896 return true;
897 }
898 }
899
900 /*
901 * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS.
902 *
903 * TouchPad Emulator: Mozilla/5.0 (hp-desktop; Linux; hpwOS/2.0; U; it-IT) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 Desktop/1.0
904 * TouchPad: Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0
905 *
906 */
907 static function is_TouchPad() {
908 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
909 return false;
910
911 $http_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
912 if ( false !== strpos( $http_user_agent, 'hp-tablet' ) || false !== strpos( $http_user_agent, 'hpwos' ) || false !== strpos( $http_user_agent, 'touchpad' ) ) {
913 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
914 return false;
915 else
916 return true;
917 }
918 else
919 return false;
920 }
921
922
923 /*
924 * Detects if the current browser is the Series 60 Open Source Browser.
925 *
926 * OSS Browser 3.2 on E75: Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1/110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413
927 *
928 * 7.0 Browser (Nokia 5800 XpressMusic (v21.0.025)) : Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/21.0.025; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413
929 *
930 * Browser 7.1 (Nokia N97 (v12.0.024)) : Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344
931 *
932 */
933 static function is_S60_OSSBrowser() {
934
935 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
936 return false;
937
938 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
939 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
940 return false;
941
942 $pos_webkit = strpos( $agent, 'webkit' );
943 if ( $pos_webkit !== false ) {
944 //First, test for WebKit, then make sure it's either Symbian or S60.
945 if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) {
946 return true;
947 } else
948 return false;
949 } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent,'series60' ) !== false ) {
950 return true;
951 } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent,'series60' ) !== false ) {
952 return true;
953 }
954
955 return false;
956 }
957
958 /*
959 *
960 * Detects if the device platform is the Symbian Series 60.
961 *
962 */
963 static function is_symbian_platform() {
964
965 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
966 return false;
967
968 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
969
970 $pos_webkit = strpos( $agent, 'webkit' );
971 if ( $pos_webkit !== false ) {
972 //First, test for WebKit, then make sure it's either Symbian or S60.
973 if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) {
974 return true;
975 } else
976 return false;
977 } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent,'series60' ) !== false ) {
978 return true;
979 } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent,'series60' ) !== false ) {
980 return true;
981 } elseif ( strpos( $agent, 'opera mini' ) !== false ) {
982 if( strpos( $agent,'symbianos' ) !== false || strpos( $agent,'symbos' ) !== false || strpos( $agent,'series 60' ) !== false )
983 return true;
984 }
985
986 return false;
987 }
988
989 /*
990 *
991 * Detects if the device platform is the Symbian Series 40.
992 * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser.
993 * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'.
994 *
995 */
996 static function is_symbian_s40_platform() {
997
998 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
999 return false;
1000
1001 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1002
1003 if ( strpos( $agent, 'series40' ) !== false ) {
1004 if( strpos( $agent,'nokia' ) !== false || strpos( $agent,'ovibrowser' ) !== false || strpos( $agent,'nokiabrowser' ) !== false )
1005 return true;
1006 }
1007
1008 return false;
1009 }
1010
1011 static function is_J2ME_platform() {
1012
1013 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1014 return false;
1015
1016 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1017
1018 if ( strpos( $agent, 'j2me/midp' ) !== false ) {
1019 return true;
1020 } elseif ( strpos( $agent, 'midp' ) !== false && strpos( $agent, 'cldc' ) ) {
1021 return true;
1022 }
1023
1024 return false;
1025 }
1026
1027
1028 /*
1029 * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets.
1030 */
1031 static function is_MaemoTablet() {
1032
1033 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1034 return false;
1035
1036 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1037
1038 $pos_maemo = strpos( $agent, 'maemo' );
1039 if ( $pos_maemo === false ) return false;
1040
1041 //Must be Linux + Tablet, or else it could be something else.
1042 if ( strpos( $agent, 'tablet' ) !== false && strpos( $agent, 'linux' ) !== false ) {
1043 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
1044 return false;
1045 else
1046 return true;
1047 } else
1048 return false;
1049 }
1050
1051 /*
1052 * Detects if the current UA is a MeeGo device (Nokia Smartphone).
1053 */
1054 static function is_MeeGo() {
1055
1056 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1057 return false;
1058
1059 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1060
1061 if ( false === strpos( $ua, 'meego' ) ) {
1062 return false;
1063 } else {
1064 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
1065 return false;
1066 else
1067 return true;
1068 }
1069 }
1070
1071
1072 /*
1073 is_webkit() can be used to check the User Agent for an webkit generic browser
1074 */
1075 static function is_webkit() {
1076
1077 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1078 return false;
1079
1080 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1081
1082 $pos_webkit = strpos( $agent, 'webkit' );
1083
1084 if ( $pos_webkit !== false )
1085 return true;
1086 else
1087 return false;
1088 }
1089
1090 /**
1091 * Detects if the current browser is the Native Android browser.
1092 * @return boolean true if the browser is Android otherwise false
1093 */
1094 static function is_android() {
1095 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1096 return false;
1097
1098 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1099 $pos_android = strpos( $agent, 'android' );
1100 if ( $pos_android !== false ) {
1101 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
1102 return false;
1103 else
1104 return true;
1105 }
1106 else
1107 return false;
1108 }
1109
1110
1111 /**
1112 * Detects if the current browser is the Native Android Tablet browser.
1113 * Assumes 'Android' should be in the user agent, but not 'mobile'
1114 *
1115 * @return boolean true if the browser is Android and not 'mobile' otherwise false
1116 */
1117 static function is_android_tablet( ) {
1118 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1119 return false;
1120
1121 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1122
1123 $pos_android = strpos( $agent, 'android' );
1124 $pos_mobile = strpos( $agent, 'mobile' );
1125 $post_android_app = strpos( $agent, 'wp-android' );
1126
1127 if ( false !== $pos_android && false === $pos_mobile && false === $post_android_app ) {
1128 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
1129 return false;
1130 else
1131 return true;
1132 } else
1133 return false;
1134 }
1135
1136 /**
1137 * Detects if the current browser is the Kindle Fire Native browser.
1138 *
1139 * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true
1140 * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=false
1141 *
1142 * @return boolean true if the browser is Kindle Fire Native browser otherwise false
1143 */
1144 static function is_kindle_fire( ) {
1145 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1146 return false;
1147
1148 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1149 $pos_silk = strpos( $agent, 'silk/' );
1150 $pos_silk_acc = strpos( $agent, 'silk-accelerated=' );
1151 if ( $pos_silk !== false && $pos_silk_acc !== false )
1152 return true;
1153 else
1154 return false;
1155 }
1156
1157
1158 /**
1159 * Detects if the current browser is the Kindle Touch Native browser
1160 *
1161 * Mozilla/5.0 (X11; U; Linux armv7l like Android; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/533.2+ Kindle/3.0+
1162 *
1163 * @return boolean true if the browser is Kindle monochrome Native browser otherwise false
1164 */
1165 static function is_kindle_touch( ) {
1166 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1167 return false;
1168 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1169 $pos_kindle_touch = strpos( $agent, 'kindle/3.0+' );
1170 if ( false !== $pos_kindle_touch && false === self::is_kindle_fire() )
1171 return true;
1172 else
1173 return false;
1174 }
1175
1176
1177 // Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet)
1178 static function is_windows8_auth( ) {
1179 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1180 return false;
1181
1182 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1183 $pos = strpos( $agent, 'msauthhost' );
1184 if ( false !== $pos )
1185 return true;
1186 else
1187 return false;
1188 }
1189
1190 // Detect if user agent is the WordPress.com Windows 8 app.
1191 static function is_wordpress_for_win8( ) {
1192 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1193 return false;
1194
1195 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1196 $pos = strpos( $agent, 'wp-windows8' );
1197 if ( false !== $pos )
1198 return true;
1199 else
1200 return false;
1201 }
1202
1203
1204 // Detect if user agent is the WordPress.com Desktop app.
1205 static function is_wordpress_desktop_app( ) {
1206 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1207 return false;
1208
1209 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1210 $pos = strpos( $agent, 'WordPressDesktop' );
1211 if ( false !== $pos )
1212 return true;
1213 else
1214 return false;
1215 }
1216
1217
1218 /*
1219 * is_blackberry_tablet() can be used to check the User Agent for a RIM blackberry tablet
1220 * The user agent of the BlackBerry® Tablet OS follows a format similar to the following:
1221 * Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+
1222 *
1223 */
1224 static function is_blackberry_tablet() {
1225
1226 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1227 return false;
1228
1229 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1230 $pos_playbook = stripos( $agent, 'PlayBook' );
1231 $pos_rim_tablet = stripos( $agent, 'RIM Tablet' );
1232
1233 if ( ( false === $pos_playbook ) || ( false === $pos_rim_tablet ) )
1234 {
1235 return false;
1236 } else {
1237 return true;
1238 }
1239 }
1240
1241 /*
1242 is_blackbeberry() can be used to check the User Agent for a blackberry device
1243 Note that opera mini on BB matches this rule.
1244 */
1245 static function is_blackbeberry() {
1246
1247 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1248 return false;
1249
1250 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1251
1252 $pos_blackberry = strpos( $agent, 'blackberry' );
1253 if ( $pos_blackberry !== false ) {
1254 if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() )
1255 return false;
1256 else
1257 return true;
1258 } else {
1259 return false;
1260 }
1261 }
1262
1263 /*
1264 is_blackberry_10() can be used to check the User Agent for a BlackBerry 10 device.
1265 */
1266 static function is_blackberry_10() {
1267 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1268 return ( strpos( $agent, 'bb10' ) !== false ) && ( strpos( $agent, 'mobile' ) !== false );
1269 }
1270
1271 /**
1272 * Retrieve the blackberry OS version.
1273 *
1274 * Return strings are from the following list:
1275 * - blackberry-10
1276 * - blackberry-7
1277 * - blackberry-6
1278 * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule.
1279 * - blackberry-5
1280 * - blackberry-4.7
1281 * - blackberry-4.6
1282 * - blackberry-4.5
1283 *
1284 * @return string Version of the BB OS.
1285 * If version is not found, get_blackbeberry_OS_version will return boolean false.
1286 */
1287 static function get_blackbeberry_OS_version() {
1288
1289 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1290 return false;
1291
1292 if ( self::is_blackberry_10() ) {
1293 return 'blackberry-10';
1294 }
1295
1296 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1297
1298 $pos_blackberry = stripos( $agent, 'blackberry' );
1299 if ( false === $pos_blackberry ) {
1300 // not a blackberry device
1301 return false;
1302 }
1303
1304 // blackberry devices OS 6.0 or higher
1305 // Mozilla/5.0 (BlackBerry; U; BlackBerry 9670; en) AppleWebKit/534.3+ (KHTML, like Gecko) Version/6.0.0.286 Mobile Safari/534.3+
1306 // Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+
1307 // Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+
1308 $pos_webkit = stripos( $agent, 'webkit' );
1309 if ( false !== $pos_webkit ) {
1310 // detected blackberry webkit browser
1311 $pos_torch = stripos( $agent, 'BlackBerry 9800' );
1312 if ( false !== $pos_torch ) {
1313 return 'blackberry-torch'; // match the torch first edition. the 2nd edition should use the OS7 and doesn't need any special rule
1314 } else {
1315 // detecting the BB OS version for devices running OS 6.0 or higher
1316 if ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) {
1317 $version = $matches[1];
1318 $version_num = explode( '.', $version );
1319 if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
1320 return 'blackberry-6'; // not a BB device that match our rule.
1321 } else {
1322 return 'blackberry-' . $version_num[0];
1323 }
1324 } else {
1325 // if doesn't match returns the minimun version with a webkit browser. we should never fall here.
1326 return 'blackberry-6'; // not a BB device that match our rule.
1327 }
1328 }
1329 }
1330
1331 // blackberry devices <= 5.XX
1332 // BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179
1333 if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) {
1334 $version = $matches[1];
1335 } else {
1336 return false; //not a BB device that match our rule.
1337 }
1338
1339 $version_num = explode( '.', $version );
1340
1341 if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) {
1342 return false;
1343 }
1344 if ( $version_num[0] == 5 ) {
1345 return 'blackberry-5';
1346 } elseif ( $version_num[0] == 4 && $version_num[1] == 7 ) {
1347 return 'blackberry-4.7';
1348 } elseif ( $version_num[0] == 4 && $version_num[1] == 6 ) {
1349 return 'blackberry-4.6';
1350 } elseif ( $version_num[0] == 4 && $version_num[1] == 5 ) {
1351 return 'blackberry-4.5';
1352 } else {
1353 return false;
1354 }
1355
1356 }
1357
1358 /**
1359 * Retrieve the blackberry browser version.
1360 *
1361 * Return string are from the following list:
1362 * - blackberry-10
1363 * - blackberry-webkit
1364 * - blackberry-5
1365 * - blackberry-4.7
1366 * - blackberry-4.6
1367 *
1368 * @return string Type of the BB browser.
1369 * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false.
1370 */
1371 static function detect_blackberry_browser_version() {
1372
1373 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
1374 return false;
1375 }
1376
1377 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1378
1379 if ( self::is_blackberry_10() ) {
1380 return 'blackberry-10';
1381 }
1382
1383 $pos_blackberry = strpos( $agent, 'blackberry' );
1384 if ( false === $pos_blackberry ) {
1385 // not a blackberry device
1386 return false;
1387 }
1388
1389 $pos_webkit = strpos( $agent, 'webkit' );
1390
1391 if ( ! ( false === $pos_webkit ) ) {
1392 return 'blackberry-webkit';
1393 } else {
1394 if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) {
1395 $version = $matches[1];
1396 } else {
1397 return false; // not a BB device that match our rule.
1398 }
1399
1400 $version_num = explode( '.', $version );
1401
1402 if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
1403 return false;
1404 }
1405
1406 if ( $version_num[0] == 5 ) {
1407 return 'blackberry-5';
1408 } elseif ( $version_num[0] == 4 && $version_num[1] == 7 ) {
1409 return 'blackberry-4.7';
1410 } elseif ( $version_num[0] == 4 && $version_num[1] == 6 ) {
1411 return 'blackberry-4.6';
1412 } else {
1413 // A very old BB device is found or this is a BB device that doesn't match our rules.
1414 return false;
1415 }
1416 }
1417
1418 }
1419
1420 // Checks if a visitor is coming from one of the WordPress mobile apps
1421 static function is_mobile_app() {
1422
1423 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1424 return false;
1425
1426 $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1427
1428 if ( isset( $_SERVER['X_USER_AGENT'] ) && preg_match( '|wp-webos|', $_SERVER['X_USER_AGENT'] ) )
1429 return true; //wp4webos 1.1 or higher
1430
1431 $app_agents = array( 'wp-android', 'wp-blackberry', 'wp-iphone', 'wp-nokia', 'wp-webos', 'wp-windowsphone' );
1432 // the mobile reader on iOS has an incorrect UA when loading the reader
1433 // currently it is the default one provided by the iOS framework which
1434 // causes problems with 2-step-auth
1435 // User-Agent WordPress/3.1.4 CFNetwork/609 Darwin/13.0.0
1436 $app_agents[] = 'wordpress/3.1';
1437
1438 foreach ( $app_agents as $app_agent ) {
1439 if ( false !== strpos( $agent, $app_agent ) )
1440 return true;
1441 }
1442 return false;
1443 }
1444
1445 /*
1446 * Detects if the current browser is Nintendo 3DS handheld.
1447 *
1448 * example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US
1449 * can differ in language, version and region
1450 */
1451 static function is_Nintendo_3DS() {
1452 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
1453 return false;
1454 }
1455
1456 $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
1457 if ( strpos( $ua, 'nintendo 3ds' ) !== false ) {
1458 return true;
1459 }
1460 return false;
1461 }
1462
1463 /**
1464 * Was the current request made by a known bot?
1465 *
1466 * @return boolean
1467 */
1468 static function is_bot() {
1469 static $is_bot = null;
1470
1471 if ( is_null( $is_bot ) ) {
1472 $is_bot = Jetpack_User_Agent_Info::is_bot_user_agent( $_SERVER['HTTP_USER_AGENT'] );
1473 }
1474
1475 return $is_bot;
1476 }
1477
1478 /**
1479 * Is the given user-agent a known bot?
1480 * If you want an is_bot check for the current request's UA, use is_bot() instead of passing a user-agent to this method.
1481 *
1482 * @param $ua (string) A user-agent string
1483 * @return boolean
1484 */
1485 static function is_bot_user_agent( $ua = null ) {
1486
1487 if ( empty( $ua ) )
1488 return false;
1489
1490 $bot_agents = array(
1491 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl',
1492 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'httrack', 'ia_archiver', 'irlbot',
1493 'iescholar', 'infoseek', 'jumpbot', 'linkcheck', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot',
1494 'pss-webkit-request', 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop',
1495 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', 'ahrefsbot', 'pingdom.com_bot', 'kraken', 'yandexbot',
1496 'twitterbot', 'tweetmemebot', 'openhosebot', 'queryseekerspider', 'linkdexbot', 'grokkit-crawler',
1497 'livelapbot', 'germcrawler', 'domaintunocrawler', 'grapeshotcrawler', 'cloudflare-alwaysonline',
1498 );
1499
1500 foreach ( $bot_agents as $bot_agent ) {
1501 if ( false !== stripos( $ua, $bot_agent ) ) {
1502 return true;
1503 }
1504 }
1505
1506 return false;
1507 }
1508
1509
1510
1511 }
1512