Code improvements

This commit is contained in:
Sven Wappler 2017-12-10 22:33:11 +01:00
parent 19ef78f214
commit afa42d5ac5
3 changed files with 93 additions and 95 deletions

View file

@ -10,6 +10,7 @@ namespace WapplerSystems\ABTest2;
*/ */
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageRepository; use TYPO3\CMS\Frontend\Page\PageRepository;
/** /**
@ -18,7 +19,8 @@ use TYPO3\CMS\Frontend\Page\PageRepository;
* @package WapplerSystems\ABTest2 * @package WapplerSystems\ABTest2
* @author Sven Wapler <typo3YYYYY@wappler.systems> * @author Sven Wapler <typo3YYYYY@wappler.systems>
*/ */
class Helper { class Helper
{
/** @var int|null */ /** @var int|null */
protected $currentPageId = null; protected $currentPageId = null;
@ -44,19 +46,20 @@ class Helper {
/** /**
* *
* @param array $params * @param array $params
* @param $pObj * @param $pObj TypoScriptFrontendController
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function determineContentId(array $params, &$pObj) { public function determineContentId(array $params, &$pObj)
{
// only try to change the page if it's not the googlebot. // only try to change the page if it's not the googlebot.
if (false === stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot')) { if (false === stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot')) {
$this->currentPageId = $params['pObj']->id; $this->currentPageId = $pObj->id;
// Get the rootpage_id from realurl config. // Get the rootpage_id from realurl config.
$this->realurlConfig = $params['pObj']->TYPO3_CONF_VARS['EXTCONF']['realurl']; $this->realurlConfig = $pObj->TYPO3_CONF_VARS['EXTCONF']['realurl'];
if (array_key_exists($_SERVER['SERVER_NAME'], $this->realurlConfig)) { if (array_key_exists($_SERVER['SERVER_NAME'], $this->realurlConfig)) {
$this->rootpage_id = $this->realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id']; $this->rootpage_id = $this->realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id'];
} else { } else {
@ -93,7 +96,7 @@ class Helper {
} }
// If current page ID is different from the random page ID we set the correct page ID. // If current page ID is different from the random page ID we set the correct page ID.
if($this->currentPageId != $this->randomAbPageId) { if ($this->currentPageId !== $this->randomAbPageId) {
$pObj->contentPid = $this->randomAbPageId; $pObj->contentPid = $this->randomAbPageId;
$GLOBALS['TSFE']->page['content_from_pid'] = $this->randomAbPageId; $GLOBALS['TSFE']->page['content_from_pid'] = $this->randomAbPageId;
$GLOBALS['TSFE']->page['no_cache'] = true; $GLOBALS['TSFE']->page['no_cache'] = true;

View file

@ -12,15 +12,16 @@
$EM_CONF[$_EXTKEY] = array( $EM_CONF[$_EXTKEY] = array(
'title' => 'AB Test Pages', '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.', 'description' => 'With this extension, administrators can deliver different content for the same URL (AB test), depending on cookies or parameters.',
'category' => 'misc', 'category' => 'misc',
'author' => 'IllusionFACTORY', 'author' => 'Sven Wappler',
'author_email' => 'info@illusion-factory.de', 'author_email' => 'typo3YYYY@wappler.systems',
'state' => 'alpha', 'author_company' => 'WapplerSystems',
'state' => 'stable',
'uploadfolder' => false, 'uploadfolder' => false,
'createDirs' => '', 'createDirs' => '',
'clearCacheOnLoad' => 1, 'clearCacheOnLoad' => true,
'version' => '1.0.2.sw', 'version' => '0.1.0',
'constraints' => 'constraints' =>
array( array(
'depends' => 'depends' =>
@ -29,15 +30,9 @@ $EM_CONF[$_EXTKEY] = array (
'realurl' => '2.0.0-0.0.0', 'realurl' => '2.0.0-0.0.0',
), ),
'conflicts' => 'conflicts' =>
array ( array(),
),
'suggests' => 'suggests' =>
array ( array(),
), ),
),
'comment' => '',
'user' => 'timof',
'clearcacheonload' => true,
'author_company' => NULL,
); );

View file

@ -3,4 +3,4 @@
defined('TYPO3_MODE') or die(); defined('TYPO3_MODE') or die();
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc']['abtest2'] = 'WapplerSystems\\ABTest2\\ShowPage->SelectId'; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc']['abtest2'] = 'WapplerSystems\\ABTest2\\Helper->SelectId';