This plugin detects devices (such as desktop, tablet, mobile, tv, cars, console, ..), clients (browsers, feed readers, media players, PIMs, ..) as well as operating systems, brands and models.
Table of contents
- 1. Main features
- 2. Getting started
- 3. Configuration
- 4. Available methods
- 5. Examples
- 6. Credits / License
kirby-device
provides the device()
function for parsing information from the target's user agent (UA) - the black-magic voodoo science of regular expressions then enables you to identify
- operating systems
- browsers
- browser engines
- libraries (eg cURL, Perl, Wget, ..)
- media players
- personal information managers (PIMs)
- feed readers
- brands & devices
- .. and of course: bots
Use one of the following methods to install & use kirby-device
:
If you know your way around Git, you can download this plugin as a submodule:
git submodule add https://github.com/S1SYPHOS/kirby-device.git site/plugins/kirby-device
composer require S1SYPHOS/kirby-device:dev-composer
Activate the plugin with the following line in your config.php
:
c::set('plugin.kirby-device', true);
Change kirby-device
options to suit your needs:
Option | Type | Default | Description |
---|---|---|---|
plugin.kirby-device.truncate-version |
String | minor |
Defines the browser build or version format according to the semantic versioning specification (allowed values are major , minor , patch as well as build & none ). |
plugin.kirby-device.enable-filecache |
Boolean | true |
Optionally enables / disables filecache. |
These methods are available to meet your device detection requirements:
// Configuration Methods
setCache()
setYamlParser()
discardBotInformation()
skipBotDetection()
// General Device Type Methods
isBot()
isMobile()
isDesktop()
isTouchEnabled() // win8 tablets only
// General Client Type Methods
getBot() // array
getClient() // array | optionally string, eg getClient('version'))
getOs() // array | optionally string, eg getOs('version')
getDevice()
getDeviceName()
getBrand()
getBrandName()
getModel()
getUserAgent()
// Specific Device Type Methods
isSmartphone()
isFeaturePhone()
isTablet()
isPhablet()
isConsole()
isPortableMediaPlayer()
isCarBrowser()
isTV()
isSmartDisplay()
isCamera()
// Specific Client Type Methods
isBrowser()
isFeedReader()
isMobileApp()
isPIM()
isLibrary()
isMediaPlayer()
Unless stated, all getSomething()
methods return strings and all isSomething()
methods return booleans.
if (device()->isMobile()) {
// Your code here.
}
if (device()->isTablet()) {
// Your code here.
}
if(device()->isDesktop() || device()->isTablet()) {
// Your desktop & tablet code here.
}
// Get mobile device information
$brand = device()->getBrandName(); // eg 'Apple'
$model = device()->getModel(); // eg 'iPhone'
Feel free to write your own methods:
// Custom function detecting Chrome browser
function isChrome() {
return device()->getClient('name') == 'Chrome' ? true : false;
}
For more information, see the project's repo or check out its demo page.
kirby-device
is based on Matomo's DeviceDetector and was inspired by Sonja Broda's Kirby plugin kirby-mobile-detect (an implementation of Şerban Ghiţă's Mobile-Detect). It is licensed under the MIT License, but using Kirby in production requires you to buy a license. Are you ready for the next step?
I'd like to thank everybody that's making great software - you people are awesome. Also I'm always thankful for feedback and bug reports :)