Rename public directory
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace EP\EpTrack\Hook;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2016 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
||||
|
||||
class Tcemain
|
||||
{
|
||||
/**
|
||||
* @param array $fields
|
||||
* @param string $table
|
||||
* @param string $table
|
||||
* @param int $id
|
||||
* @param DataHandler $dataHandler
|
||||
*/
|
||||
public function processDatamap_preProcessFieldArray(array &$fields, $table, $id, DataHandler $dataHandler)
|
||||
{
|
||||
// Force trailing slash
|
||||
if ($table === 'tx_eptrack_domain_model_redirect') {
|
||||
$url = $fields['redirect_from'];
|
||||
if (substr($url, 0, 1) !== '/') {
|
||||
$url = '/' . $url;
|
||||
}
|
||||
if (substr($url, -1) !== '/') {
|
||||
$url .= '/';
|
||||
}
|
||||
$fields['redirect_from'] = $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace EP\EpTrack\Service;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2016 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\TimeTracker\NullTimeTracker;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\HttpUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3\CMS\Frontend\Page\PageGenerator;
|
||||
use TYPO3\CMS\Frontend\Utility\EidUtility;
|
||||
|
||||
class RequestService
|
||||
{
|
||||
use DbConnectionTrait;
|
||||
|
||||
const COOKIE_NAME = 'ep_trk';
|
||||
const COOKIE_TTL = 30;
|
||||
const CODE_PATTERN = '([a-z]{4}|PA)\d{4}.*';
|
||||
|
||||
/**
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function handleRequest()
|
||||
{
|
||||
$currentUri = GeneralUtility::getIndpEnv('REQUEST_URI');
|
||||
$this->matchRedirect($currentUri);
|
||||
$this->matchTrackingCodeInUri($currentUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currentUri
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function matchRedirect($currentUri)
|
||||
{
|
||||
$uri = strtolower(parse_url($currentUri, \PHP_URL_PATH));
|
||||
|
||||
if (substr($uri, -1) !== '/') {
|
||||
$uri .= '/';
|
||||
}
|
||||
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$redirect = $qb
|
||||
->select('*')
|
||||
->from('tx_eptrack_domain_model_redirect')
|
||||
->where('redirect_from = LOWER(:uri)')
|
||||
->andWhere('deleted = 0')
|
||||
->andWhere('hidden = 0')
|
||||
->setParameter('uri', $uri)
|
||||
->execute()
|
||||
->fetch()
|
||||
;
|
||||
|
||||
if ($redirect === false) {
|
||||
return;
|
||||
}
|
||||
$trackingCode = $redirect['tracking_code'];
|
||||
if (!empty($trackingCode)) {
|
||||
$this->setCookie($trackingCode);
|
||||
}
|
||||
$targetPageUid = $redirect['target_page_uid'];
|
||||
$responseCode = $redirect['response_code'];
|
||||
$this->initTSFE($targetPageUid);
|
||||
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
|
||||
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
|
||||
$typolinkConfig = ['parameter' => $targetPageUid, 'forceAbsoluteUrl' => true ];
|
||||
$query = $this->buildUtmParameters($redirect);
|
||||
if ($query) {
|
||||
$typolinkConfig['additionalParams'] = '&' . $query;
|
||||
}
|
||||
$uri = $cObj->typolink_URL($typolinkConfig);
|
||||
$this->redirect($uri, $responseCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $redirect
|
||||
* @return string
|
||||
*/
|
||||
public function buildUtmParameters(array $redirect)
|
||||
{
|
||||
if ($redirect['utm_source'] && $redirect['utm_medium'] && $redirect['utm_campaign'] && $redirect['utm_content']) {
|
||||
return http_build_query([
|
||||
'utm_source' => $redirect['utm_source'],
|
||||
'utm_medium' => $redirect['utm_medium'],
|
||||
'utm_campaign' => $redirect['utm_campaign'],
|
||||
'utm_content' => $redirect['utm_content'],
|
||||
]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currentUri
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function matchTrackingCodeInUri($currentUri)
|
||||
{
|
||||
$query = parse_url($currentUri, \PHP_URL_QUERY);
|
||||
$path = parse_url($currentUri, \PHP_URL_PATH);
|
||||
if (preg_match('/(' . static::CODE_PATTERN . ')\/?$/i', $path)) {
|
||||
$urlItems = GeneralUtility::trimExplode('/', $path, true);
|
||||
$code = array_pop($urlItems);
|
||||
$this->setCookie($code);
|
||||
$uri = '/';
|
||||
if (count($urlItems) > 0) {
|
||||
$uri = '/' . implode('/', $urlItems) . '/';
|
||||
}
|
||||
if ($query !== null) {
|
||||
$uri .= '?' . $query;
|
||||
}
|
||||
$this->redirect($uri);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function setCookie($code)
|
||||
{
|
||||
$expiratonDate = new \DateTime('now');
|
||||
$expiratonDate->add(new \DateInterval('P' . static::COOKIE_TTL. 'D'));
|
||||
setcookie(static::COOKIE_NAME, $code, $expiratonDate->getTimestamp(), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param string $responseCode
|
||||
*/
|
||||
protected function redirect($uri, $responseCode = '301')
|
||||
{
|
||||
HttpUtility::redirect($uri, \constant('\TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_' . $responseCode));
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $typeNum
|
||||
*/
|
||||
public function initTSFE($id = 1, $typeNum = 0)
|
||||
{
|
||||
// Preprocess possible typolink format
|
||||
if (strpos($id, 't3://') !== false) {
|
||||
parse_str(parse_url($id, PHP_URL_QUERY), $arguments);
|
||||
$id = $arguments['uid'];
|
||||
}
|
||||
|
||||
EidUtility::initTCA();
|
||||
if (!is_object($GLOBALS['TT'])) {
|
||||
$GLOBALS['TT'] = new NullTimeTracker;
|
||||
$GLOBALS['TT']->start();
|
||||
}
|
||||
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], $id, $typeNum);
|
||||
$GLOBALS['TSFE']->connectToDB();
|
||||
$GLOBALS['TSFE']->initFEuser();
|
||||
$GLOBALS['TSFE']->determineId();
|
||||
$GLOBALS['TSFE']->initTemplate();
|
||||
$GLOBALS['TSFE']->rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($id, '');
|
||||
$GLOBALS['TSFE']->getConfigArray();
|
||||
|
||||
if (ExtensionManagementUtility::isLoaded('realurl')) {
|
||||
$rootline = BackendUtility::BEgetRootLine($id);
|
||||
$host = BackendUtility::firstDomainRecord($rootline);
|
||||
$_SERVER['HTTP_HOST'] = $host;
|
||||
}
|
||||
|
||||
PageGenerator::pagegenInit();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user