Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed Mar 13, 2018
0 parents commit d6d94c8
Show file tree
Hide file tree
Showing 84 changed files with 18,818 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Martin Folkers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
102 changes: 102 additions & 0 deletions README.md
@@ -0,0 +1,102 @@
# Kirby Device
[![Release](https://img.shields.io/github/release/S1SYPHOS/kirby-device.svg?color="brightgreen")](https://github.com/S1SYPHOS/kirby-device/releases) [![License](https://img.shields.io/github/license/S1SYPHOS/kirby-device.svg)](https://github.com/S1SYPHOS/kirby-device/blob/master/LICENSE) [![Issues](https://img.shields.io/github/issues/S1SYPHOS/kirby-device.svg)](https://github.com/S1SYPHOS/kirby-device/issues)

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. Use cases](#use-cases)
- [2. Getting started](#getting-started)
- [3. Configuration](#configuration)
- [4. Credits / License](#credits--license)

## Use cases
`kirby-detect` provides the `device()` function which instantiates a new instance of the DeviceDetector class, which is able to identify

- [operating systems](https://github.com/matomo-org/device-detector#list-of-detected-operating-systems))
- [browsers](https://github.com/matomo-org/device-detector#list-of-detected-browsers))
- [browser engines](https://github.com/matomo-org/device-detector#list-of-detected-browser-engines)
- [libraries](https://github.com/matomo-org/device-detector#list-of-detected-libraries) (eg cURL, Perl, Wget, ..)
- [media players](https://github.com/matomo-org/device-detector#list-of-detected-media-players)
- [personal information managers](https://github.com/matomo-org/device-detector#list-of-detected-pims-personal-information-manager) (PIMs)
- [feed readers](https://github.com/matomo-org/device-detector#list-of-detected-feed-readers)
- [brands & devices](https://github.com/matomo-org/device-detector#list-of-brands-with-detected-devices)
- .. and of course: [bots](https://github.com/matomo-org/device-detector#list-of-detected-bots)

### Check for mobile environment

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

### Check for tablet device

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

### Only show code on desktop or tablet device

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

### .. and much more!

```php
// Get user agent (UA)
$ua = device()->getUserAgent();

// Get operating system
$os = device()->getOs();

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

Feel free to write your own methods:

```php
// Custom function detecting Chrome browser
function isChrome() {
return device()->getClient('name') == 'Chrome' ? true : false;
}
```

For more information, see the [project's repo](https://github.com/serbanghita/Mobile-Detect) or check out its [demo page](http://devicedetector.net/index.php).

## Getting started
Use one of the following methods to install & use `kirby-device`:

### Git submodule
If you know your way around Git, you can download this plugin as a [submodule](https://github.com/blog/2104-working-with-submodules):

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

### Clone or download
1. [Clone](https://github.com/S1SYPHOS/kirby-device.git) or [download](https://github.com/S1SYPHOS/kirby-device/archive/master.zip) this repository.
2. Unzip / Move the folder to `site/plugins`.

### Activate the plugin
Activate the plugin with the following line in your `config.php`:

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

## Configuration
TODO

## Credits / License
`kirby-device` is based on Matomo's [DeviceDetector](https://github.com/matomo-org/device-detector) and was inspired by [Sonja Broda](https://github.com/texnixe)'s Kirby plugin [kirby-mobile-detect](https://github.com/texnixe/kirby-mobile-detect) (an implementation of Şerban Ghiţă's [Mobile-Detect](https://github.com/serbanghita/Mobile-Detect)). It is licensed under the [MIT License](LICENSE), but **using Kirby in production** requires you to [buy a license](https://getkirby.com/buy). Are you ready for the [next step](https://getkirby.com/next)?

## 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 :)
16 changes: 16 additions & 0 deletions composer.json
@@ -0,0 +1,16 @@
{
"name": "s1syphos/kirby-device",
"description": "Comprehensive user agent & device detection for Kirby",
"type": "kirby-plugin",
"license": "MIT",
"authors": [
{
"name": "Martin Folkers",
"homepage": "https://twobrain.io",
"role": "Project Author"
}
],
"require": {
"piwik/device-detector": "^3.10"
}
}
17 changes: 17 additions & 0 deletions core/device_detection.php
@@ -0,0 +1,17 @@
<?php

namespace Kirby\Plugins\Device;

use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\DeviceParserAbstract;

class Detect {
public function detectDevice() {
DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$detect = new DeviceDetector($userAgent);
$detect->parse();

return $detect;
}
}
22 changes: 22 additions & 0 deletions kirby-device.php
@@ -0,0 +1,22 @@
<?php

/**
* Kirby Device - Comprehensive user agent & device detection for Kirby
*
* @package Kirby CMS
* @author S1SYPHOS <hello@twobrain.io>
* @link http://twobrain.io
* @version 0.1.0
* @license MIT
*/

if (c::get('plugin.kirby-device', false)) {
// Initialising composer's autoloader
require_once __DIR__ . DS . 'vendor/autoload.php';

function device() {
// Loading settings & core
require_once __DIR__ . DS . 'core' . DS . 'device_detection.php';
return (new Kirby\Plugins\Device\Detect)->detectDevice();
}
}
8 changes: 8 additions & 0 deletions package.json
@@ -0,0 +1,8 @@
{
"name": "kirby-device",
"description": "Comprehensive user agent & device detection for Kirby",
"author": "S1SYPHOS <hello@twobrain.io>",
"version": "0.1.0",
"type": "kirby-plugin",
"license": "MIT"
}
7 changes: 7 additions & 0 deletions vendor/autoload.php
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInite9eed2c4df342ec7cf40751a56edfb3d::getLoader();

0 comments on commit d6d94c8

Please sign in to comment.