2017 © Pedro Peláez
 

kirby-plugin kirby-device

Comprehensive user agent & device detection for Kirby

image

s1syphos/kirby-device

Comprehensive user agent & device detection for Kirby

  • Saturday, March 31, 2018
  • by S1SYPHOS
  • Repository
  • 2 Watchers
  • 11 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 4 Versions
  • 50 % Grown

The README.md

Kirby Device

Release License Issues, (*1)

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., (*2)

Table of contents - 1. Main features - 2. Getting started - 3. Configuration - 4. Available methods - 5. Examples - 6. Credits / License, (*3)

Main features

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, (*4)

Getting started

Use one of the following methods to install & use kirby-device:, (*5)

Git submodule

If you know your way around Git, you can download this plugin as a submodule:, (*6)

git submodule add https://github.com/S1SYPHOS/kirby-device.git site/plugins/kirby-device

Composer

composer require S1SYPHOS/kirby-device:dev-composer

Clone or download

  1. Clone or download this repository.
  2. Unzip / Move the folder to site/plugins.

Activate the plugin

Activate the plugin with the following line in your config.php:, (*7)

c::set('plugin.kirby-device', true);

Configuration

Change kirby-device options to suit your needs:, (*8)

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.

Available methods

These methods are available to meet your device detection requirements:, (*9)

// 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., (*10)

Examples

Check for mobile environment

if (device()->isMobile()) {
  // Your code here.
}

Check for tablet device

if (device()->isTablet()) {
  // Your code here.
}

Only show code on desktop or tablet device

if(device()->isDesktop() || device()->isTablet()) {
    // Your desktop & tablet code here.
}

.. and much more!

// Get mobile device information
$brand = device()->getBrandName(); // eg 'Apple'
$model = device()->getModel(); // eg 'iPhone'

Feel free to write your own methods:, (*11)

// 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., (*12)

Credits / License

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?, (*13)

Special Thanks

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 :), (*14)

The Versions

31/03 2018

dev-master

9999999-dev

Comprehensive user agent & device detection for Kirby

  Sources   Download

MIT

The Requires

 

31/03 2018

dev-composer

dev-composer

Comprehensive user agent & device detection for Kirby

  Sources   Download

MIT

The Requires

 

17/03 2018

0.2.0

0.2.0.0

Comprehensive user agent & device detection for Kirby

  Sources   Download

MIT

The Requires

 

13/03 2018

0.1.0

0.1.0.0

Comprehensive user agent & device detection for Kirby

  Sources   Download

MIT

The Requires