Great module!

It is very useful to be able to toggle blocks on and off depending on whether or not the user is on a mobile device or sitting at their laptop/desktop! This is a great compliment to adaptivetheme.

Using http://code.google.com/p/php-mobile-detect/, I've been able to cancel the effect that this module has on tablets while using it to unset particular blocks from being rendered on smartphones.

/**
 * Implements hook_block_list_alter().
 * Check the mobile device specific visibilty settings.
 * Remove the block if the visibility conditions are not met.
 */
function browscap_block_block_list_alter(&$blocks) {
  global $theme_key;

  $browser = browscap_get_browser();
  if ($browser['ismobiledevice'] == 1) {

//
//
// THE FOLLOWING LINES WERE ADDED TO ALTER THE MODULE - WITH THIS ALTERATION, THE MODULE ONLY DISABLED BLOCKS FROM SMARTPHONES, NOT TABLETS
include("Mobile_Detect.php");
$detect = new Mobile_Detect();

if(!$detect->isTablet()){
    // any tablet


    $is_mobile = TRUE;
  } 


//
//
// THE FOLLOWING LINE WAS ADDED TO ALTER THE MODULE - WITH THIS ALTERATION, THE MODULE ONLY DISABLED BLOCKS FROM SMARTPHONES, NOT TABLETS
}

While it works great, I am not yet satisfied with my hacky way of pulling this off. I wonder if anyone else would find this functionality useful and like to help me out here..

I've only used php-mobile-detect to isolate tablets so far, but it "can detect specific devices by using case-insensitive pseudo-methods":

Phones

isiPhone()
isBlackBerry()
isHTC()
isNexus()
isDellStreak()
isMotorola()
isSamsung()
isSony()
isAsus()
isPalm()
isGenericPhone()

Tablets

isBlackBerryTablet()
isiPad()
isKindle()
isSamsungTablet()
isHTCtablet()
isMotorolaTablet()
isAsusTablet()
isNookTablet()
isAcerTablet()
isYarvikTablet()
isGenericTablet()

Operating systems

isAndroidOS()
isBlackBerryOS()
isPalmOS()
isSymbianOS()
isWindowsMobileOS()
isiOS()
isFlashLiteOS()
isJavaOS()
isNokiaOS()
iswebOS()
isbadaOS()
isBREWOS()

Mobile browsers

isChrome()
isDolfin()
isOpera()
isSkyfire()
isIE()
isFirefox()
isBolt()
isTeaShark()
isBlazer()
isSafari()
isMidori()
isGenericBrowser()

-from http://code.google.com/p/php-mobile-detect/wiki/Mobile_Detect

CommentFileSizeAuthor
#3 include_mobile_detect.patch1.01 KBdshields
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wrd’s picture

This would be immensely useful. Better yet, hook it in via the block config. Instead of a radio select for the current three options, have checkboxes for showing on smartphones, tablets, and desktop, all defaulting to checked. Can then simply uncheck to hide on a given type of device.

droddis’s picture

Silly question I know, But where would I add the code listed above to get this level of functionality.

Also I'm seeing the same issue with Browscap Block not hiding blocks on a mobile view, does this override the inherent code in the Browscap Block Module?

dshields’s picture

FileSize
1.01 KB

Sorry to be so slow to reply
What I eventually did was patched the BrowscapBlock with the attached patch which references a file Mobile_Detect.php that I placed in the root of the module directory.

The latest code for Mobile_Detect.php can be found here: serbanghita/Mobile-Detect on GitHub.

I hope this helps.

dshields’s picture

If that doesn't sound like a whole lot of fun, it might be worthwhile for you to take a look at either of these:

  1. Mobile Detect Module
  2. Context Mobile Detect Module which is used with the Context Module.

I haven't explored either, as the solution I've explained works fine for what I was trying to accomplish.

marcoka’s picture

it makes a lot of sense to be able to disable blocks only on smartphones. there are a lot of tablets with 1024 width in landscape...and you do not want to disable anything there.

dshields’s picture

I'd suggest the Context Mobile Detect module for this functionality.

Jeff Burnz’s picture

Status: Active » Closed (won't fix)

Browscap does not support this functionality, so it should be a new module, aka Mobile Detect Block etc.

This is simple module that does one thing, I want to keep it that way.