Fixed bug #14097: Preview in BE opens Workspace-preview
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsfebeuserauth.php
index e3ce5d3..30e6329 100644 (file)
@@ -166,17 +166,46 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
        public $extAdmEnabled = false;
 
        /**
+        * Instance of the admin panel
+        *
+        * @var tslib_AdminPanel
+        */
+       public $adminPanel = null;
+
+       /**
         * Class for frontend editing.
         *
         * @var t3lib_frontendedit
         */
        public $frontendEdit = null;
 
-
-       public function initializeFrontendEdit() {
+       /**
+        * Initializes the admin panel.
+        *
+        * @return      void
+        */
+       public function initializeAdminPanel() {
                $this->extAdminConfig = $this->getTSConfigProp('admPanel');
 
-               if (is_array($this->extAdminConfig['enable.'])) {
+               if (isset($this->extAdminConfig['enable.'])) {
+                       foreach($this->extAdminConfig['enable.'] as $key => $value) {
+                               if ($value) {
+                                       $this->adminPanel = t3lib_div::makeInstance('tslib_AdminPanel');
+                                       $this->extAdmEnabled = true;
+
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Initializes frontend editing.
+        *
+        * @return      void
+        */
+       public function initializeFrontendEdit() {
+               if (isset($this->extAdminConfig['enable.']) && $this->isFrontendEditingActive()) {
                        foreach($this->extAdminConfig['enable.'] as $key => $value) {
                                if ($value) {
                                        if ($GLOBALS['TSFE'] instanceof tslib_fe) {
@@ -186,11 +215,10 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
                                        } else {
                                                $controllerKey = 'default';
                                        }
-                                       
+
                                        $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
                                        if ($controllerClass) {
                                                $this->frontendEdit = t3lib_div::getUserObj($controllerClass, false);
-                                               $this->extAdmEnabled = true;
                                        }
 
                                        break;
@@ -199,6 +227,38 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
                }
        }
 
+       /**
+        * Determines whether frontend editing is currently active.
+        *
+        * @return      boolean         Wheter frontend editing is active
+        */
+       public function isFrontendEditingActive() {
+               return ($this->extAdmEnabled
+                       && ($this->adminPanel->isAdminModuleEnabled('edit') && $this->adminPanel->isAdminModuleOpen('edit')
+                       || $GLOBALS['TSFE']->displayEditIcons == 1)
+               );
+       }
+
+       /**
+        * Delegates to the appropriate view and renders the admin panel content.
+        *
+        * @return      string.
+        */
+       public function displayAdminPanel() {
+               $content = $this->adminPanel->display();
+
+               return $content;
+       }
+
+       /**
+        * Determines whether the admin panel is enabled and visible.
+        *
+        * @return      boolean         Whether the admin panel is enabled and visible
+        */
+       public function isAdminPanelVisible() {
+               return ($this->extAdmEnabled && !$this->extAdminConfig['hide'] && $GLOBALS['TSFE']->config['config']['admPanel']);
+       }
+
        /*****************************************************
         *
         * TSFE BE user Access Functions
@@ -242,7 +302,7 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
                }
 
                        // Finally a check from t3lib_beuserauth::backendCheckLogin()
-               if (!$TYPO3_CONF_VARS['BE']['adminOnly'] || $this->isAdmin()) {
+               if ($this->isUserAllowedToLogin()) {
                        return true;
                } else {
                        return false;
@@ -311,10 +371,15 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
         * @return      integer         The number of pages for this page in the table "cache_pages"
         */
        public function extGetNumberOfCachedPages($pageId) {
-               $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
-               $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
-
-               return count($pageCacheEntries);
+               if (TYPO3_UseCachingFramework) {
+                       $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+                       $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
+                       $count = count($pageCacheEntries);
+               } else {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id='.intval($pageId));
+                       list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
+               }
+               return $count;
        }