|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2007-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 00029 /** 00030 * class to render the menu for the cache clearing actions 00031 * 00032 * $Id: class.clearcachemenu.php 10306 2011-01-25 19:12:05Z baschny $ 00033 * 00034 * @author Ingo Renner <ingo@typo3.org> 00035 * @package TYPO3 00036 * @subpackage core 00037 */ 00038 class ClearCacheMenu implements backend_toolbarItem { 00039 00040 protected $cacheActions; 00041 protected $optionValues; 00042 00043 /** 00044 * reference back to the backend object 00045 * 00046 * @var TYPO3backend 00047 */ 00048 protected $backendReference; 00049 00050 /** 00051 * constructor 00052 * 00053 * @param TYPO3backend TYPO3 backend object reference 00054 */ 00055 public function __construct(TYPO3backend &$backendReference = null) { 00056 $this->backendReference = $backendReference; 00057 $this->cacheActions = array(); 00058 $this->optionValues = array('all', 'pages'); 00059 00060 // Clear cache for ALL tables! 00061 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) { 00062 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', true); 00063 $this->cacheActions[] = array( 00064 'id' => 'all', 00065 'title' => $title, 00066 'href' => $this->backPath . 00067 'tce_db.php?vC=' . 00068 $GLOBALS['BE_USER']->veriCode() . 00069 '&cacheCmd=all&ajaxCall=1' . 00070 t3lib_BEfunc::getUrlToken('tceAction'), 00071 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-high') 00072 ); 00073 } 00074 00075 // Clear cache for either ALL pages 00076 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) { 00077 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', true); 00078 $this->cacheActions[] = array( 00079 'id' => 'pages', 00080 'title' => $title, 00081 'href' => $this->backPath . 00082 'tce_db.php?vC=' . 00083 $GLOBALS['BE_USER']->veriCode() . 00084 '&cacheCmd=pages&ajaxCall=1' . 00085 t3lib_BEfunc::getUrlToken('tceAction'), 00086 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-medium') 00087 ); 00088 } 00089 00090 // Clearing of cache-files in typo3conf/ + menu 00091 if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) { 00092 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', true); 00093 $this->cacheActions[] = array( 00094 'id' => 'temp_CACHED', 00095 'title' => $title, 00096 'href' => $this->backPath . 00097 'tce_db.php?vC=' . 00098 $GLOBALS['BE_USER']->veriCode() . 00099 '&cacheCmd=temp_CACHED&ajaxCall=1' . 00100 t3lib_BEfunc::getUrlToken('tceAction'), 00101 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-low') 00102 ); 00103 } 00104 00105 // hook for manipulate cacheActions 00106 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) { 00107 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) { 00108 $hookObject = t3lib_div::getUserObj($cacheAction); 00109 00110 if(!($hookObject instanceof backend_cacheActionsHook)) { 00111 throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000); 00112 } 00113 00114 $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues); 00115 } 00116 } 00117 00118 t3lib_formprotection_Factory::get()->persistTokens(); 00119 } 00120 00121 /** 00122 * checks whether the user has access to this toolbar item 00123 * 00124 * @return boolean true if user has access, false if not 00125 */ 00126 public function checkAccess() { 00127 00128 if ($GLOBALS['BE_USER']->isAdmin()) { 00129 return true; 00130 } 00131 00132 if (is_array($this->optionValues)) { 00133 foreach($this->optionValues as $value) { 00134 if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.' . $value)) { 00135 return true; 00136 } 00137 } 00138 } 00139 return false; 00140 00141 } 00142 00143 /** 00144 * Creates the selector for workspaces 00145 * 00146 * @return string workspace selector as HTML select 00147 */ 00148 public function render() { 00149 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', true); 00150 $this->addJavascriptToBackend(); 00151 $cacheMenu = array(); 00152 00153 $cacheMenu[] = '<a href="#" class="toolbar-item">' . 00154 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-cache', array('title' => $title)) . 00155 '</a>'; 00156 00157 $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">'; 00158 00159 foreach($this->cacheActions as $actionKey => $cacheAction) { 00160 $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>'; 00161 } 00162 00163 $cacheMenu[] = '</ul>'; 00164 00165 return implode(LF, $cacheMenu); 00166 } 00167 00168 /** 00169 * adds the necessary JavaScript to the backend 00170 * 00171 * @return void 00172 */ 00173 protected function addJavascriptToBackend() { 00174 $this->backendReference->addJavascriptFile('js/clearcachemenu.js'); 00175 } 00176 00177 /** 00178 * returns additional attributes for the list item in the toolbar 00179 * 00180 * @return string list item HTML attibutes 00181 */ 00182 public function getAdditionalAttributes() { 00183 return ' id="clear-cache-actions-menu"'; 00184 } 00185 00186 } 00187 00188 if(defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']) { 00189 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']); 00190 } 00191 00192 ?>
1.8.0