mirror of
https://github.com/humhub/humhub.git
synced 2025-04-20 23:21:54 +02:00
Fix DeviceDetectorHelper when no user agent (#7365)
* Enh: Fix DeviceDetectorHelper::isMobile() and DeviceDetectorHelper::isTablet() when no user agent * Add PR ID to CHANGELOG
This commit is contained in:
parent
6f1c3cf1e6
commit
d0b0803a4a
@ -1,6 +1,9 @@
|
||||
HumHub Changelog
|
||||
================
|
||||
|
||||
1.17.0-beta.5 (Unreleased)
|
||||
---------------------------------
|
||||
- Fix #7365: `DeviceDetectorHelper::isMobile()` and `DeviceDetectorHelper::isTablet()` when no user agent
|
||||
|
||||
1.17.0-beta.4 (December 24, 2024)
|
||||
---------------------------------
|
||||
|
@ -42,7 +42,7 @@ $logTargetConfig = [
|
||||
|
||||
$config = [
|
||||
'name' => 'HumHub',
|
||||
'version' => '1.17.0-beta.4',
|
||||
'version' => '1.17.0-beta.5',
|
||||
'minRecommendedPhpVersion' => '8.1',
|
||||
'minSupportedPhpVersion' => '8.1',
|
||||
'basePath' => dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
|
||||
|
@ -20,11 +20,8 @@ class DeviceDetectorHelper
|
||||
{
|
||||
public static function isMobile(): bool
|
||||
{
|
||||
$detect = new MobileDetect();
|
||||
$detect->setUserAgent(Yii::$app->request->getUserAgent());
|
||||
|
||||
try {
|
||||
return $detect->isMobile();
|
||||
return (bool)static::getMobileDetect()?->isMobile();
|
||||
} catch (MobileDetectException $e) {
|
||||
Yii::error('DeviceDetectorHelper::isMobile() error: ' . $e->getMessage());
|
||||
return false;
|
||||
@ -33,17 +30,26 @@ class DeviceDetectorHelper
|
||||
|
||||
public static function isTablet(): bool
|
||||
{
|
||||
$detect = new MobileDetect();
|
||||
$detect->setUserAgent(Yii::$app->request->getUserAgent());
|
||||
|
||||
try {
|
||||
return $detect->isTablet();
|
||||
return (bool)static::getMobileDetect()?->isTablet();
|
||||
} catch (MobileDetectException $e) {
|
||||
Yii::error('DeviceDetectorHelper::isTablet() error: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getMobileDetect(): ?MobileDetect
|
||||
{
|
||||
$userAgent = Yii::$app->request->getUserAgent();
|
||||
if (!$userAgent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$detect = new MobileDetect();
|
||||
$detect->setUserAgent($userAgent);
|
||||
return $detect;
|
||||
}
|
||||
|
||||
public static function isAppRequest(): bool
|
||||
{
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user