I'm doing theme switching based on device detection rather than URL--yes, I know this isn't recommended because it disables drupal caching, but having a single URL is part of the requirement I have to work with. When I set External Modules to use Mobile Tools for device detection, things seem to work fine. When I change to use Browscap for device detection, I get the mobile theme on a desktop on first load and have to reload with ?device=desktop to get the PC theme. Things then seem good until I restart the browser and begin again.

Any ideas?

thanks,
SB

Comments

sunset_bill’s picture

More succinctly, what it looks like is that my site seems to use the mobile theme by default when I'm using Browscap for device detection.

SB

sterndata’s picture

What's your full UserAgent string? http://whatsmyuseragent.com/

sunset_bill’s picture

It's happening with all of my browsers. Per whatsmyuseragent:

FF
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17

Safari
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1

Chrome
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24

First hit on a page in any of these with a clear cache and MT configured to use Browscap for device detection gets me the mobile theme.

thanks,
SB

akoepke’s picture

Category: support » bug
Priority: Normal » Major

I encountered the same issue and have the fix. The cause of this issue is the same as another issue I just logged for the browscap module.

In the mobile_tools/contrib/mt_browscap.module file is the following


function mt_browscap_is_mobile_device() {
  $info = browscap_get_browser();
  // detect device type
  if ($info['ismobiledevice']) {
    $type = 'mobile';
  }
  else {
    $type = 'desktop';
  }

The data returned by browscap is all strings, they are not booleans. This means that when evaluated as a boolean it will always return true.

The code above can be replaced with the following


function mt_browscap_is_mobile_device() {
  $info = browscap_get_browser();
  // detect device type
  $type = ($info['ismobiledevice'] == 'true') ? 'mobile' : 'desktop';

This evaluates the data as a string and works properly.

sunset_bill’s picture

Status: Active » Closed (fixed)

That seems to have done it, alright. Thanks!

akoepke’s picture

Status: Closed (fixed) » Needs review

I won't call this fixed until something has been committed to the dev version. I am also looking at the code of Browscap to see if the actual data it stores in the database can be changed so that proper boolean evaluations can be done.

akoepke’s picture

StatusFileSize
new931 bytes

Just thought I would post back with an update. I have had a look at the Browscap module and the way it parses the data is quite simple and a lot of the problems comes from the way that the parse_ini_file function works.

In the browscap module there is a function called _browscap_boolean which is used internally for the boolean evaluations.

Attached to this post is a patch of my changes which also adds in an iPad group as the contrib module didn't have one.

devin carlson’s picture

Status: Needs review » Closed (fixed)

Browscap was fixed in #664424: Values returned as bool with PHP < 5.3 should also be bool with PHP >= 5.3 to properly return the correct information.

chunty’s picture

Unless I'm missing something I don't think this is fixed...I've got the dev version of browscap installed and I still have the same problem.

Also I think the code replacement suggestion here whilst it may have been correct at one point is now out of date. I think you now need to replace:

<?php
if (isset($user_agent['ismobiledevice'])) {
  $device_information['type'] = 'mobile';
}
?>

on line 23 of mt_browscap.module with:

<?php
if (isset($user_agent['ismobiledevice']) && $user_agent['ismobiledevice']) {
  $device_information['type'] = 'mobile';
}
?>
Drave Robber’s picture

Confirmed - with the latest 6.x-*.*-dev of both Mobile Tools and Browscap (PHP 5.3.5-1ubuntu7.10), everything is still 'mobile'.

A typical return from browscap_get_browser() is like this:

array(29) { ["comment"]=> string(13) "Chromium 18.0" ["browser"]=> string(8) "Chromium" ["version"]=> string(4) "18.0" ["majorver"]=> string(2) "18" ["minorver"]=> string(1) "0" ["platform"]=> string(5) "Linux" ["platform_version"]=> string(7) "unknown" ["alpha"]=> string(1) "0" ["beta"]=> string(1) "0" ["win16"]=> string(1) "0" ["win32"]=> string(1) "0" ["win64"]=> string(1) "0" ["frames"]=> string(1) "1" ["iframes"]=> string(1) "1" ["tables"]=> string(1) "1" ["cookies"]=> string(1) "1" ["backgroundsounds"]=> string(1) "0" ["javascript"]=> string(1) "1" ["vbscript"]=> string(1) "0" ["javaapplets"]=> string(1) "1" ["activexcontrols"]=> string(1) "0" ["ismobiledevice"]=> string(1) "0" ["issyndicationreader"]=> string(1) "0" ["crawler"]=> string(1) "0" ["cssversion"]=> string(1) "3" ["aolversion"]=> string(1) "0" ["parent"]=> string(13) "Chromium 18.0" ["useragent"]=> string(139) "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19" ["browser_name_pattern"]=> string(90) "Mozilla/5.0 (*Linux i686*) AppleWebKit/* (KHTML, like Gecko)*Chromium/18.*Chrome/*Safari/*" }

the relevant part being ["ismobiledevice"]=> string(1) "0".

To be more or less safe against possible future changes in browscap_get_browser() return, I'd suggest a loose comparison against string '0' which would work with int 0 or boolean FALSE as well:

  if (isset($user_agent['ismobiledevice']) && $user_agent['ismobiledevice'] != '0') {
    $device_information['type'] = 'mobile';
  }

Patch to that effect attached.

Drave Robber’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Closed (fixed) » Needs review

Ah yes, issue status.

sarvab’s picture

I ran into this issue as well and would recommend we get this patch applied quickly. The module in it's current state cannot use mt-browscap at all as all browsers will be flagged as mobile.

I made a slight change to the above patch to use !empty instead of isset to be as simple as possible. empty will return TRUE for the integer or string value "0" as well as not existing / false "" etc.

devin carlson’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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