mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
#1774 Mobile class is updated for more mobile devices. Tablet PC would see PC version website and it can select also mobile site. And some enhancements.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10539 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
07b8f8c8b4
commit
d4babffdef
1 changed files with 97 additions and 16 deletions
|
|
@ -24,29 +24,70 @@ class Mobile {
|
|||
|
||||
$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;
|
||||
|
||||
$m = Context::get('m');
|
||||
if(strlen($m)==1) {
|
||||
if($m == "1") {
|
||||
$_COOKIE['mobile'] = 'true';
|
||||
setcookie('mobile', 'true', 0, $xe_web_path);
|
||||
$this->ismobile = true;
|
||||
} elseif($m == "0") {
|
||||
$_COOKIE['mobile'] = 'false';
|
||||
setcookie('mobile', 'false', 0, $xe_web_path);
|
||||
$this->ismobile = false;
|
||||
}
|
||||
} elseif(isset($_COOKIE['mobile'])) {
|
||||
if($_COOKIE['mobile'] == 'true') {
|
||||
$this->ismobile = true;
|
||||
} else {
|
||||
if($_COOKIE['user-agent'] == md5($_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
if($_COOKIE['mobile'] == 'true') {
|
||||
$this->ismobile = true;
|
||||
} else {
|
||||
$this->ismobile = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ismobile = FALSE;
|
||||
setcookie("mobile", FALSE, 0, $xe_web_path);
|
||||
setcookie("user-agent", FALSE, 0, $xe_web_path);
|
||||
if(!$this->isMobilePadCheckByAgent() && $this->isMobileCheckByAgent())
|
||||
{
|
||||
$this->ismobile = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->isMobilePadCheckByAgent())
|
||||
{
|
||||
$this->ismobile = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->isMobileCheckByAgent())
|
||||
{
|
||||
$this->ismobile = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->ismobile !== NULL)
|
||||
{
|
||||
if($this->ismobile == TRUE)
|
||||
{
|
||||
if($_COOKIE['mobile'] != 'true')
|
||||
{
|
||||
$_COOKIE['mobile'] = 'true';
|
||||
setcookie("mobile", 'true', 0, $xe_web_path);
|
||||
}
|
||||
}
|
||||
elseif($_COOKIE['mobile'] != 'false')
|
||||
{
|
||||
$_COOKIE['mobile'] = 'false';
|
||||
setcookie('mobile', 'false', 0, $xe_web_path);
|
||||
$this->ismobile = false;
|
||||
}
|
||||
} else {
|
||||
if($this->isMobileCheckByAgent()) {
|
||||
setcookie("mobile", 'true', 0, $xe_web_path);
|
||||
$this->ismobile = true;
|
||||
setcookie("mobile", 'false', 0, $xe_web_path);
|
||||
}
|
||||
|
||||
if($_COOKIE['user-agent'] != md5($_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
setcookie("user-agent",md5($_SERVER['HTTP_USER_AGENT']), 0, $xe_web_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,15 +96,55 @@ class Mobile {
|
|||
|
||||
function isMobileCheckByAgent()
|
||||
{
|
||||
$mobildAgent = array('iPod','iPhone','Android','BlackBerry','SymbianOS','Bada','Kindle','Wii','SCH-','SPH-','CANU-','Windows Phone','Windows CE','POLARIS','Palm','webOS','Dorothy Browser','IEMobile','MobileSafari','Opera Mobi','Opera Mini','MobileExplorer','Minimo','AvantGo','NetFront','Googlebot-Mobile','Nokia','LGPlayer','SonyEricsson','HTC','hp-tablet','SKT','lgtelecom','Vodafone');
|
||||
static $UACheck = NULL;
|
||||
if($UACheck !== NULL) return $UACheck;
|
||||
|
||||
foreach($mobildAgent as $agent)
|
||||
$oMobile =& Mobile::getInstance();
|
||||
$mobileAgent = array('iPod','iPhone','Android','BlackBerry','SymbianOS','Bada','Kindle','Wii','SCH-','SPH-','CANU-','Windows Phone','Windows CE','POLARIS','Palm','Dorothy Browser','IEMobile','Opera Mobi','Opera Mini','MobileExplorer','Minimo','AvantGo','NetFront','Googlebot-Mobile','Nokia','LGPlayer','SonyEricsson','HTC','SKT','lgtelecom','Vodafone');
|
||||
|
||||
if($oMobile->isMobilePadCheckByAgent())
|
||||
{
|
||||
$UACheck = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
foreach($mobileAgent as $agent)
|
||||
{
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE)
|
||||
{
|
||||
$UACheck = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
$UACheck = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* @ brief check if user-agent is a tablet PC as iPad or Andoid tablet.
|
||||
* @ return TRUE for tablet, and FALSE for else.
|
||||
*/
|
||||
function isMobilePadCheckByAgent()
|
||||
{
|
||||
$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 = array('Android' => 'Mobile');
|
||||
|
||||
foreach($padAgent as $agent)
|
||||
{
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE)
|
||||
{
|
||||
if(!isset($exceptionAgent[$agent]))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif(strpos($_SERVER['HTTP_USER_AGENT'], $exceptionAgent[$agent]) === FALSE)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue