Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Mobile Detect library http://mobiledetect.net/ #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 0 additions & 167 deletions code/MobileBrowserDetector.php

This file was deleted.

70 changes: 26 additions & 44 deletions code/MobileSiteControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
* @package mobile
*/
class MobileSiteControllerExtension extends Extension {

/**
* Instance of mobile detect class
*
* @var Mobile_Detect()
*/
protected $mobile_detect;

public function getMobileDetect() {
return $this->mobile_detect;
}

public function setMobileDetect($detector) {
$this->mobile_detect = $detector;
return $this;
}


/**
* The expiration time of a cookie set for full site requests
Expand All @@ -18,6 +35,12 @@ class MobileSiteControllerExtension extends Extension {
* Stores state information as to which site is currently served.
*/
private static $is_mobile = false;


public function onBeforeInit() {
// Set our mobile detector
$this->owner->setMobileDetect(new Mobile_Detect());
}

/**
* Override the default behavior to ensure that if this is a mobile device
Expand Down Expand Up @@ -81,13 +104,13 @@ public function onAfterInit() {
}

// User just wants to see a theme, but no redirect occurs
if(MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'MobileThemeOnly') {
if($this->owner->getMobileDetect()->isMobile() && $config->MobileSiteType == 'MobileThemeOnly') {
SSViewer::set_theme($config->MobileTheme);
self::$is_mobile = true;
}

// If on a mobile device, but not on the mobile domain and has been setup for redirection
if(!$this->onMobileDomain() && MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'RedirectToDomain') {
if(!$this->onMobileDomain() && $this->owner->getMobileDetect()->isMobile() && $config->MobileSiteType == 'RedirectToDomain') {
return $this->owner->redirect($config->MobileDomainNormalized, 301);
}
}
Expand Down Expand Up @@ -120,7 +143,7 @@ public function requestedMobileSite() {
return ($fullSiteCookie == 0);
}

return MobileBrowserDetector::is_mobile();
return $this->owner->getMobileDetect()->isMobile();
}

/**
Expand Down Expand Up @@ -165,45 +188,4 @@ public function FullSiteLink() {
public function MobileSiteLink() {
return Controller::join_links($this->owner->Link(), '?fullSite=0');
}

/**
* Is the current HTTP_USER_AGENT a known iPhone or iPod Touch
* mobile agent string?
*
* @return boolean
*/
public function IsiPhone() {
return MobileBrowserDetector::is_iphone();
}

/**
* Is the current HTTP_USER_AGENT a known Android mobile
* agent string?
*
* @return boolean
*/
public function IsAndroid() {
return MobileBrowserDetector::is_android();
}

/**
* Is the current HTTP_USER_AGENT a known Opera Mini
* agent string?
*
* @return boolean
*/
public function IsOperaMini() {
return MobileBrowserDetector::is_opera_mini();
}

/**
* Is the current HTTP_USER_AGENT a known Blackberry
* mobile agent string?
*
* @return boolean
*/
public function IsBlackBerry() {
return MobileBrowserDetector::is_blackberry();
}

}
Loading