From 26573035cc3a9edd0ad1f3790599e3923c84be53 Mon Sep 17 00:00:00 2001 From: Bjverde Date: Fri, 6 Dec 2019 00:47:24 -0300 Subject: [PATCH] :hammer: BASE #212 --- base/classes/helpers/ServerHelper.class.php | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/base/classes/helpers/ServerHelper.class.php b/base/classes/helpers/ServerHelper.class.php index d20f7d5b..19fcc5d2 100644 --- a/base/classes/helpers/ServerHelper.class.php +++ b/base/classes/helpers/ServerHelper.class.php @@ -42,9 +42,9 @@ class ServerHelper { - const DEVICE_TYPE_MOBILE = 'MOBILE'; - const DEVICE_TYPE_TABLE = 'TABLE'; - const DEVICE_TYPE_DESKTOP = 'DESKTOP'; + const DEVICE_TYPE_MOBILE = 'mobile'; + const DEVICE_TYPE_TABLE = 'tablet'; + const DEVICE_TYPE_DESKTOP = 'desktop'; public static function get($atributeName) { @@ -94,6 +94,11 @@ public static function getClientIP() return $ip; } + public static function getClientAgent(){ + $agent = ArrayHelper::get($_SERVER,'HTTP_USER_AGENT'); + return $agent; + } + /** * Return string with Device Type of client * https://code-boxx.com/detect-mobile-desktop-in-php/ @@ -102,11 +107,16 @@ public static function getClientIP() */ public static function getClientDeviceType() { - if (is_numeric(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), self::DEVICE_TYPE_MOBILE))) { - return is_numeric(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "tablet")) ? self::DEVICE_TYPE_TABLE : self::DEVICE_TYPE_DESKTOP ; - } else { - return 0; + $agent = strtolower(self::getClientAgent()); + $type = null; + if (is_numeric(strpos($agent, self::DEVICE_TYPE_MOBILE))) { + $type = self::DEVICE_TYPE_MOBILE; + } else if( is_numeric(strpos($agent, self::DEVICE_TYPE_TABLE)) ) { + $type = self::DEVICE_TYPE_TABLE; + }else{ + $type = self::DEVICE_TYPE_DESKTOP; } + return $type; } }