From 19ef78f21457f384e8e9de4083ce7f74dcebb5da Mon Sep 17 00:00:00 2001 From: Sven Wappler Date: Sun, 10 Dec 2017 22:19:30 +0100 Subject: [PATCH] First commit --- Classes/Helper.php | 115 ++++++++++++++++++ Configuration/TCA/Overrides/pages.php | 54 ++++++++ .../Private/Language/de.locallang_db.xlf | 48 ++++++++ Resources/Private/Language/locallang_db.xlf | 38 ++++++ composer.json | 14 +++ ext_emconf.php | 43 +++++++ ext_icon.png | Bin 0 -> 3450 bytes ext_localconf.php | 6 + ext_tables.php | 11 ++ ext_tables.sql | 6 + 10 files changed, 335 insertions(+) create mode 100644 Classes/Helper.php create mode 100644 Configuration/TCA/Overrides/pages.php create mode 100644 Resources/Private/Language/de.locallang_db.xlf create mode 100644 Resources/Private/Language/locallang_db.xlf create mode 100644 composer.json create mode 100644 ext_emconf.php create mode 100644 ext_icon.png create mode 100644 ext_localconf.php create mode 100644 ext_tables.php create mode 100644 ext_tables.sql 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 0000000000000000000000000000000000000000..ef81ce288743eabb87151fa3dc79fbbbc95b2e1c GIT binary patch literal 3450 zcmb_ec{J4j_kO*HvF}StiO`}AAK6kFkwzp$*;Cfy6Gf4AwAjg#H6eR;5+h_ni9)u9 z5QRcvkad{*^E>DF*YB_IAK!bPd!G9|=iGDux%ZqKYM_6Xn?sZXA;hgi)G|T{+bS`{ z#$DA8i@mpHLmS}VyA@6+%kscznzGaan5xOIX(6kLg$CD5e zaZ7z|cmg5ZfPtRz83;!IABj?st^m2GAx{hPwV~7mvQNS@SxDRikNF`OgIEzLH;1lg zF#jF4Vs#!C#^84^jK7DkWzdlTjs8$&3rW%t#sVn^pfwVvx&Ro!*nqiV_*xDvAy8on zAvj2ofWq@o?+y)~@cLiKRE1RG7F`~u(1Y(dhn|q zay1}E7|KlHb1Dp!!iRA96bBKUkf#YB!eFu!s_bC82jaybS_mp_U~K^s#9?6^o*slJ zJE8U_{GEh2QFtr>-y49j2`_YjS^%G7A$~U$8$yE@)VaYQDkSfR&J>_8L*{XKdIx)#z(_50XTXzPFw+l}SAcR4>TW^FMIc{? znE^=J3$?CLa1Jt*pzSe~UV@fj7<>uORUq{UWGKQ*E1-BoXELnJKzBMsaKK0%6dOR# zb0{~1^nZZ90?U7ZS_ohAp~MLOe1UK_h}!{UP4J@;UJ#+b7-k0{lo^($AWa_HddHN#*9RNKS)UwCN^bKhX(H5BN=)Mxls0}XfKXB*H)w$}a$j{nRS z;XRD>FMgY4tj*t!R^GY_gk94;tFJ zxQ~3ibV$*{rM&3y;7UDYoD~gxQ{(X$Dq&V5!@y+wJheaL6O5QpORX8r>1 z!84{TPTg9^ey|BPH}@ZHbZBmV=#procDlU0O1ErBdHHj)%HWy)2(k);&knJaSur!o zq5lGov5<1xe+UW)q*OcYW-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LtjeHOFv)u~d!`Mn6 zMk%P0kdUs^bY{rkyplbr@zC?J@uK&_woC+Ua+Q5?TG^YJqm-`^oZz zi^lt88{#FtMB`KhJz2SJl&(1!6Xhi^itlB{!nZ5_W)nwKEF@RoJ>iv`djm0a#OqQ>jgML-QDqwMr_9xA zU4{njO%<2Vs1xpYFqEBsr_+RYmO3-99$`bm>+4`OMwM(#ESglqD^34S7a$DE(1PDH zbVd|Ba?==`Us>=H*1VJx&o+DBT%W!ywkg}m%R|{!ko;gtQn2=5n>6Z^yuU6lcqLwg z^jFfih1)iCHqXAfbWqCtf~m+NMt^64CuXOp-IM#<`7G1_`wzQrh6rDKs4`nLr|+6x zbJ8`NFI;Pfl-V2jE?miP2;i2r%BfZT(nkPM^xp8~-W?9(1Ee78EJLRUOzgr>>oJW- zI=_1)Uvz1w?1` zfjaR-)KWc@U1CgD3kKUQ(JNet$13%?=;XGyhIlmMsc^*WWwRu!TY7S(ur{5_X0W7| z54o!`SY7q_{}=ptXg9zGLc=7 zpz5;mSWEbEQZ{QmUEF?_-k^aDUyz3lR7an+1|mM4bESGZPiQ!F@ zhW1o>4@n-Hvvavg7DHW@>&{;!#p1`?naCZ0vi7zgpWLMQ>M?L+E z_iU!uL!8!?|NC`FGm_g$*nb2HGr=--M$$#w((-`Pm%IE*Qc6m8wakP3VWH(#_uE54 nzw^E|NXnSkKF~XfF)*$E3!l=3#!a`rL8Nm=U#sM_&HeuY%t7G1 literal 0 HcmV?d00001 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 @@ +