This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6d94c8
Showing
84 changed files
with
18,818 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInite9eed2c4df342ec7cf40751a56edfb3d::getLoader(); |
Oops, something went wrong.