Update core classes to refer to UA class for robot detection

This commit is contained in:
Kijin Sung 2016-03-19 23:32:35 +09:00
parent f1441613a2
commit 37bce0343d
5 changed files with 17 additions and 93 deletions

View file

@ -686,7 +686,7 @@ class Context
public function checkSSO() public function checkSSO()
{ {
// pass if it's not GET request or XE is not yet installed // pass if it's not GET request or XE is not yet installed
if(!config('use_sso') || isCrawler()) if(!config('use_sso') || Rhymix\Framework\UA::isRobot())
{ {
return TRUE; return TRUE;
} }

View file

@ -55,9 +55,6 @@ class Mobile
return $this->ismobile = false; return $this->ismobile = false;
} }
$xe_web_path = Context::pathToUrl(_XE_PATH_);
// default setting. if there is cookie for a device, XE do not have to check if it is mobile or not and it will enhance performace of the server.
$this->ismobile = FALSE; $this->ismobile = FALSE;
$m = Context::get('m'); $m = Context::get('m');
@ -87,28 +84,14 @@ class Mobile
} }
else else
{ {
$this->ismobile = FALSE; setcookie("mobile", FALSE, 0, RX_BASEURL);
setcookie("mobile", FALSE, 0, $xe_web_path); setcookie("user-agent", FALSE, 0, RX_BASEURL);
setcookie("user-agent", FALSE, 0, $xe_web_path); $this->ismobile = Rhymix\Framework\UA::isMobile() && !Rhymix\Framework\UA::isTablet();
if(!self::isMobilePadCheckByAgent() && self::isMobileCheckByAgent())
{
$this->ismobile = TRUE;
}
} }
} }
else else
{ {
if(self::isMobilePadCheckByAgent()) $this->ismobile = Rhymix\Framework\UA::isMobile() && !Rhymix\Framework\UA::isTablet();
{
$this->ismobile = FALSE;
}
else
{
if(self::isMobileCheckByAgent())
{
$this->ismobile = TRUE;
}
}
} }
if($this->ismobile !== NULL) if($this->ismobile !== NULL)
@ -118,18 +101,18 @@ class Mobile
if($_COOKIE['mobile'] != 'true') if($_COOKIE['mobile'] != 'true')
{ {
$_COOKIE['mobile'] = 'true'; $_COOKIE['mobile'] = 'true';
setcookie("mobile", 'true', 0, $xe_web_path); setcookie("mobile", 'true', 0, RX_BASEURL);
} }
} }
elseif(isset($_COOKIE['mobile']) && $_COOKIE['mobile'] != 'false') elseif(isset($_COOKIE['mobile']) && $_COOKIE['mobile'] != 'false')
{ {
$_COOKIE['mobile'] = 'false'; $_COOKIE['mobile'] = 'false';
setcookie("mobile", 'false', 0, $xe_web_path); setcookie("mobile", 'false', 0, RX_BASEURL);
} }
if(isset($_COOKIE['mobile']) && $_COOKIE['user-agent'] != md5($_SERVER['HTTP_USER_AGENT'])) if(isset($_COOKIE['mobile']) && $_COOKIE['user-agent'] != md5($_SERVER['HTTP_USER_AGENT']))
{ {
setcookie("user-agent", md5($_SERVER['HTTP_USER_AGENT']), 0, $xe_web_path); setcookie("user-agent", md5($_SERVER['HTTP_USER_AGENT']), 0, RX_BASEURL);
} }
} }
@ -143,31 +126,7 @@ class Mobile
*/ */
public static function isMobileCheckByAgent() public static function isMobileCheckByAgent()
{ {
static $UACheck; return Rhymix\Framework\UA::isMobile();
if(isset($UACheck))
{
return $UACheck;
}
$oMobile = Mobile::getInstance();
$mobileAgent = array('iPod', 'iPhone', 'Android', 'BlackBerry', 'SymbianOS', 'Bada', 'Tizen', 'Kindle', 'Wii', 'SCH-', 'SPH-', 'CANU-', 'Windows Phone', 'Windows CE', 'POLARIS', 'Palm', 'Dorothy Browser', 'Mobile', 'Opera Mobi', 'Opera Mini', 'Minimo', 'AvantGo', 'NetFront', 'Nokia', 'LGPlayer', 'SonyEricsson', 'HTC');
if($oMobile->isMobilePadCheckByAgent())
{
$UACheck = TRUE;
return TRUE;
}
foreach($mobileAgent as $agent)
{
if(stripos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE)
{
$UACheck = TRUE;
return TRUE;
}
}
$UACheck = FALSE;
return FALSE;
} }
/** /**
@ -177,45 +136,7 @@ class Mobile
*/ */
public static function isMobilePadCheckByAgent() public static function isMobilePadCheckByAgent()
{ {
static $UACheck; return Rhymix\Framework\UA::isTablet();
if(isset($UACheck))
{
return $UACheck;
}
$padAgent = array('iPad', 'Android', 'webOS', 'hp-tablet', 'PlayBook');
// Android with 'Mobile' string is not a tablet-like device, and 'Andoroid' without 'Mobile' string is a tablet-like device.
// $exceptionAgent[0] contains exception agents for all exceptions.
$exceptionAgent = array(0 => array('Opera Mini', 'Opera Mobi'), 'Android' => 'Mobile');
foreach($padAgent as $agent)
{
if(strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE)
{
if(!isset($exceptionAgent[$agent]))
{
$UACheck = TRUE;
return TRUE;
}
elseif(strpos($_SERVER['HTTP_USER_AGENT'], $exceptionAgent[$agent]) === FALSE)
{
// If the agent is the Android, that can be either tablet and mobile phone.
foreach($exceptionAgent[0] as $val)
{
if(strpos($_SERVER['HTTP_USER_AGENT'], $val) !== FALSE)
{
$UACheck = FALSE;
return FALSE;
}
}
$UACheck = TRUE;
return TRUE;
}
}
}
$UACheck = FALSE;
return FALSE;
} }
/** /**

View file

@ -238,7 +238,7 @@ class ModuleHandler extends Handler
} }
// redirect, if site_srl of module_info is different from one of site's module_info // redirect, if site_srl of module_info is different from one of site's module_info
if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) if($module_info && $module_info->site_srl != $site_module_info->site_srl && !Rhymix\Framework\UA::isRobot())
{ {
// If the module is of virtual site // If the module is of virtual site
if($module_info->site_srl) if($module_info->site_srl)

View file

@ -999,8 +999,7 @@ function json_encode2($data)
*/ */
function isCrawler($agent = NULL) function isCrawler($agent = NULL)
{ {
$agent = $agent ?: $_SERVER['HTTP_USER_AGENT']; return Rhymix\Framework\UA::isRobot($agent);
return (bool)preg_match('@bot|crawl|sp[iy]der|https?://|google|yahoo|slurp|yeti|daum|teoma|fish|hanrss|facebook|yandex|infoseek|askjeeves|stackrambler@i', $agent);
} }
/** /**

View file

@ -1098,7 +1098,11 @@ class documentController extends document
function updateReadedCount(&$oDocument) function updateReadedCount(&$oDocument)
{ {
// Pass if Crawler access // Pass if Crawler access
if(isCrawler()) return false; if (\Rhymix\Framework\UA::isRobot())
{
return false;
}
$oDocumentModel = getModel('document'); $oDocumentModel = getModel('document');
$config = $oDocumentModel->getDocumentConfig(); $config = $oDocumentModel->getDocumentConfig();