Fixed bug #9885: Add Hook to ClearCacheMenu
authorSteffen Kamper <info@sk-typo3.de>
Wed, 14 Jan 2009 18:06:41 +0000 (18:06 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Wed, 14 Jan 2009 18:06:41 +0000 (18:06 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4714 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/classes/class.clearcachemenu.php
typo3/interfaces/interface.backend_cacheActionsHook.php [new file with mode: 0644]

index dd0cac4..32cbc82 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-01-14  Steffen Kamper  <info@sk-typo3.de> 
+
+       * Fixed bug #9885: Add Hook to ClearCacheMenu
+
 2009-01-14  Dmitry Dulepov  <dmitry@typo3.org>
 
        * Fixed bug #10116: Remove/protect adodb testfiles (thanks to Marcus Krause)
index c30c97c..3361b16 100644 (file)
@@ -38,6 +38,7 @@
 class ClearCacheMenu implements backend_toolbarItem {
 
        protected $cacheActions;
+       protected $optionValues;
 
        /**
         * reference back to the backend object
@@ -54,6 +55,7 @@ class ClearCacheMenu implements backend_toolbarItem {
        public function __construct(TYPO3backend &$backendReference = null) {
                $this->backendReference = $backendReference;
                $this->cacheActions     = array();
+               $this->optionValues     = array('all', 'pages');
 
                        // Clear cache for ALL tables!
                if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
@@ -88,6 +90,19 @@ class ClearCacheMenu implements backend_toolbarItem {
                        );
                }
 
+                       // hook for manipulate cacheActions
+               if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
+                       foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
+                               $hookObject = &t3lib_div::getUserObj($cacheAction); 
+
+                               if(!($hookObject instanceof backend_cacheActionsHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000);
+                               }
+
+                               $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
+                       }
+               }
+
        }
 
        /**
@@ -96,11 +111,20 @@ class ClearCacheMenu implements backend_toolbarItem {
         * @return  boolean  true if user has access, false if not
         */
        public function checkAccess() {
-               return (
-                       $GLOBALS['BE_USER']->isAdmin()
-                       || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')
-                       || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')
-               );
+
+               if ($GLOBALS['BE_USER']->isAdmin()) {
+                       return true;
+               }
+               
+               if (is_array($this->optionValues)) {
+                       foreach($this->optionValues as $value) {
+                               if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.' . $value)) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+               
        }
 
        /**
@@ -150,4 +174,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
+?>
diff --git a/typo3/interfaces/interface.backend_cacheActionsHook.php b/typo3/interfaces/interface.backend_cacheActionsHook.php
new file mode 100644 (file)
index 0000000..67f925d
--- /dev/null
@@ -0,0 +1,49 @@
+<?php\r
+/***************************************************************\r
+*  Copyright notice\r
+*\r
+*  (c) 2008 Steffen Kamper <info@sk-typo3.de>\r
+*  All rights reserved\r
+*\r
+*  This script is part of the TYPO3 project. The TYPO3 project is\r
+*  free software; you can redistribute it and/or modify\r
+*  it under the terms of the GNU General Public License as published by\r
+*  the Free Software Foundation; either version 2 of the License, or\r
+*  (at your option) any later version.\r
+*\r
+*  The GNU General Public License can be found at\r
+*  http://www.gnu.org/copyleft/gpl.html.\r
+*  A copy is found in the textfile GPL.txt and important notices to the license\r
+*  from the author is found in LICENSE.txt distributed with these scripts.\r
+*\r
+*\r
+*  This script is distributed in the hope that it will be useful,\r
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*  GNU General Public License for more details.\r
+*\r
+*  This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+\r
+/**\r
+ * interface for classes which hook into ClearCacheMenu and manipulate CacheMenuItems array\r
+ *\r
+ * @author     Steffen Kamper <info@sk-typo3.de> \r
+ * @package TYPO3\r
+ * @subpackage backend\r
+ */\r
+interface backend_cacheActionsHook {\r
+\r
+       /**\r
+        * modifies CacheMenuItems array\r
+        *\r
+        * @param       array   array of CacheMenuItems\r
+        * @param       array   array of AccessConfigurations-identifiers (typically  used by userTS with options.clearCache.identifier)\r
+        * @return      \r
+        */\r
+       public function manipulateCacheActions(&$cacheActions, &$optionValues);\r
+\r
+}\r
+\r
+?>\r