TYPO3 CMS  TYPO3_7-6
ClearCacheToolbarItem.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
29 {
33  protected $cacheActions = [];
34 
38  protected $optionValues = [];
39 
43  protected $iconFactory;
44 
50  public function __construct()
51  {
52  $backendUser = $this->getBackendUser();
53  $languageService = $this->getLanguageService();
54  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
55 
56  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/ClearCacheMenu');
57 
58  // Clear all page-related caches
59  if ($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.clearCache.pages')) {
60  $this->cacheActions[] = [
61  'id' => 'pages',
62  'title' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesTitle', true),
63  'description' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesDescription', true),
64  'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'pages', 'ajaxCall' => 1]),
65  'icon' => $this->iconFactory->getIcon('actions-system-cache-clear-impact-low', Icon::SIZE_SMALL)->render()
66  ];
67  $this->optionValues[] = 'pages';
68  }
69 
70  // Clear cache for ALL tables!
71  if ($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.clearCache.all')) {
72  $this->cacheActions[] = [
73  'id' => 'all',
74  'title' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesTitle', true),
75  'description' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesDescription', true),
76  'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'all', 'ajaxCall' => 1]),
77  'icon' => $this->iconFactory->getIcon('actions-system-cache-clear-impact-medium', Icon::SIZE_SMALL)->render()
78  ];
79  $this->optionValues[] = 'all';
80  }
81 
82  // Clearing of system cache (core cache, class cache etc)
83  // is only shown explicitly if activated for a BE-user (not activated for admins by default)
84  // or if the system runs in development mode (only for admins)
85  // or if $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] is set (only for admins)
86  if (
87  $backendUser->getTSConfigVal('options.clearCache.system')
88  || (GeneralUtility::getApplicationContext()->isDevelopment() && $backendUser->isAdmin())
89  || ((bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true && $backendUser->isAdmin())
90  ) {
91  $this->cacheActions[] = [
92  'id' => 'system',
93  'title' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesTitle', true),
94  'description' => $languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesDescription', true),
95  'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'system', 'ajaxCall' => 1]),
96  'icon' => $this->iconFactory->getIcon('actions-system-cache-clear-impact-high', Icon::SIZE_SMALL)->render()
97  ];
98  $this->optionValues[] = 'system';
99  }
100 
101  // Hook for manipulating cacheActions
102  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
103  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
104  $hookObject = GeneralUtility::getUserObj($cacheAction);
105  if (!$hookObject instanceof ClearCacheActionsHookInterface) {
106  throw new \UnexpectedValueException($cacheAction . ' must implement interface ' . ClearCacheActionsHookInterface::class, 1228262000);
107  }
108  $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
109  }
110  }
111  }
112 
118  public function checkAccess()
119  {
120  $backendUser = $this->getBackendUser();
121  if ($backendUser->isAdmin()) {
122  return true;
123  }
124  if (is_array($this->optionValues)) {
125  foreach ($this->optionValues as $value) {
126  if ($backendUser->getTSConfigVal('options.clearCache.' . $value)) {
127  return true;
128  }
129  }
130  }
131  return false;
132  }
133 
139  public function getItem()
140  {
141  $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache', true);
142  return '<span title="' . $title . '">'
143  . $this->iconFactory->getIcon('apps-toolbar-menu-cache', Icon::SIZE_SMALL)->render('inline')
144  . '</span>';
145  }
146 
152  public function getDropDown()
153  {
154  $result = [];
155  $result[] = '<ul class="dropdown-list">';
156  foreach ($this->cacheActions as $cacheAction) {
157  $title = $cacheAction['description'] ?: $cacheAction['title'];
158  $result[] = '<li>';
159  $result[] = '<a class="dropdown-list-link" href="' . htmlspecialchars($cacheAction['href']) . '" title="' . htmlspecialchars($title) . '">';
160  $result[] = $cacheAction['icon'] . ' ' . htmlspecialchars($cacheAction['title']);
161  $result[] = '</a>';
162  $result[] = '</li>';
163  }
164  $result[] = '</ul>';
165  return implode(LF, $result);
166  }
167 
173  public function getAdditionalAttributes()
174  {
175  return [];
176  }
177 
183  public function hasDropDown()
184  {
185  return true;
186  }
187 
193  public function getIndex()
194  {
195  return 25;
196  }
197 
203  protected function getBackendUser()
204  {
205  return $GLOBALS['BE_USER'];
206  }
207 
213  protected function getPageRenderer()
214  {
215  return GeneralUtility::makeInstance(PageRenderer::class);
216  }
217 
223  protected function getLanguageService()
224  {
225  return $GLOBALS['LANG'];
226  }
227 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']