mirror of
https://github.com/werkraum-media/abtest.git
synced 2024-11-24 05:16:10 +01:00
First commit
This commit is contained in:
parent
400a122a40
commit
19ef78f214
10 changed files with 335 additions and 0 deletions
115
Classes/Helper.php
Normal file
115
Classes/Helper.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace WapplerSystems\ABTest2;
|
||||
|
||||
/**
|
||||
* This file is part of the "abtest2" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
|
||||
/**
|
||||
* This class detects which page version (either by cookie or by random) and sets the page content ID accordingly.
|
||||
*
|
||||
* @package WapplerSystems\ABTest2
|
||||
* @author Sven Wapler <typo3YYYYY@wappler.systems>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
54
Configuration/TCA/Overrides/pages.php
Normal file
54
Configuration/TCA/Overrides/pages.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', array(
|
||||
'tx_abtest2_b_id' => 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'
|
||||
);
|
||||
|
48
Resources/Private/Language/de.locallang_db.xlf
Normal file
48
Resources/Private/Language/de.locallang_db.xlf
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<xliff version="1.0">
|
||||
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2017-10-20T11:36:00Z" product-name="abtest2">
|
||||
<header/>
|
||||
<body>
|
||||
<trans-unit id="pages.tx_abtest2_b_id">
|
||||
<source>Site B</source>
|
||||
<target>Seite B</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="pages.tx_abtest2_cookie_time">
|
||||
<source>Cookie Lifetime</source>
|
||||
<target>Cookie Lebenszeit</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="pages.tx_abtest2_header">
|
||||
<source>Additional Header Information</source>
|
||||
<target>Zusätzliche Header Informationen</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="palette_title">
|
||||
<source>AB Test Settings</source>
|
||||
<target>AB Test Einstellungen</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_month">
|
||||
<source>1 month</source>
|
||||
<target>1 Monat</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_week">
|
||||
<source>1 week</source>
|
||||
<target>1 Woche</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_day">
|
||||
<source>1 day</source>
|
||||
<target>1 Tag</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_12_day">
|
||||
<source>1/2 day</source>
|
||||
<target>1/2 Tag</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_hour">
|
||||
<source>1 hour</source>
|
||||
<target>1 Stunde</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_minute">
|
||||
<source>1 minute</source>
|
||||
<target>1 Minute</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
38
Resources/Private/Language/locallang_db.xlf
Normal file
38
Resources/Private/Language/locallang_db.xlf
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<xliff version="1.0">
|
||||
<file source-language="en" datatype="plaintext" original="messages" date="2017-10-20T11:36:00Z" product-name="abtest2">
|
||||
<header/>
|
||||
<body>
|
||||
<trans-unit id="pages.tx_abtest2_b_id">
|
||||
<source>Site B</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="pages.tx_abtest2_cookie_time">
|
||||
<source>Cookie Lifetime</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="pages.tx_abtest2_header">
|
||||
<source>Additional Header Information</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="palette_title">
|
||||
<source>AB Test Settings</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_month">
|
||||
<source>1 month</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_week">
|
||||
<source>1 week</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_day">
|
||||
<source>1 day</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_12_day">
|
||||
<source>1/2 day</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_hour">
|
||||
<source>1 hour</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="cookie_1_minute">
|
||||
<source>1 minute</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
14
composer.json
Normal file
14
composer.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
43
ext_emconf.php
Normal file
43
ext_emconf.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/***************************************************************
|
||||
* Extension Manager/Repository config file for ext "abtest2".
|
||||
*
|
||||
* Auto generated 04-12-2017 10:08
|
||||
*
|
||||
* Manual updates:
|
||||
* Only the data in the array - everything else is removed by next
|
||||
* writing. "version" and "dependencies" must not be touched!
|
||||
***************************************************************/
|
||||
|
||||
$EM_CONF[$_EXTKEY] = array (
|
||||
'title' => '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,
|
||||
);
|
||||
|
BIN
ext_icon.png
Normal file
BIN
ext_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
6
ext_localconf.php
Normal file
6
ext_localconf.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('TYPO3_MODE') or die();
|
||||
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc']['abtest2'] = 'WapplerSystems\\ABTest2\\ShowPage->SelectId';
|
11
ext_tables.php
Normal file
11
ext_tables.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
defined('TYPO3_MODE') || die('Access denied.');
|
||||
|
||||
call_user_func(
|
||||
function()
|
||||
{
|
||||
|
||||
//\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('abtest2', 'Configuration/TypoScript', 'AB Test');
|
||||
|
||||
}
|
||||
);
|
6
ext_tables.sql
Normal file
6
ext_tables.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE pages (
|
||||
tx_abtest2_b_id int(11) DEFAULT '0' NOT NULL,
|
||||
tx_abtest2_cookie_time int(11) DEFAULT '86400' NOT NULL,
|
||||
tx_abtest2_header text,
|
||||
tx_abtest2_counter int(11) DEFAULT '0' NOT NULL
|
||||
);
|
Loading…
Reference in a new issue