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
Comment | File | Size | Author |
---|---|---|---|
#3 | include_mobile_detect.patch | 1.01 KB | dshields |
Comments
Comment #1
wrd CreditAttribution: wrd commentedThis 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.
Comment #2
droddis CreditAttribution: droddis commentedSilly 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?
Comment #3
dshields CreditAttribution: dshields commentedSorry 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.
Comment #4
dshields CreditAttribution: dshields commentedIf that doesn't sound like a whole lot of fun, it might be worthwhile for you to take a look at either of these:
I haven't explored either, as the solution I've explained works fine for what I was trying to accomplish.
Comment #5
marcoka CreditAttribution: marcoka commentedit 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.
Comment #6
dshields CreditAttribution: dshields commentedI'd suggest the Context Mobile Detect module for this functionality.
Comment #7
Jeff Burnz CreditAttribution: Jeff Burnz commentedBrowscap 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.