News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - groundup

#1
/**
 * Are we using this browser?
 * @param $browser: browser we are checking for.
*/
function isBrowser($browser)
{
   global $context;

   // Don't know any browser!
   if (empty($context['browser']))
      detectBrowser();

   return !empty($context['browser']['is_' . $browser]) || !empty($context['browser'][$browser]);
}

/**
 * This function is... detecting the browser, right.
 * Loads a bunch of browser information in to $context
 */
function detectBrowser()
{
   global $context, $user_info;

   // The following determines the user agent (browser) as best it can.
   $context['browser'] = array(
      // Most desktop browsers.
      'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
      'is_webkit' => strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false,
      'is_firefox' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/~', $_SERVER['HTTP_USER_AGENT']) === 1,
      'is_gecko' = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_webkit'] && !$context['browser']['is_konqueror'];

      // Mobile browsers.
      'is_iphone' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false,
      'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false,

      // Others.
      'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false,
      'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false,
   );

   // Detect IE and not those who wish to emulate it.
   $context['browser']['is_ie'] = !$context['browser']('is_opera') && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1;

   // Detect Safari/Chrome from webkit.
   if ($context['browser']['is_webkit'])
   {
      $context['browser']['is_chrome'] = $context['browser']['is_webkit'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false;
      $context['browser']['is_safari'] = !$context['browser']['is_chrome'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false;
   }

   // More Opera checks if we are opera.
   if ($context['browser']['is_opera'])
      $context['browser'] += array(
         '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_opera9' => preg_match('~Opera[ /]9(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_opera10' => preg_match('~Opera[ /]10\\.~', $_SERVER['HTTP_USER_AGENT']) === 1 || (preg_match('~Opera[ /]9\\.[89]~', $_SERVER['HTTP_USER_AGENT']) === 1 && preg_match('~Version/1[0-9]\\.~', $_SERVER['HTTP_USER_AGENT']) === 1),
      );

   // Additional firefox checks.
   if ($context['browser']['is_firefox'])
      $context['browser'] += array(
         'is_firefox1' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/1\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox2' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/2\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox3' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/3\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
      );

   // Additional IE checks.
   if ($context['browser']['is_ie'])
   {
      $context['browser'] += array(
         'is_ie8' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') !== false,
         'is_ie5.5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false,
         'is_ie5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false;
         'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && !$context['browser']['is_web_tv'],
         'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false,
      );

      // Detect IE7 and not IE8 in combat mode.
      $context['browser']['is_ie7'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_ie8'],

      // Before IE8 we need to fix IE... lots!
      $context['browser']['ie_standards_fix'] = !$context['browser']['is_ie8'];

      $context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_ie8'] && !$context['browser']['is_ie7'];

   }

   if ($context['browser']['is_ie'] || $context['browser']['is_opera'])
      $context['browser']['needs_size_fix'] = ($context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie4'] || $context['browser']['is_opera6']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false;

   // Be you robot or human?
   if ($user_info['possibly_robot'])
   {
      // This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
      $context['browser']['possibly_robot'] = !empty($user_info['possibly_robot']);

      // Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
      if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register'))) || !$user_info['is_guest'])
         $context['browser']['possibly_robot'] = false;
   }
   else
      $context['browser']['possibly_robot'] = false;

}
#2
/**
 * Are we using this browser?
 * @param $browser: browser we are checking for.
*/
function isBrowser($browser)
{
   global $context;

   // Don't know any browser!
   if (empty($context['browser']))
      detectBrowser();

   return !empty($context['browser']['is_' . $browser]);
}

/**
 * This function is... detecting the browser, right.
 * Loads a bunch of browser information in to $context
 */
function detectBrowser()
{
   global $context, $user_info;

   // The following determines the user agent (browser) as best it can.
   $context['browser'] = array(
      // Most desktop browsers.
      'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
      'is_webkit' => strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false,
      'is_firefox' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/~', $_SERVER['HTTP_USER_AGENT']) === 1,
      'is_gecko' = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_webkit'] && !$context['browser']['is_konqueror'];

      // Mobile browsers.
      'is_iphone' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false,
      'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false,

      // Others.
      'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false,
      'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false,
   );

   // Detect IE and not those who wish to emulate it.
   $context['browser']['is_ie'] = !$context['browser']('is_opera') && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1;

   // Detect Safari/Chrome from webkit.
   if ($context['browser']['is_webkit'])
   {
      $context['browser']['is_chrome'] = $context['browser']['is_webkit'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false;
      $context['browser']['is_safari'] = !$context['browser']['is_chrome'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false;
   }

   // More Opera checks if we are opera.
   if ($context['browser']['is_opera'])
      $context['browser'] += array(
         '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_opera9' => preg_match('~Opera[ /]9(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_opera10' => preg_match('~Opera[ /]10\\.~', $_SERVER['HTTP_USER_AGENT']) === 1 || (preg_match('~Opera[ /]9\\.[89]~', $_SERVER['HTTP_USER_AGENT']) === 1 && preg_match('~Version/1[0-9]\\.~', $_SERVER['HTTP_USER_AGENT']) === 1),
      );

   // Additional firefox checks.
   if ($context['browser']['is_firefox'])
      $context['browser'] += array(
         'is_firefox1' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/1\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox2' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/2\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox3' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/3\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
      );

   // Additional IE checks.
   if ($context['browser']['is_ie'])
   {
      $context['browser'] += array(
         'is_ie8' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') !== false,
         'is_ie5.5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false,
         'is_ie5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false;
         'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && !$context['browser']['is_web_tv'],
         'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false,
      );

      // Detect IE7 and not IE8 in combat mode.
      $context['browser']['is_ie7'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_ie8'],

      // Before IE8 we need to fix IE... lots!
      $context['browser']['ie_standards_fix'] = !$context['browser']['is_ie8'];

      $context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_ie8'] && !$context['browser']['is_ie7'];

   }

   if ($context['browser']['is_ie'] || $context['browser']['is_opera'])
      $context['browser']['needs_size_fix'] = ($context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie4'] || $context['browser']['is_opera6']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false;

   // Be you robot or human?
   if ($user_info['possibly_robot'])
   {
      // This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
      $context['browser']['possibly_robot'] = !empty($user_info['possibly_robot']);

      // Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
      if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register'))) || !$user_info['is_guest'])
         $context['browser']['possibly_robot'] = false;
   }
   else
      $context['browser']['possibly_robot'] = false;

}
#3
/**
 * Are we using this browser?
 * @param $browser: browser we are checking for.
*/
function isBrowser($browser)
{
   global $context;

   // Don't know any browser!
   if (empty($context['browser']))
      detectBrowser();

   return !empty($context['is_' . $browser]);
}

/**
 * This function is... detecting the browser, right.
 * Loads a bunch of browser information in to $context
 */
function detectBrowser()
{
   global $context, $user_info;

   // The following determines the user agent (browser) as best it can.
   $context['browser'] = array(
      // Most desktop browsers.
      'is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false,
      'is_webkit' => strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false,
      'is_firefox' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/~', $_SERVER['HTTP_USER_AGENT']) === 1,
      'is_gecko' = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_webkit'] && !$context['browser']['is_konqueror'];

      // Mobile browsers.
      'is_iphone' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false,
      'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false,

      // Others.
      'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false,
      'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false,
   );

   // Detect IE and not those who wish to emulate it.
   $context['browser']['is_ie'] = !$context['browser']('is_opera') && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'] && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1;

   // Detect Safari/Chrome from webkit.
   if ($context['browser']['is_webkit'])
   {
      $context['browser']['is_chrome'] = $context['browser']['is_webkit'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false;
      $context['browser']['is_safari'] = !$context['browser']['is_chrome'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false;
   }

   // More Opera checks if we are opera.
   if ($context['browser']['is_opera'])
      $context['browser'] += array(
         '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_opera9' => preg_match('~Opera[ /]9(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_opera10' => preg_match('~Opera[ /]10\\.~', $_SERVER['HTTP_USER_AGENT']) === 1 || (preg_match('~Opera[ /]9\\.[89]~', $_SERVER['HTTP_USER_AGENT']) === 1 && preg_match('~Version/1[0-9]\\.~', $_SERVER['HTTP_USER_AGENT']) === 1),
      );

   // Additional firefox checks.
   if ($context['browser']['is_firefox'])
      $context['browser'] += array(
         'is_firefox1' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/1\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox2' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat)/2\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
         'is_firefox3' => preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/3\\.~', $_SERVER['HTTP_USER_AGENT']) === 1,
      );

   // Additional IE checks.
   if ($context['browser']['is_ie'])
   {
      $context['browser'] += array(
         'is_ie8' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') !== false,
         'is_ie5.5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false,
         'is_ie5' = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false;
         'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && !$context['browser']['is_web_tv'],
         'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false,
      );

      // Detect IE7 and not IE8 in combat mode.
      $context['browser']['is_ie7'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_ie8'],

      // Before IE8 we need to fix IE... lots!
      $context['browser']['ie_standards_fix'] = !$context['browser']['is_ie8'];

      $context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_ie8'] && !$context['browser']['is_ie7'];

   }

   if ($context['browser']['is_ie'] || $context['browser']['is_opera'])
      $context['browser']['needs_size_fix'] = ($context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie4'] || $context['browser']['is_opera6']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false;

   // Be you robot or human?
   if ($user_info['possibly_robot'])
   {
      // This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
      $context['browser']['possibly_robot'] = !empty($user_info['possibly_robot']);

      // Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
      if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register'))) || !$user_info['is_guest'])
         $context['browser']['possibly_robot'] = false;
   }
   else
      $context['browser']['possibly_robot'] = false;

}