[TASK] Move FEworkspace initialization into versioning / part 2
authorBenjamin Mack <benni@typo3.org>
Sun, 9 Oct 2011 11:55:04 +0000 (13:55 +0200)
committerTolleiv Nietsch <info@tolleiv.de>
Sun, 12 Feb 2012 00:08:15 +0000 (01:08 +0100)
As there is a hook after initializing the BE user,
the code that initializes the BE user when using
a previewlink can now be moved out of the core.

Also the same hook can now be used to do the generic
workspace initialization.

Change-Id: I11ac916a02b491905cc3e22e6fdca8b934656dbd
Resolves: #30680
Releases: 4.7
Reviewed-on: http://review.typo3.org/5643
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
typo3/sysext/version/Classes/Preview.php
typo3/sysext/version/ext_localconf.php

index 84ac226..c05056d 100644 (file)
@@ -31,7 +31,7 @@
  * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
  * @package Version
  */
-class Tx_Version_Preview {
+class Tx_Version_Preview implements t3lib_Singleton {
 
        /**
         * the GET parameter to be used
@@ -46,6 +46,12 @@ class Tx_Version_Preview {
        protected $tsfeObj;
 
        /**
+        * preview configuration
+        * @var array
+        */
+       protected $previewConfiguration = FALSE;
+
+       /**
         * hook to check if the preview is activated
         * right now, this hook is called at the end of "$TSFE->connectToDB"
         * 
@@ -55,9 +61,9 @@ class Tx_Version_Preview {
         */
        public function checkForPreview($params, &$pObj) {
                $this->tsfeObj = $pObj;
-               $previewConfiguration = $this->getPreviewConfiguration();
+               $this->previewConfiguration = $this->getPreviewConfiguration();
 
-               if (is_array($previewConfiguration)) {
+               if (is_array($this->previewConfiguration)) {
                                // In case of a keyword-authenticated preview,
                                // re-initialize the TSFE object:
                                // because the GET variables are taken from the preview
@@ -79,7 +85,50 @@ class Tx_Version_Preview {
                                // @previouslyknownas TSFE->ADMCMD_preview_postInit
                                // Clear cookies:
                        unset($_COOKIE['be_typo_user']);
-                       $this->tsfeObj->ADMCMD_preview_BEUSER_uid = $previewConfiguration['BEUSER_uid'];
+               }
+       }
+
+       /**
+        * hook after the regular BE user has been initialized
+        * if there is no BE user login, but a preview configuration
+        * the BE user of the preview configuration gets initialized
+        *
+        * @param $params holding the BE_USER object
+        * @param $pObj the instance of the tslib_fe object
+        * @return void
+        */
+       public function initializePreviewUser(&$params, &$pObj) {
+               if ((is_null($params['BE_USER']) || ($params['BE_USER'] === FALSE)) && $this->previewConfiguration !== FALSE && $this->previewConfiguration['BEUSER_uid'] > 0) {
+
+                               // New backend user object
+                       $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth');
+                       $BE_USER->userTS_dontGetCached = 1;
+                       $BE_USER->OS = TYPO3_OS;
+                       $BE_USER->setBeUserByUid($this->previewConfiguration['BEUSER_uid']);
+                       $BE_USER->unpack_uc('');
+                       if ($BE_USER->user['uid']) {
+                               $BE_USER->fetchGroupData();
+                               $pObj->beUserLogin = 1;
+                       } else {
+                               $BE_USER = NULL;
+                               $pObj->beUserLogin = 0;
+                               $_SESSION['TYPO3-TT-start'] = FALSE;
+                       }
+                       $params['BE_USER'] = $BE_USER;
+               }
+
+               // @previouslyknownas $TSFE->workspacePreviewInit()
+               // if there is a valid BE user, and the full workspace should be
+               // previewed, the workspacePreview option shouldbe set
+               $workspaceUid = $this->previewConfiguration['fullWorkspace'];
+               if ($pObj->beUserLogin && is_object($params['BE_USER']) && t3lib_utility_Math::canBeInterpretedAsInteger($workspaceUid)) {
+                       if ($workspaceUid == 0 || ($workspaceUid >= -1 && $params['BE_USER']->checkWorkspace($workspaceUid))) {
+                                       // Check Access to workspace. Live (0) is OK to preview for all.
+                               $pObj->workspacePreview = intval($workspaceUid);
+                       } else {
+                                       // No preview, will default to "Live" at the moment
+                               $pObj->workspacePreview = -99;
+                       }
                }
        }
 
index 8526f27..0e9f4cb 100644 (file)
@@ -12,6 +12,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['move
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay']['version'] = t3lib_extMgm::extPath('version', 'class.tx_version_iconworks.php:&tx_version_iconworks');
        // Register hook to check for the preview mode in the FE
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB']['version_preview'] = 'EXT:version/Classes/Preview.php:Tx_Version_Preview->checkForPreview';
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['postBeUser']['version_preview'] = 'EXT:version/Classes/Preview.php:Tx_Version_Preview->initializePreviewUser';
 
 if (TYPO3_MODE == 'BE') {
 
@@ -24,4 +25,4 @@ t3lib_extMgm::addPageTSconfig('
 }
 
 
-?>
\ No newline at end of file
+?>