[TASK] Reduce concatenation CGL violations in /typo3/classes/
[Packages/TYPO3.CMS.git] / typo3 / classes / class.clearcachemenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * class to render the menu for the cache clearing actions
30 *
31 * @author Ingo Renner <ingo@typo3.org>
32 * @package TYPO3
33 * @subpackage core
34 */
35 class ClearCacheMenu implements backend_toolbarItem {
36
37 /**
38 * @var array
39 */
40 protected $cacheActions;
41
42 /**
43 * @var array
44 */
45 protected $optionValues;
46
47 /**
48 * Reference back to the backend object
49 *
50 * @var TYPO3backend
51 */
52 protected $backendReference;
53
54 /**
55 * Constructor
56 *
57 * @param TYPO3backend $backendReference TYPO3 backend object reference
58 */
59 public function __construct(TYPO3backend &$backendReference = NULL) {
60 $this->backendReference = $backendReference;
61 $this->cacheActions = array();
62 $this->optionValues = array('all', 'pages');
63
64 // Clear cache for ALL tables!
65 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
66 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', TRUE);
67 $this->cacheActions[] = array(
68 'id' => 'all',
69 'title' => $title,
70 'href' => $this->backPath .
71 'tce_db.php?vC=' .
72 $GLOBALS['BE_USER']->veriCode() .
73 '&cacheCmd=all&ajaxCall=1' .
74 t3lib_BEfunc::getUrlToken('tceAction'),
75 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-high')
76 );
77 }
78
79 // Clear cache for either ALL pages
80 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
81 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', TRUE);
82 $this->cacheActions[] = array(
83 'id' => 'pages',
84 'title' => $title,
85 'href' => $this->backPath .
86 'tce_db.php?vC=' .
87 $GLOBALS['BE_USER']->veriCode() .
88 '&cacheCmd=pages&ajaxCall=1' .
89 t3lib_BEfunc::getUrlToken('tceAction'),
90 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-medium')
91 );
92 }
93
94 // Clearing of cache-files in typo3conf/ + menu
95 if ($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
96 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', TRUE);
97 $this->cacheActions[] = array(
98 'id' => 'temp_CACHED',
99 'title' => $title,
100 'href' => $this->backPath .
101 'tce_db.php?vC=' .
102 $GLOBALS['BE_USER']->veriCode() .
103 '&cacheCmd=temp_CACHED&ajaxCall=1' .
104 t3lib_BEfunc::getUrlToken('tceAction'),
105 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-low')
106 );
107 }
108
109 // Hook for manipulate cacheActions
110 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
111 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
112 $hookObject = t3lib_div::getUserObj($cacheAction);
113
114 if (!($hookObject instanceof backend_cacheActionsHook)) {
115 throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000);
116 }
117
118 $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
119 }
120 }
121 }
122
123 /**
124 * Checks whether the user has access to this toolbar item
125 *
126 * @return boolean TRUE if user has access, FALSE if not
127 */
128 public function checkAccess() {
129
130 if ($GLOBALS['BE_USER']->isAdmin()) {
131 return TRUE;
132 }
133
134 if (is_array($this->optionValues)) {
135 foreach($this->optionValues as $value) {
136 if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.' . $value)) {
137 return TRUE;
138 }
139 }
140 }
141 return FALSE;
142
143 }
144
145 /**
146 * Creates the selector for workspaces
147 *
148 * @return string Workspace selector as HTML select
149 */
150 public function render() {
151 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', TRUE);
152 $this->addJavascriptToBackend();
153 $cacheMenu = array();
154
155 $cacheMenu[] = '<a href="#" class="toolbar-item">' .
156 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-cache', array('title' => $title)) .
157 '</a>';
158
159 $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
160
161 foreach($this->cacheActions as $actionKey => $cacheAction) {
162 $cacheMenu[] = '<li><a href="' . htmlspecialchars($cacheAction['href']) . '">' . $cacheAction['icon'] . ' ' . $cacheAction['title'] . '</a></li>';
163 }
164
165 $cacheMenu[] = '</ul>';
166
167 return implode(LF, $cacheMenu);
168 }
169
170 /**
171 * Adds the necessary JavaScript to the backend
172 *
173 * @return void
174 */
175 protected function addJavascriptToBackend() {
176 $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
177 }
178
179 /**
180 * Returns additional attributes for the list item in the toolbar
181 *
182 * @return string List item HTML attibutes
183 */
184 public function getAdditionalAttributes() {
185 return ' id="clear-cache-actions-menu"';
186 }
187
188 }
189 ?>