reverted changes to private properties
[Packages/TYPO3.CMS.git] / typo3 / classes / class.clearcachemenu.php
index 9be13a6..6d7c492 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2007 Ingo Renner <ingo@typo3.org>
+*  (c) 2007-2008 Ingo Renner <ingo@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  */
 class ClearCacheMenu implements backend_toolbarItem {
 
-       private $cacheActions;
+       protected $cacheActions;
 
        /**
         * reference back to the backend object
         *
         * @var TYPO3backend
         */
-       private $backendReference;
+       protected $backendReference;
 
        /**
         * constructor
         *
-        * @return      void
+        * @param       TYPO3backend    TYPO3 backend object reference
         */
-       public function __construct() {
-               $this->cacheActions = array();
+       public function __construct(TYPO3backend &$backendReference = null) {
+               $this->backendReference = $backendReference;
+               $this->cacheActions     = array();
 
                        // Clear cache for ALL tables!
-               $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_all');
-               $this->cacheActions[] = array(
-                       'id'    => 'all',
-                       'title' => $title,
-                       'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=all',
-                       'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_red.png', 'width="16" height="16"').' title="'.htmlspecialchars($title).'" alt="" />'
-               );
+               if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
+                       $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all');
+                       $this->cacheActions[] = array(
+                               'id'    => 'all',
+                               'title' => $title,
+                               'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=all',
+                               'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_red.png', 'width="16" height="16"').' title="'.htmlspecialchars($title).'" alt="" />'
+                       );
+               }
 
                        // Clear cache for either ALL pages
-               $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_pages');
-               $this->cacheActions[] = array(
-                       'id'    => 'pages',
-                       'title' => $title,
-                       'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=pages',
-                       'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.htmlspecialchars($title).'" alt="" />'
-               );
+               if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
+                       $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages');
+                       $this->cacheActions[] = array(
+                               'id'    => 'pages',
+                               'title' => $title,
+                               'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=pages',
+                               'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.htmlspecialchars($title).'" alt="" />'
+                       );
+               }
 
                        // Clearing of cache-files in typo3conf/ + menu
-               if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache'])     {
-                       $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_allTypo3Conf');
+               if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
+                       $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf');
                        $this->cacheActions[] = array(
                                'id'    => 'temp_CACHED',
                                'title' => $title,
@@ -83,16 +88,19 @@ class ClearCacheMenu implements backend_toolbarItem {
                        );
                }
 
-
        }
 
        /**
-        * sets the backend reference
+        * checks whether the user has access to this toolbar item
         *
-        * @param TYPO3backend backend object reference
+        * @return  boolean  true if user has access, false if not
         */
-       public function setBackend(&$backendReference) {
-               $this->backendReference = $backendReference;
+       public function checkAccess() {
+               return (
+                       $GLOBALS['BE_USER']->isAdmin()
+                       || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')
+                       || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')
+               );
        }
 
        /**
@@ -106,10 +114,10 @@ class ClearCacheMenu implements backend_toolbarItem {
 
                $cacheMenu[] = '<a href="#" class="toolbar-item"><img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="Clear Cache" alt="" /></a>';
 
-               $cacheMenu[] = '<ul style="display: none;">';
+               $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
 
                foreach($this->cacheActions as $actionKey => $cacheAction) {
-                       $cacheMenu[] = '<li>'.$cacheAction['icon'].' <a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['title'].'</a></li>';
+                       $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>';
                }
 
                $cacheMenu[] = '</ul>';
@@ -118,12 +126,12 @@ class ClearCacheMenu implements backend_toolbarItem {
        }
 
        /**
-        * adds the neccessary javascript ot the backend
+        * adds the neccessary javascript to the backend
         *
         * @return      void
         */
        private function addJavascriptToBackend() {
-               $this->backendReference->addJavascriptFile('typo3/js/clearcachemenu.js');
+               $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
        }
 
        /**
@@ -141,4 +149,4 @@ if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classe
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']);
 }
 
-?>
\ No newline at end of file
+?>