mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 08:41:39 +09:00
add isReallyFromMobilePhone
This commit is contained in:
parent
afa0388ae2
commit
e051ae079a
1 changed files with 55 additions and 0 deletions
|
|
@ -13,6 +13,12 @@ class Mobile
|
|||
*/
|
||||
protected static $_ismobile = null;
|
||||
|
||||
/**
|
||||
* Whether mobile or not mobile mode
|
||||
* @var bool
|
||||
*/
|
||||
protected static $_ismobilereally = null;
|
||||
|
||||
/**
|
||||
* Get instance of Mobile class
|
||||
*
|
||||
|
|
@ -78,6 +84,55 @@ class Mobile
|
|||
return self::$_ismobile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current mobile mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isReallyFromMobilePhone()
|
||||
{
|
||||
// Return cached result.
|
||||
if (self::$_ismobilereally !== null)
|
||||
{
|
||||
return self::$_ismobilereally;
|
||||
}
|
||||
|
||||
// Try to detect from URL arguments and cookies, and finally fall back to user-agent detection.
|
||||
$m = Context::get('m');
|
||||
$cookie = isset($_COOKIE['rx_uatype']) ? $_COOKIE['rx_uatype'] : null;
|
||||
$uahash = base64_encode_urlsafe(md5($_SERVER['HTTP_USER_AGENT'] ?? '', true));
|
||||
if (strncmp($cookie ?? '', $uahash . ':', strlen($uahash) + 1) !== 0)
|
||||
{
|
||||
$cookie = null;
|
||||
}
|
||||
elseif ($m === null)
|
||||
{
|
||||
$m = substr($cookie, -1);
|
||||
}
|
||||
|
||||
if ($m === '1')
|
||||
{
|
||||
self::$_ismobilereally = TRUE;
|
||||
}
|
||||
elseif ($m === '0')
|
||||
{
|
||||
self::$_ismobilereally = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_ismobilereally = Rhymix\Framework\UA::isMobile() && (config('mobile.tablets') || !Rhymix\Framework\UA::isTablet());
|
||||
}
|
||||
|
||||
// Set cookie to prevent recalculation.
|
||||
$uatype = $uahash . ':' . (self::$_ismobilereally ? '1' : '0');
|
||||
if ($cookie !== $uatype)
|
||||
{
|
||||
Rhymix\Framework\Cookie::set('rx_uatype', $uatype, ['expires' => 0, 'path' => \RX_BASEURL]);
|
||||
}
|
||||
|
||||
return self::$_ismobilereally;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current mobile mode
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue