Hello all, I was having a problem getting the mobile redirect to recognize the Palm Pre as a mobile device, so I added "|pre"

I hate calling this a bug, more of a feature request,

To here (approx line 505):

case (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive

So it looks like:

case (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo|pre)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive

Seems to work just fine - I made a quick patch, but I seem to suck at patching - so check it out and see what you get! Let me know how I can do it better, patching is not my strong suit.

Thanks!

CommentFileSizeAuthor
mobile_tools_with_pre.patch1.72 KBkirikintha

Comments

twom’s picture

Thx for the update. Ill apply the patch.

In meantime, I highly recommend looking at the WURFL module (http://drupal.org/projects/wurfl)

This is a much more high quality device detection system.

Regards,
Tom

kirikintha’s picture

Sweet, thanks so much for the clarification
-k

kirikintha’s picture

I also wanted to make one more not about mobile detection - I modified this approach for a generic mobile detection script that covered some more of the obscure mobile devices, like some of the Palm OS that slipped through, or the Evo which seemed to not detect. I've tried this on Windows, Mac, Linux, with the popular mobile browsers (stock and boutique) and it seems to be a more stable at redirecting to the mobile url when it is really a mobile user agent. Or at least the client hasn't complained about this script... yet, lol.

Just to note: WURFL is pretty great, but I didn't need such focused detection on this project, but I do plan on using it in the future. Thanks for all the hard work on you module!

/**
 * @name _detectMobileDevice()
 * Detect if a user agent is a mobile device or not. This uses the theory that we are not looking for desktop browsers, rather than looking for mobile devices
 * based on: http://smartmobtoolkit.wordpress.com/2008/10/16/not-device-detection
 * @param array $ignoreUserAgents = an array of values to ignore in a user agent to ignore, such as the ipad
 * @return bool true/false if a device is a mobile device or not
 */
function _detectMobileDevice($ignoreAgents = array('ipad')) {
  //Operating Systems we want to ignore
  $os       = array( 'Windows', 'Macintosh', 'Linux', 'FreeBSD', 'Solaris' );
  $crawlers = array( 'bot', 'slurp', 'spider', 'crawl' );
  $ignore   = array_merge( $os, $crawlers );
  //Turn the ignore array into a piped preg_match query
  $ignore = implode('|', $ignore); 
  //If we match anything on the ignore list, and do not have mobile in the user agent string, return false
  if (preg_match('/('.$ignore.')/i', $_SERVER['HTTP_USER_AGENT'], $matches) && !strstr(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MOBILE')) {
    return false;
  } else {
    //If we do not match on the ignore list then we are presuming we are a mobile device, unless that mobile device is to be ignored
    $ignoreAgents = implode('|', $ignoreAgents);
    if (preg_match('/('.$ignoreAgents.')/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
      return false;
    } else {
      return true;
    } 
  }
}
twom’s picture

Status: Needs review » Fixed

Hi,

Thanks for the code. Actually Mobile Tools allows you to create your contrib module to do the device detection.

You just have to implement the following hooks:

hook_is_mobile_device() {
// returns an associative array:
return array(
'type' => 'mobile' or 'desktop',
'group' => [you own defined group]
);
}

hook_device_groups() {
//return an array with device groups your contrib module supports
}

Hope this helps

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ealtman’s picture

Issue tags: +opera

This was a great note, but we discovered that the "pre" addition was inadvertently redirecting Opera desktop browsers because of the "Presto" string in the Opera user agent info.

Added yet another "case" directly under the test for the opera mini:

 case (FALSE !== stripos($user_agent, 'opera')); // we find Opera desktop in the user agent
      $mobile_browser = array('type' => 'desktop', 'group' => ' '); // set type to desktop
    break; // break out and skip the rest if we've had a match on opera

I need to update to the latest dev version, so forgive me if I've missed something.

ianchan’s picture

subscribe

akosipax’s picture

this can be fixed by using the browscap module for device detection.