DetectMobileFree
Description
Allows PmWiki to detect whether the browser viewing the wiki is on a mobile device. May be used within PmWiki (or PHP in general) to load mobile specific skins, change items within a webpage based on whether the page is viewed on a mobile device, or perform other mobile-related actions.
Download and Installation
- Download the script. (Download: detectmobilebrowsers.phpΔ)
- Unzip it into your cookbook directory (usually
pmwiki/cookbook/
). - Add the following to your local configuration file:
include_once("$FarmD/cookbook/detectmobilebrowsers.php");
Using the Script
Simply call the function from within PHP:
detect_mobile_device();
For example, you might use it in config.php
to use a different skin if a mobile device is detected.
if (detect_mobile_device()) { $Skin = 'skidoo/PDA'; } else { $Skin = 'skidoo'; }
You might also use it in config.php
to allow features in a webpage that change on a mobile device AND to change the skin if a mobile device is detected (example skin is the MobileSkin?):
include_once("$FarmD/cookbook/detectmobilebrowsers.php"); if (detect_mobile_device()) { $Skin = 'mobile'; $FmtPV['$isMobile'] = '"true"'; } else { $Skin = 'pmwiki'; $FmtPV['$isMobile'] = '"false"'; }
Now within a webpage you can use:
(:if {$isMobile}:)
and
(:if !{$isMobile}:)
markups.
Known Issues
- Out of the box, this plug-in ignores tablet devices. This is deliberate.
Change Log
23-Apr-2012 (0.0.1)
Contributors: XES & ChrisK
- wrapped Chad Smith's mobile device plug-in in a function, ready for PmWiki use.
- First release.
Credit
- Mobile device detection is based on Chad Smith's unlicensed/free PHP script available from http://detectmobilebrowsers.com/. There may be updates at the originator's website as new mobile browsers & device architectures are released.
- Credit to DetectMobile & DaveG, without whom I may not have ever thought to have a mobile browser/skin for PmWiki in the first place.
Comments
See discussion at DetectMobileFree-Talk
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.