Upgrade to TYPO3 9.5 LTS

This commit is contained in:
Björn Fromme
2019-06-06 17:20:29 +02:00
parent adab7fb39a
commit 3c472eb973
989 changed files with 4924 additions and 3674 deletions
@@ -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,197 @@
<?php
namespace EP\EpTrack\Middleware;
/***************************************************************
*
* Copyright notice
*
* (c) 2019 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 DateInterval;
use DateTime;
use Doctrine\DBAL\DBALException;
use EP\EpProducts\Traits\DbConnectionTrait;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class TrackingMiddleware implements MiddlewareInterface
{
use DbConnectionTrait;
const COOKIE_NAME = 'ep_trk';
const COOKIE_TTL = 30;
const CODE_PATTERN = '([a-z]{4}|PA)\d{4}.*';
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($redirect = $this->matchRedirect($request)) {
[$uri, $responseCode] = $redirect;
return new RedirectResponse(
$uri,
$responseCode
);
}
if ($uri = $this->matchTrackingCodeInUri($request)) {
return new RedirectResponse($uri);
}
return $handler->handle($request);
}
/**
* @param ServerRequestInterface $request
* @return array
* @throws DBALException
*/
public function matchRedirect(ServerRequestInterface $request): ?array
{
/** @var NormalizedParams $params */
$params = $request->getAttribute('normalizedParams');
$uri = strtolower($params->getRequestUri());
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 null;
}
$trackingCode = $redirect['tracking_code'];
if (!empty($trackingCode)) {
$this->setCookie($trackingCode);
}
$targetPage = $redirect['target_page_uid'];
$responseCode = $redirect['response_code'];
$controller = $this->bootFrontendController($request->getAttribute('site'));
$typolinkConfig = ['parameter' => $targetPage, 'forceAbsoluteUrl' => true];
if ($redirect['utm_source'] && $redirect['utm_medium'] && $redirect['utm_campaign'] && $redirect['utm_content']) {
$typolinkConfig['additionalParams'] = '&' . http_build_query([
'utm_source' => $redirect['utm_source'],
'utm_medium' => $redirect['utm_medium'],
'utm_campaign' => $redirect['utm_campaign'],
'utm_content' => $redirect['utm_content'],
]);
}
return [$controller->cObj->typolink_URL($typolinkConfig), $responseCode];
}
/**
* @param ServerRequestInterface $request
* @return string
* @throws Exception
*/
public function matchTrackingCodeInUri(ServerRequestInterface $request): ?string
{
/** @var NormalizedParams $params */
$params = $request->getAttribute('normalizedParams');
$query = $params->getQueryString();
$path = $params->getRequestUri();
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 (!empty($query)) {
$uri .= '?' . $query;
}
return $uri;
}
return null;
}
/**
* @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(), '/');
}
/**
* Borrowed from \TYPO3\CMS\Redirects\Service\RedirectService
*
* @param SiteInterface|null $site
* @param array $queryParams
* @return TypoScriptFrontendController
* @throws ServiceUnavailableException
* @throws ImmediateResponseException
*/
protected function bootFrontendController(?SiteInterface $site, array $queryParams = []): TypoScriptFrontendController
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling'] = false;
/** @var TypoScriptFrontendController $controller */
$controller = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
null,
$site ? $site->getRootPageId() : $GLOBALS['TSFE']->id,
0
);
$controller->fe_user = $GLOBALS['TSFE']->fe_user ?? null;
$controller->fetch_the_id();
$controller->calculateLinkVars($queryParams);
$controller->getConfigArray();
$controller->settingLanguage();
$controller->settingLocale();
$controller->newCObj();
return $controller;
}
}
@@ -0,0 +1,15 @@
<?php
return [
'frontend' => [
'ep/track' => [
'target' => \EP\EpTrack\Middleware\TrackingMiddleware::class,
'before' => [
'typo3/cms-frontend/base-redirect-resolver',
],
'after' => [
'typo3/cms-frontend/site',
],
],
],
];
@@ -0,0 +1,219 @@
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect',
'default_sortby' => 'ORDER BY label',
'label' => 'label',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => true,
'versioningWS' => true,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
],
'searchFields' => 'label, redirect_from, tracking_code',
'iconfile' => 'EXT:ep_track/Resources/Public/Icons/tx_eptrack_domain_model_redirect.gif'
],
'interface' => [
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, label, redirect_from,
target_page_uid, tracking_code, response_code, utm_source, utm_medium, utm_campaign, utm_content',
],
'types' => [
'1' => [
'showitem' => 'hidden, label, redirect_from, target_page_uid, --palette--;;codes, --palette--;UTM;utm',
],
],
'palettes' => [
'codes' => ['showitem' => 'tracking_code, response_code'],
'utm' => ['showitem' => 'utm_source, utm_medium, utm_campaign, utm_content'],
],
'columns' => [
'sys_language_uid' => [
'exclude' => 0,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => [
['LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1],
['LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0]
],
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 0,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['', 0],
],
'foreign_table' => 'tx_eptrack_domain_model_redirect',
'foreign_table_where' => 'AND tx_eptrack_domain_model_redirect.pid=###CURRENT_PID### AND tx_eptrack_domain_model_redirect.sys_language_uid IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
't3ver_label' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
]
],
'hidden' => [
'exclude' => 0,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
'config' => [
'type' => 'check',
],
],
'starttime' => [
'exclude' => 0,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
'config' => [
'type' => 'input',
'size' => 13,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => [
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'renderType' => 'inputDateTime',
],
],
'endtime' => [
'exclude' => 0,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
'config' => [
'type' => 'input',
'size' => 13,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => [
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
],
'behaviour' => [
'allowLanguageSynchronization' => true,
],
'renderType' => 'inputDateTime',
],
],
'sorting' => [
'config' => [
'type' => 'passthrough'
],
],
'label' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.label',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
],
],
'redirect_from' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.redirect_from',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim,required,unique,lower'
],
],
'target_page_uid' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.target_page_uid',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'required',
'renderType' => 'inputLink',
],
],
'tracking_code' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.tracking_code',
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'trim',
],
],
'response_code' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.response_code',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'default' => '301',
'items' => [
['301', '301'],
['302', '302'],
],
],
],
'utm_source' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.utm_source',
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'trim',
],
],
'utm_medium' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.utm_medium',
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'trim',
],
],
'utm_campaign' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.utm_campaign',
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'trim',
],
],
'utm_content' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_track/Resources/Private/Language/locallang.xlf:tx_eptrack_domain_model_redirect.utm_content',
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'trim',
],
],
]
];
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="de" datatype="plaintext" original="messages" date="2016-05-04T20:49:43Z" product-name="ep_track">
<header/>
<body>
<trans-unit id="tx_eptrack_domain_model_redirect">
<source>Redirect</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.label">
<source>Bezeichnung</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.redirect_from">
<source>Redirect URL</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.target_page_uid">
<source>Zielseite</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.tracking_code">
<source>Trackingcode</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.response_code">
<source>Typ</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.utm_source">
<source>Source</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.utm_medium">
<source>Medium</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.utm_campaign">
<source>Campaign</source>
</trans-unit>
<trans-unit id="tx_eptrack_domain_model_redirect.utm_content">
<source>Content</source>
</trans-unit>
</body>
</file>
</xliff>
Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

@@ -0,0 +1,15 @@
<?php
$EM_CONF[$_EXTKEY] = [
'title' => 'E&P Tracking',
'description' => '',
'category' => 'plugin',
'author' => 'Björn Fromme',
'author_email' => '[email protected]',
'state' => 'stable',
'author_company' => 'dreipunktnull',
'version' => '1.1.0',
'constraints' => [
'depends' => [],
],
];
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@@ -0,0 +1,4 @@
<?php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][$_EXTKEY] =
\EP\EpTrack\Hook\Tcemain::class;
@@ -0,0 +1,49 @@
# noinspection SqlNoDataSourceInspectionForFile
#
# Table structure for table 'tx_eptrack_domain_model_redirect'
#
CREATE TABLE tx_eptrack_domain_model_redirect (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
label varchar(255) DEFAULT '' NOT NULL,
redirect_from varchar(255) DEFAULT '' NOT NULL,
target_page_uid varchar(255) DEFAULT '' NOT NULL,
tracking_code varchar(255) DEFAULT '' NOT NULL,
response_code char(3) DEFAULT '301' NOT NULL,
utm_source varchar(255) DEFAULT '' NOT NULL,
utm_medium varchar(255) DEFAULT '' NOT NULL,
utm_campaign varchar(255) DEFAULT '' NOT NULL,
utm_content varchar(255) DEFAULT '' NOT NULL,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
crdate int(11) unsigned DEFAULT '0' NOT NULL,
cruser_id int(11) unsigned DEFAULT '0' NOT NULL,
deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
hidden tinyint(4) unsigned DEFAULT '0' NOT NULL,
starttime int(11) unsigned DEFAULT '0' NOT NULL,
endtime int(11) unsigned DEFAULT '0' NOT NULL,
t3ver_oid int(11) DEFAULT '0' NOT NULL,
t3ver_id int(11) DEFAULT '0' NOT NULL,
t3ver_wsid int(11) DEFAULT '0' NOT NULL,
t3ver_label varchar(255) DEFAULT '' NOT NULL,
t3ver_state tinyint(4) DEFAULT '0' NOT NULL,
t3ver_stage int(11) DEFAULT '0' NOT NULL,
t3ver_count int(11) DEFAULT '0' NOT NULL,
t3ver_tstamp int(11) DEFAULT '0' NOT NULL,
t3ver_move_id int(11) DEFAULT '0' NOT NULL,
sys_language_uid int(11) DEFAULT '0' NOT NULL,
l10n_parent int(11) DEFAULT '0' NOT NULL,
l10n_diffsource mediumblob,
PRIMARY KEY (uid),
KEY parent (pid),
KEY redirectfrom (redirect_from),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
);