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

Alternate cookie/redirect policy #2

Open
wants to merge 4 commits 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
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
- No features added, support for Typo3 4.x dropped. Please use version 1.4.4 if you still use 4.x!
- However some renaming took place

2014-12-03 Hannes Lau <[email protected]>
* Prepare for next release
- A standard cookie will not force a redirect from the mobile to the standard version anymore. Instead the cookies just serve to prevent an automatic redirection from standard to mobile.
- Allow to configure the cookie domain

2014-09-29 Carsten Windler <[email protected]>
* Version 1.4.4 released:
- Feature #61801: Ensure compatibility with Typo3 6.2.x
Expand Down
50 changes: 34 additions & 16 deletions Classes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function checkRedirect()
}

// here the real detection begins
if ($this->detectMobile() && $this->conf['redirection_enabled']) {
if ($this->conf['redirection_enabled'] && !$this->isStandardAccepted() && $this->detectMobile()) {
$this->redirectToMobileUrl(false);
}

Expand Down Expand Up @@ -445,8 +445,13 @@ protected function setExtensionCookie($cookieValue)
{
if ($this->conf['use_cookie']) {
$this->debugLog('Setting cookie', array('cookie_value' => $cookieValue));

return setcookie($this->conf['cookie_name'], $cookieValue, time()+$this->conf['cookie_lifetime'], "/");
return setcookie(
$this->conf['cookie_name'],
$cookieValue,
time()+$this->conf['cookie_lifetime'],
"/", // path
trim($this->conf['cookie_domain']) // domain
);
} else {
return false;
}
Expand Down Expand Up @@ -474,7 +479,7 @@ public function isStandardUrlRequested()

/**
* Determine if the standard mode is forced
* (checks Cookie and GET params)
* (checks GET params)
*
* @return boolean - true if standard mode is forced, false otherwise
*
Expand All @@ -486,12 +491,7 @@ public function isStandardForced()
$this->debugLog(print_r($_GET, 1));
$this->debugLog("--------------- isStandardForced END ----------------------");

return ((isset($_COOKIE[$this->conf['cookie_name']]) &&
$_COOKIE[$this->conf['cookie_name']] == self::MOBILEREDIRECT_COOKIE_STANDARD &&
!isset($_GET[$this->conf['is_mobile_name']])) ||
(!empty($this->conf['no_mobile_name']) && isset($_GET[$this->conf['no_mobile_name']])))
? true
: false;
return (!empty($this->conf['no_mobile_name']) && isset($_GET[$this->conf['no_mobile_name']])) ? true : false;
}

/**
Expand All @@ -507,12 +507,30 @@ public function isMobileForced()
$this->debugLog(print_r($_GET, 1));
$this->debugLog("--------------- isMobileForced END ----------------------");

return ((isset($_COOKIE[$this->conf['cookie_name']]) &&
$_COOKIE[$this->conf['cookie_name']] == self::MOBILEREDIRECT_COOKIE_MOBILE &&
!isset($_GET[$this->conf['no_mobile_name']])) ||
(!empty($this->conf['is_mobile_name']) && isset($_GET[$this->conf['is_mobile_name']])))
? true
: false;
return (!empty($this->conf['is_mobile_name']) && isset($_GET[$this->conf['is_mobile_name']])) ? true : false;
}



/**
* Determine if the standard mode is accepted
* (checks Cookie)
*
* @return boolean - true if the standard is forced OR a standard cookie is set
*/
public function isStandardAccepted()
{
$this->debugLog("--------------- isMobileAccepted BEGIN ----------------------");
$this->debugLog(print_r($_COOKIE,1));
$this->debugLog("--------------- isMobileAccepted END ----------------------");

return
$this->isStandardForced()
|| (
!$this->isMobileForced()
&& ((isset($_COOKIE[$this->conf['cookie_name']]) && $_COOKIE[$this->conf['cookie_name']] == self::MOBILEREDIRECT_COOKIE_STANDARD))
)
;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"license": "GPL-2.0+",
"require": {
"typo3/cms-core": "^6.2.0|^7.6.0"
"typo3/cms-core": "^6.2.0|^7.6.0|^8"
},
"require-dev": {
"mikey179/vfsStream": "1.4.*@dev",
Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ cookie_name = tx_cwmobileredirect
# cat=basic; type=text; label=Cookie lifetime:Seconds until the Cookie expires
cookie_lifetime = 3600

# cat=basic; type=text; label=Cookie domain:Domain for which the cookie will be valid. Defaults to hostname.
cookie_domain =

# cat=basic; type=text; label=is mobile GET name:GET-Parameter to force mobile version (e.g. www.domain.com?isMobile)
is_mobile_name = isMobile

Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
array (
'depends' =>
array (
'typo3' => '7.5.0-7.99.99',
'typo3' => '7.5.0-8.99.99',
),
'conflicts' =>
array (
Expand Down