$context['browser']['is_ie'], $context['browser']['is_ie9'] does not exist!

Started by SoLoGHoST, February 25, 2013, 12:57:32 AM

Previous topic - Next topic

SoLoGHoST

Currently in SMF 2.0.4 is_ie is wrong, and is_ie9 does not exist in Load.php.  I know it is difficult to keep up with all of the millions of different versions of Internet Explorer, since IE 4, but IE 9 has been out for awhile now, and well, would be nice if we were able to use a $context variable that we don't have to create ourselves in our scripts to be able to test for ALL IE versions or just IE 9.

Currently, code is as follows:

$context['browser']['is_ie'] = $context['browser']['is_ie4'] || $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'] || $context['browser']['is_ie7'] || $context['browser']['is_ie8'];

So, just need to include IE 9 in here.

NanoSector

And IE10, and upcoming IE11, ...

I think we need one check to rule them all, not dozens of is_ie# variables.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

SoLoGHoST

I agree!  Also, quite frankly, I don't think we need to check for IE 4 through IE 6.  I believe it's safe to say, that almost no one uses these browsers anymore!

Antechinus

Ever heard of China? Lotsa people there. Lotsa IE6 there. ;)

Since one of the stipulations for 2.0.x was that it would support back to IE6, and since this is already coded, there's not really a lot of point in removing it (although obviously you can if you want to).

A generic ['is_ie'] really isn't that much use, because the different versions of IE have such different characteristics. From IE9 onwards this hopefully wont be the case, but it certainly applies to all earlier versions, so in practice the individual detection is likely to be more use than the generic.

There's already a thread in the private dev boards about adding detection of later versions, and also fixing a few odd conditionals that mistakenly treat IE9 and up as <IE8 (because at the time, IE8 was the highest and had barely been released).

I'm currently using this array:

// The following determines the user agent (browser) as best it can.
$context['browser'] = array(
'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
'is_opera6' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 6') !== false,
'is_opera7' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/7') !== false,
'is_opera8' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 8') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/8') !== false,
'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') === false,
'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false,
'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false,
'is_webkit' => strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'PlayBook') === false,
'is_safari' => strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false,
'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false,
'is_firefox' => strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Android') === false,
// Teh mobile stuffz. Hopefully it will work. :P
'is_iphone' => (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false) && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false,
'is_ipad' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false,
'is_ie_mobile' => (strpos($_SERVER['HTTP_USER_AGENT'], 'PocketIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'IEMobile') !== false),
'is_android_phone' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false,
'is_android_tablet' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') === false,
'is_blackberry' => strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'PlayBook') !== false,
'is_symbian' => strpos($_SERVER['HTTP_USER_AGENT'], 'SymbianOS') !== false,
'is_netfront' => strpos($_SERVER['HTTP_USER_AGENT'], 'NetFront') !== false,
'is_palm' => strpos($_SERVER['HTTP_USER_AGENT'], 'Palm') !== false,
'is_web_os' => strpos($_SERVER['HTTP_USER_AGENT'], 'Web OS') !== false,
'is_opera_mobi' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false,
'is_opera_mini' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false,
'is_fennec' => strpos($_SERVER['HTTP_USER_AGENT'], 'Fennec') !== false,
);

$context['browser']['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_safari'] && !$context['browser']['is_konqueror'];
$context['browser']['is_chrome'] = !$context['browser']['is_android_phone'] && !$context['browser']['is_android_tablet'] && $context['browser']['is_webkit'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false;

// Internet Explorer 5 and 6 are often "emulated".
$context['browser']['is_ie10'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 10') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie9'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie8'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie7'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'];
$context['browser']['is_ie5.5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];
$context['browser']['is_ie5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];


$context['browser']['is_ie'] = $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'] || $context['browser']['is_ie7'] || $context['browser']['is_ie8'] || $context['browser']['is_ie9'] || $context['browser']['is_ie10'];
$context['browser']['is_lte_ie9'] = $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'] || $context['browser']['is_ie7'] || $context['browser']['is_ie8'] || $context['browser']['is_ie9'];


$context['browser']['needs_size_fix'] = false;

$context['browser']['is_mobile'] = $context['browser']['is_iphone'] || $context['browser']['is_ie_mobile'] || $context['browser']['is_android_phone'] || $context['browser']['is_blackberry'] || $context['browser']['is_symbian'] || $context['browser']['is_netfront'] || $context['browser']['is_palm'] || $context['browser']['is_web_os'] || $context['browser']['is_opera_mobi'] || $context['browser']['is_opera_mini'] || $context['browser']['is_fennec'];
$context['browser']['is_tablet'] = $context['browser']['is_ipad'] || $context['browser']['is_android_tablet'];

emanuele

Known bug, already reported, already fixed in 2.1, not going to be fixed (except maybe in "some way") in 2.0. ;)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

NanoSector

Is ie6 may stay but the rest is next to useless and can go to is_ie.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: