TYPO3 CMS  TYPO3_6-2
ClearCacheToolbarItem.php
Go to the documentation of this file.
1 <?php
3 
20 
27 
31  protected $cacheActions;
32 
36  protected $optionValues;
37 
43  protected $backendReference;
44 
49  public $backPath = '';
50 
57  public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
58  $this->backendReference = $backendReference;
59  $this->cacheActions = array();
60  $this->optionValues = array();
61  $backendUser = $this->getBackendUser();
62 
63  // Clear all page-related caches
64  if ($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.clearCache.pages')) {
65  $this->cacheActions[] = array(
66  'id' => 'pages',
67  'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesTitle', TRUE),
68  'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesDescription', TRUE),
69  'href' => $this->backPath . 'tce_db.php?vC=' . $backendUser->veriCode() . '&cacheCmd=pages&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
70  'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-low')
71  );
72  $this->optionValues[] = 'pages';
73  }
74 
75  // Clear cache for ALL tables!
76  if ($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.clearCache.all')) {
77  $this->cacheActions[] = array(
78  'id' => 'all',
79  'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesTitle', TRUE),
80  'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesDescription', TRUE),
81  'href' => $this->backPath . 'tce_db.php?vC=' . $backendUser->veriCode() . '&cacheCmd=all&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
82  'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-medium')
83  );
84  $this->optionValues[] = 'all';
85  }
86 
87  // Clearing of system cache (core cache, class cache etc)
88  // is only shown explicitly if activated for a BE-user (not activated for admins by default)
89  // or if the system runs in development mode (only for admin)
90  // or if $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] is set (only for admins)
91  if ($backendUser->getTSConfigVal('options.clearCache.system')
92  || (GeneralUtility::getApplicationContext()->isDevelopment() && $backendUser->isAdmin())
93  || ((bool) $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === TRUE && $backendUser->isAdmin())) {
94  $this->cacheActions[] = array(
95  'id' => 'system',
96  'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesTitle', TRUE),
97  'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesDescription', TRUE),
98  'href' => $this->backPath . 'tce_db.php?vC=' . $backendUser->veriCode() . '&cacheCmd=system&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
99  'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-high')
100  );
101  $this->optionValues[] = 'system';
102  }
103  // Hook for manipulating cacheActions
104  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
105  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
106  $hookObject = GeneralUtility::getUserObj($cacheAction);
107  if (!$hookObject instanceof \TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface) {
108  throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\Toolbar\\ClearCacheActionsHookInterface', 1228262000);
109  }
110  $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
111  }
112  }
113  }
114 
120  public function checkAccess() {
121  $backendUser = $this->getBackendUser();
122  if ($backendUser->isAdmin()) {
123  return TRUE;
124  }
125  if (is_array($this->optionValues)) {
126  foreach ($this->optionValues as $value) {
127  if ($backendUser->getTSConfigVal('options.clearCache.' . $value)) {
128  return TRUE;
129  }
130  }
131  }
132  return FALSE;
133  }
134 
140  public function render() {
141  $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache', TRUE);
142  $this->addJavascriptToBackend();
143  $cacheMenu = array();
144  $cacheMenu[] = '<a href="#" class="toolbar-item">' . IconUtility::getSpriteIcon('apps-toolbar-menu-cache', array('title' => $title)) . '</a>';
145  $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
146  foreach ($this->cacheActions as $actionKey => $cacheAction) {
147  $cacheMenu[] = '<li><a href="' . htmlspecialchars($cacheAction['href'])
148  . '" title="' . htmlspecialchars($cacheAction['description'] ?: $cacheAction['title']) . '">'
149  . $cacheAction['icon'] . ' ' . htmlspecialchars($cacheAction['title']) . '</a></li>';
150  }
151  $cacheMenu[] = '</ul>';
152  return implode(LF, $cacheMenu);
153  }
154 
160  protected function addJavascriptToBackend() {
161  $this->backendReference->addJavascriptFile('sysext/backend/Resources/Public/JavaScript/clearcachemenu.js');
162  }
163 
169  public function getAdditionalAttributes() {
170  return 'id="clear-cache-actions-menu"';
171  }
172 
178  protected function getBackendUser() {
179  return $GLOBALS['BE_USER'];
180  }
181 }
__construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference=NULL)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static getUrlToken($formName='securityToken', $tokenName='formToken')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]