Merge branch 'release/2019.07.062'
This commit is contained in:
@@ -62,31 +62,25 @@ class BookingUrlUtility
|
|||||||
|
|
||||||
$query = static::buildQuery($bookingId, $hotelId, $dateEnd, $template, $isDayTrip);
|
$query = static::buildQuery($bookingId, $hotelId, $dateEnd, $template, $isDayTrip);
|
||||||
|
|
||||||
$trackingCookie = null;
|
$epCookie = CookieUtility::getPaCookie();
|
||||||
$bpnCookie = null;
|
$bpnCookie = CookieUtility::getBpnCookie();
|
||||||
|
|
||||||
if (isset($_COOKIE[static::COOKIE_NAME])) {
|
if (isset($_COOKIE[static::COOKIE_NAME])) {
|
||||||
if (!preg_match('/^([a-z]{4}|PA)\d{4}$/', $_COOKIE[static::COOKIE_NAME])) {
|
if (!preg_match('/^([a-z]{4}|PA)\d{3,4}$/', $_COOKIE[static::COOKIE_NAME])) {
|
||||||
setcookie(static::COOKIE_NAME, '', time() - 3600);
|
setcookie(static::COOKIE_NAME, '', time() - 3600);
|
||||||
unset($_COOKIE[static::COOKIE_NAME]);
|
unset($_COOKIE[static::COOKIE_NAME]);
|
||||||
} else {
|
} else {
|
||||||
$trackingCookie = $_COOKIE[static::COOKIE_NAME];
|
$epCookie = $_COOKIE[static::COOKIE_NAME];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($_COOKIE[static::COOKIE_NAME_BPN])) {
|
|
||||||
$bpnCookie = $_COOKIE[static::COOKIE_NAME_BPN];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($paCode) {
|
if ($paCode) {
|
||||||
$query['agenturcode'] = $paCode;
|
$query['agenturcode'] = $paCode;
|
||||||
} elseif ($bpnCookie) {
|
} elseif ($bpnCookie) {
|
||||||
$query['agenturcode'] = $bpnCookie;
|
$query['agenturcode'] = $bpnCookie;
|
||||||
} elseif ($trackingCookie) {
|
} elseif ($epCookie) {
|
||||||
if (preg_match('/^PA\d+/', $trackingCookie)) {
|
$queryParameter = CookieUtility::getQueryParameter($epCookie);
|
||||||
$query['agenturcode'] = $trackingCookie;
|
$query[$queryParameter] = $epCookie;
|
||||||
} else {
|
|
||||||
$query['crminfo'] = $trackingCookie;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::buildUrl($query);
|
return static::buildUrl($query);
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace EP\EpProducts\Utility;
|
||||||
|
|
||||||
|
class CookieUtility
|
||||||
|
{
|
||||||
|
const COOKIENAME_TRK = 'ep_trk';
|
||||||
|
const COOKIETTL_TRK = 30;
|
||||||
|
const COOKIENAME_BPN = 'bpn_cookie';
|
||||||
|
const PATTERN = '/^PA\d{3,4}$/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public static function getPaCookie()
|
||||||
|
{
|
||||||
|
if (!isset($_COOKIE[static::COOKIENAME_TRK])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cookieValue = $_COOKIE[static::COOKIENAME_TRK];
|
||||||
|
|
||||||
|
if (!preg_match(static::PATTERN, $cookieValue)) {
|
||||||
|
setcookie(static::COOKIENAME_TRK, '', time() - 3600);
|
||||||
|
unset($_COOKIE[static::COOKIENAME_TRK]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cookieValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public static function getBpnCookie()
|
||||||
|
{
|
||||||
|
if (!isset($_COOKIE[static::COOKIENAME_BPN])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_COOKIE[static::COOKIENAME_BPN];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getQueryParameter($code)
|
||||||
|
{
|
||||||
|
if (!preg_match(static::PATTERN, $code)) {
|
||||||
|
return 'crminfo';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'agenturcode';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function setPaCookie($code)
|
||||||
|
{
|
||||||
|
$expiratonDate = new \DateTime('now');
|
||||||
|
$expiratonDate->add(new \DateInterval('P' . static::COOKIETTL_TRK . 'D'));
|
||||||
|
setcookie(
|
||||||
|
static::COOKIENAME_TRK,
|
||||||
|
strtoupper($code),
|
||||||
|
$expiratonDate->getTimestamp(),
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ namespace EP\EpTheme\DataProcessing;
|
|||||||
|
|
||||||
use EP\EpProducts\Service\ResellerDataService;
|
use EP\EpProducts\Service\ResellerDataService;
|
||||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||||
|
use EP\EpProducts\Utility\CookieUtility;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||||
@@ -67,7 +68,7 @@ class ContextProcessor implements DataProcessorInterface
|
|||||||
$processedData['context']['paCode'] = $resellerData['paCode'];
|
$processedData['context']['paCode'] = $resellerData['paCode'];
|
||||||
} elseif ($paCode = $this->getPaCodeFromRequest()) {
|
} elseif ($paCode = $this->getPaCodeFromRequest()) {
|
||||||
$processedData['context']['paCode'] = $paCode;
|
$processedData['context']['paCode'] = $paCode;
|
||||||
} elseif ($cookieData = $this->getCookieData()) {
|
} elseif ($cookieData = CookieUtility::getPaCookie()) {
|
||||||
$processedData['context']['paCode'] = $cookieData;
|
$processedData['context']['paCode'] = $cookieData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +104,7 @@ class ContextProcessor implements DataProcessorInterface
|
|||||||
|
|
||||||
if (array_key_exists('pa', $items)) {
|
if (array_key_exists('pa', $items)) {
|
||||||
$paCode = $items['pa'];
|
$paCode = $items['pa'];
|
||||||
$expiratonDate = new \DateTime('now');
|
CookieUtility::setPaCookie($paCode);
|
||||||
$expiratonDate->add(new \DateInterval('P' . '30D'));
|
|
||||||
setcookie('ep_trk', $paCode, $expiratonDate->getTimestamp(), '/');
|
|
||||||
|
|
||||||
return $paCode;
|
return $paCode;
|
||||||
}
|
}
|
||||||
@@ -113,18 +112,6 @@ class ContextProcessor implements DataProcessorInterface
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getCookieData()
|
|
||||||
{
|
|
||||||
if (isset($_COOKIE['ep_trk']) && preg_match('/^PA\d{3,4}$/', $_COOKIE['ep_trk'])) {
|
|
||||||
return $_COOKIE['ep_trk'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uid
|
* @param int $uid
|
||||||
* @param string $table
|
* @param string $table
|
||||||
|
|||||||
@@ -27,10 +27,9 @@ namespace EP\EpTrack\Middleware;
|
|||||||
* This copyright notice MUST APPEAR in all copies of the script!
|
* This copyright notice MUST APPEAR in all copies of the script!
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
use DateInterval;
|
|
||||||
use DateTime;
|
|
||||||
use Doctrine\DBAL\DBALException;
|
use Doctrine\DBAL\DBALException;
|
||||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||||
|
use EP\EpProducts\Utility\CookieUtility;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -48,14 +47,10 @@ class TrackingMiddleware implements MiddlewareInterface
|
|||||||
{
|
{
|
||||||
use DbConnectionTrait;
|
use DbConnectionTrait;
|
||||||
|
|
||||||
const COOKIE_NAME = 'ep_trk';
|
const CODE_PATTERN = 'PA\d{3,4}';
|
||||||
const COOKIE_TTL = 30;
|
|
||||||
const CODE_PATTERN = '([a-z]{4}|PA)\d{3,4}';
|
|
||||||
|
|
||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
$this->cleanupCookies();
|
|
||||||
|
|
||||||
if ($redirect = $this->matchRedirect($request)) {
|
if ($redirect = $this->matchRedirect($request)) {
|
||||||
[$uri, $responseCode] = $redirect;
|
[$uri, $responseCode] = $redirect;
|
||||||
|
|
||||||
@@ -104,8 +99,9 @@ class TrackingMiddleware implements MiddlewareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$trackingCode = $redirect['tracking_code'];
|
$trackingCode = $redirect['tracking_code'];
|
||||||
|
|
||||||
if (!empty($trackingCode)) {
|
if (!empty($trackingCode)) {
|
||||||
$this->setCookie($trackingCode);
|
CookieUtility::setPaCookie($trackingCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
$targetPage = $redirect['target_page_uid'];
|
$targetPage = $redirect['target_page_uid'];
|
||||||
@@ -139,13 +135,13 @@ class TrackingMiddleware implements MiddlewareInterface
|
|||||||
$query = $params->getQueryString();
|
$query = $params->getQueryString();
|
||||||
$path = $params->getRequestUri();
|
$path = $params->getRequestUri();
|
||||||
|
|
||||||
if (!preg_match('/^\/' . static::CODE_PATTERN . '\/?$/i', $path)) {
|
if (!preg_match('/^\/PA\d{3,4}\/?$/i', $path)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$urlItems = GeneralUtility::trimExplode('/', $path, true);
|
$urlItems = GeneralUtility::trimExplode('/', $path, true);
|
||||||
$code = array_pop($urlItems);
|
$code = array_pop($urlItems);
|
||||||
$this->setCookie($code);
|
CookieUtility::setPaCookie($code);
|
||||||
$uri = '/';
|
$uri = '/';
|
||||||
if (count($urlItems) > 0) {
|
if (count($urlItems) > 0) {
|
||||||
$uri = '/' . implode('/', $urlItems) . '/';
|
$uri = '/' . implode('/', $urlItems) . '/';
|
||||||
@@ -157,29 +153,6 @@ class TrackingMiddleware implements MiddlewareInterface
|
|||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $code
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function setCookie($code): void
|
|
||||||
{
|
|
||||||
$expiratonDate = new DateTime('now');
|
|
||||||
$expiratonDate->add(new DateInterval('P' . static::COOKIE_TTL . 'D'));
|
|
||||||
setcookie(static::COOKIE_NAME, $code, $expiratonDate->getTimestamp(), '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function cleanupCookies(): void
|
|
||||||
{
|
|
||||||
if (!isset($_COOKIE[static::COOKIE_NAME])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!preg_match('/^' . static::CODE_PATTERN . '$/', $_COOKIE[static::COOKIE_NAME])) {
|
|
||||||
setcookie(static::COOKIE_NAME, '', time() - 3600);
|
|
||||||
unset($_COOKIE[static::COOKIE_NAME]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Borrowed from \TYPO3\CMS\Redirects\Service\RedirectService
|
* Borrowed from \TYPO3\CMS\Redirects\Service\RedirectService
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user