diff --git a/Classes/Helper.php b/Classes/Helper.php new file mode 100644 index 0000000..cb69d6e --- /dev/null +++ b/Classes/Helper.php @@ -0,0 +1,115 @@ + + */ +class Helper { + + /** @var int|null */ + protected $currentPageId = null; + + /** @var int|null */ + protected $rootpage_id = null; + + /** @var int|null */ + protected $realurlConfig = null; + + /** @var int|null */ + protected $selectBSite = null; + + /** @var int|null */ + protected $cookieLifeTime = null; + + /** @var int|null */ + protected $randomAbPageId = null; + + /** @var string */ + protected $additionalHeaderData; + + /** + * + * @param array $params + * @param $pObj + * @return void + * @throws \InvalidArgumentException + */ + public function determineContentId(array $params, &$pObj) { + + // only try to change the page if it's not the googlebot. + if(false === stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot')) { + + $this->currentPageId = $params['pObj']->id; + + // Get the rootpage_id from realurl config. + $this->realurlConfig = $params['pObj']->TYPO3_CONF_VARS['EXTCONF']['realurl']; + if(array_key_exists($_SERVER['SERVER_NAME'], $this->realurlConfig)) { + $this->rootpage_id = $this->realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id']; + } else { + $this->rootpage_id = $this->realurlConfig['_DEFAULT']['pagePath']['rootpage_id']; + } + + // If the ID is NULL, then we set this value to the rootpage_id. NULL is the "Home"page, ID is a specific sub-page, e.g. www.domain.de (NULL) - www.domain.de/page.html (ID) + if(!$this->currentPageId) { + if($this->rootpage_id) { + $this->currentPageId = $this->rootpage_id; + } else { + // Leave the function because we can not determine the ID. + return; + } + } + + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); + $currentPagePropertiesArray = $pageRepository->getPage($this->currentPageId); + + $this->selectBSite = $currentPagePropertiesArray['tx_abtest2_b_id']; + $this->cookieLifeTime = $currentPagePropertiesArray['tx_abtest2_cookie_time']; + + if($this->selectBSite) { + if((int)$_COOKIE['abtest2-'.$this->currentPageId] > 0) { + $this->randomAbPageId = (int)$_COOKIE['abtest2-'.$this->currentPageId]; + } else { + $randomPage = rand(0,1); // 0 = original ID; 1 = "B" site. + if($randomPage) { + $this->randomAbPageId = $this->selectBSite; + } else { + $this->randomAbPageId = $this->currentPageId; + } + setcookie('abtest2-'.$this->currentPageId,$this->randomAbPageId,time()+$this->cookieLifeTime); + } + + // If current page ID is different from the random page ID we set the correct page ID. + if($this->currentPageId != $this->randomAbPageId) { + $pObj->contentPid = $this->randomAbPageId; + $GLOBALS['TSFE']->page['content_from_pid'] = $this->randomAbPageId; + $GLOBALS['TSFE']->page['no_cache'] = true; + } + } + + // If additional headerdata is present then we specify additionalHeaderData. + $randomPagePropertiesArray = $pageRepository->getPage($this->randomAbPageId); + $this->additionalHeaderData = $randomPagePropertiesArray['tx_abtest2_header']; + if($this->additionalHeaderData) { + $GLOBALS['TSFE']->additionalHeaderData['abtest2'] = $this->additionalHeaderData; + } + + } + + } +} + + diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php new file mode 100644 index 0000000..d666e6d --- /dev/null +++ b/Configuration/TCA/Overrides/pages.php @@ -0,0 +1,54 @@ + array( + 'exclude' => 1, + 'label' => 'LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:pages.tx_abtest2_b_id', + 'config' => array( + 'type' => 'group', + 'internal_type' => 'db', + 'allowed' => 'pages', + 'maxitems' => 1, + 'size' => 1 + ) + ), + 'tx_abtest2_cookie_time' => array( + 'exclude' => 1, + 'label' => 'LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:pages.tx_abtest2_cookie_time', + 'config' => array( + 'type' => 'select', + 'renderType' => 'selectSingle', + 'items' => array( + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_1_month', 2419200], + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_1_week', 604800], + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_1_day', 86400], + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_12_day', 43200], + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_1_hour', 3600], + ['LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:cookie_1_minute', 60] + ) + ) + ), + 'tx_abtest2_header' => array( + 'exclude' => 1, + 'label' => 'LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:pages.tx_abtest2_header', + 'config' => array( + 'type' => 'text' + ) + ), + 'tx_abtest2_counter' => array( + 'exclude' => 1, + 'label' => 'LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:pages.tx_abtest2_counter', + 'config' => array( + 'type' => 'text' + ) + ) +)); + +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages', + '--palette--;LLL:EXT:abtest2/Resources/Private/Language/locallang_db.xlf:palette_title;tx_abtest2', '', + 'after:subtitle'); + +$GLOBALS['TCA']['pages']['palettes']['tx_abtest2'] = array( + 'showitem' => 'tx_abtest2_b_id,--linebreak--,tx_abtest2_header,tx_abtest2_cookie_time,tx_abtest2_counter' +); + diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf new file mode 100644 index 0000000..a535e59 --- /dev/null +++ b/Resources/Private/Language/de.locallang_db.xlf @@ -0,0 +1,48 @@ + + + +
+ + + Site B + Seite B + + + Cookie Lifetime + Cookie Lebenszeit + + + Additional Header Information + Zusätzliche Header Informationen + + + AB Test Settings + AB Test Einstellungen + + + 1 month + 1 Monat + + + 1 week + 1 Woche + + + 1 day + 1 Tag + + + 1/2 day + 1/2 Tag + + + 1 hour + 1 Stunde + + + 1 minute + 1 Minute + + + + \ No newline at end of file diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf new file mode 100644 index 0000000..0ed975f --- /dev/null +++ b/Resources/Private/Language/locallang_db.xlf @@ -0,0 +1,38 @@ + + + +
+ + + Site B + + + Cookie Lifetime + + + Additional Header Information + + + AB Test Settings + + + 1 month + + + 1 week + + + 1 day + + + 1/2 day + + + 1 hour + + + 1 minute + + + + \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fd1d400 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "svewap/abtest2", + "type": "typo3-cms-extension", + "description": "", + "authors": [], + "require": { + "typo3/cms-core": "^8.7.1" + }, + "autoload": { + "psr-4": { + "WapplerSystems\\ABTest2\\": "Classes" + } + } +} diff --git a/ext_emconf.php b/ext_emconf.php new file mode 100644 index 0000000..fe103cd --- /dev/null +++ b/ext_emconf.php @@ -0,0 +1,43 @@ + 'AB Test Pages', + 'description' => 'This extension supports TYPO3 administrators in performing A/B tests. This is useful when a site owner want to measure whether a new version improves or reduces user interaction compared to the current version.', + 'category' => 'misc', + 'author' => 'IllusionFACTORY', + 'author_email' => 'info@illusion-factory.de', + 'state' => 'alpha', + 'uploadfolder' => false, + 'createDirs' => '', + 'clearCacheOnLoad' => 1, + 'version' => '1.0.2.sw', + 'constraints' => + array ( + 'depends' => + array ( + 'typo3' => '7.6.0-8.7.99', + 'realurl' => '2.0.0-0.0.0', + ), + 'conflicts' => + array ( + ), + 'suggests' => + array ( + ), + ), + 'comment' => '', + 'user' => 'timof', + 'clearcacheonload' => true, + 'author_company' => NULL, +); + diff --git a/ext_icon.png b/ext_icon.png new file mode 100644 index 0000000..ef81ce2 Binary files /dev/null and b/ext_icon.png differ diff --git a/ext_localconf.php b/ext_localconf.php new file mode 100644 index 0000000..8df6bce --- /dev/null +++ b/ext_localconf.php @@ -0,0 +1,6 @@ +SelectId'; \ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php new file mode 100644 index 0000000..7f0051f --- /dev/null +++ b/ext_tables.php @@ -0,0 +1,11 @@ +