Skip to content

Commit

Permalink
Ready to release 4.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Lannoy committed Nov 22, 2024
1 parent 58f62e3 commit 7b035a1
Show file tree
Hide file tree
Showing 25 changed files with 4,137 additions and 1,116 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ All notable changes to **Device Detector** are documented in this *changelog*.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and **Device Detector** adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.2.0] - 2024-11-22

### Added
- Compatibility with WordPress 6.7.

### Changed
- Upgraded UDD from version 6.3.2 to version 6.4.1: dozens of added and improved detections.
- Ability to self-update from Github.
- The plugin user agent is now more consistent and "standard".

### Fixed
- There's a WordPress core "feature" which causes some PII to leak (to wp.org) during plugin and theme updates. This is no more the case for this plugin.
- In some cases, a WordPress notice can be triggered concerning the loading sequence of translations.

### Removed
- Test site launching from wordpress.org plugin page.
- All Databeam hooks and libraries, as the Databeam project is abandoned.
- Dependency on wp.org for updates.

## [4.1.0] - 2024-09-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion device-detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Device Detector
* Plugin URI: https://perfops.one/device-detector
* Description: Full featured analytics reporting and management tool that detects all devices accessing your WordPress site.
* Version: 4.1.0
* Version: 4.2.0
* Requires at least: 6.2
* Requires PHP: 8.1
* Author: Pierre Lannoy / PerfOps One
Expand Down
2 changes: 1 addition & 1 deletion includes/libraries/class-libraries.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function init() {
'name' => 'Universal Device Detection',
'prefix' => 'UDD',
'base' => PODD_VENDOR_DIR . 'udd/',
'version' => '6.3.1',
'version' => '6.4.1',
// phpcs:ignore
'author' => 'Matomo Analytics',
'url' => 'https://github.com/matomo-org/device-detector',
Expand Down
35 changes: 33 additions & 2 deletions includes/libraries/udd/ClientHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class ClientHints
*/
protected $app = '';

/**
* Represents `Sec-CH-UA-Form-Factors` header field: form factor device type name
*
* @var array
*/
protected $formFactors = [];

/**
* Constructor
*
Expand All @@ -88,8 +95,9 @@ class ClientHints
* @param string $architecture `Sec-CH-UA-Arch` header field
* @param string $bitness `Sec-CH-UA-Bitness`
* @param string $app `HTTP_X-REQUESTED-WITH`
* @param array $formFactors `Sec-CH-UA-Form-Factors` header field
*/
public function __construct(string $model = '', string $platform = '', string $platformVersion = '', string $uaFullVersion = '', array $fullVersionList = [], bool $mobile = false, string $architecture = '', string $bitness = '', string $app = '') // phpcs:ignore Generic.Files.LineLength
public function __construct(string $model = '', string $platform = '', string $platformVersion = '', string $uaFullVersion = '', array $fullVersionList = [], bool $mobile = false, string $architecture = '', string $bitness = '', string $app = '', array $formFactors = []) // phpcs:ignore Generic.Files.LineLength
{
$this->model = $model;
$this->platform = $platform;
Expand All @@ -100,6 +108,7 @@ public function __construct(string $model = '', string $platform = '', string $p
$this->architecture = $architecture;
$this->bitness = $bitness;
$this->app = $app;
$this->formFactors = $formFactors;
}

/**
Expand Down Expand Up @@ -224,6 +233,16 @@ public function getApp(): string
return $this->app;
}

/**
* Returns the formFactor device type name
*
* @return array
*/
public function getFormFactors(): array
{
return $this->formFactors;
}

/**
* Factory method to easily instantiate this class using an array containing all available (client hint) headers
*
Expand All @@ -237,6 +256,7 @@ public static function factory(array $headers): ClientHints
$app = '';
$mobile = false;
$fullVersionList = [];
$formFactors = [];

foreach ($headers as $name => $value) {
switch (\str_replace('_', '-', \strtolower((string) $name))) {
Expand Down Expand Up @@ -319,6 +339,16 @@ public static function factory(array $headers): ClientHints
$app = $value;
}

break;
case 'formfactors':
case 'http-sec-ch-ua-form-factors':
case 'sec-ch-ua-form-factors':
if (\is_array($value)) {
$formFactors = \array_map('\strtolower', $value);
} elseif (\preg_match_all('~"([a-z]+)"~i', \strtolower($value), $matches)) {
$formFactors = $matches[1];
}

break;
}
}
Expand All @@ -332,7 +362,8 @@ public static function factory(array $headers): ClientHints
$mobile,
$architecture,
$bitness,
$app
$app,
$formFactors
);
}
}
25 changes: 23 additions & 2 deletions includes/libraries/udd/DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DeviceDetector
/**
* Current version number of DeviceDetector
*/
public const VERSION = '6.3.2';
public const VERSION = '6.4.1';

/**
* Constant used as value for unknown browser / os
Expand Down Expand Up @@ -1039,6 +1039,27 @@ protected function parseDevice(): void
$this->device = AbstractDeviceParser::DEVICE_TYPE_TABLET;
}

/**
* All devices running Puffin Secure Browser that contain letter 'D' are assumed to be desktops
*/
if (null === $this->device && $this->matchUserAgent('Puffin/(?:\d+[.\d]+)[LMW]D')) {
$this->device = AbstractDeviceParser::DEVICE_TYPE_DESKTOP;
}

/**
* All devices running Puffin Web Browser that contain letter 'P' are assumed to be smartphones
*/
if (null === $this->device && $this->matchUserAgent('Puffin/(?:\d+[.\d]+)[AIFLW]P')) {
$this->device = AbstractDeviceParser::DEVICE_TYPE_SMARTPHONE;
}

/**
* All devices running Puffin Web Browser that contain letter 'T' are assumed to be tablets
*/
if (null === $this->device && $this->matchUserAgent('Puffin/(?:\d+[.\d]+)[AILW]T')) {
$this->device = AbstractDeviceParser::DEVICE_TYPE_TABLET;
}

/**
* All devices running Opera TV Store are assumed to be a tv
*/
Expand All @@ -1049,7 +1070,7 @@ protected function parseDevice(): void
/**
* All devices that contain Andr0id in string are assumed to be a tv
*/
if ($this->matchUserAgent('Andr0id|(?:Android(?: UHD)?|Google) TV|\(lite\) TV|BRAVIA')) {
if ($this->matchUserAgent('Andr0id|(?:Android(?: UHD)?|Google) TV|\(lite\) TV|BRAVIA| TV$')) {
$this->device = AbstractDeviceParser::DEVICE_TYPE_TV;
}

Expand Down
Loading

0 comments on commit 7b035a1

Please sign in to comment.