s1syphos/kirby-device

该软件包已被弃用且不再维护。未建议替代软件包。

为 Kirby 提供的综合用户代理及设备检测

安装: 9

依赖关系: 0

建议者: 0

安全: 0

星星: 12

观察者: 2

分支: 0

开放问题: 0

类型:kirby-plugin

0.2.0 2018-03-17 19:25 UTC

This package is auto-updated.

Last update: 2021-12-19 04:11:50 UTC


README

Release License Issues

此插件可检测设备(如桌面、平板电脑、手机、电视、汽车、游戏机等)、客户端(浏览器、聚合阅读器、媒体播放器、个人信息管理器等)以及操作系统、品牌和型号。

目录

主要功能

kirby-device 提供了 device() 函数,用于从目标用户的代理(UA)中解析信息 - 这是一种 黑魔法占卜科学,然后您可以识别

入门

使用以下方法之一安装和使用 kirby-device

Git 子模块

如果您熟悉 Git,您可以将此插件作为 子模块 下载

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

Composer

composer require S1SYPHOS/kirby-device:dev-composer

克隆或下载

  1. 克隆下载 此存储库。
  2. 解压缩 / 将文件夹移动到 site/plugins

激活插件

在您的 config.php 中使用以下行激活插件

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

配置

更改 kirby-device 选项以满足您的需求

选项 类型 默认值 描述
plugin.kirby-device.truncate-version 字符串 小版本 根据 语义版本控制规范 定义浏览器构建或版本格式(允许的值是 majorminorpatch 以及 build & none)。
plugin.kirby-device.enable-filecache 布尔值 true 可选地启用/禁用文件缓存。

可用方法

这些方法可用于满足您的设备检测需求

// 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()

除非特别说明,所有 getSomething() 方法返回字符串,所有 isSomething() 方法返回布尔值。

示例

检查移动环境

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'

请随意编写您自己的方法

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

有关更多信息,请参阅项目的仓库或查看其演示页面

致谢 / 许可证

kirby-device 基于Matomo的 DeviceDetector,并受到 Sonja Broda 的 Kirby 插件 kirby-mobile-detect(Şerban Ghiţă 的 Mobile-Detect 的实现)的启发。它根据 MIT 许可证授权,但在生产中使用 Kirby 需要您购买许可证。您准备好下一步了吗?

特别感谢

我要感谢每一位制作出色软件的人 - 你们很棒。我也总是感谢反馈和错误报告 :)